diff mbox series

[-next,v7,2/4] mm/zswap: skip invalid or unchanged parameter

Message ID 20230325071420.2246461-3-liushixin2@huawei.com (mailing list archive)
State New
Headers show
Series Delay the initialization of zswap | expand

Commit Message

Liu Shixin March 25, 2023, 7:14 a.m. UTC
If parameter is invalid or no change required, return directly. This can
reduces unnecessary printing.

Signed-off-by: Liu Shixin <liushixin2@huawei.com>
---
 mm/zswap.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

Comments

Sergey Senozhatsky March 26, 2023, 3:08 a.m. UTC | #1
On (23/03/25 15:14), Liu Shixin wrote:
> +++ b/mm/zswap.c
> @@ -761,15 +761,15 @@ static int __zswap_param_set(const char *val, const struct kernel_param *kp,
>  	char *s = strstrip((char *)val);
>  	int ret;
>  
> +	/* no change required */
> +	if (!strcmp(s, *(char **)kp->arg) && zswap_has_pool)
> +		return 0;
> +
>  	if (zswap_init_failed) {
>  		pr_err("can't set param, initialization failed\n");
>  		return -ENODEV;
>  	}
>  
> -	/* no change required */
> -	if (!strcmp(s, *(char **)kp->arg) && zswap_has_pool)
> -		return 0;

I probably would suggest to simply remove `*(char **)kp->arg`
from zswap code entirely, it doesn't solve any real problem
(as far as I can tell).
Sergey Senozhatsky March 26, 2023, 3:17 a.m. UTC | #2
On (23/03/25 15:14), Liu Shixin wrote:
>  static int zswap_enabled_param_set(const char *val,
>  				   const struct kernel_param *kp)
>  {
> +	bool res;
> +
> +	if (kstrtobool(val, &res))
> +		return -EINVAL;
> +
> +	/* no change required */
> +	if (res == *(bool *)kp->arg)
> +		return 0;

Bool kernel param can be any of these letters 'YyTt1NnFf0'. Doing things
to kp->arg outside of kernel/params.c is not going to be easy, let's not
even try.
Sergey Senozhatsky March 26, 2023, 4:53 a.m. UTC | #3
On (23/03/26 12:17), Sergey Senozhatsky wrote:
> On (23/03/25 15:14), Liu Shixin wrote:
> >  static int zswap_enabled_param_set(const char *val,
> >  				   const struct kernel_param *kp)
> >  {
> > +	bool res;
> > +
> > +	if (kstrtobool(val, &res))
> > +		return -EINVAL;
> > +
> > +	/* no change required */
> > +	if (res == *(bool *)kp->arg)
> > +		return 0;
> 
> Bool kernel param can be any of these letters 'YyTt1NnFf0'. Doing things
> to kp->arg outside of kernel/params.c is not going to be easy, let's not
> even try.

Please disregard my previous email. kp->arg is always true or false
at this point. I'd still prefer to not do kp->arg in zswap.
Christoph Hellwig March 26, 2023, 11:25 p.m. UTC | #4
On Sun, Mar 26, 2023 at 01:53:27PM +0900, Sergey Senozhatsky wrote:
> > > +	if (kstrtobool(val, &res))
> > > +		return -EINVAL;
> > > +
> > > +	/* no change required */
> > > +	if (res == *(bool *)kp->arg)
> > > +		return 0;
> > 
> > Bool kernel param can be any of these letters 'YyTt1NnFf0'. Doing things
> > to kp->arg outside of kernel/params.c is not going to be easy, let's not
> > even try.
> 
> Please disregard my previous email. kp->arg is always true or false
> at this point. I'd still prefer to not do kp->arg in zswap.

The whole parameter handling in zswap is a mess and I don't really
have a good idea how to solve it all.

But for this "paramter not changed" case I think we can helper a lot
by adding a core moduleparam.h helper to encapsule it.  I.e.:

static inline bool param_bool_unchanged(bool val,
		const struct kernel_param *kp)

	return val == *(bool *)kp->arg);
}

and at least keep it out of zswap.
Liu Shixin March 27, 2023, 1:22 a.m. UTC | #5
On 2023/3/27 7:25, Christoph Hellwig wrote:
> On Sun, Mar 26, 2023 at 01:53:27PM +0900, Sergey Senozhatsky wrote:
>>>> +	if (kstrtobool(val, &res))
>>>> +		return -EINVAL;
>>>> +
>>>> +	/* no change required */
>>>> +	if (res == *(bool *)kp->arg)
>>>> +		return 0;
>>> Bool kernel param can be any of these letters 'YyTt1NnFf0'. Doing things
>>> to kp->arg outside of kernel/params.c is not going to be easy, let's not
>>> even try.
>> Please disregard my previous email. kp->arg is always true or false
>> at this point. I'd still prefer to not do kp->arg in zswap.
> The whole parameter handling in zswap is a mess and I don't really
> have a good idea how to solve it all.
>
> But for this "paramter not changed" case I think we can helper a lot
> by adding a core moduleparam.h helper to encapsule it.  I.e.:
>
> static inline bool param_bool_unchanged(bool val,
> 		const struct kernel_param *kp)
>
> 	return val == *(bool *)kp->arg);
> }
>
> and at least keep it out of zswap.
Thanks for your advice. I will try this way.
>
> .
>
diff mbox series

Patch

diff --git a/mm/zswap.c b/mm/zswap.c
index 6d2b879f091e..d2adc1ffe47d 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -761,15 +761,15 @@  static int __zswap_param_set(const char *val, const struct kernel_param *kp,
 	char *s = strstrip((char *)val);
 	int ret;
 
+	/* no change required */
+	if (!strcmp(s, *(char **)kp->arg) && zswap_has_pool)
+		return 0;
+
 	if (zswap_init_failed) {
 		pr_err("can't set param, initialization failed\n");
 		return -ENODEV;
 	}
 
-	/* no change required */
-	if (!strcmp(s, *(char **)kp->arg) && zswap_has_pool)
-		return 0;
-
 	/* if this is load-time (pre-init) param setting,
 	 * don't create a pool; that's done during init.
 	 */
@@ -864,6 +864,15 @@  static int zswap_zpool_param_set(const char *val,
 static int zswap_enabled_param_set(const char *val,
 				   const struct kernel_param *kp)
 {
+	bool res;
+
+	if (kstrtobool(val, &res))
+		return -EINVAL;
+
+	/* no change required */
+	if (res == *(bool *)kp->arg)
+		return 0;
+
 	if (zswap_init_failed) {
 		pr_err("can't enable, initialization failed\n");
 		return -ENODEV;