From: Joshua Hahn <joshua.hahnjy@gmail.com>
To: Yajun Deng <yajun.deng@linux.dev>
Cc: akpm@linux-foundation.org, vbabka@suse.cz, surenb@google.com,
mhocko@suse.com, jackmanb@google.com, hannes@cmpxchg.org,
ziy@nvidia.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm/page_alloc: Avoid duplicate NR_FREE_PAGES updates in move_to_free_list()
Date: Fri, 9 Jan 2026 08:31:39 -0800 [thread overview]
Message-ID: <20260109163140.1605599-1-joshua.hahnjy@gmail.com> (raw)
In-Reply-To: <20260109105121.328780-1-yajun.deng@linux.dev>
On Fri, 9 Jan 2026 18:51:21 +0800 Yajun Deng <yajun.deng@linux.dev> wrote:
> In move_to_free_list(), when a page block changes its migration type,
> we need to update free page counts for both the old and new types.
> Originally, this was done by two calls to account_freepages(), which
> updates NR_FREE_PAGES and also type-specific counters. However, this
> causes NR_FREE_PAGES to be updated twice, while the net change is zero
> in most cases.
>
> This patch introduces a new function account_freepages_both() that
> updates the statistics for both old and new migration types in one go.
> It avoids the double update of NR_FREE_PAGES by computing the net change
> only when the isolation status changes.
>
> The optimization avoid duplicate NR_FREE_PAGES updates in
> move_to_free_list().
Hi Yajun,
I hope you are doing well, thank you for the patch! I was hoping to better
understand the motivation behind this patch.
From my perspective, I believe that the current state of the code is
not optimal, but it is also not problematic. account_freepages seems like
a relatively cheap function (at the core, it's just some atomic operations).
Personally I also think that semantically, the code currently makes sense;
we are doing the accounting for the old mounttype, then for the new mounttype,
in a way that cancels out. And given that there is still some cases where
the work doesn't end up canceling out due to one of the mounttypes being
MIGRATE_ISOLATE, I think that there is enough purpose in making the two
calls to do the accounting twice.
On the other hand I think there is only one place in the codebase that
will use account_freepages_both, so it might make the burden to understand
the code a bit higher.
What do you think? I don't have a strong stance on whether the performance
effects are big here (if this change indeed has a big performance implication,
then we should definitely go forth with this!) but I do believe the current
code is quite semantically sound and more readable.
Thank you again for the patch. I hope you have a great day!
Joshua
next prev parent reply other threads:[~2026-01-09 16:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-09 10:51 Yajun Deng
2026-01-09 16:31 ` Joshua Hahn [this message]
2026-01-11 0:10 ` Andrew Morton
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=20260109163140.1605599-1-joshua.hahnjy@gmail.com \
--to=joshua.hahnjy@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=hannes@cmpxchg.org \
--cc=jackmanb@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
--cc=yajun.deng@linux.dev \
--cc=ziy@nvidia.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