Skip to contentSkip to conversation

fanotify10, fanotify23: fix cleanup of vfs_cache_pressure

PATCH In review Amir Goldstein 2 participants 5 messages Jun 23, 2025 – Jun 25, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fanotify10, fanotify23: fix cleanup of vfs_cache_pressure

Avoid setting vfs_cache_pressure to zero if test was not run because kernel does not support fanotify.

---
 testcases/kernel/syscalls/fanotify/fanotify10.c | 8 ++++----
 testcases/kernel/syscalls/fanotify/fanotify23.c | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify10.c +4 -4
index ccb4f55df..2d33416f3 100644
@@ -102,7 +102,6 @@ static int ignore_mark_unsupported;
 #define DROP_CACHES_FILE "/proc/sys/vm/drop_caches"
 #define CACHE_PRESSURE_FILE "/proc/sys/vm/vfs_cache_pressure"
 
-static int old_cache_pressure;
 static pid_t child_pid;
 static int bind_mount_created;
 static unsigned int num_classes = NUM_CLASSES;
@@ -925,7 +924,6 @@ static void setup(void)
 	SAFE_MKDIR(MNT2_PATH, 0755);
 	mount_cycle();
 
-	SAFE_FILE_SCANF(CACHE_PRESSURE_FILE, "%d", &old_cache_pressure);
 	/* Set high priority for evicting inodes */
 	SAFE_FILE_PRINTF(CACHE_PRESSURE_FILE, "500");
 }
@@ -939,8 +937,6 @@ static void cleanup(void)
 	if (bind_mount_created)
 		SAFE_UMOUNT(MNT2_PATH);
 
-	SAFE_FILE_PRINTF(CACHE_PRESSURE_FILE, "%d", old_cache_pressure);
-
 	for (i = 0; i < max_file_multi; i++) {
 		char path[PATH_MAX];
 
@@ -972,6 +968,10 @@ static struct tst_test test = {
 		TEST_APP,
 		NULL
 	},
+	.save_restore = (const struct tst_path_val[]) {
+		{CACHE_PRESSURE_FILE, NULL, TST_SR_TCONF},
+		{}
+	},
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "9bdda4e9cf2d"},
 		{"linux-git", "2f02fd3fa13e"},
testcases/kernel/syscalls/fanotify/fanotify23.c +4 -4
index 26c9e87fb..36c7779da 100644
@@ -35,7 +35,6 @@
 #define DROP_CACHES_FILE "/proc/sys/vm/drop_caches"
 #define CACHE_PRESSURE_FILE "/proc/sys/vm/vfs_cache_pressure"
 
-static int old_cache_pressure;
 static int fd_notify;
 
 static unsigned long long event_set[EVENT_MAX];
@@ -234,7 +233,6 @@ static void setup(void)
 						FAN_MARK_FILESYSTEM,
 						FAN_ATTRIB, MOUNT_PATH);
 
-	SAFE_FILE_SCANF(CACHE_PRESSURE_FILE, "%d", &old_cache_pressure);
 	/* Set high priority for evicting inodes */
 	SAFE_FILE_PRINTF(CACHE_PRESSURE_FILE, "500");
 }
@@ -243,8 +241,6 @@ static void cleanup(void)
 {
 	if (fd_notify > 0)
 		SAFE_CLOSE(fd_notify);
-
-	SAFE_FILE_PRINTF(CACHE_PRESSURE_FILE, "%d", old_cache_pressure);
 }
 
 static struct tst_test test = {
@@ -259,6 +255,10 @@ static struct tst_test test = {
 		{.type = "ext2"},
 		{}
 	},
+	.save_restore = (const struct tst_path_val[]) {
+		{CACHE_PRESSURE_FILE, NULL, TST_SR_TCONF},
+		{}
+	},
 };
 
 #else
Signature · 5 lines
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Acked-by Wei Gao on v1 1/1
#1 lore raw
Quoted 93 lines · Amir Goldstein

