diff mbox series

[v6,3/3] mm: vmscan: refactor updating current->reclaim_state

Message ID 20230413104034.1086717-4-yosryahmed@google.com (mailing list archive)
State New
Headers show
Series Ignore non-LRU-based reclaim in memcg reclaim | expand

Commit Message

Yosry Ahmed April 13, 2023, 10:40 a.m. UTC
During reclaim, we keep track of pages reclaimed from other means than
LRU-based reclaim through scan_control->reclaim_state->reclaimed_slab,
which we stash a pointer to in current task_struct.

However, we keep track of more than just reclaimed slab pages through
this. We also use it for clean file pages dropped through pruned inodes,
and xfs buffer pages freed. Rename reclaimed_slab to reclaimed, and add
a helper function that wraps updating it through current, so that future
changes to this logic are contained within include/linux/swap.h.

Signed-off-by: Yosry Ahmed <yosryahmed@google.com>
---
 fs/inode.c           |  3 +--
 fs/xfs/xfs_buf.c     |  3 +--
 include/linux/swap.h | 17 ++++++++++++++++-
 mm/slab.c            |  3 +--
 mm/slob.c            |  6 ++----
 mm/slub.c            |  5 ++---
 6 files changed, 23 insertions(+), 14 deletions(-)

Comments

David Hildenbrand April 13, 2023, 11:20 a.m. UTC | #1
On 13.04.23 12:40, Yosry Ahmed wrote:
> During reclaim, we keep track of pages reclaimed from other means than
> LRU-based reclaim through scan_control->reclaim_state->reclaimed_slab,
> which we stash a pointer to in current task_struct.
> 
> However, we keep track of more than just reclaimed slab pages through
> this. We also use it for clean file pages dropped through pruned inodes,
> and xfs buffer pages freed. Rename reclaimed_slab to reclaimed, and add

Would "reclaimed_non_lru" be more expressive? Then,

mm_account_reclaimed_pages() -> mm_account_non_lru_reclaimed_pages()


Apart from that LGTM.
Yosry Ahmed April 13, 2023, 11:29 a.m. UTC | #2
On Thu, Apr 13, 2023 at 4:21 AM David Hildenbrand <david@redhat.com> wrote:
>
> On 13.04.23 12:40, Yosry Ahmed wrote:
> > During reclaim, we keep track of pages reclaimed from other means than
> > LRU-based reclaim through scan_control->reclaim_state->reclaimed_slab,
> > which we stash a pointer to in current task_struct.
> >
> > However, we keep track of more than just reclaimed slab pages through
> > this. We also use it for clean file pages dropped through pruned inodes,
> > and xfs buffer pages freed. Rename reclaimed_slab to reclaimed, and add
>
> Would "reclaimed_non_lru" be more expressive? Then,
>
> mm_account_reclaimed_pages() -> mm_account_non_lru_reclaimed_pages()
>
>
> Apart from that LGTM.

Thanks!

I suck at naming things. If you think "reclaimed_non_lru" is better,
then we can do that. FWIW mm_account_reclaimed_pages() was taken from
a suggestion from Dave Chinner. My initial version had a terrible
name: report_freed_pages(), so I am happy with whatever you see fit.

Should I re-spin for this or can we change it in place?

>
> --
> Thanks,
>
> David / dhildenb
>
David Hildenbrand April 13, 2023, 11:31 a.m. UTC | #3
On 13.04.23 13:29, Yosry Ahmed wrote:
> On Thu, Apr 13, 2023 at 4:21 AM David Hildenbrand <david@redhat.com> wrote:
>>
>> On 13.04.23 12:40, Yosry Ahmed wrote:
>>> During reclaim, we keep track of pages reclaimed from other means than
>>> LRU-based reclaim through scan_control->reclaim_state->reclaimed_slab,
>>> which we stash a pointer to in current task_struct.
>>>
>>> However, we keep track of more than just reclaimed slab pages through
>>> this. We also use it for clean file pages dropped through pruned inodes,
>>> and xfs buffer pages freed. Rename reclaimed_slab to reclaimed, and add
>>
>> Would "reclaimed_non_lru" be more expressive? Then,
>>
>> mm_account_reclaimed_pages() -> mm_account_non_lru_reclaimed_pages()
>>
>>
>> Apart from that LGTM.
> 
> Thanks!
> 
> I suck at naming things. If you think "reclaimed_non_lru" is better,
> then we can do that. FWIW mm_account_reclaimed_pages() was taken from
> a suggestion from Dave Chinner. My initial version had a terrible
> name: report_freed_pages(), so I am happy with whatever you see fit.
> 
> Should I re-spin for this or can we change it in place?

Respin would be good, but maybe wait a bit more on other comments. I'm 
bad at naming things as well :)
Dave Chinner April 13, 2023, 9 p.m. UTC | #4
On Thu, Apr 13, 2023 at 04:29:43AM -0700, Yosry Ahmed wrote:
> On Thu, Apr 13, 2023 at 4:21 AM David Hildenbrand <david@redhat.com> wrote:
> >
> > On 13.04.23 12:40, Yosry Ahmed wrote:
> > > During reclaim, we keep track of pages reclaimed from other means than
> > > LRU-based reclaim through scan_control->reclaim_state->reclaimed_slab,
> > > which we stash a pointer to in current task_struct.
> > >
> > > However, we keep track of more than just reclaimed slab pages through
> > > this. We also use it for clean file pages dropped through pruned inodes,
> > > and xfs buffer pages freed. Rename reclaimed_slab to reclaimed, and add
> >
> > Would "reclaimed_non_lru" be more expressive? Then,
> >
> > mm_account_reclaimed_pages() -> mm_account_non_lru_reclaimed_pages()
> >
> >
> > Apart from that LGTM.
> 
> Thanks!
> 
> I suck at naming things. If you think "reclaimed_non_lru" is better,
> then we can do that. FWIW mm_account_reclaimed_pages() was taken from
> a suggestion from Dave Chinner. My initial version had a terrible
> name: report_freed_pages(), so I am happy with whatever you see fit.
> 
> Should I re-spin for this or can we change it in place?

I don't care for the noise all the bikeshed painting has generated
for a simple change like this.  If it's a fix for a bug, and the
naming is good enough, just merge it already, ok?

-Dave.
Yosry Ahmed April 13, 2023, 9:38 p.m. UTC | #5
On Thu, Apr 13, 2023 at 2:01 PM Dave Chinner <david@fromorbit.com> wrote:
>
> On Thu, Apr 13, 2023 at 04:29:43AM -0700, Yosry Ahmed wrote:
> > On Thu, Apr 13, 2023 at 4:21 AM David Hildenbrand <david@redhat.com> wrote:
> > >
> > > On 13.04.23 12:40, Yosry Ahmed wrote:
> > > > During reclaim, we keep track of pages reclaimed from other means than
> > > > LRU-based reclaim through scan_control->reclaim_state->reclaimed_slab,
> > > > which we stash a pointer to in current task_struct.
> > > >
> > > > However, we keep track of more than just reclaimed slab pages through
> > > > this. We also use it for clean file pages dropped through pruned inodes,
> > > > and xfs buffer pages freed. Rename reclaimed_slab to reclaimed, and add
> > >
> > > Would "reclaimed_non_lru" be more expressive? Then,
> > >
> > > mm_account_reclaimed_pages() -> mm_account_non_lru_reclaimed_pages()
> > >
> > >
> > > Apart from that LGTM.
> >
> > Thanks!
> >
> > I suck at naming things. If you think "reclaimed_non_lru" is better,
> > then we can do that. FWIW mm_account_reclaimed_pages() was taken from
> > a suggestion from Dave Chinner. My initial version had a terrible
> > name: report_freed_pages(), so I am happy with whatever you see fit.
> >
> > Should I re-spin for this or can we change it in place?
>
> I don't care for the noise all the bikeshed painting has generated
> for a simple change like this.  If it's a fix for a bug, and the
> naming is good enough, just merge it already, ok?

Sorry for all the noise. I think this version is in good enough shape.

