[LTP] [PATCH] fanotify10, fanotify23: fix cleanup of vfs_cache_pressure

Wei Gao wegao@suse.com
Tue Jun 24 18:38:30 CEST 2025


On Mon, Jun 23, 2025 at 09:37:17AM +0200, Amir Goldstein wrote:
> Avoid setting vfs_cache_pressure to zero if test was not run
> because kernel does not support fanotify.
> 
> Reported-by: Al Viro <viro@zeniv.linux.org.uk>
> Link: https://lore.kernel.org/linux-fsdevel/20250622215140.GX1880847@ZenIV/
> Signed-off-by: Amir Goldstein <amir73il@gmail.com>
> ---
>  testcases/kernel/syscalls/fanotify/fanotify10.c | 8 ++++----
>  testcases/kernel/syscalls/fanotify/fanotify23.c | 8 ++++----
>  2 files changed, 8 insertions(+), 8 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/fanotify/fanotify10.c b/testcases/kernel/syscalls/fanotify/fanotify10.c
> index ccb4f55df..2d33416f3 100644
> --- a/testcases/kernel/syscalls/fanotify/fanotify10.c
> +++ b/testcases/kernel/syscalls/fanotify/fanotify10.c
> @@ -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"},
> diff --git a/testcases/kernel/syscalls/fanotify/fanotify23.c b/testcases/kernel/syscalls/fanotify/fanotify23.c
> index 26c9e87fb..36c7779da 100644
> --- a/testcases/kernel/syscalls/fanotify/fanotify23.c
> +++ b/testcases/kernel/syscalls/fanotify/fanotify23.c
> @@ -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
> -- 
> 2.43.0

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

Acked-by: Wei Gao <wegao@suse.com>
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp


More information about the ltp mailing list