Avoid setting vfs_cache_pressure to zero if test was not run because kernel does not support fanotify.

---
 testcases/kernel/syscalls/fanotify/fanotify10.c | 8 ++++----
 testcases/kernel/syscalls/fanotify/fanotify23.c | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify10.c +4 -4
index ccb4f55df..2d33416f3 100644
@@ -102,7 +102,6 @@ static int ignore_mark_unsupported;
 #define DROP_CACHES_FILE "/proc/sys/vm/drop_caches"
 #define CACHE_PRESSURE_FILE "/proc/sys/vm/vfs_cache_pressure"
 
-static int old_cache_pressure;
 static pid_t child_pid;
 static int bind_mount_created;
 static unsigned int num_classes = NUM_CLASSES;
@@ -925,7 +924,6 @@ static void setup(void)
 	SAFE_MKDIR(MNT2_PATH, 0755);
 	mount_cycle();
 
-	SAFE_FILE_SCANF(CACHE_PRESSURE_FILE, "%d", &old_cache_pressure);
 	/* Set high priority for evicting inodes */
 	SAFE_FILE_PRINTF(CACHE_PRESSURE_FILE, "500");
 }
@@ -939,8 +937,6 @@ static void cleanup(void)
 	if (bind_mount_created)
 		SAFE_UMOUNT(MNT2_PATH);
 
-	SAFE_FILE_PRINTF(CACHE_PRESSURE_FILE, "%d", old_cache_pressure);
-
 	for (i = 0; i < max_file_multi; i++) {
 		char path[PATH_MAX];
 
@@ -972,6 +968,10 @@ static struct tst_test test = {
 		TEST_APP,
 		NULL
 	},
+	.save_restore = (const struct tst_path_val[]) {
+		{CACHE_PRESSURE_FILE, NULL, TST_SR_TCONF},
+		{}
+	},
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "9bdda4e9cf2d"},
 		{"linux-git", "2f02fd3fa13e"},
testcases/kernel/syscalls/fanotify/fanotify23.c +4 -4
index 26c9e87fb..36c7779da 100644
@@ -35,7 +35,6 @@
 #define DROP_CACHES_FILE "/proc/sys/vm/drop_caches"
 #define CACHE_PRESSURE_FILE "/proc/sys/vm/vfs_cache_pressure"
 
-static int old_cache_pressure;
 static int fd_notify;
 
 static unsigned long long event_set[EVENT_MAX];
@@ -234,7 +233,6 @@ static void setup(void)
 						FAN_MARK_FILESYSTEM,
 						FAN_ATTRIB, MOUNT_PATH);
 
-	SAFE_FILE_SCANF(CACHE_PRESSURE_FILE, "%d", &old_cache_pressure);
 	/* Set high priority for evicting inodes */
 	SAFE_FILE_PRINTF(CACHE_PRESSURE_FILE, "500");
 }
@@ -243,8 +241,6 @@ static void cleanup(void)
 {
 	if (fd_notify > 0)
 		SAFE_CLOSE(fd_notify);
-
-	SAFE_FILE_PRINTF(CACHE_PRESSURE_FILE, "%d", old_cache_pressure);
 }
 
 static struct tst_test test = {
@@ -259,6 +255,10 @@ static struct tst_test test = {
 		{.type = "ext2"},
 		{}
 	},
+	.save_restore = (const struct tst_path_val[]) {
+		{CACHE_PRESSURE_FILE, NULL, TST_SR_TCONF},
+		{}
+	},
 };
 
 #else
Signature · 1 line
2.43.0

For me this patch more looks like an improvement instead of a fix. Thanks for your patch.

Quoted 4 lines
Signature · 2 lines
-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw
Quoted 92 lines · Wei Gao
Quoted 90 lines · Amir Goldstein

Avoid setting vfs_cache_pressure to zero if test was not run because kernel does not support fanotify.

