Re: [PATCH -next 2/3] mm/zswap: delay the initializaton of zswap until the first enablement

From: Andrew Morton
Date: Thu Aug 25 2022 - 22:01:52 EST


On Thu, 25 Aug 2022 22:20:36 +0800 Liu Shixin <liushixin2@xxxxxxxxxx> wrote:

> In the initialization of zswap, about 18MB memory will be allocated for
> zswap_pool in my machine. Since not all users use zswap, the memory may be
> wasted. Save the memory for these users by delaying the initialization of
> zswap to first enablement.
>
> ...
>
> +static int __init init_zswap(void)
> +{
> + /* skip init if zswap is disabled when system startup */
> + if (!zswap_enabled)
> + return 0;
> + return zswap_setup();
> +}
> +

I can't resist.

--- a/mm/zswap.c~mm-zswap-delay-the-initializaton-of-zswap-until-the-first-enablement-fix
+++ a/mm/zswap.c
@@ -1556,7 +1556,7 @@ cache_fail:
return -ENOMEM;
}

-static int __init init_zswap(void)
+static int __init zswap_init(void)
{
/* skip init if zswap is disabled when system startup */
if (!zswap_enabled)
@@ -1565,7 +1565,7 @@ static int __init init_zswap(void)
}

/* must be late so crypto has time to come up */
-late_initcall(init_zswap);
+late_initcall(zswap_init);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Seth Jennings <sjennings@xxxxxxxxxxxxxx>");

It's the usual way and makes things more consistent.