From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795952957; b=1iC3ZoRjeHX1RgUX2MbJhofxX+t2OSHWE+QAAuDDGAguP4sHbHQDC5+rcXuiqXOZje7Z gAy6gsTJZ20y8r3I0U8LID/+qh1dH5PeCzNNgAyP+idu598btpzrJfeO5rH6cs1Z0f/xH pMtiFxfD4AiXowA2mrF8HVl+6g2g3YabcNCfTFG2aXxRq3tULYZKA1OdG0sCU+M7vipRq atZYd4vJcjko4xgUNBguA2otX2RYTwQWxr1hMfK08VMmgiLLlJH+MJ44ZychvjyfewCxG vPqd964R/Jhnh08rhQqmZHqKMMMssVZcWeXykBMNOrj0Mp0tKjKh27XCTtSP1hsSZZQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795952957; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=Xp16Uj81nXuIFInG/jAhVxsXCTVhqRLqV24rCHxS+WM=; b=XTtxI+WARvaC90dP+gJrqmYS8/59KQkuOtvxdW5tCHuw4JPrnvrVCeOftmjV7fHvXsGh bSmomgelTKtLzKlgvvS8nOJr8+SIieKuiYjb6H1KMNcipPdk5uBxjeNGqvXUdIv31D0KO fDyemnEkaNsuq7XhdOK8l/Pn71m0TBkLD7s0iGCY4U/fvkkqz7gcV/9/K8Zpert7Sroji C5buHNyM2QJFdAdL2ovzmK9HDFOHQIfXfNme3Y7DPGapX/dOlYCfH+IzofuOJxDipziyh LmAV/gPAOUoVXP5GS74//NBXuAWuT8zrtF1vOPoskvoGPEYZpYGaAsia3m3yBLQh1aw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dnQnJDE0; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2B8A606A6A6; Sun, 29 Nov 2026 11:49:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dnQnJDE0 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D5641F00896; Sun, 29 Nov 2026 11:49:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795952957; bh=Xp16Uj81nXuIFInG/jAhVxsXCTVhqRLqV24rCHxS+WM=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=dnQnJDE0DiTZEI3+OiQV1/bUIw1OiKZV8pGkftc9ePmo3H+XjSj1EpsXT2XoMvXLl mZrY9psW8bN0sYTba8R3jlGSaoJ4Kn6GLI3QHX5Ef38H2ZbioqqAMV/Zv8C5n1WP0a gUyd/0N3nUA2PJFpi6RK/FQiwjZO9fuBtq+SwCic9yWxR7jv+J1f/FgaUGNcbGObAn GYL7yGPOGrON6eZYfSQhzMW/6XlXR4KhKAEC1EjlTNWbVQm2mtT18Z64/gwMOsAs8e UGcOk0jveqkpdzMm2dDNMJRUA7/Brdn02zr1LXEqvgnvsXgBSwxVCovXuPoXlykN33 Q46fPPT1Wrd0w== Date: Sun, 29 Nov 2026 13:49:08 +0200 From: Mike Rapoport To: Pratyush Yadav Cc: Chris Down , Pasha Tatashin , Alexander Graf , Jonathan Corbet , Shuah Khan , Randy Dunlap , Andrew Morton , Tarun Sahu , David Matlack , Samiullah Khawaja , kexec@lists.infradead.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [RFC PATCH 0/5] KHO map Message-ID: References: <20261116134013.1636689-1-pratyush@kernel.org> <2vxz1p8jhcpx.fsf@kernel.org> 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=us-ascii Content-Disposition: inline In-Reply-To: <2vxz1p8jhcpx.fsf@kernel.org> On Tue, Nov 17, 2026 at 01:19:38PM +0100, Pratyush Yadav wrote: > Hi Chris, > > On Tue, Nov 17 2026, Chris Down wrote: > > > Hi Pratyush, > > > > Pratyush Yadav writes: > >>The main user of the map is memfd. Currently memfd uses a vmalloc buffer > >>that has a pair of {index,pfn} to track the folios in the file. That > >>uses 16 bytes per page. The KHO map uses only 8 bytes per page with some > >>overhead. So for a 1 GiB memfd, it uses roughly half the memory. > > > > That only holds for order-0 folios though. A leaf covers 512 indices, so > > a populated memfd needs one leaf page for every 2M of file whatever the > > folio size, while the array needs 16 bytes per folio. Per 2M of file, > > that works out as: > > > > folio size array map map/array > > 4K (o0) 8K 4K 0.5x > > 8K (o1) 4K 4K 1x > > 16K (o2) 2K 4K 2x > > 64K (o4) 512 4K 8x > > 2M (o9) 16 4K 256x > > Right. > > > > >>- Multi-index entry support: currently, while the map is very efficient > >> with 4k folios, it is horribly inefficient with 2M folios. Each folio > >> in the memfd takes up a full page to track. Multi-index entry support > >> can fix this by tracking entries that cover a whole page in the > >> previous level, similar to page tables. > > > > Since patch 5 makes things worse for memfds with large folios, I agree > > with Pasha that this needs fixing before memfd switches over. Storing > > Right, I agree as well. > > > PMD-sized entries at L1 fixes the 2M case, but mTHP sizes between 4K and > > 2M would still take a full leaf for every 2M of file. Do you expect > > mTHP-backed memfds to be preserved? If so, it's probably worth handling > > them in the format before it becomes ABI. > > mTHP will still work, it will just be less space efficient than 2M THPs. > Even then, the overhead is around 2M for every 1G, which is roughly > 0.2%. Even then, I don't think that is too bad. If you want to be more > space efficient, use 2M THPs, or hugetlb[*]. I think that is a fair > tradeoff. Using larger page sizes also makes KHO more efficient. > > We _can_ make mTHPs fairly efficient, but that comes at the cost of a > more complicated ABI. For example, we can have a per-order KHO map in > the memfd, and shift the keys by the order. That should improve the > density. We could also do some other tricks like the shifted key > encoding scheme that KHO preserved memory map uses (see > kho_encode_radix_key()) to improve density. > > So unless someone can explain why mTHP memfds are important to optimize > for, I'd say mTHP users can either take the 0.2% preservation overhead, > or use 2M THPs. In general mm moves to managing memory in larger chunks and mTHP is one of the means for that and sometime in the future mTHP is going to be "mainstream". So the question is "when" rather than "why" ;-) And I believe we should consider how much complexity it will add later too, including the handling of compatibility. E.g. a per-order KHO map does not sound that complex if we add it now, but extending ABI to support that along with the current proposal could add some pain. > -- > Regards, > Pratyush Yadav -- Sincerely yours, Mike.