---
 testcases/kernel/syscalls/fanotify/fanotify10.c | 8 ++++----
 testcases/kernel/syscalls/fanotify/fanotify23.c | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify10.c +4 -4
index ccb4f55df..2d33416f3 100644
@@ -102,7 +102,6 @@ static int ignore_mark_unsupported;
 #define DROP_CACHES_FILE "/proc/sys/vm/drop_caches"
 #define CACHE_PRESSURE_FILE "/proc/sys/vm/vfs_cache_pressure"
 
-static int old_cache_pressure;
 static pid_t child_pid;
 static int bind_mount_created;
 static unsigned int num_classes = NUM_CLASSES;
@@ -925,7 +924,6 @@ static void setup(void)
      SAFE_MKDIR(MNT2_PATH, 0755);
      mount_cycle();
 
-     SAFE_FILE_SCANF(CACHE_PRESSURE_FILE, "%d", &old_cache_pressure);
      /* Set high priority for evicting inodes */
      SAFE_FILE_PRINTF(CACHE_PRESSURE_FILE, "500");
 }
@@ -939,8 +937,6 @@ static void cleanup(void)
      if (bind_mount_created)
              SAFE_UMOUNT(MNT2_PATH);
 
-     SAFE_FILE_PRINTF(CACHE_PRESSURE_FILE, "%d", old_cache_pressure);
-
      for (i = 0; i < max_file_multi; i++) {
              char path[PATH_MAX];
 
@@ -972,6 +968,10 @@ static struct tst_test test = {
              TEST_APP,
              NULL
      },
+     .save_restore = (const struct tst_path_val[]) {
+             {CACHE_PRESSURE_FILE, NULL, TST_SR_TCONF},
+             {}
+     },
      .tags = (const struct tst_tag[]) {
              {"linux-git", "9bdda4e9cf2d"},
              {"linux-git", "2f02fd3fa13e"},
testcases/kernel/syscalls/fanotify/fanotify23.c +4 -4
index 26c9e87fb..36c7779da 100644
@@ -35,7 +35,6 @@
 #define DROP_CACHES_FILE "/proc/sys/vm/drop_caches"
 #define CACHE_PRESSURE_FILE "/proc/sys/vm/vfs_cache_pressure"
 
-static int old_cache_pressure;
 static int fd_notify;
 
 static unsigned long long event_set[EVENT_MAX];
@@ -234,7 +233,6 @@ static void setup(void)
                                              FAN_MARK_FILESYSTEM,
                                              FAN_ATTRIB, MOUNT_PATH);
 
-     SAFE_FILE_SCANF(CACHE_PRESSURE_FILE, "%d", &old_cache_pressure);
      /* Set high priority for evicting inodes */
      SAFE_FILE_PRINTF(CACHE_PRESSURE_FILE, "500");
 }
@@ -243,8 +241,6 @@ static void cleanup(void)
 {
      if (fd_notify > 0)
              SAFE_CLOSE(fd_notify);
-
-     SAFE_FILE_PRINTF(CACHE_PRESSURE_FILE, "%d", old_cache_pressure);
 }
 
 static struct tst_test test = {
@@ -259,6 +255,10 @@ static struct tst_test test = {
              {.type = "ext2"},
              {}
      },
+     .save_restore = (const struct tst_path_val[]) {
+             {CACHE_PRESSURE_FILE, NULL, TST_SR_TCONF},
+             {}
+     },
 };
 
Quoted 7 lines
Quoted 3 lines
testcases/kernel/syscalls/fanotify/fanotify23.c +0 -1
 #else
--

2.43.0

For me this patch more looks like an improvement instead of a fix. Thanks for your patch.

It is a fix to the problem reported by Al Viro in the linked message.

Thanks,
Amir.

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw
Quoted 101 lines · Amir Goldstein
Quoted 92 lines · Wei Gao
Quoted 90 lines · Amir Goldstein

Avoid setting vfs_cache_pressure to zero if test was not run because kernel does not support fanotify.

