All of lore.kernel.org
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Alexandre Ghiti <alexghiti@meta.com>
Cc: Alexandre Ghiti <alex@ghiti.fr>,
	Andrew Morton <akpm@linux-foundation.org>,
	Zi Yan <ziy@nvidia.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	"Liam R. Howlett" <liam@infradead.org>,
	Nico Pache <nico.pache@linux.dev>,
	Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
	Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
	Usama Arif <usama.arif@linux.dev>,
	Kiryl Shutsemau <kas@kernel.org>,
	Vlastimil Babka <vbabka@kernel.org>,
	Mike Rapoport <rppt@kernel.org>, Michal Hocko <mhocko@suse.com>,
	Lorenzo Stoakes <ljs@kernel.org>,
	Suren Baghdasaryan <surenb@google.com>,
	Shakeel Butt <shakeel.butt@linux.dev>,
	Pedro Falcato <pfalcato@suse.de>, Jann Horn <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: Thu, 3 Dec 2026 13:32:19 +0100	[thread overview]
Message-ID: <12bfa898-77e4-445a-a2e6-c5d191105fe7@kernel.org> (raw)
In-Reply-To: <CAEmasaXHshPc4tOap+QfJHje8nSaLLyydabeXpML37LOTsSdog@mail.gmail.com>

On 12/2/26 15:26, Alexandre Ghiti wrote:
> Hi David,
> 
> On Wed, Dec 2, 2026 at 12:22 PM David Hildenbrand (Arm)
> <david@kernel.org> wrote:
>>
>>>
>> On 12/2/26 11:28, Alexandre Ghiti wrote:
>>
>> Hi,
>>
>>> 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.
>>
>> Right. User space should avoid doing stupid things.
> 
> I think it's hard for userspace when a hugepage becomes partly used,
> it can either keep it whole and waste its free memory, or give the
> free pages back with MADV_DONTNEED and lose the PMD. I see
> MADV_DONTNEED as an honest hint from userspace: "I have used this THP
> for a while, but I'm not sure I'll need all of it in the near future,
> but I'd like to keep the TLB benefits as long as possible. But under
> memory pressure, the kernel can take it."

MADV_DONTNEED means "zap". We'd have to introduce something new with different
semantics. Which I am not a fan of.

If you care about THP benefits, don't shatter THPs with MADV_DONTNEED.

> 
>>
>>>
>>> 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.
>>
>> The job of the underused shrinking is to detect over-allocation. Not "user space
>> used it and then partially freed it".
> 
> I thought the goal of the underused shrinker was broader than just
> over-allocation, which raises these questions:

No. It's all about over-allocation right now. That's why we scan exactly once.

-- 
Cheers,

David


  reply	other threads:[~2026-12-03 12:32 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 10:28 [RFC PATCH] mm: madvise: don't split a PMD on partial THP MADV_DONTNEED 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) [this message]
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-04  9:21           ` Pedro Falcato
2026-12-03 20:06     ` Shakeel Butt
2026-12-03 10:28 ` sashiko-bot
2026-12-04  3:16 ` Lance Yang

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=12bfa898-77e4-445a-a2e6-c5d191105fe7@kernel.org \
    --to=david@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=alex@ghiti.fr \
    --cc=alexghiti@meta.com \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=dev.jain@arm.com \
    --cc=jannh@google.com \
    --cc=kas@kernel.org \
    --cc=lance.yang@linux.dev \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.