From: Kairui Song <ryncsn@gmail.com>
To: Kemeng Shi <shikemeng@huaweicloud.com>
Cc: akpm@linux-foundation.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/6] mm, swap: avoid BUG_ON in relocate_cluster()
Date: Sun, 23 Feb 2025 02:43:42 +0800 [thread overview]
Message-ID: <CAMgjq7DwUciLTcw-jsCzTz9bz+KMKqzbzCYSr58ZFhCNKPVpaw@mail.gmail.com> (raw)
In-Reply-To: <20250222160850.505274-4-shikemeng@huaweicloud.com>
On Sat, Feb 22, 2025 at 3:12 PM Kemeng Shi <shikemeng@huaweicloud.com> wrote:
>
> If allocation is racy with swapoff, we may call free_cluster for cluster
> already in free list and trigger bug on as following:
Maybe capitalize this "bug on" to BUG_ON to be consistent with the title.
> Allocation Swapoff
> cluster_alloc_swap_entry
> ...
> /* may get a free cluster with offset */
> offset = xxx;
> if (offset)
> ci = lock_cluster(si, offset);
>
> ...
> del_from_avail_list(p, true);
> si->flags &= ~SWP_WRITEOK;
>
> alloc_swap_scan_cluster(si, ci, ...)
> ...
> /* failed to alloc entry from free entry */
> if (!cluster_alloc_range(...))
> break;
> ...
> /* add back a free cluster */
> relocate_cluster(si, ci);
> if (!ci->count)
> free_cluster(si, ci);
> VM_BUG_ON(ci->flags == CLUSTER_FLAG_FREE);
>
> Despite bug_on could be triggered, call free_cluster() for free cluster
> only move cluster to tail of list and should be fine.
>
> Check cluster is not free before calling free_cluster() in
> relocate_cluster() to avoid bug_on.
Same here.
>
> Fixes: 3b644773eefda ("mm, swap: reduce contention on device lock")
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
> ---
> mm/swapfile.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 425126c0a07d..fc45b9d56639 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -653,7 +653,8 @@ static void relocate_cluster(struct swap_info_struct *si,
> return;
>
> if (!ci->count) {
> - free_cluster(si, ci);
> + if (ci->flags != CLUSTER_FLAG_FREE)
> + free_cluster(si, ci);
> } else if (ci->count != SWAPFILE_CLUSTER) {
> if (ci->flags != CLUSTER_FLAG_FRAG)
> move_cluster(si, ci, &si->frag_clusters[ci->order],
> --
> 2.30.0
Thanks, other than minor commit message issue:
Reviewed-by: Kairui Song <kasong@tencent.com>
next prev parent reply other threads:[~2025-02-22 18:44 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-22 16:08 [PATCH 0/6] Some random fixes and cleanups to mm/swapfile.c Kemeng Shi
2025-02-22 16:08 ` [PATCH 1/6] mm: swap: avoid losting cluster in swap_reclaim_full_clusters() Kemeng Shi
2025-02-22 17:19 ` Kairui Song
2025-02-24 1:17 ` Kemeng Shi
2025-02-22 16:08 ` [PATCH 2/6] mm: swap: use correct step in loop to wait all clusters in wait_for_allocation() Kemeng Shi
2025-02-22 17:32 ` Kairui Song
2025-02-22 16:08 ` [PATCH 3/6] mm, swap: avoid BUG_ON in relocate_cluster() Kemeng Shi
2025-02-22 18:43 ` Kairui Song [this message]
2025-02-22 16:08 ` [PATCH 4/6] mm, swap: remove setting SWAP_MAP_BAD for discard cluster Kemeng Shi
2025-02-24 1:24 ` Kairui Song
2025-02-22 16:08 ` [PATCH 5/6] mm, swap: correct comment in swap_usage_sub() Kemeng Shi
2025-02-22 16:08 ` [PATCH 6/6] mm: swap: remove stale comment of swap_reclaim_full_clusters() Kemeng Shi
2025-02-23 1:44 ` [PATCH 0/6] Some random fixes and cleanups to mm/swapfile.c Andrew Morton
2025-02-24 1:27 ` Kemeng Shi
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=CAMgjq7DwUciLTcw-jsCzTz9bz+KMKqzbzCYSr58ZFhCNKPVpaw@mail.gmail.com \
--to=ryncsn@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=shikemeng@huaweicloud.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