[RFC,v2,1/6] slub: Keep track of whether slub is on the per-node partial list
Commit Message
From: Chengming Zhou <zhouchengming@bytedance.com>
Now we rely on the "frozen" bit to see if we should manipulate the
slab->slab_list, which will be changed in the following patch.
Instead we introduce another way to keep track of whether slub is on
the per-node partial list, here we reuse the PG_workingset bit.
Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
---
include/linux/page-flags.h | 2 ++
mm/slab.h | 19 +++++++++++++++++++
mm/slub.c | 3 +++
3 files changed, 24 insertions(+)
Comments
On Sat, Oct 21, 2023 at 02:43:12PM +0000, chengming.zhou@linux.dev wrote:
> +++ b/include/linux/page-flags.h
> @@ -478,6 +478,8 @@ PAGEFLAG(Active, active, PF_HEAD) __CLEARPAGEFLAG(Active, active, PF_HEAD)
> TESTCLEARFLAG(Active, active, PF_HEAD)
> PAGEFLAG(Workingset, workingset, PF_HEAD)
> TESTCLEARFLAG(Workingset, workingset, PF_HEAD)
> + __SETPAGEFLAG(Workingset, workingset, PF_HEAD)
> + __CLEARPAGEFLAG(Workingset, workingset, PF_HEAD)
This makes me nervous. The __ versions can only be used when there are
guaranteed to be no other accesses to the flags. It's never going to
be the case that we want code to call __folio_set_workingset().
_Assuming_ that it's safe to use the non-atomic flag setting, I'd
rather see this done as ...
static inline void slab_set_node_partial(struct slab *slab)
{
__folio_set_workingset(slab_folio(slab));
__set_bit(PG_workingset, folio_flags(slab_folio(slab), 0));
}
On Mon, Oct 23, 2023 at 01:32:27PM +0100, Matthew Wilcox wrote:
> _Assuming_ that it's safe to use the non-atomic flag setting, I'd
> rather see this done as ...
>
> static inline void slab_set_node_partial(struct slab *slab)
> {
> __folio_set_workingset(slab_folio(slab));
Ugh, I meant to delete this line. I meant to just write the next line.
> __set_bit(PG_workingset, folio_flags(slab_folio(slab), 0));
> }
On 2023/10/24 00:22, Matthew Wilcox wrote:
> On Mon, Oct 23, 2023 at 01:32:27PM +0100, Matthew Wilcox wrote:
>> _Assuming_ that it's safe to use the non-atomic flag setting, I'd
>> rather see this done as ...
>>
>> static inline void slab_set_node_partial(struct slab *slab)
>> {
>> __folio_set_workingset(slab_folio(slab));
>
> Ugh, I meant to delete this line. I meant to just write the next line.
>
>> __set_bit(PG_workingset, folio_flags(slab_folio(slab), 0));
>> }
Yes, it's safe to use the non-atomic version here, since it's protected
by the slub per-node list_lock and we want better performance here.
Ok, will change to directly use __set_bit() and __clear_bit() instead of
polluting the "workingset" interfaces there.
Thanks.
@@ -478,6 +478,8 @@ PAGEFLAG(Active, active, PF_HEAD) __CLEARPAGEFLAG(Active, active, PF_HEAD)
TESTCLEARFLAG(Active, active, PF_HEAD)
PAGEFLAG(Workingset, workingset, PF_HEAD)
TESTCLEARFLAG(Workingset, workingset, PF_HEAD)
+ __SETPAGEFLAG(Workingset, workingset, PF_HEAD)
+ __CLEARPAGEFLAG(Workingset, workingset, PF_HEAD)
__PAGEFLAG(Slab, slab, PF_NO_TAIL)
PAGEFLAG(Checked, checked, PF_NO_COMPOUND) /* Used by some filesystems */
@@ -193,6 +193,25 @@ static inline void __slab_clear_pfmemalloc(struct slab *slab)
__folio_clear_active(slab_folio(slab));
}
+/*
+ * Slub reuse PG_workingset bit to keep track of whether it's on
+ * the per-node partial list.
+ */
+static inline bool slab_test_node_partial(const struct slab *slab)
+{
+ return folio_test_workingset((struct folio *)slab_folio(slab));
+}
+
+static inline void slab_set_node_partial(struct slab *slab)
+{
+ __folio_set_workingset(slab_folio(slab));
+}
+
+static inline void slab_clear_node_partial(struct slab *slab)
+{
+ __folio_clear_workingset(slab_folio(slab));
+}
+
static inline void *slab_address(const struct slab *slab)
{
return folio_address(slab_folio(slab));
@@ -2127,6 +2127,7 @@ __add_partial(struct kmem_cache_node *n, struct slab *slab, int tail)
list_add_tail(&slab->slab_list, &n->partial);
else
list_add(&slab->slab_list, &n->partial);
+ slab_set_node_partial(slab);
}
static inline void add_partial(struct kmem_cache_node *n,
@@ -2141,6 +2142,7 @@ static inline void remove_partial(struct kmem_cache_node *n,
{
lockdep_assert_held(&n->list_lock);
list_del(&slab->slab_list);
+ slab_clear_node_partial(slab);
n->nr_partial--;
}
@@ -4831,6 +4833,7 @@ static int __kmem_cache_do_shrink(struct kmem_cache *s)
if (free == slab->objects) {
list_move(&slab->slab_list, &discard);
+ slab_clear_node_partial(slab);
n->nr_partial--;
dec_slabs_node(s, node, slab->objects);
} else if (free <= SHRINK_PROMOTE_MAX)