From: Hugh Dickins <hughd@google.com>
To: Chen Wandun <chenwandun@huawei.com>
Cc: akpm@linux-foundation.org, shli@kernel.org, hughd@google.com,
arnd@arndb.de, minchan@kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] swapfile: fix uncorrect statistical count about free swap
Date: Sun, 4 Dec 2022 20:13:53 -0800 (PST) [thread overview]
Message-ID: <c5c36749-d59a-345b-e7c6-925fdf17e2bd@google.com> (raw)
In-Reply-To: <20221205024726.3111808-1-chenwandun@huawei.com>
On Mon, 5 Dec 2022, Chen Wandun wrote:
> The counter of free swap turn to negtive during swapoff, this
> phenomenon can be observed in oom log, such as:
>
> 1226 total pagecache pages
> 47 pages in swap cache
> Swap cache stats: add 119633, delete 119814, find 26832/82125
> Free swap = -31796kB
> Total swap = 0kB
> 1048576 pages RAM
>
> Subtract the size of swap partition from free swap should put behind
> try_to_unuse, otherwise, it will result in negtive counter if swap
> partition is in use.
>
> Fixes: ec8acf20afb8 ("swap: add per-partition lock for swapfile")
> Signed-off-by: Chen Wandun <chenwandun@huawei.com>
No: it is intentional, and long established, that the count goes negative
during swapoff - that helps to inform you that it is in swapoff.
Hugh
> ---
> mm/swapfile.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/mm/swapfile.c b/mm/swapfile.c
> index 72e481aacd5d..5b9b695be84b 100644
> --- a/mm/swapfile.c
> +++ b/mm/swapfile.c
> @@ -2316,8 +2316,6 @@ static void setup_swap_info(struct swap_info_struct *p, int prio,
> static void _enable_swap_info(struct swap_info_struct *p)
> {
> p->flags |= SWP_WRITEOK;
> - atomic_long_add(p->pages, &nr_swap_pages);
> - total_swap_pages += p->pages;
>
> assert_spin_locked(&swap_lock);
> /*
> @@ -2353,6 +2351,8 @@ static void enable_swap_info(struct swap_info_struct *p, int prio,
> spin_lock(&swap_lock);
> spin_lock(&p->lock);
> _enable_swap_info(p);
> + atomic_long_add(p->pages, &nr_swap_pages);
> + total_swap_pages += p->pages;
> spin_unlock(&p->lock);
> spin_unlock(&swap_lock);
> }
> @@ -2444,8 +2444,6 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
> least_priority++;
> }
> plist_del(&p->list, &swap_active_head);
> - atomic_long_sub(p->pages, &nr_swap_pages);
> - total_swap_pages -= p->pages;
> p->flags &= ~SWP_WRITEOK;
> spin_unlock(&p->lock);
> spin_unlock(&swap_lock);
> @@ -2500,6 +2498,8 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
> spin_lock(&p->lock);
> }
>
> + atomic_long_sub(p->pages, &nr_swap_pages);
> + total_swap_pages -= p->pages;
> swap_file = p->swap_file;
> old_block_size = p->old_block_size;
> p->swap_file = NULL;
> --
> 2.25.1
>
>
prev parent reply other threads:[~2022-12-05 4:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-05 2:47 Chen Wandun
2022-12-05 4:13 ` Hugh Dickins [this message]
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=c5c36749-d59a-345b-e7c6-925fdf17e2bd@google.com \
--to=hughd@google.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=chenwandun@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=minchan@kernel.org \
--cc=shli@kernel.org \
/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