From 1bfdbe01ff300ebbf92d68c15722d2ba861aac3b Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Mon, 15 May 2006 04:21:33 +0000 Subject: Limit size of bitmap to 2million chunks. When creating a file bitmap, choose a default size that results in fewer than 2^21 chunks. Without this kmalloc failure in the kernel becomes likely. Signed-off-by: Neil Brown --- bitmap.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'bitmap.c') diff --git a/bitmap.c b/bitmap.c index 33deab1..75492f7 100644 --- a/bitmap.c +++ b/bitmap.c @@ -341,6 +341,17 @@ int CreateBitmap(char *filename, int force, char uuid[16], return rv; } + if (chunksize == UnSet) { + /* We don't want more than 2^21 chunks, as 2^11 fill up one + * 4K page (2 bytes per chunk), and 2^10 address of those + * fill up a 4K indexing page. 2^20 might be safer... + */ + chunksize = DEFAULT_BITMAP_CHUNK; + /* <<21 for 2^21 chunks, >>9 to convert bytes to sectors */ + while (array_size > (chunksize << (21-9))) + chunksize <<= 1; + } + memset(&sb, 0, sizeof(sb)); sb.magic = BITMAP_MAGIC; sb.version = major; -- cgit