linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fs: drop_caches: draining pages before dropping caches
@ 2023-06-30  9:22 Andrew Yang
  2023-07-03 10:16 ` Christian Brauner
  2023-07-04 18:06 ` Andrew Morton
  0 siblings, 2 replies; 3+ messages in thread
From: Andrew Yang @ 2023-06-30  9:22 UTC (permalink / raw)
  To: Alexander Viro, Christian Brauner, Matthias Brugger,
	AngeloGioacchino Del Regno
  Cc: wsd_upstream, casper.li, Andrew Yang, linux-fsdevel, linux-kernel,
	linux-arm-kernel, linux-mediatek

We expect a file page access after dropping caches should be a major
fault, but sometimes it's still a minor fault. That's because a file
page can't be dropped if it's in a per-cpu pagevec. Draining all pages
from per-cpu pagevec to lru list before trying to drop caches.

Signed-off-by: Andrew Yang <andrew.yang@mediatek.com>
---
 fs/drop_caches.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/drop_caches.c b/fs/drop_caches.c
index e619c31b6bd9..b9575957a7c2 100644
--- a/fs/drop_caches.c
+++ b/fs/drop_caches.c
@@ -10,6 +10,7 @@
 #include <linux/writeback.h>
 #include <linux/sysctl.h>
 #include <linux/gfp.h>
+#include <linux/swap.h>
 #include "internal.h"
 
 /* A global variable is a bit ugly, but it keeps the code simple */
@@ -59,6 +60,7 @@ int drop_caches_sysctl_handler(struct ctl_table *table, int write,
 		static int stfu;
 
 		if (sysctl_drop_caches & 1) {
+			lru_add_drain_all();
 			iterate_supers(drop_pagecache_sb, NULL);
 			count_vm_event(DROP_PAGECACHE);
 		}
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] fs: drop_caches: draining pages before dropping caches
  2023-06-30  9:22 [PATCH] fs: drop_caches: draining pages before dropping caches Andrew Yang
@ 2023-07-03 10:16 ` Christian Brauner
  2023-07-04 18:06 ` Andrew Morton
  1 sibling, 0 replies; 3+ messages in thread
From: Christian Brauner @ 2023-07-03 10:16 UTC (permalink / raw)
  To: Andrew Yang, linux-mm
  Cc: Alexander Viro, Matthias Brugger, AngeloGioacchino Del Regno,
	wsd_upstream, casper.li, linux-fsdevel, linux-kernel,
	linux-arm-kernel, linux-mediatek, Matthew Wilcox

Really more suitable for -mm to review.

On Fri, Jun 30, 2023 at 05:22:02PM +0800, Andrew Yang wrote:
> We expect a file page access after dropping caches should be a major
> fault, but sometimes it's still a minor fault. That's because a file
> page can't be dropped if it's in a per-cpu pagevec. Draining all pages
> from per-cpu pagevec to lru list before trying to drop caches.
> 
> Signed-off-by: Andrew Yang <andrew.yang@mediatek.com>
> ---
>  fs/drop_caches.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/fs/drop_caches.c b/fs/drop_caches.c
> index e619c31b6bd9..b9575957a7c2 100644
> --- a/fs/drop_caches.c
> +++ b/fs/drop_caches.c
> @@ -10,6 +10,7 @@
>  #include <linux/writeback.h>
>  #include <linux/sysctl.h>
>  #include <linux/gfp.h>
> +#include <linux/swap.h>
>  #include "internal.h"
>  
>  /* A global variable is a bit ugly, but it keeps the code simple */
> @@ -59,6 +60,7 @@ int drop_caches_sysctl_handler(struct ctl_table *table, int write,
>  		static int stfu;
>  
>  		if (sysctl_drop_caches & 1) {
> +			lru_add_drain_all();
>  			iterate_supers(drop_pagecache_sb, NULL);
>  			count_vm_event(DROP_PAGECACHE);
>  		}
> -- 
> 2.18.0
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] fs: drop_caches: draining pages before dropping caches
  2023-06-30  9:22 [PATCH] fs: drop_caches: draining pages before dropping caches Andrew Yang
  2023-07-03 10:16 ` Christian Brauner
@ 2023-07-04 18:06 ` Andrew Morton
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2023-07-04 18:06 UTC (permalink / raw)
  To: Andrew Yang
  Cc: Alexander Viro, Christian Brauner, Matthias Brugger,
	AngeloGioacchino Del Regno, wsd_upstream, casper.li,
	linux-fsdevel, linux-kernel, linux-arm-kernel, linux-mediatek,
	linux-mm

On Fri, 30 Jun 2023 17:22:02 +0800 Andrew Yang <andrew.yang@mediatek.com> wrote:

> We expect a file page access after dropping caches should be a major
> fault, but sometimes it's still a minor fault. That's because a file
> page can't be dropped if it's in a per-cpu pagevec. Draining all pages
> from per-cpu pagevec to lru list before trying to drop caches.
> 
> --- a/fs/drop_caches.c
> +++ b/fs/drop_caches.c
> @@ -10,6 +10,7 @@
>  #include <linux/writeback.h>
>  #include <linux/sysctl.h>
>  #include <linux/gfp.h>
> +#include <linux/swap.h>
>  #include "internal.h"
>  
>  /* A global variable is a bit ugly, but it keeps the code simple */
> @@ -59,6 +60,7 @@ int drop_caches_sysctl_handler(struct ctl_table *table, int write,
>  		static int stfu;
>  
>  		if (sysctl_drop_caches & 1) {
> +			lru_add_drain_all();
>  			iterate_supers(drop_pagecache_sb, NULL);
>  			count_vm_event(DROP_PAGECACHE);
>  		}

um, yes.  I'm suprised that this oversight has survived 20+ years.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-07-04 18:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-30  9:22 [PATCH] fs: drop_caches: draining pages before dropping caches Andrew Yang
2023-07-03 10:16 ` Christian Brauner
2023-07-04 18:06 ` Andrew Morton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).