Skip to content

Minimize xa_node allocation during xarry split

Zi Yan linux-fsdevel linux-mm lkml 4 versions – Applied

Status from this message: [merged mm-stable] mm-shmem-use-xas_try_split-in-shmem_split_large_entry.patch removed from -mm tree

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest posting 2/22 patches 0 repliesApplied 2/2
  2. v3 posting 1/22 patches 6 repliesSuperseded
  3. v22 patches 16 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v12 patches1 replySuperseded

Patches in v3 posting 2/2 All 2 applied

#Subject and filesSizeRepliesApplied
1/2mm/filemap: use xas_try_split() in __filemap_add_folio()include/linux/xarray.h lib/xarray.c mm/filemap.c+50 -270 repliesApplied
2/2mm/shmem: use xas_try_split() in shmem_split_large_entry()mm/shmem.c+28 -310 repliesApplied

Reviews trailers per patch

1 of 2 patches has a Reviewed-by or Acked-by.

PatchBaolin Wang
1/2
2/2R-b T-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH RESEND v3 0/2] Minimize xa_node allocation during xarry split

Hi Andrew,

It is on top of mm-unstable with old V3 (plus a fixup) reverted, so that you can replace the old one with this. Since the patch 1/2 on mm-unstable tree is not the same as my original one, which caused a compilation issue and would confuse people due to a comment is relocated incorrectly.

Thanks.

When splitting a multi-index entry in XArray from order-n to order-m, existing xas_split_alloc()+xas_split() approach requires
2^(n % XA_CHUNK_SHIFT) xa_node allocations. But its callers, __filemap_add_folio() and shmem_split_large_entry(), use at most 1 xa_node. To minimize xa_node allocation and remove the limitation of no split from order-12 (or above) to order-0 (or anything between 0 and 5)[1], xas_try_split() was added[2], which allocates
(n / XA_CHUNK_SHIFT - m / XA_CHUNK_SHIFT) xa_node. It is used for non-uniform folio split, but can be used by __filemap_add_folio() and shmem_split_large_entry().

xas_split_alloc() and xas_split() split an order-9 to order-0:

         ---------------------------------
         |   |   |   |   |   |   |   |   |
         | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
         |   |   |   |   |   |   |   |   |
         ---------------------------------
           |   |                   |   |
     -------   ---               ---   -------
     |           |     ...       |           |
     V           V               V           V
----------- -----------     ----------- -----------
| xa_node | | xa_node | ... | xa_node | | xa_node |
----------- -----------     ----------- -----------

xas_try_split() splits an order-9 to order-0:
---------------------------------

   |   |   |   |   |   |   |   |   |
   | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
   |   |   |   |   |   |   |   |   |
   ---------------------------------
     |
     |
     V

-----------
| xa_node |
-----------

xas_try_split() is designed to be called iteratively with n = m + 1. xas_try_split_mini_order() is added to minmize the number of calls to xas_try_split() by telling the caller the next minimal order to split to instead of n - 1. Splitting order-n to order-m when m= l * XA_CHUNK_SHIFT does not require xa_node allocation and requires 1 xa_node when n=l * XA_CHUNK_SHIFT and m = n - 1, so it is OK to use xas_try_split() with n > m + 1 when no new xa_node is needed.

xfstests quick group test passed on xfs and tmpfs.

Changelog
===
From V2[3]:
1. Fixed shmem_split_large_entry() by setting swap offset correct. (Thank Baolin for the detailed review)
2. Used updated xas_try_split() to avoid a bug when xa_node is allocated by xas_nomem() instead of xas_try_split() itself.

Let me know your comments.

[1] https://lore.kernel.org/linux-mm/[email protected]/
[2] https://lore.kernel.org/linux-mm/[email protected]/
[3] https://lore.kernel.org/linux-mm/[email protected]/

Zi Yan (2):
mm/filemap: use xas_try_split() in __filemap_add_folio() mm/shmem: use xas_try_split() in shmem_split_large_entry()

 include/linux/xarray.h |  7 +++++
 lib/xarray.c           | 25 ++++++++++++++++++
 mm/filemap.c           | 45 +++++++++++++-------------------
 mm/shmem.c             | 59 ++++++++++++++++++++----------------------
 4 files changed, 78 insertions(+), 58 deletions(-)
Signature · 1 line
2.47.2