mirror of
https://github.com/torvalds/linux.git
synced 2024-12-06 02:52:22 +00:00
ac2e5327a5
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 <ming.lei@canonical.com> Reported-by: Felipe Balbi <balbi@ti.com> Cc: Jens Axboe <axboe@kernel.dk> Reviewed-by: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
55 lines
1.1 KiB
C
55 lines
1.1 KiB
C
#include <linux/pagemap.h>
|
|
#include <linux/blkdev.h>
|
|
#include <linux/genhd.h>
|
|
|
|
/*
|
|
* add_gd_partition adds a partitions details to the devices partition
|
|
* description.
|
|
*/
|
|
struct parsed_partitions {
|
|
struct block_device *bdev;
|
|
char name[BDEVNAME_SIZE];
|
|
struct {
|
|
sector_t from;
|
|
sector_t size;
|
|
int flags;
|
|
bool has_info;
|
|
struct partition_meta_info info;
|
|
} *parts;
|
|
int next;
|
|
int limit;
|
|
bool access_beyond_eod;
|
|
char *pp_buf;
|
|
};
|
|
|
|
void free_partitions(struct parsed_partitions *state);
|
|
|
|
struct parsed_partitions *
|
|
check_partition(struct gendisk *, struct block_device *);
|
|
|
|
static inline void *read_part_sector(struct parsed_partitions *state,
|
|
sector_t n, Sector *p)
|
|
{
|
|
if (n >= get_capacity(state->bdev->bd_disk)) {
|
|
state->access_beyond_eod = true;
|
|
return NULL;
|
|
}
|
|
return read_dev_sector(state->bdev, n, p);
|
|
}
|
|
|
|
static inline void
|
|
put_partition(struct parsed_partitions *p, int n, sector_t from, sector_t size)
|
|
{
|
|
if (n < p->limit) {
|
|
char tmp[1 + BDEVNAME_SIZE + 10 + 1];
|
|
|
|
p->parts[n].from = from;
|
|
p->parts[n].size = size;
|
|
snprintf(tmp, sizeof(tmp), " %s%d", p->name, n);
|
|
strlcat(p->pp_buf, tmp, PAGE_SIZE);
|
|
}
|
|
}
|
|
|
|
extern int warn_no_part;
|
|
|