linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Zi Yan <ziy@nvidia.com>
To: fujunjie <fujunjie1@qq.com>
Cc: akpm@linux-foundation.org, vbabka@suse.cz, surenb@google.com,
	mhocko@suse.com, jackmanb@google.com, hannes@cmpxchg.org,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] mm/page_alloc: optimize lowmem_reserve max lookup using its semantic monotonicity
Date: Sat, 15 Nov 2025 12:51:36 -0500	[thread overview]
Message-ID: <36C81D51-A931-44BA-B58D-223950FD370F@nvidia.com> (raw)
In-Reply-To: <tencent_EB0FED91B01B1F8B6DAEE96719C5F5797F07@qq.com>

On 14 Nov 2025, at 22:02, fujunjie wrote:

> calculate_totalreserve_pages() currently finds the maximum
> lowmem_reserve[j] for a zone by scanning the full forward range
> [j = zone_idx .. MAX_NR_ZONES). However, for a given zone i, the
> lowmem_reserve[j] array (for j > i) is naturally expected to form a
> monotonically non-decreasing sequence in j, not as an implementation
> detail, but as a consequence that naturally arises from the semantics
> of lowmem_reserve[].
>
> For zone "i", lowmem_reserve[j] expresses how many pages in zone i must
> effectively be kept in reserve when deciding whether an allocation class
> that may allocate from zones up to j is allowed to fall back into i. It
> protects less flexible allocation classes (which cannot use higher
> zones) from being starved by more flexible ones.
>
> Viewed from this semantics, it is natural to expect a partial ordering in j:
> as j increases, the allocation class gains access to a strictly larger
> set of fallback zones. Therefore lowmem_reserve[j] is expected to be
> monotonically non-decreasing in j: more flexible allocation classes must
> not be allowed to deplete low zones more aggressively than less flexible
> ones.
>
> In other words, if lowmem_reserve[j] were ever observed to *decrease*
> as j grows, that would be unexpected from the reserve semantics' point of
> view and would likely indicate a semantic change or a misconfiguration.
>
> The current implementation in setup_per_zone_lowmem_reserve() reflects
> this policy by accumulating managed pages from higher zones and applying
> the configured ratio, which results in a non-decreasing sequence. This
> patch makes calculate_totalreserve_pages() rely on that monotonicity
> explicitly and finds the maximum reserve value by scanning backward and
> stopping at the first non-zero entry. This avoids unnecessary iteration
> and reflects the conceptual model more directly. No functional behavior
> changes.
>
> To maintain this assumption explicitly, a comment is added next to
> setup_per_zone_lowmem_reserve() documenting the monotonicity expectation
> and noting that calculate_totalreserve_pages() relies on it.
>
> Changes in v2:
>   - Reword the semantic explanation of lowmem_reserve[] monotonicity to
>     clarify that it arises naturally from its semantics.
>   - Maintain a minimal reference to the invariant in
>     calculate_totalreserve_pages(), with full documentation placed in
>     setup_per_zone_lowmem_reserve().
>
> Signed-off-by: fujunjie <fujunjie1@qq.com>
> ---
>  mm/page_alloc.c | 33 +++++++++++++++++++++++++++++----
>  1 file changed, 29 insertions(+), 4 deletions(-)
>
Acked-by: Zi Yan <ziy@nvidia.com>

--
Best Regards,
Yan, Zi


      reply	other threads:[~2025-11-15 17:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-15  3:02 fujunjie
2025-11-15 17:51 ` Zi Yan [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=36C81D51-A931-44BA-B58D-223950FD370F@nvidia.com \
    --to=ziy@nvidia.com \
    --cc=akpm@linux-foundation.org \
    --cc=fujunjie1@qq.com \
    --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 \
    /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