slub: name kmalloc slabs at creation time
Subsystems (2)
PATCH 2/2 slub: name kmalloc slabs at creation time
During slub's initialization, most kmalloc slabs are named "kmalloc" at creation time, and later, once slub is fully initialized, get renamed to kmalloc-<size>. The trouble is that slab names passed to option slub_debug will not get recognized, because they will all be called "kmalloc" at the time the command-line option is being processed.
This patch reserves a small static array to hold the names of the kmalloc slabs, and uses a small helper function __uitoa (unsigned integer to ascii) to format names as appropriately.
--- mm/slub.c | 35 +++++++++++++++++++++++++++-------- 1 files changed, 27 insertions(+), 8 deletions(-)
mm/slub.c +27 -8
@@ -3070,6 +3070,11 @@ static struct kmem_cache *kmem_cache;static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT ];#endif +#define KMALLOC_NAME_SUFFIX_MAX 8 +#define KMALLOC_NAME_MAX (strlen("kmalloc-") + KMALLOC_NAME_SUFFIX_MAX) +#define KMALLOC_CACHE_NAME_LEN (SLUB_PAGE_SHIFT - KMALLOC_SHIFT_LOW) +static char kmalloc_cache_names[KMALLOC_CACHE_NAME_LEN *KMALLOC_NAME_MAX ]; +static int __init setup_slub_min_order (char *str) {get_option (&str, &slub_min_order);
@@ -3544,6 +3549,19 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s) } } +/* Convert a positive integer to its decimal string representation, starting at +* the end of the buffer and going backwards, not exceeding maxlen characters. +*/ +static __init char *__pos_int_to_string (unsigned int value,char * string, +int maxindex,int maxlen) +{ +int i = maxindex -1 ; + string[maxindex] =0 ; +for (; value && i && maxlen; i--, maxlen--, value /=10 ) + string[i] ='0' + (value %10 ); +return string + i +1 ; +} +void __init kmem_cache_init (void ) {int i;
@@ -3552,6 +3570,7 @@ void __init kmem_cache_init(void)int order;struct kmem_cache *temp_kmem_cache_node;unsigned long kmalloc_size; +char *name_start; kmem_size = offsetof(struct kmem_cache , node) + nr_node_ids *sizeof (struct kmem_cache_node *);
@@ -3652,8 +3671,15 @@ void __init kmem_cache_init(void) caches++; } + name_start = kmalloc_cache_names;for (i =KMALLOC_SHIFT_LOW ; i <SLUB_PAGE_SHIFT ; i++) { - kmalloc_caches[i] =create_kmalloc_cache ("kmalloc" ,1 << i,0 ); +char *name =__pos_int_to_string (1 << i, name_start, +KMALLOC_NAME_MAX -1 , +KMALLOC_NAME_SUFFIX_MAX ); + name -=8 ; +strncpy (name,"kmalloc-" ,8 ); + name_start +=KMALLOC_NAME_MAX ; + kmalloc_caches[i] =create_kmalloc_cache (name,1 << i,0 ); caches++; }
@@ -3670,13 +3696,6 @@ void __init kmem_cache_init(void)BUG_ON (!kmalloc_caches[2 ]->name); } -for (i =KMALLOC_SHIFT_LOW ; i <SLUB_PAGE_SHIFT ; i++) { -char *s =kasprintf (GFP_NOWAIT ,"kmalloc-%d" ,1 << i); - -BUG_ON (!s); - kmalloc_caches[i]->name = s; - } -#ifdef CONFIG_SMP register_cpu_notifier (&slab_notifier);#endif
Signature · 8 lines
1.7.3.1 -- 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/ . Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/ Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 3 lines · Iliyan Malchev
This patch reserves a small static array to hold the names of the kmalloc slabs, and uses a small helper function
__uitoa(unsigned integer to ascii) to format names as appropriately
simple_strtoull etc is not satisfactory?
mm/slub.c static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s) · line 3563
Quoted 12 lines
mm/slub.c +12
-0+/* Convert a positive integer to its decimal string representation, starting at +* the end of the buffer and going backwards, not exceeding maxlen characters. +*/ +static __init char *__pos_int_to_string (unsigned int value,char * string, +int maxindex,int maxlen) +{ +int i = maxindex -1 ; + string[maxindex] =0 ; +for (; value && i && maxlen; i--, maxlen--, value /=10 ) + string[i] ='0' + (value %10 ); +return string + i +1 ; +}
Please use the standard string operations of the kernel.
mm/slub.c void __init kmem_cache_init(void) · line 3679
Quoted 11 lines
mm/slub.c +5
-1@@ -3652,8 +3671,15 @@ void __init kmem_cache_init(void) caches++; } + name_start = kmalloc_cache_names;for (i =KMALLOC_SHIFT_LOW ; i <SLUB_PAGE_SHIFT ; i++) { - kmalloc_caches[i] =create_kmalloc_cache ("kmalloc" ,1 << i,0 ); +char *name =__pos_int_to_string (1 << i, name_start, +KMALLOC_NAME_MAX -1 , +KMALLOC_NAME_SUFFIX_MAX ); + name -=8 ;
8 is what? The length of "kmalloc-" right?
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>