From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 770D728CF6F for ; Fri, 27 Feb 2026 11:14:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772190853; cv=none; b=GRtPqux3kYC79/mDiMsR7Uq2FYsthFdQbGs1TdwiunnkCKyROjrRxGYVCazbHKY8v3D0aOmvtY7JESeBDKTC2FCD83JxX6al4dKhDRAlDe9SxJDB+LQ7y575wDfzgPPYt9CGVg32swSOliDkk4dBYGIs8axnkmkbqqiE/zZW8iQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772190853; c=relaxed/simple; bh=rDj55xy5qWHKyarknE/Z0wVjWpD8BZOlqshU3NNzLAk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=eO8WV9w+VdwpYIkmE7/jbTyHI9N4oGbggFDnSx5v1d1Q0cpw3Htdk59dpDqgsDHXDnq4vL1FXYAupzizJ3IQvTFaTvsAqdacOoDWXDB07OsukDe7KEU69AjHi/DnLBpXav24ivSJ6394MV3c0jXxDJKNafLgZdjAFplHYxsOlX0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=fjb+QxCd; arc=none smtp.client-ip=91.218.175.188 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) header.d=linux.dev header.i=@linux.dev header.b="fjb+QxCd" Message-ID: <1d3a4e8e-9ea0-42e7-b8e7-d92fb27f80f4@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1772190839; h=from:from: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; bh=uXPJJ+uhWU3/FibG5pPc63uoF/bg2b2LZnaOHcLIOXA=; b=fjb+QxCdpTD3b4hr6YJTVtQxFdL+ygkZ8Otiw+cAUP2giw6sWDiSAgMSDuqQT6kvToVNoO 8K59vpmdlkwEvSNRr24BZt7S48RvMyWCLaDD2DvslmD5YU5FO7ZumLMbqR8ln6N1qw/OQO ZU+NrOiKyaHHCpYxVLcB1Tyhayipyrk= Date: Fri, 27 Feb 2026 11:13:55 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [RFC v2 00/21] mm: thp: lazy PTE page table allocation at PMD split Content-Language: en-GB To: Nico Pache Cc: Andrew Morton , david@kernel.org, lorenzo.stoakes@oracle.com, willy@infradead.org, linux-mm@kvack.org, fvdl@google.com, hannes@cmpxchg.org, riel@surriel.com, shakeel.butt@linux.dev, kas@kernel.org, baohua@kernel.org, dev.jain@arm.com, baolin.wang@linux.alibaba.com, Liam.Howlett@oracle.com, ryan.roberts@arm.com, Vlastimil Babka , lance.yang@linux.dev, linux-kernel@vger.kernel.org, kernel-team@meta.com, maddy@linux.ibm.com, mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, hca@linux.ibm.com, gor@linux.ibm.com, agordeev@linux.ibm.com, borntraeger@linux.ibm.com, svens@linux.ibm.com, linux-s390@vger.kernel.org References: <20260226113233.3987674-1-usama.arif@linux.dev> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Usama Arif In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On 26/02/2026 21:01, Nico Pache wrote: > On Thu, Feb 26, 2026 at 4:33 AM Usama Arif wrote: >> >> When the kernel creates a PMD-level THP mapping for anonymous pages, it >> pre-allocates a PTE page table via pgtable_trans_huge_deposit(). This >> page table sits unused in a deposit list for the lifetime of the THP >> mapping, only to be withdrawn when the PMD is split or zapped. Every >> anonymous THP therefore wastes 4KB of memory unconditionally. On large >> servers where hundreds of gigabytes of memory are mapped as THPs, this >> adds up: roughly 200MB wasted per 100GB of THP memory. This memory >> could otherwise satisfy other allocations, including the very PTE page >> table allocations needed when splits eventually occur. >> >> This series removes the pre-deposit and allocates the PTE page table >> lazily — only when a PMD split actually happens. Since a large number >> of THPs are never split (they are zapped wholesale when processes exit or >> munmap the full range), the allocation is avoided entirely in the common >> case. >> >> The pre-deposit pattern exists because split_huge_pmd was designed as an >> operation that must never fail: if the kernel decides to split, it needs >> a PTE page table, so one is deposited in advance. But "must never fail" >> is an unnecessarily strong requirement. A PMD split is typically triggered >> by a partial operation on a sub-PMD range — partial munmap, partial >> mprotect, partial mremap and so on. >> Most of these operations already have well-defined error handling for >> allocation failures (e.g., -ENOMEM, VM_FAULT_OOM). Allowing split to >> fail and propagating the error through these existing paths is the natural >> thing to do. Furthermore, split failing requires an order-0 allocation for >> a page table to fail, which is extremely unlikely. >> >> Designing functions like split_huge_pmd as operations that cannot fail >> has a subtle but real cost to code quality. It forces a pre-allocation >> pattern - every THP creation path must deposit a page table, and every >> split or zap path must withdraw one, creating a hidden coupling between >> widely separated code paths. >> >> This also serves as a code cleanup. On every architecture except powerpc >> with hash MMU, the deposit/withdraw machinery becomes dead code. The >> series removes the generic implementations in pgtable-generic.c and the >> s390/sparc overrides, replacing them with no-op stubs guarded by >> arch_needs_pgtable_deposit(), which evaluates to false at compile time >> on all non-powerpc architectures. > > Hi Usama, > > Thanks for tackling this, it seems like an interesting problem. Im > trying to get more into reviewing, so bare with me I may have some > stupid comments or questions. Where I can really help out is with > testing. I will build this for all RH-supported architectures and run > some automated test suites and performance metrics. I'll report back > if I spot anything. > > Cheers! > -- Nico > Thanks for the build and looking into reviewing this. All comments and questions are welcome! I had only tested on x86, and I had a look at the link you shared so its great to know that powerPC and s390 are fine.