From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796310523; b=oVssNKv69TVs5izJnKuunC/B05nkHTACSRhRyU9/nZWmKNWYjF/sAzE7JuYmdSw6T/M8 M9IfiN5eIiQzKv3d9VRA9oZXCNu3dwcFPsIFY08oY1sNQ1PTOBtzHPQacTqc4NOW0q0Lj J3+xLQskgRjV6JoPQbchajf8bFfPN/u76kc+POJF1XVD99vhwEF1KX5dyX35Zyupr0Yok qMMHhkyOPHclCJIjfDcPXMS24x39WVp3JbwhaFqwaTl9ynq93YZ6PC8exEZ90dLWTGjjX e3+geHDtaoRf1Qkyv8jPM+jeACVclzoYd7KQAFn6jz6n+F5VJ2VH01CFOoDIb4+0fNQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796310523; h=DMARC-Filter:Received:DKIM-Signature:DKIM-Signature:DKIM-Signature: DKIM-Signature:Received:Received:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition: Content-Transfer-Encoding:In-Reply-To:X-Spamd-Result:X-Spam-Score: X-Spam-Level:X-Spam-Flag; bh=c411fGO0Ar+1iUHdmvJj45UtVqxAm5CG0ln+rVn3gzM=; b=sFRjcguj4cUFRKcLey+YAZUaiWbX70v7QYanjudXpN3evgbeEbi5Lz0b4T5bFiOj7aKx WdyEREyh7NP+XrKY4NAExBVAXNRMo2fk+kzCmdL2fVgN2flPFnCts4EqqrqRm13bhyLv5 GH0sO/bB8V0NqHVvGBiRc1fKHW0w7zQB0HXsGuJNTL6efsapqaNIWHd5NRre/UrJVsV00 ktjCYbEf8GurqBgUUDwbcKdcDk3h0spCLuxw0RQkkr1VKR9buEWkrTrHPeeaE4L2q6NUQ 2ENScnC+POaITx7sRjMnSSNTC2QClk9WHtaoS+viCgNr1r+A4hZa2rt/I0AzdCdTncw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=vlgJub6H; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=cXZx3BEa; dkim=pass header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=vlgJub6H; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=cXZx3BEa; arc=none smtp.remote-ip=195.135.223.130 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5511A606A683 for ; Thu, 3 Dec 2026 15:08:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5511A606A683 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=vlgJub6H; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=cXZx3BEa; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=vlgJub6H; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=cXZx3BEa Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9675C371AE; Thu, 3 Dec 2026 15:08:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1796310515; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c411fGO0Ar+1iUHdmvJj45UtVqxAm5CG0ln+rVn3gzM=; b=vlgJub6H7LB9F/HtzXdc+9Vuu6Z0oBWVHVqaic3UJMXCdkItzDODChdp83m13QFIptXbPK YdYL3WVZkGV5nEk6ZdR0GhNxELJi9hS65v1YU7nhMfcYbu6cO2PXHQO4t4AHlP3MS6lSmy L0sU8udEj7Vw4y9uRxR3mpOeu6Km0Rk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1796310515; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c411fGO0Ar+1iUHdmvJj45UtVqxAm5CG0ln+rVn3gzM=; b=cXZx3BEag3cPoxV3nnltuyLKvaNNQsG0NsH8zGPLA07ftQHY9oBe+pCGWdMeABOREvTls1 Wf9HWo1J96KZBVDw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1796310515; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c411fGO0Ar+1iUHdmvJj45UtVqxAm5CG0ln+rVn3gzM=; b=vlgJub6H7LB9F/HtzXdc+9Vuu6Z0oBWVHVqaic3UJMXCdkItzDODChdp83m13QFIptXbPK YdYL3WVZkGV5nEk6ZdR0GhNxELJi9hS65v1YU7nhMfcYbu6cO2PXHQO4t4AHlP3MS6lSmy L0sU8udEj7Vw4y9uRxR3mpOeu6Km0Rk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1796310515; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c411fGO0Ar+1iUHdmvJj45UtVqxAm5CG0ln+rVn3gzM=; b=cXZx3BEag3cPoxV3nnltuyLKvaNNQsG0NsH8zGPLA07ftQHY9oBe+pCGWdMeABOREvTls1 Wf9HWo1J96KZBVDw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 12C3B134F6; Thu, 3 Dec 2026 15:08:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id OMq7M/GFEWsRRwAAD6G6ig (envelope-from ); Thu, 03 Dec 2026 15:08:34 +0000 Date: Thu, 3 Dec 2026 15:08:32 +0000 From: Pedro Falcato To: Alexandre Ghiti Cc: Shakeel Butt , 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: X-Spamd-Result: default: False [-13.30 / 50.00]; SUSE_INTERNAL_BYPASS(-9.00)[]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; MISSING_XM_UA(0.00)[]; RCPT_COUNT_TWELVE(0.00)[23]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,linux.dev:email] X-Spam-Score: -13.30 X-Spam-Level: X-Spam-Flag: NO 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. > > 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. 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