The slub_debug=PU,kmalloc-xx cannot work because in the
create_kmalloc_caches() the s->name is created after the
create_kmalloc_cache() is called. The name is NULL in the
create_kmalloc_cache() so the kmem_cache_flags() would not set the
slub_debug flags to the s->flags. The fix here set up a kmalloc_names
string array for the initialization purpose and delete the dynamic
name creation of kmalloc_caches.
v1->v2
- Adopted suggestion from Christoph to delete the dynamic name creation
for kmalloc_caches.
Signed-off-by: Gavin Guo <[email protected]>
---
mm/slab_common.c | 41 ++++++++++++++++++++++++++---------------
1 file changed, 26 insertions(+), 15 deletions(-)
diff --git a/mm/slab_common.c b/mm/slab_common.c
index 999bb34..61fbc4e 100644
--- a/mm/slab_common.c
+++ b/mm/slab_common.c
@@ -793,6 +793,26 @@ void __init create_kmalloc_caches(unsigned long flags)
int i;
/*
+ * The kmalloc_names is for temporary usage to make
+ * slub_debug=,kmalloc-xx option work in the boot time. The
+ * kmalloc_index() support to 2^26=64MB. So, the final entry of the
+ * table is kmalloc-67108864.
+ */
+ static const char *kmalloc_names[] = {
+ "0", "kmalloc-96", "kmalloc-192",
+ "kmalloc-8", "kmalloc-16", "kmalloc-32",
+ "kmalloc-64", "kmalloc-128", "kmalloc-256",
+ "kmalloc-512", "kmalloc-1024", "kmalloc-2048",
+ "kmalloc-4196", "kmalloc-8192", "kmalloc-16384",
+ "kmalloc-32768", "kmalloc-65536",
+ "kmalloc-131072", "kmalloc-262144",
+ "kmalloc-524288", "kmalloc-1048576",
+ "kmalloc-2097152", "kmalloc-4194304",
+ "kmalloc-8388608", "kmalloc-16777216",
+ "kmalloc-33554432", "kmalloc-67108864"
+ };
+
+ /*
* Patch up the size_index table if we have strange large alignment
* requirements for the kmalloc array. This is only the case for
* MIPS it seems. The standard arches will not generate any code here.
@@ -835,7 +855,8 @@ void __init create_kmalloc_caches(unsigned long flags)
}
for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
if (!kmalloc_caches[i]) {
- kmalloc_caches[i] = create_kmalloc_cache(NULL,
+ kmalloc_caches[i] = create_kmalloc_cache(
+ kmalloc_names[i],
1 << i, flags);
}
@@ -845,27 +866,17 @@ void __init create_kmalloc_caches(unsigned long flags)
* earlier power of two caches
*/
if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
+ kmalloc_caches[1] = create_kmalloc_cache(
+ kmalloc_names[1], 96, flags);
if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
+ kmalloc_caches[2] = create_kmalloc_cache(
+ kmalloc_names[2], 192, flags);
}
/* Kmalloc array is now usable */
slab_state = UP;
- for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
- struct kmem_cache *s = kmalloc_caches[i];
- char *n;
-
- if (s) {
- n = kasprintf(GFP_NOWAIT, "kmalloc-%d", kmalloc_size(i));
-
- BUG_ON(!n);
- s->name = n;
- }
- }
-
#ifdef CONFIG_ZONE_DMA
for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
struct kmem_cache *s = kmalloc_caches[i];
--
2.0.0
On Wed, 22 Apr 2015, Gavin Guo wrote:
> The slub_debug=PU,kmalloc-xx cannot work because in the
> create_kmalloc_caches() the s->name is created after the
> create_kmalloc_cache() is called. The name is NULL in the
> create_kmalloc_cache() so the kmem_cache_flags() would not set the
> slub_debug flags to the s->flags. The fix here set up a kmalloc_names
> string array for the initialization purpose and delete the dynamic
> name creation of kmalloc_caches.
Acked-by: Christoph Lameter <[email protected]>
On Wed, 22 Apr 2015 16:33:38 +0800 Gavin Guo <[email protected]> wrote:
> The slub_debug=PU,kmalloc-xx cannot work because in the
> create_kmalloc_caches() the s->name is created after the
> create_kmalloc_cache() is called. The name is NULL in the
> create_kmalloc_cache() so the kmem_cache_flags() would not set the
> slub_debug flags to the s->flags. The fix here set up a kmalloc_names
> string array for the initialization purpose and delete the dynamic
> name creation of kmalloc_caches.
>
> --- a/mm/slab_common.c
> +++ b/mm/slab_common.c
> @@ -793,6 +793,26 @@ void __init create_kmalloc_caches(unsigned long flags)
> int i;
>
> /*
> + * The kmalloc_names is for temporary usage to make
> + * slub_debug=,kmalloc-xx option work in the boot time. The
> + * kmalloc_index() support to 2^26=64MB. So, the final entry of the
> + * table is kmalloc-67108864.
> + */
> + static const char *kmalloc_names[] = {
> + "0", "kmalloc-96", "kmalloc-192",
> + "kmalloc-8", "kmalloc-16", "kmalloc-32",
> + "kmalloc-64", "kmalloc-128", "kmalloc-256",
> + "kmalloc-512", "kmalloc-1024", "kmalloc-2048",
> + "kmalloc-4196", "kmalloc-8192", "kmalloc-16384",
> + "kmalloc-32768", "kmalloc-65536",
> + "kmalloc-131072", "kmalloc-262144",
> + "kmalloc-524288", "kmalloc-1048576",
> + "kmalloc-2097152", "kmalloc-4194304",
> + "kmalloc-8388608", "kmalloc-16777216",
> + "kmalloc-33554432", "kmalloc-67108864"
> + };
> +
> + /*
> * Patch up the size_index table if we have strange large alignment
> * requirements for the kmalloc array. This is only the case for
> * MIPS it seems. The standard arches will not generate any code here.
> @@ -835,7 +855,8 @@ void __init create_kmalloc_caches(unsigned long flags)
> }
> for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
> if (!kmalloc_caches[i]) {
> - kmalloc_caches[i] = create_kmalloc_cache(NULL,
> + kmalloc_caches[i] = create_kmalloc_cache(
> + kmalloc_names[i],
> 1 << i, flags);
> }
You could do something like
kmalloc_caches[i] = create_kmalloc_cache(
kmalloc_names[i],
kstrtoul(kmalloc_names[i] + 8),
flags);
here, and remove those weird "96" and "192" cases.
Or if that's considered too messy, make it
static const struct {
const char *name;
unsigned size;
} kmalloc_cache_info[] = {
{ NULL, 0 },
{ "kmalloc-96", 96 },
...
};
but I'm thinking the kstrtoul() trick will be OK.
> - for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
> - struct kmem_cache *s = kmalloc_caches[i];
> - char *n;
> -
> - if (s) {
> - n = kasprintf(GFP_NOWAIT, "kmalloc-%d", kmalloc_size(i));
> -
> - BUG_ON(!n);
> - s->name = n;
> - }
> - }
> -
slab_kmem_cache_release() still does kfree_const(s->name). It will
crash?
On Wed, 22 Apr 2015 14:00:39 -0700 Andrew Morton <[email protected]> wrote:
> slab_kmem_cache_release() still does kfree_const(s->name). It will
> crash?
er, ignore this bit..
On Thu, Apr 23, 2015 at 5:00 AM, Andrew Morton
<[email protected]> wrote:
> On Wed, 22 Apr 2015 16:33:38 +0800 Gavin Guo <[email protected]> wrote:
>
>> The slub_debug=PU,kmalloc-xx cannot work because in the
>> create_kmalloc_caches() the s->name is created after the
>> create_kmalloc_cache() is called. The name is NULL in the
>> create_kmalloc_cache() so the kmem_cache_flags() would not set the
>> slub_debug flags to the s->flags. The fix here set up a kmalloc_names
>> string array for the initialization purpose and delete the dynamic
>> name creation of kmalloc_caches.
>>
>> --- a/mm/slab_common.c
>> +++ b/mm/slab_common.c
>> @@ -793,6 +793,26 @@ void __init create_kmalloc_caches(unsigned long flags)
>> int i;
>>
>> /*
>> + * The kmalloc_names is for temporary usage to make
>> + * slub_debug=,kmalloc-xx option work in the boot time. The
>> + * kmalloc_index() support to 2^26=64MB. So, the final entry of the
>> + * table is kmalloc-67108864.
>> + */
>> + static const char *kmalloc_names[] = {
>> + "0", "kmalloc-96", "kmalloc-192",
>> + "kmalloc-8", "kmalloc-16", "kmalloc-32",
>> + "kmalloc-64", "kmalloc-128", "kmalloc-256",
>> + "kmalloc-512", "kmalloc-1024", "kmalloc-2048",
>> + "kmalloc-4196", "kmalloc-8192", "kmalloc-16384",
>> + "kmalloc-32768", "kmalloc-65536",
>> + "kmalloc-131072", "kmalloc-262144",
>> + "kmalloc-524288", "kmalloc-1048576",
>> + "kmalloc-2097152", "kmalloc-4194304",
>> + "kmalloc-8388608", "kmalloc-16777216",
>> + "kmalloc-33554432", "kmalloc-67108864"
>> + };
>> +
>> + /*
>> * Patch up the size_index table if we have strange large alignment
>> * requirements for the kmalloc array. This is only the case for
>> * MIPS it seems. The standard arches will not generate any code here.
>> @@ -835,7 +855,8 @@ void __init create_kmalloc_caches(unsigned long flags)
>> }
>> for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
>> if (!kmalloc_caches[i]) {
>> - kmalloc_caches[i] = create_kmalloc_cache(NULL,
>> + kmalloc_caches[i] = create_kmalloc_cache(
>> + kmalloc_names[i],
>> 1 << i, flags);
>> }
>
> You could do something like
>
> kmalloc_caches[i] = create_kmalloc_cache(
> kmalloc_names[i],
> kstrtoul(kmalloc_names[i] + 8),
> flags);
>
> here, and remove those weird "96" and "192" cases.
Thanks for your reply. I'm not sure if I am following your idea. Would you
mean to simply replace the string like:
kmalloc_caches[1] = create_kmalloc_cache(
kmalloc_names[1], 96, flags);
as follows:
kmalloc_caches[1] = create_kmalloc_cache(
kmalloc_names[1],
kstrtoul(kmalloc_names[i] + 8),
flags);
or if you like to merge the last 2 if conditions for 96 and 192 cases to
the first if condition check:
if (!kmalloc_caches[i]) {
kmalloc_caches[i] = create_kmalloc_cache(NULL,
1 << i, flags);
}
>
> Or if that's considered too messy, make it
>
> static const struct {
> const char *name;
> unsigned size;
> } kmalloc_cache_info[] = {
> { NULL, 0 },
> { "kmalloc-96", 96 },
> ...
> };
>
> but I'm thinking the kstrtoul() trick will be OK.
>
>> - for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
>> - struct kmem_cache *s = kmalloc_caches[i];
>> - char *n;
>> -
>> - if (s) {
>> - n = kasprintf(GFP_NOWAIT, "kmalloc-%d", kmalloc_size(i));
>> -
>> - BUG_ON(!n);
>> - s->name = n;
>> - }
>> - }
>> -
>
> slab_kmem_cache_release() still does kfree_const(s->name). It will
> crash?
>
On Thu, 23 Apr 2015 11:10:40 +0800 Gavin Guo <[email protected]> wrote:
> >> for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
> >> if (!kmalloc_caches[i]) {
> >> - kmalloc_caches[i] = create_kmalloc_cache(NULL,
> >> + kmalloc_caches[i] = create_kmalloc_cache(
> >> + kmalloc_names[i],
> >> 1 << i, flags);
> >> }
> >
> > You could do something like
> >
> > kmalloc_caches[i] = create_kmalloc_cache(
> > kmalloc_names[i],
> > kstrtoul(kmalloc_names[i] + 8),
> > flags);
> >
> > here, and remove those weird "96" and "192" cases.
>
> Thanks for your reply. I'm not sure if I am following your idea. Would you
> mean to simply replace the string like:
>
> kmalloc_caches[1] = create_kmalloc_cache(
> kmalloc_names[1], 96, flags);
> as follows:
>
> kmalloc_caches[1] = create_kmalloc_cache(
> kmalloc_names[1],
> kstrtoul(kmalloc_names[i] + 8),
> flags);
>
> or if you like to merge the last 2 if conditions for 96 and 192 cases to
> the first if condition check:
>
> if (!kmalloc_caches[i]) {
> kmalloc_caches[i] = create_kmalloc_cache(NULL,
> 1 << i, flags);
> }
The latter - initialize all the caches in a single loop.
On Wed, Apr 22 2015, Gavin Guo <[email protected]> wrote:
> /*
> + * The kmalloc_names is for temporary usage to make
> + * slub_debug=,kmalloc-xx option work in the boot time. The
> + * kmalloc_index() support to 2^26=64MB. So, the final entry of the
> + * table is kmalloc-67108864.
> + */
> + static const char *kmalloc_names[] = {
The array itself could be const, but more importantly it should be
marked __initconst so that the 27*sizeof(char*) bytes can be released after init.
> + "0", "kmalloc-96", "kmalloc-192",
> + "kmalloc-8", "kmalloc-16", "kmalloc-32",
> + "kmalloc-64", "kmalloc-128", "kmalloc-256",
> + "kmalloc-512", "kmalloc-1024", "kmalloc-2048",
> + "kmalloc-4196", "kmalloc-8192", "kmalloc-16384",
"kmalloc-4096"
> + "kmalloc-32768", "kmalloc-65536",
> + "kmalloc-131072", "kmalloc-262144",
> + "kmalloc-524288", "kmalloc-1048576",
> + "kmalloc-2097152", "kmalloc-4194304",
> + "kmalloc-8388608", "kmalloc-16777216",
> + "kmalloc-33554432", "kmalloc-67108864"
> + };
On Wed, Apr 22 2015, Andrew Morton <[email protected]> wrote:
> You could do something like
>
> kmalloc_caches[i] = create_kmalloc_cache(
> kmalloc_names[i],
> kstrtoul(kmalloc_names[i] + 8),
> flags);
>
> here, and remove those weird "96" and "192" cases.
Eww. At least spell 8 as strlen("kmalloc-").
> Or if that's considered too messy, make it
>
> static const struct {
> const char *name;
> unsigned size;
> } kmalloc_cache_info[] = {
> { NULL, 0 },
> { "kmalloc-96", 96 },
> ...
> };
I'd vote for this color for the bikeshed :-)
Rasmus
Hi Rasmus,
On Thu, Apr 23, 2015 at 5:55 PM, Rasmus Villemoes
<[email protected]> wrote:
> On Wed, Apr 22 2015, Gavin Guo <[email protected]> wrote:
>
>> /*
>> + * The kmalloc_names is for temporary usage to make
>> + * slub_debug=,kmalloc-xx option work in the boot time. The
>> + * kmalloc_index() support to 2^26=64MB. So, the final entry of the
>> + * table is kmalloc-67108864.
>> + */
>> + static const char *kmalloc_names[] = {
>
> The array itself could be const, but more importantly it should be
> marked __initconst so that the 27*sizeof(char*) bytes can be released after init.
>
>> + "0", "kmalloc-96", "kmalloc-192",
>> + "kmalloc-8", "kmalloc-16", "kmalloc-32",
>> + "kmalloc-64", "kmalloc-128", "kmalloc-256",
>> + "kmalloc-512", "kmalloc-1024", "kmalloc-2048",
>> + "kmalloc-4196", "kmalloc-8192", "kmalloc-16384",
>
> "kmalloc-4096"
Good catch!!
>
>> + "kmalloc-32768", "kmalloc-65536",
>> + "kmalloc-131072", "kmalloc-262144",
>> + "kmalloc-524288", "kmalloc-1048576",
>> + "kmalloc-2097152", "kmalloc-4194304",
>> + "kmalloc-8388608", "kmalloc-16777216",
>> + "kmalloc-33554432", "kmalloc-67108864"
>> + };
>
> On Wed, Apr 22 2015, Andrew Morton <[email protected]> wrote:
>
>> You could do something like
>>
>> kmalloc_caches[i] = create_kmalloc_cache(
>> kmalloc_names[i],
>> kstrtoul(kmalloc_names[i] + 8),
>> flags);
>>
>> here, and remove those weird "96" and "192" cases.
>
> Eww. At least spell 8 as strlen("kmalloc-").
>
>> Or if that's considered too messy, make it
>>
>> static const struct {
>> const char *name;
>> unsigned size;
>> } kmalloc_cache_info[] = {
>> { NULL, 0 },
>> { "kmalloc-96", 96 },
>> ...
>> };
>
> I'd vote for this color for the bikeshed :-)
>
> Rasmus
Thanks for the review! I'll come out another version soon.