[v5,9/9] slub: Update frozen slabs documentations in the source

Message ID 20231102032330.1036151-10-chengming.zhou@linux.dev
State New
Headers
Series slub: Delay freezing of CPU partial slabs |

Commit Message

Chengming Zhou Nov. 2, 2023, 3:23 a.m. UTC
  From: Chengming Zhou <zhouchengming@bytedance.com>

The current updated scheme (which this series implemented) is:
 - node partial slabs: PG_Workingset && !frozen
 - cpu partial slabs: !PG_Workingset && !frozen
 - cpu slabs: !PG_Workingset && frozen
 - full slabs: !PG_Workingset && !frozen

The most important change is that "frozen" bit is not set for the
cpu partial slabs anymore, __slab_free() will grab node list_lock
then check by !PG_Workingset that it's not on a node partial list.

And the "frozen" bit is still kept for the cpu slabs for performance,
since we don't need to grab node list_lock to check whether the
PG_Workingset is set or not if the "frozen" bit is set in __slab_free().

Update related documentations and comments in the source.

Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
Tested-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>
---
 mm/slub.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
  

Comments

Hyeonggon Yoo Dec. 3, 2023, 9:47 a.m. UTC | #1
On Thu, Nov 2, 2023 at 12:25 PM <chengming.zhou@linux.dev> wrote:
>
> From: Chengming Zhou <zhouchengming@bytedance.com>
>
> The current updated scheme (which this series implemented) is:
>  - node partial slabs: PG_Workingset && !frozen
>  - cpu partial slabs: !PG_Workingset && !frozen
>  - cpu slabs: !PG_Workingset && frozen
>  - full slabs: !PG_Workingset && !frozen
>
> The most important change is that "frozen" bit is not set for the
> cpu partial slabs anymore, __slab_free() will grab node list_lock
> then check by !PG_Workingset that it's not on a node partial list.
>
> And the "frozen" bit is still kept for the cpu slabs for performance,
> since we don't need to grab node list_lock to check whether the
> PG_Workingset is set or not if the "frozen" bit is set in __slab_free().
>
> Update related documentations and comments in the source.
>
> Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
> Tested-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>
> ---
>  mm/slub.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/mm/slub.c b/mm/slub.c
> index c20bdf5dab0f..a307d319e82c 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -76,13 +76,22 @@
>   *
>   *   Frozen slabs
>   *
> - *   If a slab is frozen then it is exempt from list management. It is not
> - *   on any list except per cpu partial list. The processor that froze the
> + *   If a slab is frozen then it is exempt from list management. It is
> + *   the cpu slab which is actively allocated from by the processor that
> + *   froze it and it is not on any list. The processor that froze the
>   *   slab is the one who can perform list operations on the slab. Other
>   *   processors may put objects onto the freelist but the processor that
>   *   froze the slab is the only one that can retrieve the objects from the
>   *   slab's freelist.
>   *
> + *   CPU partial slabs
> + *
> + *   The partially empty slabs cached on the CPU partial list are used
> + *   for performance reasons, which speeds up the allocation process.
> + *   These slabs are not frozen, but are also exempt from list management,
> + *   by clearing the PG_workingset flag when moving out of the node
> + *   partial list. Please see __slab_free() for more details.
> + *
>   *   list_lock
>   *
>   *   The list_lock protects the partial and full list on each node and
> @@ -2617,8 +2626,7 @@ static void put_partials_cpu(struct kmem_cache *s,
>  }
>
>  /*
> - * Put a slab that was just frozen (in __slab_free|get_partial_node) into a
> - * partial slab slot if available.
> + * Put a slab into a partial slab slot if available.
>   *
>   * If we did not find a slot then simply move all the partials to the
>   * per node partial list.
> --

Looks good to me,
Reviewed-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>

Thanks!

> 2.20.1
>
  
Christoph Lameter (Ampere) Dec. 4, 2023, 9:41 p.m. UTC | #2
On Thu, 2 Nov 2023, chengming.zhou@linux.dev wrote:

> From: Chengming Zhou <zhouchengming@bytedance.com>
>
> The current updated scheme (which this series implemented) is:
> - node partial slabs: PG_Workingset && !frozen
> - cpu partial slabs: !PG_Workingset && !frozen
> - cpu slabs: !PG_Workingset && frozen
> - full slabs: !PG_Workingset && !frozen

The above would be good to include in the comments.

Acked-by: Christoph Lameter (Ampere) <cl@linux.com>
  
Chengming Zhou Dec. 5, 2023, 6:06 a.m. UTC | #3
On 2023/12/5 05:41, Christoph Lameter (Ampere) wrote:
> On Thu, 2 Nov 2023, chengming.zhou@linux.dev wrote:
> 
>> From: Chengming Zhou <zhouchengming@bytedance.com>
>>
>> The current updated scheme (which this series implemented) is:
>> - node partial slabs: PG_Workingset && !frozen
>> - cpu partial slabs: !PG_Workingset && !frozen
>> - cpu slabs: !PG_Workingset && frozen
>> - full slabs: !PG_Workingset && !frozen
> 
> The above would be good to include in the comments.
> 
> Acked-by: Christoph Lameter (Ampere) <cl@linux.com>
> 

Thanks for your review and suggestion!

Maybe something like this:

diff --git a/mm/slub.c b/mm/slub.c
index 623c17a4cdd6..21f88bd9c16b 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -93,6 +93,12 @@
  *   by clearing the PG_workingset flag when moving out of the node
  *   partial list. Please see __slab_free() for more details.
  *
+ *   To sum up, the current scheme is:
+ *   - node partial slab: PG_Workingset && !frozen
+ *   - cpu partial slab: !PG_Workingset && !frozen
+ *   - cpu slab: !PG_Workingset && frozen
+ *   - full slab: !PG_Workingset && !frozen
+ *
  *   list_lock
  *
  *   The list_lock protects the partial and full list on each node and
  
Vlastimil Babka Dec. 5, 2023, 9:39 a.m. UTC | #4
On 12/5/23 07:06, Chengming Zhou wrote:
> On 2023/12/5 05:41, Christoph Lameter (Ampere) wrote:
>> On Thu, 2 Nov 2023, chengming.zhou@linux.dev wrote:
>> 
>>> From: Chengming Zhou <zhouchengming@bytedance.com>
>>>
>>> The current updated scheme (which this series implemented) is:
>>> - node partial slabs: PG_Workingset && !frozen
>>> - cpu partial slabs: !PG_Workingset && !frozen
>>> - cpu slabs: !PG_Workingset && frozen
>>> - full slabs: !PG_Workingset && !frozen
>> 
>> The above would be good to include in the comments.
>> 
>> Acked-by: Christoph Lameter (Ampere) <cl@linux.com>
>> 
> 
> Thanks for your review and suggestion!
> 
> Maybe something like this:

Thanks, added.

> diff --git a/mm/slub.c b/mm/slub.c
> index 623c17a4cdd6..21f88bd9c16b 100644
> --- a/mm/slub.c
> +++ b/mm/slub.c
> @@ -93,6 +93,12 @@
>   *   by clearing the PG_workingset flag when moving out of the node
>   *   partial list. Please see __slab_free() for more details.
>   *
> + *   To sum up, the current scheme is:
> + *   - node partial slab: PG_Workingset && !frozen
> + *   - cpu partial slab: !PG_Workingset && !frozen
> + *   - cpu slab: !PG_Workingset && frozen
> + *   - full slab: !PG_Workingset && !frozen
> + *
>   *   list_lock
>   *
>   *   The list_lock protects the partial and full list on each node and
  

Patch

diff --git a/mm/slub.c b/mm/slub.c
index c20bdf5dab0f..a307d319e82c 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -76,13 +76,22 @@ 
  *
  *   Frozen slabs
  *
- *   If a slab is frozen then it is exempt from list management. It is not
- *   on any list except per cpu partial list. The processor that froze the
+ *   If a slab is frozen then it is exempt from list management. It is
+ *   the cpu slab which is actively allocated from by the processor that
+ *   froze it and it is not on any list. The processor that froze the
  *   slab is the one who can perform list operations on the slab. Other
  *   processors may put objects onto the freelist but the processor that
  *   froze the slab is the only one that can retrieve the objects from the
  *   slab's freelist.
  *
+ *   CPU partial slabs
+ *
+ *   The partially empty slabs cached on the CPU partial list are used
+ *   for performance reasons, which speeds up the allocation process.
+ *   These slabs are not frozen, but are also exempt from list management,
+ *   by clearing the PG_workingset flag when moving out of the node
+ *   partial list. Please see __slab_free() for more details.
+ *
  *   list_lock
  *
  *   The list_lock protects the partial and full list on each node and
@@ -2617,8 +2626,7 @@  static void put_partials_cpu(struct kmem_cache *s,
 }
 
 /*
- * Put a slab that was just frozen (in __slab_free|get_partial_node) into a
- * partial slab slot if available.
+ * Put a slab into a partial slab slot if available.
  *
  * If we did not find a slot then simply move all the partials to the
  * per node partial list.