From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 4C639606A32F for ; Sun, 29 Nov 2026 11:49:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Bvn66sbQ; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dnQnJDE0 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=Xp16Uj81nXuIFInG/jAhVxsXCTVhqRLqV24rCHxS+WM=; b=Bvn66sbQrk33yDPJG5Hgy7xFMa 0SAxg+aCw5Q4aJT6qCcXFGi00h2RDUfHm4yp/Xl2INangHMGqwMByAJTrc6nWgzgUm2SPB3agUsNV 2YfxNMbQiV/BV92pa9XrGXGs1IG+7DgebCMzgc5m3jklF8O0jUp7nfcpZk+OQkiSnutptJ5koI/hn w419NxMPxRvpxqN7nH06+9Iu9K76oJ1l+mjHyjGOxLBMok8dUI2LmZwQU8mcc/4hJ1e0H33dFSAr6 0uGUlkXC79quruiIDkZ+590vN9uCYuoe9PmQP6gzAFRP0IijKIY9P/D26MmrUJzZBw58j76uai2zu VTB4V2nQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXdPD-00000001vGU-2oxO; Sun, 29 Nov 2026 11:49:19 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXdPC-00000001vGO-3kWe for kexec@lists.infradead.org; Sun, 29 Nov 2026 11:49:18 +0000 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-BeenThere: kexec@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kexec" X-Spam-Status: No, score=-5.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 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.