Patch "dm: allocate struct mapped_device with kvzalloc" has been added to the 4.14-stable tree
Subsystems (2)
This is a note to let you know that I've just added the patch titled
dm: allocate struct mapped_device with kvzalloc
to the 4.14-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
dm-allocate-struct-mapped_device-with-kvzalloc.patch
and it can be found in the queue-4.14 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From
856eb0916d181da6d043cc33e03f54d5c5bbe54aMon Sep 17 00:00:00 2001
From: Mikulas Patocka <[email protected]>
Date: Tue, 31 Oct 2017 19:33:02 -0400
Subject: dm: allocate struct mapped_device with kvzalloc
From: Mikulas Patocka <[email protected]>
commit 856eb0916d181da6d043cc33e03f54d5c5bbe54a upstream.
The structure srcu_struct can be very big, its size is proportional to the value CONFIG_NR_CPUS. The Fedora kernel has CONFIG_NR_CPUS 8192, the field io_barrier in the struct mapped_device has 84kB in the debugging kernel and 50kB in the non-debugging kernel. The large size may result in failure of the function kzalloc_node.
In order to avoid the allocation failure, we use the function kvzalloc_node, this function falls back to vmalloc if a large contiguous chunk of memory is not available. This patch also moves the field io_barrier to the last position of struct mapped_device - the reason is that on many processor architectures, short memory offsets result in smaller code than long memory offsets - on x86-64 it reduces code size by 320 bytes.
Note to stable kernel maintainers - the kernels 4.11 and older don't have the function kvzalloc_node, you can use the function vzalloc_node instead.
--- drivers/md/dm-core.h | 3 ++- drivers/md/dm.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-)
drivers/md/dm-core.h +2 -1
@@ -29,7 +29,6 @@ struct dm_kobject_holder {* DM targets must _not_ deference a mapped_device to directly access its members! */ struct mapped_device { -struct srcu_struct io_barrier;struct mutex suspend_lock;/*
@@ -127,6 +126,8 @@ struct mapped_device {struct blk_mq_tag_set *tag_set; bool use_blk_mq:1; bool init_tio_pdu:1; + +struct srcu_struct io_barrier; };void dm_init_md_queue (struct mapped_device *md);
drivers/md/dm.c +3 -3
@@ -1695,7 +1695,7 @@ static struct mapped_device *alloc_dev(istruct mapped_device *md;void *old_md; - md =kzalloc_node (sizeof (*md),GFP_KERNEL , numa_node_id); + md =kvzalloc_node (sizeof (*md),GFP_KERNEL , numa_node_id);if (!md) {DMWARN ("unable to allocate device, out of memory." );return NULL ;
@@ -1795,7 +1795,7 @@ bad_io_barrier: bad_minor:module_put (THIS_MODULE ); bad_module_get: -kfree (md); +kvfree (md);return NULL ; }
@@ -1814,7 +1814,7 @@ static void free_dev(struct mapped_devicfree_minor (minor);module_put (THIS_MODULE ); -kfree (md); +kvfree (md); }static void __bind_mempools (struct mapped_device *md,struct dm_table *t)
Patches currently in stable-queue which might be from [email protected] are
queue-4.14/dm-allocate-struct-mapped_device-with-kvzalloc.patch queue-4.14/dm-integrity-allow-unaligned-bv_offset.patch queue-4.14/dm-crypt-allow-unaligned-bv_offset.patch