mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lance Yang <lance.yang@linux.dev>
To: alex@ghiti.fr
Cc: akpm@linux-foundation.org, david@kernel.org, ziy@nvidia.com,
	baolin.wang@linux.alibaba.com, liam@infradead.org,
	nico.pache@linux.dev, ryan.roberts@arm.com, dev.jain@arm.com,
	baohua@kernel.org, lance.yang@linux.dev, usama.arif@linux.dev,
	kas@kernel.org, vbabka@kernel.org, rppt@kernel.org,
	mhocko@suse.com, ljs@kernel.org, surenb@google.com,
	shakeel.butt@linux.dev, pfalcato@suse.de, jannh@google.com,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH] mm: madvise: don't split a PMD on partial THP MADV_DONTNEED
Date: Fri,  4 Dec 2026 11:16:11 +0800	[thread overview]
Message-ID: <20261204031611.7827-1-lance.yang@linux.dev> (raw)
In-Reply-To: <20261202102818.1317130-1-alex@ghiti.fr>


On Wed, Dec 02, 2026 at 11:28:10AM +0100, Alexandre Ghiti wrote:
>MADV_DONTNEED on a range that covers only part of a PMD-mapped THP splits
>the PMD and zaps the PTEs of the range. The THP itself is not freed: it
>stays allocated and charged as a whole, now partially mapped, until the
>deferred split shrinker splits it under memory pressure. Until then the
>process has lost the PMD mapping, and the TLB reach that comes with it, for
>no memory benefit.
>
>Besides, a THP is checked for being underused only once: it is queued on
>the deferred split list when it is created, and the shrinker drops it from
>the list for good once it has found it not underused. A long-lived THP
>whose pages are freed later is never looked at again, so its unused memory
>can't be reclaimed.
>
>When the underused THP shrinker can reclaim the range later, zero it in
>place instead: it reads as zeroes, as MADV_DONTNEED requires, and the PMD
>mapping stays. The THP is queued again on the deferred split list, so the
>shrinker looks at it again.
>
>For an exclusive anonymous THP, MADV_DONTNEED on part of it thus no longer
>leaves it partially mapped: the range reads as zeroes at once, and the
>memory is given back when reclaim needs it, once the THP holds more than
>max_ptes_none zeroed pages. Below that, the THP is not split even under
>memory pressure, where the partially mapped THP used to be split: it keeps
>up to max_ptes_none zeroed pages, the waste khugepaged already allows when
>collapsing.
>
>The range is zapped as before when the zeroed pages could not be freed,
>e.g. with max_ptes_none at 511 (the default), or when anyone else may see
>the THP, e.g. after fork or through a GUP pin.

Nice work (looked pretty good at first).

>Results on a large production workload (THP=always, max_ptes_none=0,
>allocator purging with MADV_DONTNEED), same allocator configuration before
>and after this patch:
>
>  THPs and memory                       change
>  ------------------------------------  ------
>  THPs partially mapped                   -97%
>  memory mapped by THPs (AnonHugePages)   +29%
>  underused THP splits                   +145%

Emm ... some work may shift from workload threads to deferred split, I
guess :D

Afraid overall host CPU usage could go up even if workload p99 latency
improves ... right?

>  PMD splits                              +10%
>  workload anonymous memory              +0.2%
>
>  Performance                           change
>  ------------------------------------  ------
>  p50 latency                            -1.7%
>  p99 latency                            -2.3%
>  throughput                      within noise
>  dTLB misses per instruction            -0.4%
>  IPC                                    +0.2%

And yeah, I understand why you want to keep PMD mappings intact. Some
workloads may already rely on MADV_DONTNEED zapping mappings (a partial
discard splits a PMD mapping into PTE mappings).

FWIW, An opt-in flag for process_madvise() or a new madvise() advice might
make more sense, just saying ...

[...]

Cheers, Lance

      parent reply	other threads:[~2026-12-04  3:16 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 10:28 Alexandre Ghiti
2026-12-02 11:22 ` Lorenzo Stoakes (ARM)
2026-12-03 14:10   ` Alexandre Ghiti
2026-12-02 11:22 ` David Hildenbrand (Arm)
2026-12-02 14:26   ` Alexandre Ghiti
2026-12-03 12:32     ` David Hildenbrand (Arm)
2026-12-02 16:37 ` Zi Yan
2026-12-02 17:39   ` Alexandre Ghiti
2026-12-02 20:28   ` David Hildenbrand (Arm)
2026-12-02 18:04 ` Shakeel Butt
2026-12-03 14:53   ` Alexandre Ghiti
2026-12-03 15:08     ` Pedro Falcato
2026-12-03 15:36       ` Alexandre Ghiti
2026-12-03 20:07         ` Shakeel Butt
2026-12-03 20:06     ` Shakeel Butt
2026-12-04  3:16 ` Lance Yang [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=20261204031611.7827-1-lance.yang@linux.dev \
    --to=lance.yang@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=alex@ghiti.fr \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=jannh@google.com \
    --cc=kas@kernel.org \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=nico.pache@linux.dev \
    --cc=pfalcato@suse.de \
    --cc=rppt@kernel.org \
    --cc=ryan.roberts@arm.com \
    --cc=shakeel.butt@linux.dev \
    --cc=surenb@google.com \
    --cc=usama.arif@linux.dev \
    --cc=vbabka@kernel.org \
    --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

all inboxes | Powered by JetHome®