* [PATCH] list_lru: expand list_lru_add() docs with info about sublists
@ 2024-11-28 12:12 Alice Ryhl
2024-11-28 21:12 ` Dave Chinner
2024-11-28 23:05 ` Matthew Wilcox
0 siblings, 2 replies; 6+ messages in thread
From: Alice Ryhl @ 2024-11-28 12:12 UTC (permalink / raw)
To: Dave Chinner, Andrew Morton
Cc: Johannes Weiner, Nhat Pham, Qi Zheng, Roman Gushchin,
Muchun Song, Michal Hocko, Shakeel Butt, linux-mm, cgroups,
linux-kernel, Alice Ryhl
The documentation for list_lru_add() and list_lru_del() has not been
updated since lru lists were originally introduced by commit
a38e40824844 ("list: add a new LRU list type"). Back then, list_lru
stored all of the items in a single list, but the implementation has
since been expanded to use many sublists internally.
Thus, update the docs to mention that the requirements about not using
the item with several lists at the same time also applies not using
different sublists. Also mention that list_lru items are reparented when
the memcg is deleted as discussed on the LKML [1].
Link: https://lore.kernel.org/all/Z0eXrllVhRI9Ag5b@dread.disaster.area/ [1]
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
include/linux/list_lru.h | 48 +++++++++++++++++++++++++++++++++++-------------
1 file changed, 35 insertions(+), 13 deletions(-)
diff --git a/include/linux/list_lru.h b/include/linux/list_lru.h
index 05c166811f6b..d4fc967247ae 100644
--- a/include/linux/list_lru.h
+++ b/include/linux/list_lru.h
@@ -91,15 +91,26 @@ void memcg_reparent_list_lrus(struct mem_cgroup *memcg, struct mem_cgroup *paren
* @memcg: the cgroup of the sublist to add the item to.
*
* If the element is already part of a list, this function returns doing
- * nothing. Therefore the caller does not need to keep state about whether or
- * not the element already belongs in the list and is allowed to lazy update
- * it. Note however that this is valid for *a* list, not *this* list. If
- * the caller organize itself in a way that elements can be in more than
- * one type of list, it is up to the caller to fully remove the item from
- * the previous list (with list_lru_del() for instance) before moving it
- * to @lru.
+ * nothing. This means that it is not necessary to keep state about whether or
+ * not the element already belongs in the list. That said, this logic only
+ * works if the item is in *this* list. If the item might be in some other
+ * list, then you cannot rely on this check and you must remove it from the
+ * other list before trying to insert it.
*
- * Return: true if the list was updated, false otherwise
+ * The lru list consists of many sublists internally; the @nid and @memcg
+ * parameters are used to determine which sublist to insert the item into.
+ * It's important to use the right value of @nid and @memcg when deleting the
+ * item, since it might otherwise get deleted from the wrong sublist.
+ *
+ * This also applies when attempting to insert the item multiple times - if
+ * the item is currently in one sublist and you call list_lru_add() again, you
+ * must pass the right @nid and @memcg parameters so that the same sublist is
+ * used.
+ *
+ * You must ensure that the memcg is not freed during this call (e.g., with
+ * rcu or by taking a css refcnt).
+ *
+ * Return value: true if the item was added, false otherwise
*/
bool list_lru_add(struct list_lru *lru, struct list_head *item, int nid,
struct mem_cgroup *memcg);
@@ -113,7 +124,7 @@ bool list_lru_add(struct list_lru *lru, struct list_head *item, int nid,
* memcg of the sublist is determined by @item list_head. This assumption is
* valid for slab objects LRU such as dentries, inodes, etc.
*
- * Return value: true if the list was updated, false otherwise
+ * Return value: true if the item was added, false otherwise
*/
bool list_lru_add_obj(struct list_lru *lru, struct list_head *item);
@@ -125,10 +136,21 @@ bool list_lru_add_obj(struct list_lru *lru, struct list_head *item);
* @memcg: the cgroup of the sublist to delete the item from.
*
* This function works analogously as list_lru_add() in terms of list
- * manipulation. The comments about an element already pertaining to
- * a list are also valid for list_lru_del().
+ * manipulation.
+ *
+ * The comments in list_lru_add() about an element already being in a list are
+ * also valid for list_lru_del(), that is, you can delete an item that has
+ * already been removed or never been added. However, if the item is in a
+ * list, it must be in *this* list, and you must pass the right value of @nid
+ * and @memcg so that the right sublist is used.
+ *
+ * You must ensure that the memcg is not freed during this call (e.g., with
+ * rcu or by taking a css refcnt). When a memcg is deleted, list_lru entries
+ * are automatically moved to the parent memcg. This is done in a race-free
+ * way, so during deletion of an memcg both the old and new memcg will resolve
+ * to the same sublist internally.
*
- * Return: true if the list was updated, false otherwise
+ * Return value: true if the item was removed, false otherwise
*/
bool list_lru_del(struct list_lru *lru, struct list_head *item, int nid,
struct mem_cgroup *memcg);
@@ -142,7 +164,7 @@ bool list_lru_del(struct list_lru *lru, struct list_head *item, int nid,
* memcg of the sublist is determined by @item list_head. This assumption is
* valid for slab objects LRU such as dentries, inodes, etc.
*
- * Return value: true if the list was updated, false otherwise.
+ * Return value: true if the item was removed, false otherwise.
*/
bool list_lru_del_obj(struct list_lru *lru, struct list_head *item);
---
base-commit: b86545e02e8c22fb89218f29d381fa8e8b91d815
change-id: 20241128-list_lru_memcg_docs-d736e1d81a7f
Best regards,
--
Alice Ryhl <aliceryhl@google.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] list_lru: expand list_lru_add() docs with info about sublists
2024-11-28 12:12 [PATCH] list_lru: expand list_lru_add() docs with info about sublists Alice Ryhl
@ 2024-11-28 21:12 ` Dave Chinner
2024-11-28 23:05 ` Matthew Wilcox
1 sibling, 0 replies; 6+ messages in thread
From: Dave Chinner @ 2024-11-28 21:12 UTC (permalink / raw)
To: Alice Ryhl
Cc: Andrew Morton, Johannes Weiner, Nhat Pham, Qi Zheng,
Roman Gushchin, Muchun Song, Michal Hocko, Shakeel Butt,
linux-mm, cgroups, linux-kernel
On Thu, Nov 28, 2024 at 12:12:11PM +0000, Alice Ryhl wrote:
> The documentation for list_lru_add() and list_lru_del() has not been
> updated since lru lists were originally introduced by commit
> a38e40824844 ("list: add a new LRU list type"). Back then, list_lru
> stored all of the items in a single list, but the implementation has
> since been expanded to use many sublists internally.
>
> Thus, update the docs to mention that the requirements about not using
> the item with several lists at the same time also applies not using
> different sublists. Also mention that list_lru items are reparented when
> the memcg is deleted as discussed on the LKML [1].
>
> Link: https://lore.kernel.org/all/Z0eXrllVhRI9Ag5b@dread.disaster.area/ [1]
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> ---
> include/linux/list_lru.h | 48 +++++++++++++++++++++++++++++++++++-------------
> 1 file changed, 35 insertions(+), 13 deletions(-)
Looks fine to me.
Reviewed-by: Dave Chinner <dchinner@redhat.com>
--
Dave Chinner
david@fromorbit.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] list_lru: expand list_lru_add() docs with info about sublists
2024-11-28 12:12 [PATCH] list_lru: expand list_lru_add() docs with info about sublists Alice Ryhl
2024-11-28 21:12 ` Dave Chinner
@ 2024-11-28 23:05 ` Matthew Wilcox
2024-11-29 8:58 ` Alice Ryhl
1 sibling, 1 reply; 6+ messages in thread
From: Matthew Wilcox @ 2024-11-28 23:05 UTC (permalink / raw)
To: Alice Ryhl
Cc: Dave Chinner, Andrew Morton, Johannes Weiner, Nhat Pham,
Qi Zheng, Roman Gushchin, Muchun Song, Michal Hocko,
Shakeel Butt, linux-mm, cgroups, linux-kernel
On Thu, Nov 28, 2024 at 12:12:11PM +0000, Alice Ryhl wrote:
> - * Return: true if the list was updated, false otherwise
> + * Return value: true if the item was added, false otherwise
This is an incorrect change. The section is always called 'Return', not
'Return value'; see Documentation/doc-guide/kernel-doc.rst. And I
think it was fine to say "list was updated" rather than "item was
added". They're basically synonyms.
> - * Return value: true if the list was updated, false otherwise
> + * Return value: true if the item was added, false otherwise
Ditto (and other similar changes)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] list_lru: expand list_lru_add() docs with info about sublists
2024-11-28 23:05 ` Matthew Wilcox
@ 2024-11-29 8:58 ` Alice Ryhl
2024-11-29 14:36 ` Matthew Wilcox
0 siblings, 1 reply; 6+ messages in thread
From: Alice Ryhl @ 2024-11-29 8:58 UTC (permalink / raw)
To: Matthew Wilcox
Cc: Dave Chinner, Andrew Morton, Johannes Weiner, Nhat Pham,
Qi Zheng, Roman Gushchin, Muchun Song, Michal Hocko,
Shakeel Butt, linux-mm, cgroups, linux-kernel
On Fri, Nov 29, 2024 at 12:05 AM Matthew Wilcox <willy@infradead.org> wrote:
>
> On Thu, Nov 28, 2024 at 12:12:11PM +0000, Alice Ryhl wrote:
> > - * Return: true if the list was updated, false otherwise
> > + * Return value: true if the item was added, false otherwise
>
> This is an incorrect change. The section is always called 'Return', not
> 'Return value'; see Documentation/doc-guide/kernel-doc.rst. And I
> think it was fine to say "list was updated" rather than "item was
> added". They're basically synonyms.
>
> > - * Return value: true if the list was updated, false otherwise
> > + * Return value: true if the item was added, false otherwise
>
> Ditto (and other similar changes)
Oh I had not noticed the "Return"/"Return value" change. It must be a
copy-paste artifact from list_lru_del_obj() which already uses "Return
value". Would you like me to change that one to 'Return'?
As for the other rewording, I thought it was slightly more
unambiguous, but don't feel strongly about it.
Alice
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] list_lru: expand list_lru_add() docs with info about sublists
2024-11-29 8:58 ` Alice Ryhl
@ 2024-11-29 14:36 ` Matthew Wilcox
2024-11-29 14:59 ` Alice Ryhl
0 siblings, 1 reply; 6+ messages in thread
From: Matthew Wilcox @ 2024-11-29 14:36 UTC (permalink / raw)
To: Alice Ryhl
Cc: Dave Chinner, Andrew Morton, Johannes Weiner, Nhat Pham,
Qi Zheng, Roman Gushchin, Muchun Song, Michal Hocko,
Shakeel Butt, linux-mm, cgroups, linux-kernel
On Fri, Nov 29, 2024 at 09:58:27AM +0100, Alice Ryhl wrote:
> Oh I had not noticed the "Return"/"Return value" change. It must be a
> copy-paste artifact from list_lru_del_obj() which already uses "Return
> value". Would you like me to change that one to 'Return'?
Yes please!
> As for the other rewording, I thought it was slightly more
> unambiguous, but don't feel strongly about it.
I don't feel strongly about it either.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] list_lru: expand list_lru_add() docs with info about sublists
2024-11-29 14:36 ` Matthew Wilcox
@ 2024-11-29 14:59 ` Alice Ryhl
0 siblings, 0 replies; 6+ messages in thread
From: Alice Ryhl @ 2024-11-29 14:59 UTC (permalink / raw)
To: Matthew Wilcox
Cc: Dave Chinner, Andrew Morton, Johannes Weiner, Nhat Pham,
Qi Zheng, Roman Gushchin, Muchun Song, Michal Hocko,
Shakeel Butt, linux-mm, cgroups, linux-kernel
On Fri, Nov 29, 2024 at 3:36 PM Matthew Wilcox <willy@infradead.org> wrote:
>
> On Fri, Nov 29, 2024 at 09:58:27AM +0100, Alice Ryhl wrote:
> > Oh I had not noticed the "Return"/"Return value" change. It must be a
> > copy-paste artifact from list_lru_del_obj() which already uses "Return
> > value". Would you like me to change that one to 'Return'?
>
> Yes please!
Done in v2:
https://lore.kernel.org/all/20241129-list_lru_memcg_docs-v2-1-e285ff1c481b@google.com/
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-11-29 15:00 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-28 12:12 [PATCH] list_lru: expand list_lru_add() docs with info about sublists Alice Ryhl
2024-11-28 21:12 ` Dave Chinner
2024-11-28 23:05 ` Matthew Wilcox
2024-11-29 8:58 ` Alice Ryhl
2024-11-29 14:36 ` Matthew Wilcox
2024-11-29 14:59 ` Alice Ryhl
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox