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 F26FF606A32C for ; Sun, 29 Nov 2026 11:49:28 +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 kanga.kvack.org (Postfix) id 3E89A6B05B0; Sun, 29 Nov 2026 06:49:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 398B06B05B1; Sun, 29 Nov 2026 06:49:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2AFC46B05B4; Sun, 29 Nov 2026 06:49:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id F19E96B05B0 for ; Sun, 29 Nov 2026 06:49:21 -0500 (EST) Received: from smtpin29.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 0F971A062C for ; Sun, 29 Nov 2026 11:49:21 +0000 (UTC) X-FDA: 85487986122.29.85D91ED Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by imf06.hostedemail.com (Postfix) with ESMTP id 561A218000D for ; Sun, 29 Nov 2026 11:49:19 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=dnQnJDE0; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf06.hostedemail.com: domain of rppt@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1795952959; b=pFePF6jstHJh/lBmKMK9MnI8sO4ByAxKtbTlFhlhFVSousog6Y4RnW1Mo/l6gRdO3z1cTO WMMYuZNVtWCxQFGCkr8R6ykb3oetwOUbgQQ6IOZDCYjjfEHCIfihWHBnjuA4r80qKR3iVM Ie/ZkphWolPZTzW/mxZYTkCE8F12zbQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1795952959; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Xp16Uj81nXuIFInG/jAhVxsXCTVhqRLqV24rCHxS+WM=; b=1CTMz9AGtkZD6qnNLcstiTuy7XXO0yFmstVk9j0KehJ3aClsAsRb8Ncuhl6hORKReP80Na bVf6CB3Nen7YUp8KeKdj8CYQLozQ++2CJXK4LpNJzjKQISEQE8iQS3da0yhE8ZgBVU75jF gaw37maEhcV59H6iqFdSz6aEibQ8Vug= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20260515 header.b=dnQnJDE0; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf06.hostedemail.com: domain of rppt@kernel.org designates 172.234.252.31 as permitted sender) smtp.mailfrom=rppt@kernel.org Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id A8063401A3; Sun, 29 Nov 2026 11:49:17 +0000 (UTC) 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-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2vxz1p8jhcpx.fsf@kernel.org> X-Stat-Signature: ubgj3i8fymcm99gwhqaqyfps1twndfsh X-Rspamd-Queue-Id: 561A218000D X-Rspam-User: X-Rspamd-Server: rspam03 X-Spam-Status: No, score=-5.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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-HE-Tag: 1795952959-535214 X-HE-Meta: U2FsdGVkX18Hwn3RB6l/YsE/iAI0lMpsCsoKFRJSftC208gHglgUCnxDibcwHTpAPXHyVh25tSo0XMRv3E8NLHTYqOYdrP3dqJjkK5lW66F6NnpbHFku3GlhI8shJJCimXvyP5jl5OzS39T9f83RHC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f0Pl3A6HeDJKV25iUPen2nOQTX/N+ygUndiwAhRCo1RWK0BOed1e6Amtk1hJNY8AW46FcVBvF4U6EChJqdSaivA/kXSKrSRvuJwYvdR/iiH7uMSsGRgRLJvUQGI6JuSF43hvWdX7r+MoeE3/82Sa3KJbeG8iH03PEh+gf6mTVZVDV13CQhvnOiH9bfuFt/70YLErvUSlqrK+OYtrtUejOR3Mtn1aFCI7pbTA0fbH4ocBVgJ81dPLTbi8sKxXQCxk/MFrJ8= 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 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.