mm/slab_common: add SLAB_NO_MERGE flag for use when creating slabs
Subsystems (3)
PATCH 1/2 mm/slab_common: add SLAB_NO_MERGE flag for use when creating slabs
The slab aliasing/merging by default transition went unnoticed (at least to the DM subsystem). Add a new SLAB_NO_MERGE flag that allows individual slabs to be created without slab merging. This beats forcing all slabs to be created in this fashion by specifying sl[au]b_nomerge on the kernel commandline.
DM has historically taken care to have separate named slabs that each devices' mempool_t are backed by. These separate slabs are useful -- even if only to aid inspection of DM's memory use (via /proc/slabinfo) on production systems.
I stumbled onto slab merging as a side-effect of a leak in dm-cache being attributed to 'kmalloc-96' rather than the expected 'dm_bio_prison_cell' named slab. Moving forward DM will disable slab merging for all of DM's slabs by using SLAB_NO_MERGE.
--- include/linux/slab.h | 2 ++ mm/slab.h | 2 +- mm/slab_common.c | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-)
include/linux/slab.h +2 -0
@@ -87,6 +87,8 @@# define SLAB_FAILSLAB 0x00000000UL#endif +#define SLAB_NO_MERGE 0x04000000UL/* Do not merge with existing slab */ +/* The following flags affect the page allocator grouping pages by mobility */ #define SLAB_RECLAIM_ACCOUNT 0x00020000UL/* Objects are reclaimable */ #define SLAB_TEMPORARY SLAB_RECLAIM_ACCOUNT/* Objects are short-lived */
mm/slab.h +1 -1
@@ -115,7 +115,7 @@ static inline unsigned long kmem_cache_flags(unsigned long object_size,/* Legal flag mask for kmem_cache_create(), for various configurations */ #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \ - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS ) + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_NO_MERGE)#if defined(CONFIG_DEBUG_SLAB )#define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
mm/slab_common.c +1 -1
@@ -35,7 +35,7 @@ struct kmem_cache *kmem_cache;*/ #define SLAB_NEVER_MERGE (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER | \ SLAB_TRACE | SLAB_DESTROY_BY_RCU | SLAB_NOLEAKTRACE | \ - SLAB_FAILSLAB) + SLAB_FAILSLAB | SLAB_NO_MERGE)#define SLAB_MERGE_SAME (SLAB_RECLAIM_ACCOUNT | SLAB_CACHE_DMA | SLAB_NOTRACK)
Signature · 7 lines
2.3.2 (Apple Git-55) -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/2 dm: disable slab merging for all DM slabs
It is useful to be able to observe DM's slab memory use by looking at "dm_" named slabs in /proc/slabinfo without having to enable SLAB_DEBUG options on production systems.
before:
$ cat /proc/slabinfo | grep dm_ | cut -d' ' -f1 dm_mpath_io dm_uevent dm_rq_target_io
after:
$ cat /proc/slabinfo | grep dm_ | cut -d' ' -f1 dm_thin_new_mapping dm_mpath_io dm_mq_policy_cache_entry dm_cache_migration dm_bio_prison_cell dm_snap_pending_exception dm_exception dm_dirty_log_flush_entry dm_kcopyd_job dm_io dm_uevent dm_clone_request dm_rq_target_io dm_target_io
--- drivers/md/dm-bio-prison.c | 2 +- drivers/md/dm-bufio.c | 2 +- drivers/md/dm-cache-policy-mq.c | 2 +- drivers/md/dm-cache-target.c | 3 +-- drivers/md/dm-io.c | 3 ++- drivers/md/dm-kcopyd.c | 4 ++-- drivers/md/dm-log-userspace-base.c | 2 +- drivers/md/dm-mpath.c | 3 +-- drivers/md/dm-snap.c | 4 ++-- drivers/md/dm-thin.c | 2 +- drivers/md/dm-uevent.c | 2 +- drivers/md/dm.c | 8 ++++---- 12 files changed, 18 insertions(+), 19 deletions(-)
drivers/md/dm-bio-prison.c +1 -1
@@ -398,7 +398,7 @@ EXPORT_SYMBOL_GPL(dm_deferred_set_add_work);static int __init dm_bio_prison_init (void ) { - _cell_cache =KMEM_CACHE (dm_bio_prison_cell,0 ); + _cell_cache =KMEM_CACHE (dm_bio_prison_cell,SLAB_NO_MERGE );if (!_cell_cache)return -ENOMEM ;
drivers/md/dm-bufio.c +1 -1
@@ -1636,7 +1636,7 @@ struct dm_bufio_client *dm_bufio_client_create(struct block_device *bdev, unsignif (!DM_BUFIO_CACHE (c)) {DM_BUFIO_CACHE (c) =kmem_cache_create (DM_BUFIO_CACHE_NAME (c), c->block_size, - c->block_size,0 ,NULL ); + c->block_size,SLAB_NO_MERGE ,NULL );if (!DM_BUFIO_CACHE (c)) { r = -ENOMEM ;mutex_unlock (&dm_bufio_clients_lock);
drivers/md/dm-cache-policy-mq.c +1 -1
@@ -1444,7 +1444,7 @@ static int __init mq_init(void) mq_entry_cache =kmem_cache_create ("dm_mq_policy_cache_entry" ,sizeof (struct entry ), __alignof__(struct entry ), -0 ,NULL ); +SLAB_NO_MERGE ,NULL );if (!mq_entry_cache)return -ENOMEM ;
drivers/md/dm-cache-target.c +1 -2
@@ -394,7 +394,6 @@ static void wake_worker(struct cache *cache)static struct dm_bio_prison_cell *alloc_prison_cell (struct cache *cache) { -/* FIXME: change to use a local slab. */ return dm_bio_prison_alloc_cell (cache->prison,GFP_NOWAIT ); }
@@ -3854,7 +3853,7 @@ static int __init dm_cache_init(void)return r; } - migration_cache =KMEM_CACHE (dm_cache_migration,0 ); + migration_cache =KMEM_CACHE (dm_cache_migration,SLAB_NO_MERGE );if (!migration_cache) {dm_unregister_target (&cache_target);return -ENOMEM ;
drivers/md/dm-io.c +2 -1
@@ -526,7 +526,8 @@ EXPORT_SYMBOL(dm_io);int __init dm_io_init (void ) { - _dm_io_cache =KMEM_CACHE (io,0 ); + _dm_io_cache =kmem_cache_create ("dm_io" ,sizeof (struct io ), + __alignof__(struct io ),SLAB_NO_MERGE ,NULL );if (!_dm_io_cache)return -ENOMEM ;
drivers/md/dm-kcopyd.c +2 -2
@@ -364,9 +364,9 @@ static struct kmem_cache *_job_cache;int __init dm_kcopyd_init (void ) { - _job_cache =kmem_cache_create ("kcopyd_job" , + _job_cache =kmem_cache_create ("dm_kcopyd_job" ,sizeof (struct kcopyd_job ) * (SPLIT_COUNT +1 ), - __alignof__(struct kcopyd_job ),0 ,NULL ); + __alignof__(struct kcopyd_job ),SLAB_NO_MERGE ,NULL );if (!_job_cache)return -ENOMEM ;
drivers/md/dm-log-userspace-base.c +1 -1
@@ -893,7 +893,7 @@ static int __init userspace_dirty_log_init(void) {int r =0 ; - _flush_entry_cache =KMEM_CACHE (dm_dirty_log_flush_entry,0 ); + _flush_entry_cache =KMEM_CACHE (dm_dirty_log_flush_entry,SLAB_NO_MERGE );if (!_flush_entry_cache) {DMWARN ("Unable to create flush_entry_cache: No memory." );return -ENOMEM ;
drivers/md/dm-mpath.c +1 -2
@@ -1727,8 +1727,7 @@ static int __init dm_multipath_init(void) {int r; -/* allocate a slab for the dm_ios */ - _mpio_cache =KMEM_CACHE (dm_mpath_io,0 ); + _mpio_cache =KMEM_CACHE (dm_mpath_io,SLAB_NO_MERGE );if (!_mpio_cache)return -ENOMEM ;
drivers/md/dm-snap.c +2 -2
@@ -2441,14 +2441,14 @@ static int __init dm_snapshot_init(void) goto bad_origin_hash; } - exception_cache =KMEM_CACHE (dm_exception,0 ); + exception_cache =KMEM_CACHE (dm_exception,SLAB_NO_MERGE );if (!exception_cache) {DMERR ("Couldn't create exception cache." ); r = -ENOMEM ; goto bad_exception_cache; } - pending_cache =KMEM_CACHE (dm_snap_pending_exception,0 ); + pending_cache =KMEM_CACHE (dm_snap_pending_exception,SLAB_NO_MERGE );if (!pending_cache) {DMERR ("Couldn't create pending cache." ); r = -ENOMEM ;
drivers/md/dm-thin.c +1 -1
@@ -4314,7 +4314,7 @@ static int __init dm_thin_init(void) r = -ENOMEM ; - _new_mapping_cache =KMEM_CACHE (dm_thin_new_mapping,0 ); + _new_mapping_cache =KMEM_CACHE (dm_thin_new_mapping,SLAB_NO_MERGE );if (!_new_mapping_cache) goto bad_new_mapping_cache;
drivers/md/dm-uevent.c +1 -1
@@ -204,7 +204,7 @@ EXPORT_SYMBOL_GPL(dm_path_uevent);int dm_uevent_init (void ) { - _dm_event_cache =KMEM_CACHE (dm_uevent,0 ); + _dm_event_cache =KMEM_CACHE (dm_uevent,SLAB_NO_MERGE );if (!_dm_event_cache)return -ENOMEM ;
drivers/md/dm.c +4 -4
@@ -314,17 +314,17 @@ static int __init local_init(void) {int r = -ENOMEM ; -/* allocate a slab for the dm_ios */ - _io_cache =KMEM_CACHE (dm_io,0 ); + _io_cache =kmem_cache_create ("dm_target_io" ,sizeof (struct dm_io ), + __alignof__(struct dm_io ),SLAB_NO_MERGE ,NULL );if (!_io_cache)return r; - _rq_tio_cache =KMEM_CACHE (dm_rq_target_io,0 ); + _rq_tio_cache =KMEM_CACHE (dm_rq_target_io,SLAB_NO_MERGE );if (!_rq_tio_cache) goto out_free_io_cache; _rq_cache =kmem_cache_create ("dm_clone_request" ,sizeof (struct request ), - __alignof__(struct request ),0 ,NULL ); + __alignof__(struct request ),SLAB_NO_MERGE ,NULL );if (!_rq_cache) goto out_free_rq_tio_cache;
Signature · 7 lines
2.3.2 (Apple Git-55) -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 5 lines · Mike Snitzer
The slab aliasing/merging by default transition went unnoticed (at least to the DM subsystem). Add a new
SLAB_NO_MERGEflag that allows individual slabs to be created without slab merging. This beats forcing all slabs to be created in this fashion by specifying sl[au]b_nomerge on the kernel commandline.
I didn't realise that this merging had also been applied to SLAB - I thought it was just SLUB that did this. Indeed, one of the prime reasons for using SLAB over SLUB was that it didn't merge caches and so still gave excellent visibility of runtime slab memory usage on production systems.
I had no idea that commit 12220de ("mm/slab: support slab merge") had made SLAB do this as well as it was not cc'd to any of the people/subsystems that maintain code that uses slab caches. IMNSHO the commit message gives pretty flimsy justification for such a change, especially considering we need to deal with slab caches that individually grow to contain hundreds of millions of objects.
Quoted 4 lines
DM has historically taken care to have separate named slabs that each devices'
mempool_tare backed by. These separate slabs are useful -- even if only to aid inspection of DM's memory use (via/proc/slabinfo) on production systems.
Yup, that's one of the reasons XFS has 17 separate slab caches. The other main reason is that slab separation also helps keep memory corruption and use-after free issues contained; if you have a problem with the objects from one slab cache, the isolation of the slab makes it less likely that the problem propagates to other subsystems. Hence failures also tend to be isolated to the code that has the leak/corruption problem, making them easier to triage and debug on production systems...
Quoted 4 lines
I stumbled onto slab merging as a side-effect of a leak in dm-cache being attributed to 'kmalloc-96' rather than the expected '
dm_bio_prison_cell' named slab. Moving forward DM will disable slab merging for all of DM's slabs by usingSLAB_NO_MERGE.
Seems like a fine idea to me. I can apply it to various slabs in XFS once it's merged....
Cheers,
Dave.
Signature · 8 lines
Dave Chinner [email protected] -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>