Andrew, could you please replace v4 with this v6 without patch 2 as
multiple people pointed out that it is unneeded? Sorry for the hassle.

>
> -Dave.
> --
> Dave Chinner
> david@fromorbit.com
Michal Hocko April 14, 2023, 8:18 a.m. UTC | #6
On Thu 13-04-23 10:40:34, Yosry Ahmed wrote:
> During reclaim, we keep track of pages reclaimed from other means than
> LRU-based reclaim through scan_control->reclaim_state->reclaimed_slab,
> which we stash a pointer to in current task_struct.
> 
> However, we keep track of more than just reclaimed slab pages through
> this. We also use it for clean file pages dropped through pruned inodes,
> and xfs buffer pages freed. Rename reclaimed_slab to reclaimed, and add
> a helper function that wraps updating it through current, so that future
> changes to this logic are contained within include/linux/swap.h.
> 
> Signed-off-by: Yosry Ahmed <yosryahmed@google.com>

Acked-by: Michal Hocko <mhocko@suse.com>
Andrew Morton April 14, 2023, 9:47 p.m. UTC | #7
On Thu, 13 Apr 2023 14:38:03 -0700 Yosry Ahmed <yosryahmed@google.com> wrote:

> > > I suck at naming things. If you think "reclaimed_non_lru" is better,
> > > then we can do that. FWIW mm_account_reclaimed_pages() was taken from
> > > a suggestion from Dave Chinner. My initial version had a terrible
> > > name: report_freed_pages(), so I am happy with whatever you see fit.
> > >
> > > Should I re-spin for this or can we change it in place?
> >
> > I don't care for the noise all the bikeshed painting has generated
> > for a simple change like this.  If it's a fix for a bug, and the
> > naming is good enough, just merge it already, ok?
> 
> Sorry for all the noise. I think this version is in good enough shape.
> 
> Andrew, could you please replace v4 with this v6 without patch 2 as
> multiple people pointed out that it is unneeded? Sorry for the hassle.

I like patch 2!

mm.git presently has the v6 series.  All of it ;)
Yosry Ahmed April 14, 2023, 11:11 p.m. UTC | #8
On Fri, Apr 14, 2023 at 2:47 PM Andrew Morton <akpm@linux-foundation.org> wrote:
>
> On Thu, 13 Apr 2023 14:38:03 -0700 Yosry Ahmed <yosryahmed@google.com> wrote:
>
> > > > I suck at naming things. If you think "reclaimed_non_lru" is better,
> > > > then we can do that. FWIW mm_account_reclaimed_pages() was taken from
> > > > a suggestion from Dave Chinner. My initial version had a terrible
> > > > name: report_freed_pages(), so I am happy with whatever you see fit.
> > > >
> > > > Should I re-spin for this or can we change it in place?
> > >
> > > I don't care for the noise all the bikeshed painting has generated
> > > for a simple change like this.  If it's a fix for a bug, and the
> > > naming is good enough, just merge it already, ok?
> >
> > Sorry for all the noise. I think this version is in good enough shape.
> >
> > Andrew, could you please replace v4 with this v6 without patch 2 as
> > multiple people pointed out that it is unneeded? Sorry for the hassle.
>
> I like patch 2!
>
> mm.git presently has the v6 series.  All of it ;)

Thanks Andrew :)
diff mbox series

Patch

diff --git a/fs/inode.c b/fs/inode.c
index 4558dc2f1355..e60fcc41faf1 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -864,8 +864,7 @@  static enum lru_status inode_lru_isolate(struct list_head *item,
 				__count_vm_events(KSWAPD_INODESTEAL, reap);
 			else
 				__count_vm_events(PGINODESTEAL, reap);
-			if (current->reclaim_state)
-				current->reclaim_state->reclaimed_slab += reap;
+			mm_account_reclaimed_pages(reap);
 		}
 		iput(inode);
 		spin_lock(lru_lock);
diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
index 54c774af6e1c..15d1e5a7c2d3 100644
--- a/fs/xfs/xfs_buf.c
+++ b/fs/xfs/xfs_buf.c
@@ -286,8 +286,7 @@  xfs_buf_free_pages(
 		if (bp->b_pages[i])
 			__free_page(bp->b_pages[i]);
 	}
-	if (current->reclaim_state)
-		current->reclaim_state->reclaimed_slab += bp->b_page_count;
+	mm_account_reclaimed_pages(bp->b_page_count);
 
 	if (bp->b_pages != bp->b_page_array)
 		kmem_free(bp->b_pages);
diff --git a/include/linux/swap.h b/include/linux/swap.h
index 209a425739a9..e131ac155fb9 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -153,13 +153,28 @@  union swap_header {
  * memory reclaim
  */
 struct reclaim_state {
-	unsigned long reclaimed_slab;
+	/* pages reclaimed outside of LRU-based reclaim */
+	unsigned long reclaimed;
 #ifdef CONFIG_LRU_GEN
 	/* per-thread mm walk data */
 	struct lru_gen_mm_walk *mm_walk;
 #endif
 };
 
+/*
+ * mm_account_reclaimed_pages(): account reclaimed pages outside of LRU-based
+ * reclaim
+ * @pages: number of pages reclaimed
+ *
+ * If the current process is undergoing a reclaim operation, increment the
+ * number of reclaimed pages by @pages.
+ */
+static inline void mm_account_reclaimed_pages(unsigned long pages)
+{
+	if (current->reclaim_state)
+		current->reclaim_state->reclaimed += pages;
+}
+
 #ifdef __KERNEL__
 
 struct address_space;
diff --git a/mm/slab.c b/mm/slab.c
index dabc2a671fc6..64bf1de817b2 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -1392,8 +1392,7 @@  static void kmem_freepages(struct kmem_cache *cachep, struct slab *slab)
 	smp_wmb();
 	__folio_clear_slab(folio);
 
-	if (current->reclaim_state)
-		current->reclaim_state->reclaimed_slab += 1 << order;
+	mm_account_reclaimed_pages(1 << order);
 	unaccount_slab(slab, order, cachep);
 	__free_pages(&folio->page, order);
 }
diff --git a/mm/slob.c b/mm/slob.c
index fe567fcfa3a3..79cc8680c973 100644
--- a/mm/slob.c
+++ b/mm/slob.c
@@ -61,7 +61,7 @@ 
 #include <linux/slab.h>
 
 #include <linux/mm.h>
-#include <linux/swap.h> /* struct reclaim_state */
+#include <linux/swap.h> /* mm_account_reclaimed_pages() */
 #include <linux/cache.h>
 #include <linux/init.h>
 #include <linux/export.h>
@@ -211,9 +211,7 @@  static void slob_free_pages(void *b, int order)
 {
 	struct page *sp = virt_to_page(b);
 
-	if (current->reclaim_state)
-		current->reclaim_state->reclaimed_slab += 1 << order;
-
+	mm_account_reclaimed_pages(1 << order);
 	mod_node_page_state(page_pgdat(sp), NR_SLAB_UNRECLAIMABLE_B,
 			    -(PAGE_SIZE << order));
 	__free_pages(sp, order);
diff --git a/mm/slub.c b/mm/slub.c
index 39327e98fce3..7aa30eef8235 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -11,7 +11,7 @@ 
  */
 
 #include <linux/mm.h>
-#include <linux/swap.h> /* struct reclaim_state */
+#include <linux/swap.h> /* mm_account_reclaimed_pages() */
 #include <linux/module.h>
 #include <linux/bit_spinlock.h>
 #include <linux/interrupt.h>
@@ -2063,8 +2063,7 @@  static void __free_slab(struct kmem_cache *s, struct slab *slab)
 	/* Make the mapping reset visible before clearing the flag */
 	smp_wmb();
 	__folio_clear_slab(folio);
-	if (current->reclaim_state)
-		current->reclaim_state->reclaimed_slab += pages;
+	mm_account_reclaimed_pages(pages);
 	unaccount_slab(slab, order, s);
 	__free_pages(&folio->page, order);
 }