From: Nhat Pham <nphamcs@gmail.com>
To: Chengming Zhou <zhouchengming@bytedance.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Yosry Ahmed <yosryahmed@google.com>,
linux-kernel@vger.kernel.org,
Johannes Weiner <hannes@cmpxchg.org>,
linux-mm@kvack.org, Chris Li <chriscli@google.com>
Subject: Re: [PATCH 1/2] mm/zswap: make sure each swapfile always have zswap rb-tree
Date: Thu, 18 Jan 2024 10:16:39 -0800 [thread overview]
Message-ID: <CAKEwX=Oj+Vb1d8aahBJ6=51XZY0rG-G06CnQeqiD8=M7KbjtZQ@mail.gmail.com> (raw)
In-Reply-To: <20240117-b4-zswap-lock-optimize-v1-1-23f6effe5775@bytedance.com>
On Wed, Jan 17, 2024 at 1:23 AM Chengming Zhou
<zhouchengming@bytedance.com> wrote:
>
> Not all zswap interfaces can handle the absence of the zswap rb-tree,
> actually only zswap_store() has handled it for now.
>
> To make things simple, we make sure each swapfile always have the
> zswap rb-tree prepared before being enabled and used. The preparation
> is unlikely to fail in practice, this patch just make it explicit.
>
> Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
This seems fine to me. IIUC, zswap_swapon() only fails when the rbtree
allocation fails, and the tree's memory footprint is small so that's
unlikely anyway.
Acked-by: Nhat Pham <nphamcs@gmail.com>
> ---
> include/linux/zswap.h | 7 +++++--
> mm/swapfile.c | 10 +++++++---
> mm/zswap.c | 7 ++++---
> 3 files changed, 16 insertions(+), 8 deletions(-)
>
> diff --git a/include/linux/zswap.h b/include/linux/zswap.h
> index 0b709f5bc65f..eca388229d9a 100644
> --- a/include/linux/zswap.h
> +++ b/include/linux/zswap.h
> @@ -30,7 +30,7 @@ struct zswap_lruvec_state {
> bool zswap_store(struct folio *folio);
> bool zswap_load(struct folio *folio);
> void zswap_invalidate(int type, pgoff_t offset);
> -void zswap_swapon(int type);
> +int zswap_swapon(int type);
> void zswap_swapoff(int type);
> void zswap_memcg_offline_cleanup(struct mem_cgroup *memcg);
> void zswap_lruvec_state_init(struct lruvec *lruvec);
> @@ -51,7 +51,10 @@ static inline bool zswap_load(struct folio *folio)
> }
>
> static inline void zswap_invalidate(int type, pgoff_t offset) {}
> -static inline void zswap_swapon(int type) {}
> +static inline int zswap_swapon(int type)
> +{
> + return 0;
> +}
> static inline void zswap_swapoff(int type) {}
> static inline void zswap_memcg_offline_cleanup(struct mem_cgroup *memcg) {}
> static inline void zswap_lruvec_state_init(struct lruvec *lruvec) {}
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 3eec686484ef..6c53ea06626b 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -2347,8 +2347,6 @@ static void enable_swap_info(struct swap_info_struct *p, int prio,
> unsigned char *swap_map,
> struct swap_cluster_info *cluster_info)
> {
> - zswap_swapon(p->type);
> -
> spin_lock(&swap_lock);
> spin_lock(&p->lock);
> setup_swap_info(p, prio, swap_map, cluster_info);
> @@ -3166,6 +3164,10 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
> if (error)
> goto bad_swap_unlock_inode;
>
> + error = zswap_swapon(p->type);
> + if (error)
> + goto free_swap_address_space;
> +
> /*
> * Flush any pending IO and dirty mappings before we start using this
> * swap device.
> @@ -3174,7 +3176,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
> error = inode_drain_writes(inode);
> if (error) {
> inode->i_flags &= ~S_SWAPFILE;
> - goto free_swap_address_space;
> + goto free_swap_zswap;
> }
>
> mutex_lock(&swapon_mutex);
> @@ -3198,6 +3200,8 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
>
> error = 0;
> goto out;
> +free_swap_zswap:
> + zswap_swapoff(p->type);
> free_swap_address_space:
> exit_swap_address_space(p->type);
> bad_swap_unlock_inode:
> diff --git a/mm/zswap.c b/mm/zswap.c
> index ca25b676048e..d88faea85978 100644
> --- a/mm/zswap.c
> +++ b/mm/zswap.c
> @@ -1519,7 +1519,7 @@ bool zswap_store(struct folio *folio)
> if (folio_test_large(folio))
> return false;
>
> - if (!zswap_enabled || !tree)
> + if (!zswap_enabled)
> return false;
>
> /*
> @@ -1772,19 +1772,20 @@ void zswap_invalidate(int type, pgoff_t offset)
> spin_unlock(&tree->lock);
> }
>
> -void zswap_swapon(int type)
> +int zswap_swapon(int type)
> {
> struct zswap_tree *tree;
>
> tree = kzalloc(sizeof(*tree), GFP_KERNEL);
> if (!tree) {
> pr_err("alloc failed, zswap disabled for swap type %d\n", type);
> - return;
> + return -ENOMEM;
> }
>
> tree->rbroot = RB_ROOT;
> spin_lock_init(&tree->lock);
> zswap_trees[type] = tree;
> + return 0;
> }
>
> void zswap_swapoff(int type)
>
> --
> b4 0.10.1
next prev parent reply other threads:[~2024-01-18 18:16 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-17 9:23 [PATCH 0/2] mm/zswap: optimize the scalability of " Chengming Zhou
2024-01-17 9:23 ` [PATCH 1/2] mm/zswap: make sure each swapfile always have " Chengming Zhou
2024-01-18 15:05 ` Johannes Weiner
2024-01-18 17:37 ` Yosry Ahmed
2024-01-18 18:16 ` Nhat Pham [this message]
2024-01-17 9:23 ` [PATCH 2/2] mm/zswap: split " Chengming Zhou
2024-01-18 15:11 ` Johannes Weiner
2024-01-19 6:20 ` Chengming Zhou
2024-01-18 19:24 ` Nhat Pham
2024-01-19 6:24 ` Chengming Zhou
2024-01-17 18:37 ` [PATCH 0/2] mm/zswap: optimize the scalability of " Yosry Ahmed
2024-01-17 23:41 ` Chris Li
2024-01-17 23:47 ` Yosry Ahmed
2024-01-18 0:17 ` Chris Li
2024-01-18 0:34 ` Yosry Ahmed
2024-01-18 1:03 ` Chris Li
2024-01-18 3:51 ` Yosry Ahmed
2024-01-18 0:49 ` Nhat Pham
2024-01-18 15:34 ` Johannes Weiner
2024-01-18 17:30 ` Yosry Ahmed
2024-01-18 18:06 ` Johannes Weiner
2024-01-18 18:37 ` Yosry Ahmed
2024-01-19 6:40 ` Chengming Zhou
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=Oj+Vb1d8aahBJ6=51XZY0rG-G06CnQeqiD8=M7KbjtZQ@mail.gmail.com' \
--to=nphamcs@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=chriscli@google.com \
--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