From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 070B734B1A6 for ; Mon, 17 Nov 2025 22:47:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763419637; cv=none; b=FxWW74setUZmZ3y3VMZAZ2KiEBwFs8huf0jIw1jQpL+18vFjfq+Cv5+81ASr4QMgahawAoVER7Qnsqa/UCXMGtgEtHlivH26obvcrwXHWXaF1fIamWOJKFhkezviguagouO0QRiXHjRDS1jWPG4SBPkE9fHhp1szwD26WWBvpjA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763419637; c=relaxed/simple; bh=UOAkVT0QBtGAkDYvikFyyvijQD/qAyngzgkE5TD1HUY=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=lhjhLe30IzqrMaHJIo1YeEGD+XY7nOM7R8/YT+LZGdE4LQHXbyRDhjdrRKc/y80u44QDLiGg4JGlemOxGen9sEWjLDUwB/j1ziK10Tg+7yO/ZHfyMk7leTy0oGptY1jD6Vlxr2dytUuhAgZEsSQKFfqcgQj9szNj5flxYoL6P2I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ackerleytng.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=oaIkjuHN; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ackerleytng.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="oaIkjuHN" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-3438744f11bso8698288a91.2 for ; Mon, 17 Nov 2025 14:47:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763419635; x=1764024435; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=lad1asYiF8cA2ZLix/TncpNgjY0XYbNhIlYI0rkVv5A=; b=oaIkjuHNfUbrGyhMPZwfQCZEHL/97APKX17xVLxe3O4WuEiJi5BO480LsYRDCH3BsX tRIX+4BvKQ1yABIBjEkRqpZdSgUL3jkJ81FCZtIhKgZxe7StJc5aUV/BrzZ3YKRQY2/U YoGjhRShWaUNZenfYbwdAmmB4gXvyC68FRB5ngeKSYMFjHDAdTlrgK8UYOJDwiNeRrDd W9DmzkXNbA/tTclvV9wl6IHJF/fB1CCVkyKoXx1bPLH8lwIAYuDOWlg26GCVBpzbxkJo GPaUd8QLtd/gWi3gbZiY5zccdOlQ59u3cmiBJFMzqIzullKtSqS38GFKo/qiRn5Pvstn 7k0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763419635; x=1764024435; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=lad1asYiF8cA2ZLix/TncpNgjY0XYbNhIlYI0rkVv5A=; b=KAcyFoAAVsbthDPccpYC2GccmRU+DkEbfdZFWjK0KSneQUh8BGLhANOTrO0MdAOtLr k1Gi/VTCyT/khavEtH8OBx47s4GFoqnQQ6KiY68y9kq9g2noJBRRBiwe3w9e4icJ5jUi LI1rasOAlWHyehjn+XY23ca2ohzzZalAdIh5BcPBuL350ceNDLajdRk7jQEwBvYUWDAu DGROgXycwkTnmYHgbBj6LMNkZH46izqQpUFMB+5yYRPm7Oc4Jdkqs5TNc3lfyP7KwX2C /iGf96bEkAo6iLuK2tKYAE6KDndk57GqSotqtUl3VWrQ3uaG+oXaLzywI6glKaFJ5/rs Ywww== X-Forwarded-Encrypted: i=1; AJvYcCUDiXg/B7gFQNW3M9IdymEtTQZkIBqb6S0UVRFbUiZmN4EZG89J9dSqZtpEnJePz9bDp/pIVVpB06stwxo=@vger.kernel.org X-Gm-Message-State: AOJu0YwIbMg1xqo2gOinlTie6WUgTql3NZTzSRQKqRsGL2v8MoVq+Fmh kP2sU4+UYZg+AuoMMWy9aCtIhAvD+H2rWrgQN7pQ9FYwyflDe4zJiSdMby5GJhNt7JpZZ5Y/BIC SheOiqimay8KRajM9475fxxlJeQ== X-Google-Smtp-Source: AGHT+IHY//5/zSbJ96y0G1CVtIuXJVFgzUswEPddLr7yG1C8L/6rE6jUZ9/sELe1ezgM/wYNnndev+VmhVo67HX+sA== X-Received: from pjboc6.prod.google.com ([2002:a17:90b:1c06:b0:343:387b:f2fb]) (user=ackerleytng job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:350c:b0:340:b06f:7134 with SMTP id 98e67ed59e1d1-343fa62bcf6mr15075381a91.20.1763419635363; Mon, 17 Nov 2025 14:47:15 -0800 (PST) Date: Mon, 17 Nov 2025 14:46:57 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog Message-ID: <20251117224701.1279139-1-ackerleytng@google.com> Subject: [RFC PATCH 0/4] Extend xas_split* to support splitting arbitrarily large entries From: Ackerley Tng To: willy@infradead.org, akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: david@redhat.com, michael.roth@amd.com, vannapurve@google.com, Ackerley Tng Content-Type: text/plain; charset="UTF-8" guest_memfd is planning to store huge pages in the filemap, and guest_memfd's use of huge pages involves splitting of huge pages into individual pages. Splitting of huge pages also involves splitting of the filemap entries for the pages being split. To summarize the context of how these patches will be used, + guest_memfd stores huge pages (up to 1G pages) in the filemap. + During folio splitting, guest_memfd needs split the folios, and approaches that by first splitting the filemap (XArray) entries that the folio occupies, and then splitting the struct folios themselves. + Splitting from a 1G to 4K folio requires splitting an entry in a shift-18 XArray node to a shift-0 node in the xarray, which goes beyond 2 levels of XArray nodes, and is currently not supported. This work-in-progress series at [1] shows the context of how these patches for XArray entry splitting will be used. [1] https://github.com/googleprodkernel/linux-cc/tree/wip-gmem-conversions-hugetlb-restructuring This patch series extends xas_split_alloc() to allocate enough nodes for splitting an XArray node beyond 2 levels, and extends xas_split() to use the allocated nodes in a split beyond 2 levels. Merging of XArray entries can be performed with xa_store_order() at the original order, and hence no change to the XArray library is required. xas_destroy() cleans up any allocated and unused nodes in struct xa_state, and so no further changes are necessary there. Please let me know + If this extension is welcome + Your thoughts on the approach: is it too many nodes to allocate at once? Would a recursive implementation be preferred? + If there are any bugs, particularly around how xas_split() interacts with LRU Thank you! Ackerley Tng (4): XArray: Initialize nodes while splitting instead of while allocating XArray: Update xas_split_alloc() to allocate enough nodes to split large entries XArray: Support splitting for arbitrarily large entries XArray: test: Increase split order test range in check_split() lib/test_xarray.c | 6 +- lib/xarray.c | 210 ++++++++++++++++++++++++++++++++++------------ 2 files changed, 162 insertions(+), 54 deletions(-) -- 2.52.0.rc1.455.g30608eb744-goog