2020-08-11 02:04:40

by Abel Wu

[permalink] [raw]
Subject: [PATCH] mm/slub: make add_full() condition more explicit

From: Abel Wu <[email protected]>

The commit below is incomplete, as it didn't handle the add_full() part.
commit a4d3f8916c65 ("slub: remove useless kmem_cache_debug() before remove_full()")

This patch checks for SLAB_STORE_USER instead of kmem_cache_debug(),
since that should be the only context in which we need the list_lock for
add_full().

Signed-off-by: Abel Wu <[email protected]>
---
mm/slub.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mm/slub.c b/mm/slub.c
index f226d66408ee..df93a5a0e9a4 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2182,7 +2182,8 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
}
} else {
m = M_FULL;
- if (kmem_cache_debug(s) && !lock) {
+#ifdef CONFIG_SLUB_DEBUG
+ if ((s->flags & SLAB_STORE_USER) && !lock) {
lock = 1;
/*
* This also ensures that the scanning of full
@@ -2191,6 +2192,7 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
*/
spin_lock(&n->list_lock);
}
+#endif
}

if (l != m) {
--
2.28.0.windows.1


2020-08-17 09:23:41

by Abel Wu

[permalink] [raw]
Subject: Re: [PATCH] mm/slub: make add_full() condition more explicit

ping :)

On 2020/8/11 10:02, [email protected] wrote:
> From: Abel Wu <[email protected]>
>
> The commit below is incomplete, as it didn't handle the add_full() part.
> commit a4d3f8916c65 ("slub: remove useless kmem_cache_debug() before remove_full()")
>
> This patch checks for SLAB_STORE_USER instead of kmem_cache_debug(),
> since that should be the only context in which we need the list_lock for
> add_full().
>
> Signed-off-by: Abel Wu <[email protected]>
> ---
> mm/slub.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/mm/slub.c b/mm/slub.c
> index f226d66408ee..df93a5a0e9a4 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -2182,7 +2182,8 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
> }
> } else {
> m = M_FULL;
> - if (kmem_cache_debug(s) && !lock) {
> +#ifdef CONFIG_SLUB_DEBUG
> + if ((s->flags & SLAB_STORE_USER) && !lock) {
> lock = 1;
> /*
> * This also ensures that the scanning of full
> @@ -2191,6 +2192,7 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
> */
> spin_lock(&n->list_lock);
> }
> +#endif
> }
>
> if (l != m) {
>

2020-08-19 19:38:22

by Andrew Morton

[permalink] [raw]
Subject: Re: [PATCH] mm/slub: make add_full() condition more explicit

On Tue, 11 Aug 2020 10:02:36 +0800 <[email protected]> wrote:

> From: Abel Wu <[email protected]>
>
> The commit below is incomplete, as it didn't handle the add_full() part.
> commit a4d3f8916c65 ("slub: remove useless kmem_cache_debug() before remove_full()")
>
> This patch checks for SLAB_STORE_USER instead of kmem_cache_debug(),
> since that should be the only context in which we need the list_lock for
> add_full().
>

Does this contradict what the comment tells us?

* This also ensures that the scanning of full
* slabs from diagnostic functions will not see
* any frozen slabs.


2020-08-20 01:58:15

by Abel Wu

[permalink] [raw]
Subject: Re: [PATCH] mm/slub: make add_full() condition more explicit



On 2020/8/20 3:37, Andrew Morton wrote:
> On Tue, 11 Aug 2020 10:02:36 +0800 <[email protected]> wrote:
>
>> From: Abel Wu <[email protected]>
>>
>> The commit below is incomplete, as it didn't handle the add_full() part.
>> commit a4d3f8916c65 ("slub: remove useless kmem_cache_debug() before remove_full()")
>>
>> This patch checks for SLAB_STORE_USER instead of kmem_cache_debug(),
>> since that should be the only context in which we need the list_lock for
>> add_full().
>>
>
> Does this contradict what the comment tells us?
>
> * This also ensures that the scanning of full
> * slabs from diagnostic functions will not see
> * any frozen slabs.
>
I don't think so. If the flag SLAB_STORE_USER is not set, the slab won't
be added to the full list no matter this patch is applied or not, since
the check inside add_full() will guard for that. Am I missing something
here?
Regards,
Abel

2020-10-16 17:10:21

by Vlastimil Babka

[permalink] [raw]
Subject: Re: [PATCH] mm/slub: make add_full() condition more explicit

On 8/11/20 4:02 AM, [email protected] wrote:
> From: Abel Wu <[email protected]>
>
> The commit below is incomplete, as it didn't handle the add_full() part.
> commit a4d3f8916c65 ("slub: remove useless kmem_cache_debug() before remove_full()")
>
> This patch checks for SLAB_STORE_USER instead of kmem_cache_debug(),
> since that should be the only context in which we need the list_lock for
> add_full().
>
> Signed-off-by: Abel Wu <[email protected]>
> ---
> mm/slub.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/mm/slub.c b/mm/slub.c
> index f226d66408ee..df93a5a0e9a4 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -2182,7 +2182,8 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
> }
> } else {
> m = M_FULL;
> - if (kmem_cache_debug(s) && !lock) {
> +#ifdef CONFIG_SLUB_DEBUG
> + if ((s->flags & SLAB_STORE_USER) && !lock) {
> lock = 1;
> /*
> * This also ensures that the scanning of full
> @@ -2191,6 +2192,7 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
> */
> spin_lock(&n->list_lock);
> }
> +#endif
> }
>
> if (l != m) {
>

Hm I missed this, otherwise I would have suggested the following

-----8<-----
From 0b43c7e20c81241f4b74cdb366795fc0b94a25c9 Mon Sep 17 00:00:00 2001
From: Vlastimil Babka <[email protected]>
Date: Fri, 16 Oct 2020 18:46:06 +0200
Subject: [PATCH] mm, slub: use kmem_cache_debug_flags() in deactivate_slab()

Commit 9cf7a1118365 ("mm/slub: make add_full() condition more explicit")
replaced an unnecessarily generic kmem_cache_debug(s) check with an explicit
check of SLAB_STORE_USER and #ifdef CONFIG_SLUB_DEBUG.

We can achieve the same specific check with the recently added
kmem_cache_debug_flags() which removes the #ifdef and restores the
no-branch-overhead benefit of static key check when slub debugging is not
enabled.

Signed-off-by: Vlastimil Babka <[email protected]>
---
mm/slub.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/mm/slub.c b/mm/slub.c
index 61d0d2968413..28d78238f31e 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2245,8 +2245,7 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
}
} else {
m = M_FULL;
-#ifdef CONFIG_SLUB_DEBUG
- if ((s->flags & SLAB_STORE_USER) && !lock) {
+ if (kmem_cache_debug_flags(s, SLAB_STORE_USER) && !lock) {
lock = 1;
/*
* This also ensures that the scanning of full
@@ -2255,7 +2254,6 @@ static void deactivate_slab(struct kmem_cache *s, struct page *page,
*/
spin_lock(&n->list_lock);
}
-#endif
}

if (l != m) {
--
2.28.0