From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 11E54606A32D for ; Thu, 3 Dec 2026 20:06:13 +0000 (UTC) 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 Received: by kanga.kvack.org (Postfix) id C38DC6B05BE; Thu, 3 Dec 2026 15:06:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C102F6B05BF; Thu, 3 Dec 2026 15:06:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B26956B05C0; Thu, 3 Dec 2026 15:06:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 8ED2D6B05BE for ; Thu, 3 Dec 2026 15:06:11 -0500 (EST) Received: from smtpin28.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0A5A714014E for ; Thu, 3 Dec 2026 20:06:11 +0000 (UTC) X-FDA: 85503753342.28.5362A70 Received: from mta1.migadu.com (out-111.mta1.migadu.com [95.215.58.111]) by imf19.hostedemail.com (Postfix) with ESMTP id C47F71A0018 for ; Thu, 3 Dec 2026 20:06:08 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=eteI53Ah; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf19.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.111 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796328369; b=aaJPAMjnb8dnFHIpEnZJplaEOdxsy82Puxkjsyhg3rG/2enu5WNrmJllclKVQrVe2qzrah 5CxETZzBAkh3WjYrMxSwfYNpGk9Z74SxjbFudBWscWOIVcW2lMuLfg6656bMjYcZ+Bj+ue ofw34iPZy+uShyR32vVJKCyCo02zbqk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796328369; h=from:from:sender:reply-to:subject:subject: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:dkim-signature; bh=MgeEHIoaMHlU1J+Pk02DTKEyl35a46V0vQjd3Z2wpwQ=; b=pkqzXYWA4vMB1ZkP6U2e31kGAz+P3S3hrmU3EqJMK2LknQ3wNLVwmkDCCLsLKGfB26yPdx 15zDILIa2KADiA9mS02uQqvnz66ioxrogSKQXAi9JWWgC6Y3Z4XZyX1NcI9lASMGWpcgRs uY7o817abiJKiZH3rDplPaoNs0KXoCk= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=eteI53Ah; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf19.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.111 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev X-Envelope-To: linux-mm@kvack.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-mm@kvack.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-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: C47F71A0018 X-Stat-Signature: r3cz1gobqfqp4rjqm6fbw68tjmoak3y9 X-Spam-Status: No, score=-5.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Rspam-User: X-HE-Tag: 1796328368-417049 X-HE-Meta: U2FsdGVkX1+dyBkh4sdJ9AF58tkt1OSA7ieGIfX3g49wECEOp2pNxpgxJbq7wMy/bJeh49j0cnP1nXGMczWGDzPj73SyohMfqWviW7crCz6TCpzyIZoVoaQnZXshHvVq7ED5ee5a1Smp6VRZDq9Dee8gC1J6hLDEHKTtxNJJs2lEKfhSbVLC+CE99V7acl2a3RGn+3uuePrHz8fQHaGVWcQzZxsgzmOd1pUmG66htapDRLGma7U2LSpYkYrk8dgRwz2OhtiaEzO8OfOqMPV0G1mtj4yHtJ/6M+ZwwrkFiqWv3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/KA1EK8QeLa1S0/fbXIL5hkrKvq2fbZmbFyq8n8Vnyy3veArPzoibY70WIUYBqL+pBJYlpcVHnS5ezhw4ZCWjM06qQknn40mM46JYaZ19Rq7JO9flpbupEkc510qbYvIayA7KEo3RfID8fff8NvLjkyNvQ9znFTXpwYUkaQMkc5Co3xYc+1SxHa9sYRCE+meODZA4EPAcaq2ilLiX6AQbdxV4brheb0nl Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 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.