From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.107 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796328369; b=DGdtTHTZLDssqpGCzpitiUakBUOXrmgE/O1USJ0zIrH1/OTroMpEyxMUE/ZMLfoh3Zqh 6Wrj86TqUmiLFxE01b6Z7zZJ179exlFPZ4e7k4OWg1rHefUWN7RmpiOj4pi6i1aOcS7QZ rXcDkTmo5yS4R7kxNgVtQCO3XD041li4UHcbj2xbDS3Pzm9mHi8xlJhcfamnBMzPa9V3u nsN11VpqHw9FcORI+nn14740cCf9XICId+zz1MU4Q2Uk0KfpATUCHVQA8+d19emjC7L0F 6CGkDJgeWkAPjI7cQeT1TgOzVQhe6gNpyteN1baHUY0b7BR2R7GQs+IyggDInLB8TNA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796328369; 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=MgeEHIoaMHlU1J+Pk02DTKEyl35a46V0vQjd3Z2wpwQ=; b=HAOX1sHQgJRK8NiI+wGmXSKCuKppVqC6b8cstMocy1b++7rIjWbvMpNfrGoiHHVpP8Ts /3wdbimbgd/RiKDwawDP/j9eLVk6zr9aFLijix5hVEcQr9iPAic1mrDtU4ZmHfjOtdAdr SuStifv0HyYymlWeze+vSNtzghWPGkgvSY34znyGmHYIrWbRKmkma/ClmKYAhjJbb+aBY chx3jk52eOT2GF7LChaP8z/TZELPNLs5xpsc8VkHAEx7xmD1eeK+jG1OH1QDkiLc/44hE KhUsbg/7R5i5n3YHJN/RQY5hEAM7yk7IlyHX/zfn9IkoeRjkvaLJljEcUVU0X9gkPGQ== 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=eteI53Ah; arc=none smtp.remote-ip=95.215.58.107 Received: from mta1.migadu.com (out-107.mta1.migadu.com [95.215.58.107]) (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 2F3E0606A322 for ; Thu, 3 Dec 2026 20:06:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2F3E0606A322 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=eteI53Ah X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=ELmrwxPGVo7vuJuxzUb4PPygLn4EV1SBXOoR93I2i2E=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796328367; v=1; x=1796933167; b=eteI53Ah2In93qdjxhD2U1ZhekWWKZGcIPG4b8nsYQTilNdAIZNhhnR7+MMzsV2KLZICiPHT jjNnX2v3bZ80S1T8F2Bz8D0ABRq5uWyigN+1HIcyYKWlj3DfDXR9qo1s+1L2vOacEdFoVty94fx uSD6sb2sIL9BdxXqvSY0GHok= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 6df2cc24d62137a7; Thu, 03 Dec 2026 20:06:06 +0000 X-Mizu-Trace-ID: 6df2cc24d62137a7 X-Migadu-Flow: FLOW_OUT Date: Thu, 3 Dec 2026 12:06:05 -0800 From: Shakeel Butt To: Alexandre Ghiti Cc: 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 , Pedro Falcato , 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 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. > > 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. Oh that is very important information and I think you should start with this problem as the motivation. > > But since David says MADV_DONTNEED means zap, I'll try something else. Yes, this is not MADV_DONTNEED. I remember Rik proposed MADV_LAZYFREE for reducing the tlb flushing. Maybe you can repurpose that idea but focus on how userspace malloc implementations can share userspace freelist information with the kernel. It does not have to be madvise() but I think the problem is worth solving.