From ac2e5327a5e4f6477afc6a3b3b0dc6e0476d71d4 Mon Sep 17 00:00:00 2001 From: Ming Lei Date: Wed, 27 Feb 2013 17:05:19 -0800 Subject: block/partitions: optimize memory allocation in check_partition() Currently, sizeof(struct parsed_partitions) may be 64KB in 32bit arch, so it is easy to trigger page allocation failure by check_partition, especially in hotplug block device situation(such as, USB mass storage, MMC card, ...), and Felipe Balbi has observed the failure. This patch does below optimizations on the allocation of struct parsed_partitions to try to address the issue: - make parsed_partitions.parts as pointer so that the pointed memory can fit in 32KB buffer, then approximate 32KB memory can be saved - vmalloc the buffer pointed by parsed_partitions.parts because 32KB is still a bit big for kmalloc - given that many devices have the partition count limit, so only allocate disk_max_parts() partitions instead of 256 partitions always Signed-off-by: Ming Lei Reported-by: Felipe Balbi Cc: Jens Axboe Reviewed-by: Yasuaki Ishimatsu Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- block/partition-generic.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'block/partition-generic.c') diff --git a/block/partition-generic.c b/block/partition-generic.c index 1cb4deca132..789cdea0589 100644 --- a/block/partition-generic.c +++ b/block/partition-generic.c @@ -418,7 +418,7 @@ int rescan_partitions(struct gendisk *disk, struct block_device *bdev) int p, highest, res; rescan: if (state && !IS_ERR(state)) { - kfree(state); + free_partitions(state); state = NULL; } @@ -525,7 +525,7 @@ rescan: md_autodetect_dev(part_to_dev(part)->devt); #endif } - kfree(state); + free_partitions(state); return 0; } -- cgit v1.2.3