mm, slab: Make kmalloc_info[] contain all types of names
Subsystems (2)
v6 cover mm, slab: Make kmalloc_info[] contain all types of names
Changes in v6
--
1. abandon patch 4-7 (Because there is not enough reason to explain that they are beneficial)
Changes in v5
--
1. patch 1/7:
- rename SET_KMALLOC_SIZE to INIT_KMALLOC_INFO
2. patch 5/7:
- fix build errors (Reported-by: kbuild test robot)
- make all_kmalloc_info[] static (Reported-by: kbuild test robot)
3. patch 6/7:
- for robustness, determine kmalloc_cache is !NULL in new_kmalloc_cache()
4. add ack tag from David Rientjes
Changes in v4
--
1. [old] abandon patch 4/4
2. [new] patch 4/7:
- return ZERO_SIZE_ALLOC instead 0 for zero sized requests
3. [new] patch 5/7:
- reorder kmalloc_info[], kmalloc_caches[] (in order of size)
- hard to split, so slightly larger
4. [new] patch 6/7:
- initialize kmalloc_cache[] with the same size but different types
5. [new] patch 7/7:
- modify kmalloc_caches[type][idx] to kmalloc_caches[idx][type]
Patch 4-7 are newly added, more information can be obtained from commit messages.
Changes in v3
--
1. restore __initconst (patch 1/4)
2. rename patch 3/4
3. add more clarification for patch 4/4
4. add ack tag from Roman Gushchin
Changes in v2
--
1. remove __initconst (patch 1/5)
2. squash patch 2/5
3. add ack tag from Vlastimil Babka
There are three types of kmalloc, KMALLOC_NORMAL, KMALLOC_RECLAIM and KMALLOC_DMA.
The name of KMALLOC_NORMAL is contained in kmalloc_info[].name, but the names of KMALLOC_RECLAIM and KMALLOC_DMA are dynamically generated by kmalloc_cache_name().
Patch1 predefines the names of all types of kmalloc to save the time spent dynamically generating names.
These changes make sense, and the time spent by new_kmalloc_cache() has been reduced by approximately 36.3%.
Time spent by new_kmalloc_cache()
(CPU cycles)
5.3-rc7 66264
5.3-rc7+patch 42188
Pengfei Li (3):
mm, slab: Make kmalloc_info[] contain all types of names mm, slab: Remove unused kmalloc_size()
mm, slab_common: Use enum kmalloc_cache_type to iterate over kmalloc
caches
include/linux/slab.h | 20 ----------- mm/slab.c | 7 ++-- mm/slab.h | 2 +- mm/slab_common.c | 99 ++++++++++++++++++++++++++++------------------------ 4 files changed, 58 insertions(+), 70 deletions(-)
Signature · 1 line
2.7.4
PATCH v6 1/3 mm, slab: Make kmalloc_info[] contain all types of names
There are three types of kmalloc, KMALLOC_NORMAL, KMALLOC_RECLAIM and KMALLOC_DMA.
The name of KMALLOC_NORMAL is contained in kmalloc_info[].name, but the names of KMALLOC_RECLAIM and KMALLOC_DMA are dynamically generated by kmalloc_cache_name().
This patch predefines the names of all types of kmalloc to save the time spent dynamically generating names.
Besides, remove the kmalloc_cache_name() that is no longer used.
--- mm/slab.c | 2 +- mm/slab.h | 2 +- mm/slab_common.c | 91 ++++++++++++++++++++++++++++++-------------------------- 3 files changed, 51 insertions(+), 44 deletions(-)
mm/slab.c +1 -1
@@ -1247,7 +1247,7 @@ void __init kmem_cache_init(void)* structures first. Without this, further allocations will bug. */ kmalloc_caches[KMALLOC_NORMAL ][INDEX_NODE ] =create_kmalloc_cache ( - kmalloc_info[INDEX_NODE ].name, + kmalloc_info[INDEX_NODE ].name[KMALLOC_NORMAL ],kmalloc_size (INDEX_NODE ),ARCH_KMALLOC_FLAGS ,0 ,kmalloc_size (INDEX_NODE )); slab_state =PARTIAL_NODE ;
mm/slab.h +1 -1
@@ -76,7 +76,7 @@ extern struct kmem_cache *kmem_cache;/* A table of kmalloc cache names and sizes */ extern const struct kmalloc_info_struct { -const char *name; +const char *name[NR_KMALLOC_TYPES ];unsigned int size; } kmalloc_info[];
mm/slab_common.c +49 -42
122 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v6 2/3 mm, slab: Remove unused kmalloc_size()
In reply to Pengfei LiThe size of kmalloc can be obtained from kmalloc_info[], so remove kmalloc_size() that will not be used anymore.
--- include/linux/slab.h | 20 -------------------- mm/slab.c | 5 +++-- mm/slab_common.c | 5 ++--- 3 files changed, 5 insertions(+), 25 deletions(-)
include/linux/slab.h +0 -20
@@ -557,26 +557,6 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)return __kmalloc (size, flags); } -/* -* Determine size used for the nth kmalloc cache. -* return size or 0 if a kmalloc cache for that -* size does not exist -*/ -static __always_inline unsigned int kmalloc_size(unsigned int n) -{ -#ifndef CONFIG_SLOB -if (n >2 ) -return 1U << n; - -if (n ==1 &&KMALLOC_MIN_SIZE <=32 ) -return 96 ; - -if (n ==2 &&KMALLOC_MIN_SIZE <=64 ) -return 192 ; -#endif -return 0 ; -} - static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node) {#ifndef CONFIG_SLOB
mm/slab.c +3 -2
@@ -1248,8 +1248,9 @@ void __init kmem_cache_init(void)*/ kmalloc_caches[KMALLOC_NORMAL ][INDEX_NODE ] =create_kmalloc_cache ( kmalloc_info[INDEX_NODE ].name[KMALLOC_NORMAL ], -kmalloc_size (INDEX_NODE ),ARCH_KMALLOC_FLAGS , -0 ,kmalloc_size (INDEX_NODE )); + kmalloc_info[INDEX_NODE ].size, +ARCH_KMALLOC_FLAGS ,0 , + kmalloc_info[INDEX_NODE ].size); slab_state =PARTIAL_NODE ;setup_kmalloc_cache_index_table ();
mm/slab_common.c +2 -3
@@ -1239,11 +1239,10 @@ void __init create_kmalloc_caches(slab_flags_t flags)struct kmem_cache *s = kmalloc_caches[KMALLOC_NORMAL ][i];if (s) { -unsigned int size =kmalloc_size (i); - kmalloc_caches[KMALLOC_DMA ][i] =create_kmalloc_cache ( kmalloc_info[i].name[KMALLOC_DMA ], - size,SLAB_CACHE_DMA | flags,0 ,0 ); + kmalloc_info[i].size, +SLAB_CACHE_DMA | flags,0 ,0 ); } }#endif
Signature · 1 line
2.7.4
PATCH v6 3/3 mm, slab_common: Use enum kmalloc_cache_type to iterate over kmalloc caches
In reply to Pengfei LiThe type of local variable *type* of new_kmalloc_cache() should be enum kmalloc_cache_type instead of int, so correct it.
--- mm/slab_common.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
mm/slab_common.c +3 -2
@@ -1192,7 +1192,7 @@ void __init setup_kmalloc_cache_index_table(void) }static void __init -new_kmalloc_cache (int idx,int type,slab_flags_t flags) +new_kmalloc_cache (int idx,enum kmalloc_cache_type type,slab_flags_t flags) {if (type ==KMALLOC_RECLAIM ) flags |=SLAB_RECLAIM_ACCOUNT ;
@@ -1210,7 +1210,8 @@ new_kmalloc_cache(int idx, int type, slab_flags_t flags)*/ void __init create_kmalloc_caches (slab_flags_t flags) { -int i, type; +int i; +enum kmalloc_cache_type type;for (type =KMALLOC_NORMAL ; type <=KMALLOC_RECLAIM ; type++) {for (i =KMALLOC_SHIFT_LOW ; i <=KMALLOC_SHIFT_HIGH ; i++) {
Signature · 1 line
2.7.4
Andrew Morton
maintainerQuoted 4 lines · On Mon, 23 Sep 2019 20:27:25 +0800 Pengfei Li <[email protected]> wrote:
Changes in v6
--
1. abandon patch 4-7 (Because there is not enough reason to explain that they are beneficial)
So http://lkml.kernel.org/r/20190923004022.GC15734@shao2-debian can no longer occur?
Quoted 12 lines
Changes in v5
--
1. patch 1/7:
- renameSET_KMALLOC_SIZEtoINIT_KMALLOC_INFO
2. patch 5/7:
- fix build errors (Reported-by: kbuild test robot)
- make all_kmalloc_info[] static (Reported-by: kbuild test robot)
3. patch 6/7:
- for robustness, determinekmalloc_cacheis !NULL innew_kmalloc_cache()
4. add ack tag from David Rientjes
Quoted 11 lines · Andrew Morton
Quoted 4 lines · On Mon, 23 Sep 2019 20:27:25 +0800 Pengfei Li <[email protected]> wrote:
Changes in v6
--
1. abandon patch 4-7 (Because there is not enough reason to explain that they are beneficial)So http://lkml.kernel.org/r/20190923004022.GC15734@shao2-debian can no longer occur?
Sorry for such a late reply.
Yes, it‘s caused by [patch v5 5/7]. So do not occur in v6.
Quoted 15 lines
Quoted 12 lines
Changes in v5
--
1. patch 1/7:
- renameSET_KMALLOC_SIZEtoINIT_KMALLOC_INFO
2. patch 5/7:
- fix build errors (Reported-by: kbuild test robot)
- make all_kmalloc_info[] static (Reported-by: kbuild test robot)
3. patch 6/7:
- for robustness, determinekmalloc_cacheis !NULL innew_kmalloc_cache()
4. add ack tag from David Rientjes