Skip to contentSkip to conversation

slub: do not merge cache if slub_debug contains a never-merge flag

PATCH Superseded Grygorii Maistrenko 4 participants 9 messages Dec 23, 2016 – Jan 4, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 slub: do not merge cache if slub_debug contains a never-merge flag

In case CONFIG_SLUB_DEBUG_ON=n find_mergeable() gets debug features from commandline but never checks if there are features from the SLAB_NEVER_MERGE set.
As a result selected by slub_debug caches are always mergeable if they have been created without a custom constructor set or without one of the SLAB_* debug features on.

This adds the necessary check and makes selected slab caches unmergeable if one of the SLAB_NEVER_MERGE features is set from commandline.

---
 mm/slab_common.c | 3 +++
 1 file changed, 3 insertions(+)
mm/slab_common.c +3 -0
index 329b03843863..7341cba8c58b 100644
@@ -266,6 +266,9 @@ struct kmem_cache *find_mergeable(size_t size, size_t align,
 	size = ALIGN(size, align);
 	flags = kmem_cache_flags(size, flags, name, NULL);
 
+	if (flags & SLAB_NEVER_MERGE)
+		return NULL;
+
 	list_for_each_entry_reverse(s, &slab_caches, list) {
 		if (slab_unmergeable(s))
 			continue;
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>
#1 lore raw
Quoted 6 lines · Grygorii Maistrenko

In case CONFIG_SLUB_DEBUG_ON=n find_mergeable() gets debug features from commandline but never checks if there are features from the SLAB_NEVER_MERGE set.
As a result selected by slub_debug caches are always mergeable if they have been created without a custom constructor set or without one of the SLAB_* debug features on.

WTF is this nonsense? That check is done a few lines earlier!

struct kmem_cache *ind_mergeable(size_t size, size_t align,
unsigned long flags, const char *name, void (*ctor)(void *))

{
        struct kmem_cache *s;

        if (slab_nomerge || (flags & SLAB_NEVER_MERGE))    <----- !!!!!!
                return NULL;

        if (ctor)
                return NULL;

        size = ALIGN(size, sizeof(void *));
        align = calculate_alignment(flags,
Quoted 15 lines

This adds the necessary check and makes selected slab caches unmergeable if one of the SLAB_NEVER_MERGE features is set from commandline.

---
 mm/slab_common.c | 3 +++
 1 file changed, 3 insertions(+)
mm/slab_common.c +0 -0
index 329b03843863..7341cba8c58b 100644

mm/slab_common.c struct kmem_cache *find_mergeable(size_t size, size_t align, · line 274

Quoted 9 lines
mm/slab_common.c +3 -0
@@ -266,6 +266,9 @@ struct kmem_cache *find_mergeable(size_t size, size_t align,
 	size = ALIGN(size, align);
 	flags = kmem_cache_flags(size, flags, name, NULL);
 
+	if (flags & SLAB_NEVER_MERGE)
+		return NULL;
+
 	list_for_each_entry_reverse(s, &slab_caches, list) {
 		if (slab_unmergeable(s))
 			continue;

--
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>

#2 lore raw
Quoted 12 lines · Christoph Lameter
Quoted 6 lines · Grygorii Maistrenko

In case CONFIG_SLUB_DEBUG_ON=n find_mergeable() gets debug features from commandline but never checks if there are features from the SLAB_NEVER_MERGE set.
As a result selected by slub_debug caches are always mergeable if they have been created without a custom constructor set or without one of the SLAB_* debug features on.

WTF is this nonsense? That check is done a few lines earlier!

Quoted 7 lines

struct kmem_cache *ind_mergeable(size_t size, size_t align,
unsigned long flags, const char *name, void (*ctor)(void *))

{
        struct kmem_cache *s;

        if (slab_nomerge || (flags & SLAB_NEVER_MERGE))    <----- !!!!!!
                return NULL;

This one check is done on flags passed to kmem_cache_create().

Quoted 6 lines
        if (ctor)
                return NULL;

        size = ALIGN(size, sizeof(void *));
        align = calculate_alignment(flags,
	flags = kmem_cache_flags(size, flags, name, NULL);

I added here the missing line. This updates flags from commandline and after this we do not check it.

Quoted 19 lines
Quoted 19 lines

This adds the necessary check and makes selected slab caches unmergeable if one of the SLAB_NEVER_MERGE features is set from commandline.

---
 mm/slab_common.c | 3 +++
 1 file changed, 3 insertions(+)
mm/slab_common.c +0 -0
index 329b03843863..7341cba8c58b 100644
@@ -266,6 +266,9 @@ struct kmem_cache *find_mergeable(size_t size, size_t align,
 	size = ALIGN(size, align);
 	flags = kmem_cache_flags(size, flags, name, NULL);
 
Quoted 7 lines

mm/slab_common.c struct kmem_cache *find_mergeable(size_t size, size_t align, · line 274

Quoted 7 lines
mm/slab_common.c +3 -0
+	if (flags & SLAB_NEVER_MERGE)
+		return NULL;
+
 	list_for_each_entry_reverse(s, &slab_caches, list) {
 		if (slab_unmergeable(s))
 			continue;

--
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>

#3 lore raw
Quoted 14 lines · Grygorii Maistrenko
Quoted 7 lines

struct kmem_cache *ind_mergeable(size_t size, size_t align,
unsigned long flags, const char *name, void (*ctor)(void *))

{
        struct kmem_cache *s;

        if (slab_nomerge || (flags & SLAB_NEVER_MERGE))    <----- !!!!!!
                return NULL;

This one check is done on flags passed to kmem_cache_create().

Quoted 4 lines
        if (ctor)
                return NULL;
Quoted 6 lines
Quoted 2 lines

size = ALIGN(size, sizeof(void *));
align = calculate_alignment(flags,

	flags = kmem_cache_flags(size, flags, name, NULL);

I added here the missing line. This updates flags from commandline and after this we do not check it.

Then please move the check down below the flags update.

--
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>

#4 lore raw

PATCH v2 1/1 slub: do not merge cache if slub_debug contains a never-merge flag

In case CONFIG_SLUB_DEBUG_ON=n, find_mergeable() gets debug features from commandline but never checks if there are features from the SLAB_NEVER_MERGE set.
As a result selected by slub_debug caches are always mergeable if they have been created without a custom constructor set or without one of the SLAB_* debug features on.

This moves the SLAB_NEVER_MERGE check below the flags update from commandline to make sure it won't merge the slab cache if one of the debug features is on.

---
 mm/slab_common.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

New in v2:
- (flags & SLAB_NEVER_MERGE) check is moved down below the flags update as suggested by Christoph Lameter

mm/slab_common.c +4 -1
index 329b03843863..a85a01439490 100644
@@ -255,7 +255,7 @@ struct kmem_cache *find_mergeable(size_t size, size_t align,
 {
 	struct kmem_cache *s;
 
-	if (slab_nomerge || (flags & SLAB_NEVER_MERGE))
+	if (slab_nomerge)
 		return NULL;
 
 	if (ctor)
@@ -266,6 +266,9 @@ struct kmem_cache *find_mergeable(size_t size, size_t align,
 	size = ALIGN(size, align);
 	flags = kmem_cache_flags(size, flags, name, NULL);
 
+	if (flags & SLAB_NEVER_MERGE)
+		return NULL;
+
 	list_for_each_entry_reverse(s, &slab_caches, list) {
 		if (slab_unmergeable(s))
 			continue;
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>
Reviewed-by on v2 1/1
#5 lore raw
Quoted 7 lines · Grygorii Maistrenko

In case CONFIG_SLUB_DEBUG_ON=n, find_mergeable() gets debug features from commandline but never checks if there are features from the SLAB_NEVER_MERGE set.
As a result selected by slub_debug caches are always mergeable if they have been created without a custom constructor set or without one of the SLAB_* debug features on.

Quoted 5 lines

This moves the SLAB_NEVER_MERGE check below the flags update from commandline to make sure it won't merge the slab cache if one of the debug features is on.

Quoted 22 lines
---
  mm/slab_common.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)

New in v2:
- (flags & SLAB_NEVER_MERGE) check is moved down below the flags update as suggested by Christoph Lameter

mm/slab_common.c +1 -1
index 329b03843863..a85a01439490 100644
@@ -255,7 +255,7 @@ struct kmem_cache *find_mergeable(size_t size, size_t align,
  {
  	struct kmem_cache *s;
 
-	if (slab_nomerge || (flags & SLAB_NEVER_MERGE))
+	if (slab_nomerge)
  		return NULL;
 
  	if (ctor)

mm/slab_common.c struct kmem_cache *find_mergeable(size_t size, size_t align, · line 274

Quoted 9 lines
mm/slab_common.c +3 -0
@@ -266,6 +266,9 @@ struct kmem_cache *find_mergeable(size_t size, size_t align,
  	size = ALIGN(size, align);
  	flags = kmem_cache_flags(size, flags, name, NULL);
 
+	if (flags & SLAB_NEVER_MERGE)
+		return NULL;
+
  	list_for_each_entry_reverse(s, &slab_caches, list) {
  		if (slab_unmergeable(s))
  			continue;

--
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>

reviewer Acked-by on v2 1/1
#6 lore raw
In reply to Grygorii Maistrenko
Quoted 7 lines · Grygorii Maistrenko

In case CONFIG_SLUB_DEBUG_ON=n, find_mergeable() gets debug features from commandline but never checks if there are features from the SLAB_NEVER_MERGE set.
As a result selected by slub_debug caches are always mergeable if they have been created without a custom constructor set or without one of the SLAB_* debug features on.

Quoted 5 lines

This moves the SLAB_NEVER_MERGE check below the flags update from commandline to make sure it won't merge the slab cache if one of the debug features is on.

--
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>

#7 lore raw

PATCH v2 1/1 slub: do not merge cache if slub_debug contains a never-merge flag

In reply to Christoph Lameter

In case CONFIG_SLUB_DEBUG_ON=n, find_mergeable() gets debug features from commandline but never checks if there are features from the SLAB_NEVER_MERGE set.
As a result selected by slub_debug caches are always mergeable if they have been created without a custom constructor set or without one of the SLAB_* debug features on.

This moves the SLAB_NEVER_MERGE check below the flags update from commandline to make sure it won't merge the slab cache if one of the debug features is on.

---
 mm/slab_common.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

New in v2:
- (flags & SLAB_NEVER_MERGE) check is moved down below the flags update as suggested by Christoph Lameter

mm/slab_common.c +4 -1
index 329b03843863..a85a01439490 100644
@@ -255,7 +255,7 @@ struct kmem_cache *find_mergeable(size_t size, size_t align,
 {
 	struct kmem_cache *s;
 
-	if (slab_nomerge || (flags & SLAB_NEVER_MERGE))
+	if (slab_nomerge)
 		return NULL;
 
 	if (ctor)
@@ -266,6 +266,9 @@ struct kmem_cache *find_mergeable(size_t size, size_t align,
 	size = ALIGN(size, align);
 	flags = kmem_cache_flags(size, flags, name, NULL);
 
+	if (flags & SLAB_NEVER_MERGE)
+		return NULL;
+
 	list_for_each_entry_reverse(s, &slab_caches, list) {
 		if (slab_unmergeable(s))
 			continue;
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>