From: "David Hildenbrand (Red Hat)" <david@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>,
Wei Yang <richard.weiyang@gmail.com>
Cc: lorenzo.stoakes@oracle.com, ziy@nvidia.com,
baolin.wang@linux.alibaba.com, Liam.Howlett@oracle.com,
npache@redhat.com, ryan.roberts@arm.com, dev.jain@arm.com,
baohua@kernel.org, lance.yang@linux.dev, linux-mm@kvack.org
Subject: Re: [Patch v3] mm/huge_memory: simplify page tracking in remap_page() during folio split
Date: Tue, 23 Dec 2025 11:05:09 +0100 [thread overview]
Message-ID: <ab1eb404-f51c-4c02-95d5-93c108a81e34@kernel.org> (raw)
In-Reply-To: <20251222101419.10e73a9f2b35df440abd8a62@linux-foundation.org>
On 12/22/25 19:14, Andrew Morton wrote:
> On Mon, 22 Dec 2025 13:45:31 +0000 Wei Yang <richard.weiyang@gmail.com> wrote:
>
>> After splitting a large folio, the resulting anonymous folios must be
>> remapped.
>>
>> Currently, the code tracks progress by recording the number of processed
>> pages in an index variable (e.g., @i) and comparing it against the
>> total. This commit simplifies the logic by directly subtracting the
>> processed pages from the remaining count. This approach is more
>> straightforward and reduces the number of local variables.
>>
>> Additionally, this commit renames the variable nr to nr_pages to improve
>> code readability and self-documentation.
>>
>> ...
>>
>> --- a/mm/huge_memory.c
>> +++ b/mm/huge_memory.c
>> @@ -3423,17 +3423,15 @@ bool unmap_huge_pmd_locked(struct vm_area_struct *vma, unsigned long addr,
>> return __discard_anon_folio_pmd_locked(vma, addr, pmdp, folio);
>> }
>>
>> -static void remap_page(struct folio *folio, unsigned long nr, int flags)
>> +static void remap_page(struct folio *folio, unsigned long nr_pages, int flags)
>> {
>> - int i = 0;
>> -
>> /* If unmap_folio() uses try_to_migrate() on file, remove this check */
>> if (!folio_test_anon(folio))
>> return;
>> for (;;) {
>> remove_migration_ptes(folio, folio, RMP_LOCKED | flags);
>> - i += folio_nr_pages(folio);
>> - if (i >= nr)
>> + nr_pages -= folio_nr_pages(folio);
>> + if (!nr_pages)
>> break;
>> folio = folio_next(folio);
>> }
>
> This changes behavior when nr_pages was too large. It would be best to
> mention this and to describe why this is OK. Or to check for
> ((signed)nr_pages <= 0).
>
> Also, isn't it a bit nasty to alter an incoming arg? I think it's best
> to treat all those as const - part of the function's calling
> environment. Yes, C permits this hack but that was a mistake!
For small functions I think it's quite acceptable.
But yeah, for bigger functions it can happen too easily that one ends up
reusing a now-modified value by mistake.
--
Cheers
David
prev parent reply other threads:[~2025-12-23 10:05 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-22 13:45 Wei Yang
2025-12-22 18:14 ` Andrew Morton
2025-12-23 10:05 ` David Hildenbrand (Red Hat) [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=ab1eb404-f51c-4c02-95d5-93c108a81e34@kernel.org \
--to=david@kernel.org \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=dev.jain@arm.com \
--cc=lance.yang@linux.dev \
--cc=linux-mm@kvack.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=npache@redhat.com \
--cc=richard.weiyang@gmail.com \
--cc=ryan.roberts@arm.com \
--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