From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.147 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796328478; b=YNIKy49eHDXukWQgEcBzhWhv1NzK5sELp599qkIVrAYH99qEISlP3kIZe2brCM+9ukv1 eaje3AEXFCCyruhKl0bxSCbCXhRQO0Inl5x0iDJDktaUpAHWBL8B4ugl1gv4mB2F61PbP 6tny+xGsCQ+WwEKzFqOL8Pkxz/obiw2aTH7lPCAuMfk2LTLALzz/qG2UhOLUhFryLC1m1 96hFjz/N8Yp9yMUjt07z8hEBtNgdnoLkZNKnIm8Z/eC/hPnhhOOjgFdorTvOQfXYAcAI9 9whzecnIY3GyDzb3BM1u4ann+CoYtSxM8CSUGVwK7e4/ygWx2N/CEcS6UCQmQtZTJ9A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796328478; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition: Content-Transfer-Encoding:In-Reply-To; bh=wS0aDssTTqul0ENIM8mUHVnwouVeTVgGoVFbJcA8Crg=; b=vHRnLi6n7QIRDg1mcYuaX4qsl6PW+ZJD19rVu+jPfoe8YRwLPILLkMdan3A/RDZQxDHU M0kPsgnch6nqpo5NbfD6vNDDxa/n9No4KVhX264GJlcRAdB4rsQDFZvgYL0t6+WMU4Xtb agfxBZng8AKVtsupPIDfjVUQQCMUs/Jj2e2JBWteFNroEQ5dGmzOwWFqbo9Hr8SPK0q2m tsDXkM/WmeNEVGTtmaG+iISqLO5jyQVH0PvLYvtE8tuJMz3QLshdg2r6P8WuYkLTTj8MS zqNllUy10eVL1hjL0HsO9/dMN3uqakBuFfh1gh4sQD2tS1Tr0a5paJ5RZBQfOIsP3mA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=TtlzynD5; arc=none smtp.remote-ip=95.215.58.147 Received: from mta1.migadu.com (out-147.mta1.migadu.com [95.215.58.147]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2620A606A322 for ; Thu, 3 Dec 2026 20:07:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2620A606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=TtlzynD5 X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=RZeP50Vrv8qyfUswV8ryoYn/O1LlF4rrtSFpBNqks1Q=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796328476; v=1; x=1796933276; b=TtlzynD5EJpqhgW82gTPwwRaRqdPArgFIJC4z3CFLYAc8b6uwSuBTRIzH25NKzBdCo+YkDu0 QBD+OjfJkrWa09jzquTPJUVeb9d1fVmWNsYoFQFLByQr/3NHEYSEEB7IMt8o22Gwf446qFgX+iu HMHdAWQlm7vL+P/s7vsiyi7o= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 734d12786da5932c; Thu, 03 Dec 2026 20:07:55 +0000 X-Mizu-Trace-ID: 734d12786da5932c X-Migadu-Flow: FLOW_OUT Date: Thu, 3 Dec 2026 12:07:54 -0800 From: Shakeel Butt To: Alexandre Ghiti Cc: Pedro Falcato , Alexandre Ghiti , Andrew Morton , David Hildenbrand , Zi Yan , Baolin Wang , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Usama Arif , Kiryl Shutsemau , Vlastimil Babka , Mike Rapoport , Michal Hocko , Lorenzo Stoakes , Suren Baghdasaryan , Jann Horn , 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 Message-ID: References: <20261202102818.1317130-1-alex@ghiti.fr> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Thu, Dec 03, 2026 at 04:36:31PM +0100, Alexandre Ghiti wrote: > Hi Pedro, > > On Thu, Dec 3, 2026 at 4:08 PM Pedro Falcato wrote: > > > > > > > On Thu, Dec 03, 2026 at 03:53:08PM +0100, Alexandre Ghiti wrote: > > > Hi Shakeel, > > > > > > On Wed, Dec 2, 2026 at 7:04 PM Shakeel Butt wrote: > > > > > > > > > > > > > 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. > > > > > > > > Isn't the actual problem higher and unexpected memory usage? Application or the > > > > malloc implementations do madvise(MADV_DONTNEED) to release memory and expect at > > > > least decrease in RSS. Why not fix the cgroup memory usage as well by > > > > synchronously break the THP as well. See > > > > https://lore.kernel.org/all/20211120201230.920082-1-shakeelb@google.com/ > > > > > > > > > > > > > > The memcg charge is not the problem I'm facing (though it exists!). My > > > issue is that the allocator leaves many partially mapped THPs, even > > > when that memory may be reused soon after (which userspace can't > > > easily know), and the TLB benefit goes away. > > > > I would say doing a madvise() *at all* is silly; at least every time a range > > is free. > > It doesn't happen every time, it only happens after some threshold > that needs adjustment. > > > > > > > > > If the allocator stops purging hugepages that are only partly free, > > > the THPs stay intact (along with the TLB benefit) but RSS grows > > > noticeably, which is also unacceptable. > > > > > > So what I'm looking for is a way for userspace to tell the kernel > > > which parts of a THP are free, so that the kernel can reclaim that > > > internal fragmentation when the memory is actually needed. > > > > > > But since David says MADV_DONTNEED means zap, I'll try something else. > > > > MADV_NOHUGEPAGE? But that requires a VMA split, which sucks. I had the > > idea (from Kiryl IIRC) on my post-LPC list that splitting off these > > hints onto a separate tree (freeing us from VMA splitting) could be a > > good idea. > > > > I thought about using MADV_NOHUGEPAGE indeed (and all the other > madvise flags)...The hint tree sounds like a nice idea indeed. > MADV_NOHUGEPAGE takes mmap lock in write mode and malloc implementations are not keep to do operations that take mmap_lock in write mode. > > Either way, you still pay the system call, which still sucks. > > > > *Something something *transparent* huge pages* > > (I didn't have time lately to work on this :/) > > > > > > -- > > Pedro > > Thanks for your comments! > > Alex