---
 testcases/kernel/syscalls/fanotify/fanotify10.c | 8 ++++----
 testcases/kernel/syscalls/fanotify/fanotify23.c | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify10.c +4 -4
index ccb4f55df..2d33416f3 100644
@@ -102,7 +102,6 @@ static int ignore_mark_unsupported;
 #define DROP_CACHES_FILE "/proc/sys/vm/drop_caches"
 #define CACHE_PRESSURE_FILE "/proc/sys/vm/vfs_cache_pressure"
 
-static int old_cache_pressure;
 static pid_t child_pid;
 static int bind_mount_created;
 static unsigned int num_classes = NUM_CLASSES;
@@ -925,7 +924,6 @@ static void setup(void)
      SAFE_MKDIR(MNT2_PATH, 0755);
      mount_cycle();
 
-     SAFE_FILE_SCANF(CACHE_PRESSURE_FILE, "%d", &old_cache_pressure);
      /* Set high priority for evicting inodes */
      SAFE_FILE_PRINTF(CACHE_PRESSURE_FILE, "500");
 }
@@ -939,8 +937,6 @@ static void cleanup(void)
      if (bind_mount_created)
              SAFE_UMOUNT(MNT2_PATH);
 
-     SAFE_FILE_PRINTF(CACHE_PRESSURE_FILE, "%d", old_cache_pressure);
-
      for (i = 0; i < max_file_multi; i++) {
              char path[PATH_MAX];
 
@@ -972,6 +968,10 @@ static struct tst_test test = {
              TEST_APP,
              NULL
      },
+     .save_restore = (const struct tst_path_val[]) {
+             {CACHE_PRESSURE_FILE, NULL, TST_SR_TCONF},
+             {}
+     },
      .tags = (const struct tst_tag[]) {
              {"linux-git", "9bdda4e9cf2d"},
              {"linux-git", "2f02fd3fa13e"},
testcases/kernel/syscalls/fanotify/fanotify23.c +4 -4
index 26c9e87fb..36c7779da 100644
@@ -35,7 +35,6 @@
 #define DROP_CACHES_FILE "/proc/sys/vm/drop_caches"
 #define CACHE_PRESSURE_FILE "/proc/sys/vm/vfs_cache_pressure"
 
-static int old_cache_pressure;
 static int fd_notify;
 
 static unsigned long long event_set[EVENT_MAX];
@@ -234,7 +233,6 @@ static void setup(void)
                                              FAN_MARK_FILESYSTEM,
                                              FAN_ATTRIB, MOUNT_PATH);
 
-     SAFE_FILE_SCANF(CACHE_PRESSURE_FILE, "%d", &old_cache_pressure);
      /* Set high priority for evicting inodes */
      SAFE_FILE_PRINTF(CACHE_PRESSURE_FILE, "500");
 }
@@ -243,8 +241,6 @@ static void cleanup(void)
 {
      if (fd_notify > 0)
              SAFE_CLOSE(fd_notify);
-
-     SAFE_FILE_PRINTF(CACHE_PRESSURE_FILE, "%d", old_cache_pressure);
 }
 
 static struct tst_test test = {
@@ -259,6 +255,10 @@ static struct tst_test test = {
              {.type = "ext2"},
              {}
      },
+     .save_restore = (const struct tst_path_val[]) {
+             {CACHE_PRESSURE_FILE, NULL, TST_SR_TCONF},
+             {}
+     },
 };
 
Quoted 7 lines
Quoted 3 lines
testcases/kernel/syscalls/fanotify/fanotify23.c +0 -1
 #else
--

2.43.0

For me this patch more looks like an improvement instead of a fix. Thanks for your patch.

Quoted 1 line

It is a fix to the problem reported by Al Viro in the linked message.

Thanks, after check email carefully, i guess the the test skip initial old_cache_pressure in setup but do wirte 0 to old_cache_pressure in cleanup trigger the issue.

Quoted 3 lines

Thanks,
Amir.

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp