Skip to contentSkip to conversation

fs: drop_caches: draining pages before dropping caches

PATCH Applied Andrew Yang 3 participants 3 messages Jun 30, 2023 – Jul 4, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs: drop_caches: draining pages before dropping caches

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.

---
 fs/drop_caches.c | 2 ++
 1 file changed, 2 insertions(+)
fs/drop_caches.c +2 -0
index e619c31b6bd9..b9575957a7c2 100644
@@ -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);
 		}
Signature · 1 line
2.18.0
#1 lore raw

Really more suitable for -mm to review.

Quoted 33 lines · Andrew Yang

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.

---
 fs/drop_caches.c | 2 ++
 1 file changed, 2 insertions(+)
fs/drop_caches.c +2 -0
index e619c31b6bd9..b9575957a7c2 100644
@@ -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);
 		}
Signature · 1 line
2.18.0
maintainer
#2 lore raw
In reply to Andrew Yang
Quoted 16 lines · On Fri, 30 Jun 2023 17:22:02 +0800 Andrew Yang <[email protected]> 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.

fs/drop_caches.c +1 -0
@@ -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 */

fs/drop_caches.c int drop_caches_sysctl_handler(struct ctl_table *table, int write, · line 66

Quoted 7 lines
fs/drop_caches.c +1 -0
@@ -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.