[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20260110161048.0aa9c7e32af3e690a671ef8d@linux-foundation.org>
Date: Sat, 10 Jan 2026 16:10:48 -0800
From: Andrew Morton <akpm@...ux-foundation.org>
To: Yajun Deng <yajun.deng@...ux.dev>
Cc: vbabka@...e.cz, surenb@...gle.com, mhocko@...e.com, jackmanb@...gle.com,
hannes@...xchg.org, ziy@...dia.com, linux-mm@...ck.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] mm/page_alloc: Avoid duplicate NR_FREE_PAGES updates in
move_to_free_list()
On Fri, 9 Jan 2026 18:51:21 +0800 Yajun Deng <yajun.deng@...ux.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().
Seems nice and LGTM.
> +static inline void account_freepages_both(struct zone *zone, int nr_pages,
> + int old_mt, int new_mt)
> +{
> + lockdep_assert_held(&zone->lock);
> +
> + bool old_isolated = is_migrate_isolate(old_mt);
> + bool new_isolated = is_migrate_isolate(new_mt);
We do permit C99 definition ordering nowadays, but I do think our eyes
and brains prefer the old-school style.
So here I'd personally prefer
bool old_isolated = is_migrate_isolate(old_mt);
bool new_isolated = is_migrate_isolate(new_mt);
lockdep_assert_held(&zone->lock);
Or simply remove the assertion - it doesn't look useful to me. If we
aren't holding zone->lock here then the kernel is so screwed up we
should all just go home.
Powered by blists - more mailing lists