linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Nhat Pham <nphamcs@gmail.com>
To: Johannes Weiner <hannes@cmpxchg.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Yosry Ahmed <yosryahmed@google.com>,
	 Chengming Zhou <zhouchengming@bytedance.com>,
	linux-mm@kvack.org,  linux-kernel@vger.kernel.org
Subject: Re: [PATCH 13/20] mm: zswap: function ordering: pool params
Date: Tue, 30 Jan 2024 13:22:15 -0800	[thread overview]
Message-ID: <CAKEwX=NgCmqpxQOENfv+8CPzQLnwv=1A38GJROSXFdC3CEOPFw@mail.gmail.com> (raw)
In-Reply-To: <20240130014208.565554-14-hannes@cmpxchg.org>

On Mon, Jan 29, 2024 at 5:42 PM Johannes Weiner <hannes@cmpxchg.org> wrote:
>
> The parameters primarily control pool attributes. Move those
> operations up to the pool section.
>
> Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
> ---
>  mm/zswap.c | 312 ++++++++++++++++++++++++++---------------------------
>  1 file changed, 156 insertions(+), 156 deletions(-)
>
> diff --git a/mm/zswap.c b/mm/zswap.c
> index 168afd6767b3..e650fc587116 100644
> --- a/mm/zswap.c
> +++ b/mm/zswap.c
> @@ -590,6 +590,162 @@ static struct zswap_pool *zswap_pool_find_get(char *type, char *compressor)
>         return NULL;
>  }
>
> +/*********************************
> +* param callbacks
> +**********************************/
> +
> +static bool zswap_pool_changed(const char *s, const struct kernel_param *kp)
> +{
> +       /* no change required */
> +       if (!strcmp(s, *(char **)kp->arg) && zswap_has_pool)
> +               return false;
> +       return true;
> +}
> +
> +/* val must be a null-terminated string */
> +static int __zswap_param_set(const char *val, const struct kernel_param *kp,
> +                            char *type, char *compressor)
> +{
> +       struct zswap_pool *pool, *put_pool = NULL;
> +       char *s = strstrip((char *)val);
> +       int ret = 0;
> +       bool new_pool = false;
> +
> +       mutex_lock(&zswap_init_lock);
> +       switch (zswap_init_state) {
> +       case ZSWAP_UNINIT:
> +               /* if this is load-time (pre-init) param setting,
> +                * don't create a pool; that's done during init.
> +                */
> +               ret = param_set_charp(s, kp);
> +               break;
> +       case ZSWAP_INIT_SUCCEED:
> +               new_pool = zswap_pool_changed(s, kp);
> +               break;
> +       case ZSWAP_INIT_FAILED:
> +               pr_err("can't set param, initialization failed\n");
> +               ret = -ENODEV;
> +       }
> +       mutex_unlock(&zswap_init_lock);
> +
> +       /* no need to create a new pool, return directly */
> +       if (!new_pool)
> +               return ret;
> +
> +       if (!type) {
> +               if (!zpool_has_pool(s)) {
> +                       pr_err("zpool %s not available\n", s);
> +                       return -ENOENT;
> +               }
> +               type = s;
> +       } else if (!compressor) {
> +               if (!crypto_has_acomp(s, 0, 0)) {
> +                       pr_err("compressor %s not available\n", s);
> +                       return -ENOENT;
> +               }
> +               compressor = s;
> +       } else {
> +               WARN_ON(1);
> +               return -EINVAL;
> +       }
> +
> +       spin_lock(&zswap_pools_lock);
> +
> +       pool = zswap_pool_find_get(type, compressor);
> +       if (pool) {
> +               zswap_pool_debug("using existing", pool);
> +               WARN_ON(pool == zswap_pool_current());
> +               list_del_rcu(&pool->list);
> +       }
> +
> +       spin_unlock(&zswap_pools_lock);
> +
> +       if (!pool)
> +               pool = zswap_pool_create(type, compressor);
> +
> +       if (pool)
> +               ret = param_set_charp(s, kp);
> +       else
> +               ret = -EINVAL;
> +
> +       spin_lock(&zswap_pools_lock);
> +
> +       if (!ret) {
> +               put_pool = zswap_pool_current();
> +               list_add_rcu(&pool->list, &zswap_pools);
> +               zswap_has_pool = true;
> +       } else if (pool) {
> +               /* add the possibly pre-existing pool to the end of the pools
> +                * list; if it's new (and empty) then it'll be removed and
> +                * destroyed by the put after we drop the lock
> +                */
> +               list_add_tail_rcu(&pool->list, &zswap_pools);
> +               put_pool = pool;
> +       }
> +
> +       spin_unlock(&zswap_pools_lock);
> +
> +       if (!zswap_has_pool && !pool) {
> +               /* if initial pool creation failed, and this pool creation also
> +                * failed, maybe both compressor and zpool params were bad.
> +                * Allow changing this param, so pool creation will succeed
> +                * when the other param is changed. We already verified this
> +                * param is ok in the zpool_has_pool() or crypto_has_acomp()
> +                * checks above.
> +                */
> +               ret = param_set_charp(s, kp);
> +       }
> +
> +       /* drop the ref from either the old current pool,
> +        * or the new pool we failed to add
> +        */
> +       if (put_pool)
> +               zswap_pool_put(put_pool);
> +
> +       return ret;
> +}
> +
> +static int zswap_compressor_param_set(const char *val,
> +                                     const struct kernel_param *kp)
> +{
> +       return __zswap_param_set(val, kp, zswap_zpool_type, NULL);
> +}
> +
> +static int zswap_zpool_param_set(const char *val,
> +                                const struct kernel_param *kp)
> +{
> +       return __zswap_param_set(val, kp, NULL, zswap_compressor);
> +}
> +
> +static int zswap_enabled_param_set(const char *val,
> +                                  const struct kernel_param *kp)
> +{
> +       int ret = -ENODEV;
> +
> +       /* if this is load-time (pre-init) param setting, only set param. */
> +       if (system_state != SYSTEM_RUNNING)
> +               return param_set_bool(val, kp);
> +
> +       mutex_lock(&zswap_init_lock);
> +       switch (zswap_init_state) {
> +       case ZSWAP_UNINIT:
> +               if (zswap_setup())
> +                       break;
> +               fallthrough;
> +       case ZSWAP_INIT_SUCCEED:
> +               if (!zswap_has_pool)
> +                       pr_err("can't enable, no pool configured\n");
> +               else
> +                       ret = param_set_bool(val, kp);
> +               break;
> +       case ZSWAP_INIT_FAILED:
> +               pr_err("can't enable, initialization failed\n");
> +       }
> +       mutex_unlock(&zswap_init_lock);
> +
> +       return ret;
> +}
> +
>  /* should be called under RCU */
>  #ifdef CONFIG_MEMCG
>  static inline struct mem_cgroup *mem_cgroup_from_entry(struct zswap_entry *entry)
> @@ -1163,162 +1319,6 @@ static void shrink_worker(struct work_struct *w)
>         zswap_pool_put(pool);
>  }
>
> -/*********************************
> -* param callbacks
> -**********************************/
> -
> -static bool zswap_pool_changed(const char *s, const struct kernel_param *kp)
> -{
> -       /* no change required */
> -       if (!strcmp(s, *(char **)kp->arg) && zswap_has_pool)
> -               return false;
> -       return true;
> -}
> -
> -/* val must be a null-terminated string */
> -static int __zswap_param_set(const char *val, const struct kernel_param *kp,
> -                            char *type, char *compressor)
> -{
> -       struct zswap_pool *pool, *put_pool = NULL;
> -       char *s = strstrip((char *)val);
> -       int ret = 0;
> -       bool new_pool = false;
> -
> -       mutex_lock(&zswap_init_lock);
> -       switch (zswap_init_state) {
> -       case ZSWAP_UNINIT:
> -               /* if this is load-time (pre-init) param setting,
> -                * don't create a pool; that's done during init.
> -                */
> -               ret = param_set_charp(s, kp);
> -               break;
> -       case ZSWAP_INIT_SUCCEED:
> -               new_pool = zswap_pool_changed(s, kp);
> -               break;
> -       case ZSWAP_INIT_FAILED:
> -               pr_err("can't set param, initialization failed\n");
> -               ret = -ENODEV;
> -       }
> -       mutex_unlock(&zswap_init_lock);
> -
> -       /* no need to create a new pool, return directly */
> -       if (!new_pool)
> -               return ret;
> -
> -       if (!type) {
> -               if (!zpool_has_pool(s)) {
> -                       pr_err("zpool %s not available\n", s);
> -                       return -ENOENT;
> -               }
> -               type = s;
> -       } else if (!compressor) {
> -               if (!crypto_has_acomp(s, 0, 0)) {
> -                       pr_err("compressor %s not available\n", s);
> -                       return -ENOENT;
> -               }
> -               compressor = s;
> -       } else {
> -               WARN_ON(1);
> -               return -EINVAL;
> -       }
> -
> -       spin_lock(&zswap_pools_lock);
> -
> -       pool = zswap_pool_find_get(type, compressor);
> -       if (pool) {
> -               zswap_pool_debug("using existing", pool);
> -               WARN_ON(pool == zswap_pool_current());
> -               list_del_rcu(&pool->list);
> -       }
> -
> -       spin_unlock(&zswap_pools_lock);
> -
> -       if (!pool)
> -               pool = zswap_pool_create(type, compressor);
> -
> -       if (pool)
> -               ret = param_set_charp(s, kp);
> -       else
> -               ret = -EINVAL;
> -
> -       spin_lock(&zswap_pools_lock);
> -
> -       if (!ret) {
> -               put_pool = zswap_pool_current();
> -               list_add_rcu(&pool->list, &zswap_pools);
> -               zswap_has_pool = true;
> -       } else if (pool) {
> -               /* add the possibly pre-existing pool to the end of the pools
> -                * list; if it's new (and empty) then it'll be removed and
> -                * destroyed by the put after we drop the lock
> -                */
> -               list_add_tail_rcu(&pool->list, &zswap_pools);
> -               put_pool = pool;
> -       }
> -
> -       spin_unlock(&zswap_pools_lock);
> -
> -       if (!zswap_has_pool && !pool) {
> -               /* if initial pool creation failed, and this pool creation also
> -                * failed, maybe both compressor and zpool params were bad.
> -                * Allow changing this param, so pool creation will succeed
> -                * when the other param is changed. We already verified this
> -                * param is ok in the zpool_has_pool() or crypto_has_acomp()
> -                * checks above.
> -                */
> -               ret = param_set_charp(s, kp);
> -       }
> -
> -       /* drop the ref from either the old current pool,
> -        * or the new pool we failed to add
> -        */
> -       if (put_pool)
> -               zswap_pool_put(put_pool);
> -
> -       return ret;
> -}
> -
> -static int zswap_compressor_param_set(const char *val,
> -                                     const struct kernel_param *kp)
> -{
> -       return __zswap_param_set(val, kp, zswap_zpool_type, NULL);
> -}
> -
> -static int zswap_zpool_param_set(const char *val,
> -                                const struct kernel_param *kp)
> -{
> -       return __zswap_param_set(val, kp, NULL, zswap_compressor);
> -}
> -
> -static int zswap_enabled_param_set(const char *val,
> -                                  const struct kernel_param *kp)
> -{
> -       int ret = -ENODEV;
> -
> -       /* if this is load-time (pre-init) param setting, only set param. */
> -       if (system_state != SYSTEM_RUNNING)
> -               return param_set_bool(val, kp);
> -
> -       mutex_lock(&zswap_init_lock);
> -       switch (zswap_init_state) {
> -       case ZSWAP_UNINIT:
> -               if (zswap_setup())
> -                       break;
> -               fallthrough;
> -       case ZSWAP_INIT_SUCCEED:
> -               if (!zswap_has_pool)
> -                       pr_err("can't enable, no pool configured\n");
> -               else
> -                       ret = param_set_bool(val, kp);
> -               break;
> -       case ZSWAP_INIT_FAILED:
> -               pr_err("can't enable, initialization failed\n");
> -       }
> -       mutex_unlock(&zswap_init_lock);
> -
> -       return ret;
> -}
> -
>  static bool zswap_compress(struct folio *folio, struct zswap_entry *entry)
>  {
>         struct crypto_acomp_ctx *acomp_ctx;
> --
> 2.43.0
>

Reviewed-by: Nhat Pham <nphamcs@gmail.com>


  reply	other threads:[~2024-01-30 21:22 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-30  1:36 [PATCH 00/20] mm: zswap: cleanups Johannes Weiner
2024-01-30  1:36 ` [PATCH 01/20] mm: zswap: rename zswap_free_entry to zswap_entry_free Johannes Weiner
2024-01-30  3:13   ` Chengming Zhou
     [not found]     ` <20240130031938.GA772725@cmpxchg.org>
2024-01-30  3:21       ` Chengming Zhou
2024-01-30  3:36   ` Chengming Zhou
2024-01-30  8:08   ` Yosry Ahmed
2024-01-30  9:11   ` Nhat Pham
2024-01-30  1:36 ` [PATCH 02/20] mm: zswap: inline and remove zswap_entry_find_get() Johannes Weiner
2024-01-30  3:37   ` Chengming Zhou
2024-01-30  8:09   ` Yosry Ahmed
2024-01-30 16:24   ` Nhat Pham
2024-01-30  1:36 ` [PATCH 03/20] mm: zswap: move zswap_invalidate_entry() to related functions Johannes Weiner
2024-01-30  3:38   ` Chengming Zhou
2024-01-30  8:09   ` Yosry Ahmed
2024-01-30 16:25   ` Nhat Pham
2024-01-30  1:36 ` [PATCH 04/20] mm: zswap: warn when referencing a dead entry Johannes Weiner
2024-01-30  3:39   ` [External] " Chengming Zhou
2024-01-30  8:10   ` Yosry Ahmed
2024-01-30 16:27   ` Nhat Pham
2024-01-30  1:36 ` [PATCH 05/20] mm: zswap: clean up zswap_entry_put() Johannes Weiner
2024-01-30  3:39   ` Chengming Zhou
2024-01-30  7:51   ` Yosry Ahmed
2024-01-30 16:31     ` Nhat Pham
2024-01-30 17:02       ` Yosry Ahmed
2024-01-30  8:10   ` Yosry Ahmed
2024-01-30  1:36 ` [PATCH 06/20] mm: zswap: rename __zswap_load() to zswap_decompress() Johannes Weiner
2024-01-30  3:19   ` Chengming Zhou
2024-01-30  8:11   ` Yosry Ahmed
2024-01-30 16:33   ` Nhat Pham
2024-01-30  1:36 ` [PATCH 07/20] mm: zswap: break out zwap_compress() Johannes Weiner
2024-01-30  3:23   ` Chengming Zhou
2024-01-30  8:11   ` Yosry Ahmed
2024-01-30 16:21   ` Nhat Pham
2024-01-30  1:36 ` [PATCH 08/20] mm: zswap: further cleanup zswap_store() Johannes Weiner
2024-01-30  3:35   ` Chengming Zhou
2024-01-30  8:12   ` Yosry Ahmed
2024-01-30 18:18   ` Nhat Pham
2024-01-30  1:36 ` [PATCH 09/20] mm: zswap: simplify zswap_invalidate() Johannes Weiner
2024-01-30  3:35   ` Chengming Zhou
2024-01-30  8:12   ` Yosry Ahmed
2024-01-30 16:50   ` Nhat Pham
2024-01-30  1:36 ` [PATCH 10/20] mm: zswap: function ordering: pool alloc & free Johannes Weiner
2024-01-30 19:31   ` Nhat Pham
2024-01-30  1:36 ` [PATCH 11/20] mm: zswap: function ordering: pool refcounting Johannes Weiner
2024-01-30 20:13   ` Nhat Pham
2024-01-31 11:23     ` Johannes Weiner
2024-01-31 23:23       ` Nhat Pham
2024-01-30  1:36 ` [PATCH 12/20] mm: zswap: function ordering: zswap_pools Johannes Weiner
2024-01-30 21:16   ` Nhat Pham
2024-01-30  1:36 ` [PATCH 13/20] mm: zswap: function ordering: pool params Johannes Weiner
2024-01-30 21:22   ` Nhat Pham [this message]
2024-01-30  1:36 ` [PATCH 14/20] mm: zswap: function ordering: public lru api Johannes Weiner
2024-01-30 23:47   ` Nhat Pham
2024-01-31 11:40     ` Johannes Weiner
2024-01-30  1:36 ` [PATCH 15/20] mm: zswap: function ordering: move entry sections out of LRU section Johannes Weiner
2024-01-30 23:48   ` Nhat Pham
2024-01-30  1:36 ` [PATCH 16/20] mm: zswap: function ordering: move entry section out of tree section Johannes Weiner
2024-01-31 23:24   ` Nhat Pham
2024-01-30  1:36 ` [PATCH 17/20] mm: zswap: function ordering: compress & decompress functions Johannes Weiner
2024-01-31 23:25   ` Nhat Pham
2024-01-30  1:36 ` [PATCH 18/20] mm: zswap: function ordering: per-cpu compression infra Johannes Weiner
2024-01-31 23:33   ` Nhat Pham
2024-01-30  1:36 ` [PATCH 19/20] mm: zswap: function ordering: writeback Johannes Weiner
2024-01-31 23:36   ` Nhat Pham
2024-01-30  1:36 ` [PATCH 20/20] mm: zswap: function ordering: shrink_memcg_cb Johannes Weiner
2024-01-31 23:37   ` Nhat Pham
2024-01-30  8:16 ` [PATCH 00/20] mm: zswap: cleanups Yosry Ahmed
2024-01-30 12:21   ` Sergey Senozhatsky
2024-01-30 15:52     ` Johannes Weiner
2024-01-31  1:03       ` Sergey Senozhatsky
2024-01-30 15:46   ` Johannes Weiner
2024-01-30 17:15     ` Yosry Ahmed
2024-01-30 23:54   ` Nhat Pham

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAKEwX=NgCmqpxQOENfv+8CPzQLnwv=1A38GJROSXFdC3CEOPFw@mail.gmail.com' \
    --to=nphamcs@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=yosryahmed@google.com \
    --cc=zhouchengming@bytedance.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox