mm, slab: rename kmalloc-node cache to kmalloc-<size>
Subsystems (2)
PATCH 1/1 mm, slab: rename kmalloc-node cache to kmalloc-<size>
SLAB as part of its bootstrap pre-creates one kmalloc cache that can fit the kmem_cache_node management structure, and puts it into the generic kmalloc cache array (e.g. for 128b objects). The name of this cache is "kmalloc-node", which is confusing for readers of /proc/slabinfo as the cache is used for generic allocations (and not just the kmem_cache_node struct) and it appears as the kmalloc-128 cache is missing.
An easy solution is to use the kmalloc-<size> name when pre-creating the cache, which we can get from the kmalloc_info array.
Example /proc/slabinfo before the patch:
...
kmalloc-256 1647 1984 256 16 1 : tunables 120 60 8 : slabdata 124 124 828 kmalloc-192 1974 1974 192 21 1 : tunables 120 60 8 : slabdata 94 94 133 kmalloc-96 1332 1344 128 32 1 : tunables 120 60 8 : slabdata 42 42 219 kmalloc-64 2505 5952 64 64 1 : tunables 120 60 8 : slabdata 93 93 715 kmalloc-32 4278 4464 32 124 1 : tunables 120 60 8 : slabdata 36 36 346 kmalloc-node 1352 1376 128 32 1 : tunables 120 60 8 : slabdata 43 43 53 kmem_cache 132 147 192 21 1 : tunables 120 60 8 : slabdata 7 7 0
After the patch:
...
kmalloc-256 1672 2160 256 16 1 : tunables 120 60 8 : slabdata 135 135 807 kmalloc-192 1992 2016 192 21 1 : tunables 120 60 8 : slabdata 96 96 203 kmalloc-96 1159 1184 128 32 1 : tunables 120 60 8 : slabdata 37 37 116 kmalloc-64 2561 4864 64 64 1 : tunables 120 60 8 : slabdata 76 76 785 kmalloc-32 4253 4340 32 124 1 : tunables 120 60 8 : slabdata 35 35 270 kmalloc-128 1256 1280 128 32 1 : tunables 120 60 8 : slabdata 40 40 39 kmem_cache 125 147 192 21 1 : tunables 120 60 8 : slabdata 7 7 0
--- mm/slab.c | 3 ++- mm/slab.h | 1 + mm/slab_common.c | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-)
mm/slab.c +2 -1
@@ -1293,7 +1293,8 @@ void __init kmem_cache_init(void)* Initialize the caches that provide memory for the kmem_cache_node * structures first. Without this, further allocations will bug. */ - kmalloc_caches[INDEX_NODE ] =create_kmalloc_cache ("kmalloc-node" , + kmalloc_caches[INDEX_NODE ] =create_kmalloc_cache ( +get_kmalloc_cache_name (INDEX_NODE ),kmalloc_size (INDEX_NODE ),ARCH_KMALLOC_FLAGS ); slab_state =PARTIAL_NODE ;setup_kmalloc_cache_index_table ();
mm/slab.h +1 -0
@@ -78,6 +78,7 @@ unsigned long calculate_alignment(unsigned long flags,/* Kmalloc array related functions */ void setup_kmalloc_cache_index_table (void );void create_kmalloc_caches (unsigned long ); +const char *get_kmalloc_cache_name (int index);/* Find the kmalloc slab corresponding for a certain size */ struct kmem_cache *kmalloc_slab (size_t ,gfp_t );
mm/slab_common.c +5 -0
@@ -937,6 +937,11 @@ static struct { {"kmalloc-67108864", 67108864} }; +const char *get_kmalloc_cache_name (int index) +{ +return kmalloc_info[index].name; +} +/* * Patch up the size_index table if we have strange large alignment * requirements for the kmalloc array. This is only the case for
Signature · 7 lines
2.11.0 -- 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>
kbuild test robot
build botreproduce: make ARCH=i386 allmodconfig make ARCH=i386
Hi Vlastimil,
[auto build test WARNING on mmotm/master]
[also build test WARNING on v4.10-rc6]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Vlastimil-Babka/mm-slab-rename-kmalloc-node-cache-to-kmalloc-size/20170204-021843 base: git://git.cmpxchg.org/linux-mmotm.git master config: i386-allmodconfig compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901
reproduce:
make ARCH=i386 allmodconfig
make ARCH=i386
All warnings (new ones prefixed by >>):
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Quoted 5 lines · kbuild test robot
Hi Vlastimil,
[auto build test WARNING on mmotm/master]
[also build test WARNING on v4.10-rc6]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
Hi,
there are no warnings below?
Vlastimil
Quoted 9 lines
url: https://github.com/0day-ci/linux/commits/Vlastimil-Babka/mm-slab-rename-kmalloc-node-cache-to-kmalloc-size/20170204-021843 base: git://git.cmpxchg.org/linux-mmotm.git master config: i386-allmodconfig compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901reproduce:
make ARCH=i386 allmodconfig
make ARCH=i386
Quoted 6 lines
All warnings (new ones prefixed by >>):
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
--
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>
--
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>
mm/slab.c void __init kmem_cache_init(void) · line 1297
Quoted 11 lines · Vlastimil Babka
mm/slab.c +2
-1@@ -1293,7 +1293,8 @@ void __init kmem_cache_init(void)* Initialize the caches that provide memory for the kmem_cache_node * structures first. Without this, further allocations will bug. */ - kmalloc_caches[INDEX_NODE] = create_kmalloc_cache("kmalloc-node", + kmalloc_caches[INDEX_NODE] = create_kmalloc_cache( + get_kmalloc_cache_name(INDEX_NODE),
Could we lose the 'get_' from the front? I think 'kmalloc_cache_name()' is just as informative.
--
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 2 lines · Matthew Wilcox
Could we lose the '
get_' from the front? I think 'kmalloc_cache_name()' is just as informative.
Hmmm.. Expose the static array in mm/slab.h instead? There may be other cases in which the allocator specific code may need that information.
kbuild test robot
build botreproduce: wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree…
Hi Vlastimil,
[auto build test WARNING on mmotm/master]
[also build test WARNING on v4.10-rc7 next-20170207]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Vlastimil-Babka/mm-slab-rename-kmalloc-node-cache-to-kmalloc-size/20170204-021843 base: git://git.cmpxchg.org/linux-mmotm.git master config: arm-allyesconfig (attached as .config) compiler: arm-linux-gnueabi-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm
All warnings (new ones prefixed by >>):
>> WARNING: mm/built-in.o(.text+0x3b49c): Section mismatch in reference from the function get_kmalloc_cache_name() to the (unknown reference) .init.rodata:(unknown)
The function get_kmalloc_cache_name() references
the (unknown reference) __initconst (unknown).
This is often because get_kmalloc_cache_name lacks a __initconst annotation or the annotation of (unknown) is wrong.
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Andrew Morton
maintainerQuoted 16 lines · On Wed, 8 Feb 2017 01:15:17 +0800 kbuild test robot <[email protected]> wrote:
Hi Vlastimil,
[auto build test WARNING on mmotm/master]
[also build test WARNING on v4.10-rc7 next-20170207]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]url: https://github.com/0day-ci/linux/commits/Vlastimil-Babka/mm-slab-rename-kmalloc-node-cache-to-kmalloc-size/20170204-021843 base: git://git.cmpxchg.org/linux-mmotm.git master config: arm-allyesconfig (attached as .config) compiler: arm-linux-gnueabi-gcc (Debian 6.1.1-9) 6.1.1 20160705reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm
Quoted 7 lines
All warnings (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
WARNING: mm/built-in.o(.text+0x3b49c): Section mismatch in reference from the function
get_kmalloc_cache_name()to the (unknown reference) .init.rodata:(unknown)The function
get_kmalloc_cache_name()references
the (unknown reference)__initconst(unknown).
This is often becauseget_kmalloc_cache_namelacks a__initconstannotation or the annotation of (unknown) is wrong.
yup, thanks.
mm/slab_common.c renamed from mm/slab_common.c~mm-slab-rename-kmalloc-node-cache-to-kmalloc-size-fix +1 -1
@@ -935,7 +935,7 @@ static struct { {"kmalloc-67108864", 67108864} }; -const char *get_kmalloc_cache_name (int index) +const char *__init get_kmalloc_cache_name (int index) {return kmalloc_info[index].name; }
_
--
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 20 lines · Andrew Morton
Quoted 18 lines · On Wed, 8 Feb 2017 01:15:17 +0800 kbuild test robot <[email protected]> wrote:
Hi Vlastimil,
[auto build test WARNING on mmotm/master]
[also build test WARNING on v4.10-rc7 next-20170207]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]url: https://github.com/0day-ci/linux/commits/Vlastimil-Babka/mm-slab-rename-kmalloc-node-cache-to-kmalloc-size/20170204-021843 base: git://git.cmpxchg.org/linux-mmotm.git master config: arm-allyesconfig (attached as .config) compiler: arm-linux-gnueabi-gcc (Debian 6.1.1-9) 6.1.1 20160705reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=armAll warnings (new ones prefixed by >>):
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
WARNING: mm/built-in.o(.text+0x3b49c): Section mismatch in reference from the function
get_kmalloc_cache_name()to the (unknown reference) .init.rodata:(unknown)The function
get_kmalloc_cache_name()references
the (unknown reference)__initconst(unknown).
This is often becauseget_kmalloc_cache_namelacks a__initconstannotation or the annotation of (unknown) is wrong.yup, thanks.
Thanks for the fix.
I was going to implement Christoph's suggestion and export the whole structure in mm/slab.h, but gcc was complaining that I'm redefining it, until I created a typedef first. Is it worth the trouble? Below is how it would look like.
Vlastimil
----8<----
mm/slab.c +1 -1
@@ -1294,7 +1294,7 @@ void __init kmem_cache_init(void)* structures first. Without this, further allocations will bug. */ kmalloc_caches[INDEX_NODE ] =create_kmalloc_cache ( -get_kmalloc_cache_name (INDEX_NODE ), + kmalloc_info[INDEX_NODE ].name,kmalloc_size (INDEX_NODE ),ARCH_KMALLOC_FLAGS ); slab_state =PARTIAL_NODE ;setup_kmalloc_cache_index_table ();
mm/slab.h +7 -1
@@ -71,6 +71,13 @@ extern struct list_head slab_caches;/* The slab cache that manages slab cache information */ extern struct kmem_cache *kmem_cache; +/* A table of kmalloc cache names and sizes */ +typedef struct { +const char *name; +unsigned long size; +}kmalloc_info_t ; +extern const kmalloc_info_t kmalloc_info[]; +unsigned long calculate_alignment (unsigned long flags,unsigned long align,unsigned long size);
@@ -78,7 +85,6 @@ unsigned long calculate_alignment(unsigned long flags,/* Kmalloc array related functions */ void setup_kmalloc_cache_index_table (void );void create_kmalloc_caches (unsigned long ); -const char *get_kmalloc_cache_name (int index);/* Find the kmalloc slab corresponding for a certain size */ struct kmem_cache *kmalloc_slab (size_t ,gfp_t );
mm/slab_common.c +1 -9
@@ -917,10 +917,7 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)* kmalloc_index() supports up to 2^26=64MB, so the final entry of the table is * kmalloc-67108864. */ -static struct { -const char *name; -unsigned long size; -}const kmalloc_info[]__initconst = { +const kmalloc_info_t kmalloc_info[]__initconst = { {NULL ,0 }, {"kmalloc-96" ,96 }, {"kmalloc-192" ,192 }, {"kmalloc-8" ,8 }, {"kmalloc-16" ,16 }, {"kmalloc-32" ,32 },
@@ -937,11 +934,6 @@ static struct { {"kmalloc-67108864", 67108864} }; -const char *get_kmalloc_cache_name (int index) -{ -return kmalloc_info[index].name; -} -/* * Patch up the size_index table if we have strange large alignment * requirements for the kmalloc array. This is only the case for
--
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>
Sorry, used old Willy's address.
Quoted 96 lines · Vlastimil Babka
Quoted 20 lines · Andrew Morton
Quoted 18 lines · On Wed, 8 Feb 2017 01:15:17 +0800 kbuild test robot <[email protected]> wrote:
Hi Vlastimil,
[auto build test WARNING on mmotm/master]
[also build test WARNING on v4.10-rc7 next-20170207]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]url: https://github.com/0day-ci/linux/commits/Vlastimil-Babka/mm-slab-rename-kmalloc-node-cache-to-kmalloc-size/20170204-021843 base: git://git.cmpxchg.org/linux-mmotm.git master config: arm-allyesconfig (attached as .config) compiler: arm-linux-gnueabi-gcc (Debian 6.1.1-9) 6.1.1 20160705reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=armAll warnings (new ones prefixed by >>):
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
WARNING: mm/built-in.o(.text+0x3b49c): Section mismatch in reference from the function
get_kmalloc_cache_name()to the (unknown reference) .init.rodata:(unknown)The function
get_kmalloc_cache_name()references
the (unknown reference)__initconst(unknown).
This is often becauseget_kmalloc_cache_namelacks a__initconstannotation or the annotation of (unknown) is wrong.yup, thanks.
Thanks for the fix.
I was going to implement Christoph's suggestion and export the whole structure in
mm/slab.h, but gcc was complaining that I'm redefining it, until I created a typedef first. Is it worth the trouble? Below is how it would look like.Vlastimil
----8<----
mm/slab.c +1
-1@@ -1294,7 +1294,7 @@ void __init kmem_cache_init(void)* structures first. Without this, further allocations will bug. */ kmalloc_caches[INDEX_NODE ] =create_kmalloc_cache ( -get_kmalloc_cache_name (INDEX_NODE ), + kmalloc_info[INDEX_NODE ].name,kmalloc_size (INDEX_NODE ),ARCH_KMALLOC_FLAGS ); slab_state =PARTIAL_NODE ;setup_kmalloc_cache_index_table ();mm/slab.h +7
-1@@ -71,6 +71,13 @@ extern struct list_head slab_caches;/* The slab cache that manages slab cache information */ extern struct kmem_cache *kmem_cache; +/* A table of kmalloc cache names and sizes */ +typedef struct { +const char *name; +unsigned long size; +}kmalloc_info_t ; +extern const kmalloc_info_t kmalloc_info[]; +unsigned long calculate_alignment (unsigned long flags,unsigned long align,unsigned long size);@@ -78,7 +85,6 @@ unsigned long calculate_alignment(unsigned long flags,/* Kmalloc array related functions */ void setup_kmalloc_cache_index_table (void );void create_kmalloc_caches (unsigned long ); -const char *get_kmalloc_cache_name (int index);/* Find the kmalloc slab corresponding for a certain size */ struct kmem_cache *kmalloc_slab (size_t ,gfp_t );mm/slab_common.c +1
-4@@ -917,10 +917,7 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)* kmalloc_index() supports up to 2^26=64MB, so the final entry of the table is * kmalloc-67108864. */ -static struct { -const char *name; -unsigned long size; -}const kmalloc_info[]__initconst = { +const kmalloc_info_t kmalloc_info[]__initconst = { {NULL ,0 }, {"kmalloc-96" ,96 }, {"kmalloc-192" ,192 }, {"kmalloc-8" ,8 }, {"kmalloc-16" ,16 }, {"kmalloc-32" ,32 },@@ -937,11 +934,6 @@ static struct { {"kmalloc-67108864", 67108864}
mm/slab_common.c static struct { · line 939
Quoted 10 lines
mm/slab_common.c +0
-5}; -const char *get_kmalloc_cache_name (int index) -{ -return kmalloc_info[index].name; -} -/* * Patch up the size_index table if we have strange large alignment * requirements for the kmalloc array. This is only the case for
--
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 3 lines · Vlastimil Babka
I was going to implement Christoph's suggestion and export the whole structure in
mm/slab.h, but gcc was complaining that I'm redefining it, until I created a typedef first. Is it worth the trouble? Below is how it would look like.
Looks good to me.
--
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>
Andrew Morton
maintainerQuoted 40 lines · On Wed, 8 Feb 2017 10:12:13 +0100 Vlastimil Babka <[email protected]> wrote:
Quoted 20 lines · Andrew Morton
Quoted 18 lines · On Wed, 8 Feb 2017 01:15:17 +0800 kbuild test robot <[email protected]> wrote:
Hi Vlastimil,
[auto build test WARNING on mmotm/master]
[also build test WARNING on v4.10-rc7 next-20170207]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]url: https://github.com/0day-ci/linux/commits/Vlastimil-Babka/mm-slab-rename-kmalloc-node-cache-to-kmalloc-size/20170204-021843 base: git://git.cmpxchg.org/linux-mmotm.git master config: arm-allyesconfig (attached as .config) compiler: arm-linux-gnueabi-gcc (Debian 6.1.1-9) 6.1.1 20160705reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=armAll warnings (new ones prefixed by >>):
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
WARNING: mm/built-in.o(.text+0x3b49c): Section mismatch in reference from the function
get_kmalloc_cache_name()to the (unknown reference) .init.rodata:(unknown)The function
get_kmalloc_cache_name()references
the (unknown reference)__initconst(unknown).
This is often becauseget_kmalloc_cache_namelacks a__initconstannotation or the annotation of (unknown) is wrong.yup, thanks.
Thanks for the fix.
I was going to implement Christoph's suggestion and export the whole structure in
mm/slab.h, but gcc was complaining that I'm redefining it, until I created a typedef first. Is it worth the trouble? Below is how it would look like....
mm/slab.h extern struct list_head slab_caches; · line 79
Quoted 9 lines
mm/slab.h +6
-0@@ -71,6 +71,13 @@ extern struct list_head slab_caches;/* The slab cache that manages slab cache information */ extern struct kmem_cache *kmem_cache; +/* A table of kmalloc cache names and sizes */ +typedef struct { +const char *name; +unsigned long size; +}kmalloc_info_t ; +extern const kmalloc_info_t kmalloc_info[];
Why is the typedef needed? Can't we use something like
extern const struct kmalloc_info_struct {
const char *name;
unsigned long size;
} kmalloc_info[];...
const struct kmalloc_info_struct kmalloc_info[] __initconst = {
{NULL, 0}, {"kmalloc-96", 96},
{"kmalloc-192", 192}, {"kmalloc-8", 8},
{"kmalloc-16", 16}, {"kmalloc-32", 32},
...
{"kmalloc-67108864", 67108864}
};--
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 16 lines · Andrew Morton
Quoted 14 lines · On Wed, 8 Feb 2017 10:12:13 +0100 Vlastimil Babka <[email protected]> wrote:
Thanks for the fix.
I was going to implement Christoph's suggestion and export the whole structure in
mm/slab.h, but gcc was complaining that I'm redefining it, until I created a typedef first. Is it worth the trouble? Below is how it would look like....
mm/slab.h +0
-0@@ -71,6 +71,13 @@ extern struct list_head slab_caches;/* The slab cache that manages slab cache information */ extern struct kmem_cache *kmem_cache;
Quoted 8 lines
mm/slab.h extern struct list_head slab_caches; · line 79
Quoted 6 lines
mm/slab.h +6
-0+/* A table of kmalloc cache names and sizes */ +typedef struct { +const char *name; +unsigned long size; +}kmalloc_info_t ; +extern const kmalloc_info_t kmalloc_info[];Why is the typedef needed? Can't we use something like
Duh, right, I can't C. Thanks.
----8<----