diff mbox series

drop_caches: re-enable message after disabling

Message ID 20250216100514.3948-1-rwchen404@gmail.com (mailing list archive)
State New
Headers show
Series drop_caches: re-enable message after disabling | expand

Commit Message

Ruiwu Chen Feb. 16, 2025, 10:05 a.m. UTC
When 'echo 4 > /proc/sys/vm/drop_caches' the message is disabled,
but there is no interface to enable the message, only by restarting
the way, so I want to add the 'echo 0 > /proc/sys/vm/drop_caches'
way to enabled the message again.

Signed-off-by: Ruiwu Chen <rwchen404@gmail.com>
---
 fs/drop_caches.c | 7 +++++--
 kernel/sysctl.c  | 2 +-
 2 files changed, 6 insertions(+), 3 deletions(-)

Comments

Joel Granados Feb. 21, 2025, 8:50 a.m. UTC | #1
On Sun, Feb 16, 2025 at 06:05:14PM +0800, Ruiwu Chen wrote:
> When 'echo 4 > /proc/sys/vm/drop_caches' the message is disabled,
> but there is no interface to enable the message, only by restarting
> the way, so I want to add the 'echo 0 > /proc/sys/vm/drop_caches'
> way to enabled the message again.
> 
> Signed-off-by: Ruiwu Chen <rwchen404@gmail.com>
> ---
>  fs/drop_caches.c | 7 +++++--
>  kernel/sysctl.c  | 2 +-
>  2 files changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/drop_caches.c b/fs/drop_caches.c
> index d45ef541d848..c90cfaf9756d 100644
> --- a/fs/drop_caches.c
> +++ b/fs/drop_caches.c
> @@ -57,7 +57,7 @@ int drop_caches_sysctl_handler(const struct ctl_table *table, int write,
>  	if (ret)
>  		return ret;
>  	if (write) {
> -		static int stfu;
> +		static bool stfu;
>  
>  		if (sysctl_drop_caches & 1) {
>  			lru_add_drain_all();
> @@ -73,7 +73,10 @@ int drop_caches_sysctl_handler(const struct ctl_table *table, int write,
>  				current->comm, task_pid_nr(current),
>  				sysctl_drop_caches);
>  		}
> -		stfu |= sysctl_drop_caches & 4;
> +		if (sysctl_drop_caches == 0)
> +			stfu = false;
> +		else if (sysctl_drop_caches == 4)
> +			stfu = true;
>  	}
>  	return 0;
>  }
> diff --git a/kernel/sysctl.c b/kernel/sysctl.c
> index cb57da499ebb..f2e06e074724 100644
> --- a/kernel/sysctl.c
> +++ b/kernel/sysctl.c
> @@ -2088,7 +2088,7 @@ static const struct ctl_table vm_table[] = {
>  		.maxlen		= sizeof(int),
>  		.mode		= 0200,
>  		.proc_handler	= drop_caches_sysctl_handler,
> -		.extra1		= SYSCTL_ONE,
> +		.extra1		= SYSCTL_ZERO,
>  		.extra2		= SYSCTL_FOUR,
>  	},
>  	{
> -- 
> 2.27.0
> 

All this has changed with Kaixiong's move of the vm_table.

Please rebase this on top of sysctl-next [1] and send a V2

Best

[1] https://git.kernel.org/pub/scm/linux/kernel/git/sysctl/sysctl.git/log/?h=sysctl-next
diff mbox series

Patch

diff --git a/fs/drop_caches.c b/fs/drop_caches.c
index d45ef541d848..c90cfaf9756d 100644
--- a/fs/drop_caches.c
+++ b/fs/drop_caches.c
@@ -57,7 +57,7 @@  int drop_caches_sysctl_handler(const struct ctl_table *table, int write,
 	if (ret)
 		return ret;
 	if (write) {
-		static int stfu;
+		static bool stfu;
 
 		if (sysctl_drop_caches & 1) {
 			lru_add_drain_all();
@@ -73,7 +73,10 @@  int drop_caches_sysctl_handler(const struct ctl_table *table, int write,
 				current->comm, task_pid_nr(current),
 				sysctl_drop_caches);
 		}
-		stfu |= sysctl_drop_caches & 4;
+		if (sysctl_drop_caches == 0)
+			stfu = false;
+		else if (sysctl_drop_caches == 4)
+			stfu = true;
 	}
 	return 0;
 }
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index cb57da499ebb..f2e06e074724 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2088,7 +2088,7 @@  static const struct ctl_table vm_table[] = {
 		.maxlen		= sizeof(int),
 		.mode		= 0200,
 		.proc_handler	= drop_caches_sysctl_handler,
-		.extra1		= SYSCTL_ONE,
+		.extra1		= SYSCTL_ZERO,
 		.extra2		= SYSCTL_FOUR,
 	},
 	{