Skip to content

mm/shmem, swap: bugfix and improvement of mTHP swap in

Kairui Song linux-mm lkml stable 6 versions – Applied

Status from this message: [merged mm-stable] mm-shmem-swap-fix-major-fault-counting.patch removed from -mm tree

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v6 Latest8 patches 2 repliesApplied 8/8
  2. v58 patches 13 repliesSuperseded
  3. v49 patches 7 repliesSuperseded
Earlier versions · 3
VersionPostedPatchesRepliesStatus
v37 patches15 repliesSuperseded
v24 patches11 repliesSuperseded
v14 patches17 repliesSuperseded

Patches in v6 All 8 applied

#Subject and filesSizeRepliesApplied
1/8mm/shmem, swap: improve cached mTHP handling and fix potential hangmm/shmem.c+30 -90 repliesApplied
2/8mm/shmem, swap: avoid redundant Xarray lookup during swapinmm/shmem.c+25 -90 repliesApplied
3/8mm/shmem, swap: tidy up THP swapin checksmm/shmem.c+18 -210 repliesApplied
4/8mm/shmem, swap: tidy up swap entry splittingmm/shmem.c+23 -330 repliesApplied
5/8mm/shmem, swap: never use swap cache and readahead for SWP_SYNCHRONOUS_IOmm/shmem.c+28 -130 repliesApplied
6/8mm/shmem, swap: simplify swapin path and result handlingmm/shmem.c+19 -260 repliesApplied
7/8mm/shmem, swap: rework swap entry and index calculation for large swapinmm/shmem.c+33 -340 repliesApplied
8/8mm/shmem, swap: fix major fault countingmm/shmem.c+5 -70 repliesApplied

Reviews trailers per patch

All 8 patches have a Reviewed-by or Acked-by.

PatchKemeng ShiBaolin WangDev Jain
1/8R-b R-b T-b
2/8R-b R-b R-b
3/8R-b
4/8R-b T-b
5/8R-b
6/8R-b
7/8R-b T-b
8/8R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v6 thread

Cover letter [PATCH v6 0/8] mm/shmem, swap: bugfix and improvement of mTHP swap in

From: Kairui Song <[email protected]>

The current THP swapin path have several problems. It may potentially hang, may cause redundant faults due to false positive swap cache lookup, and it issues redundant Xarray walks. !CONFIG_TRANSPARENT_HUGEPAGE builds may also contain unnecessary THP checks.

This series fixes all of the mentioned issues, the code should be more robust and prepared for the swap table series. Now 4 walks is reduced to 3 (get order & confirm, confirm, insert folio), !CONFIG_TRANSPARENT_HUGEPAGE build overhead is also minimized, and comes with a sanity check now.

The performance is slightly better after this series, sequential swap in of 24G data from ZRAM, using transparent_hugepage_tmpfs=always (24 samples each):

Before:         avg: 10.66s, stddev: 0.04
After patch 1:  avg: 10.58s, stddev: 0.04
After patch 2:  avg: 10.65s, stddev: 0.05
After patch 3:  avg: 10.65s, stddev: 0.04
After patch 4:  avg: 10.67s, stddev: 0.04
After patch 5:  avg: 9.79s,  stddev: 0.04
After patch 6:  avg: 9.79s,  stddev: 0.05
After patch 7:  avg: 9.78s,  stddev: 0.05
After patch 8:  avg: 9.79s,  stddev: 0.04

Several patches improve the performance by a little, which is about ~8% faster in total.

Build kernel test showed very slightly improvement, testing with make -j48 with defconfig in a 768M memcg also using ZRAM as swap, and transparent_hugepage_tmpfs=always (6 test runs):

Before:         avg: 3334.66s, stddev: 43.76
After patch 1:  avg: 3349.77s, stddev: 18.55
After patch 2:  avg: 3325.01s, stddev: 42.96
After patch 3:  avg: 3354.58s, stddev: 14.62
After patch 4:  avg: 3336.24s, stddev: 32.15
After patch 5:  avg: 3325.13s, stddev: 22.14
After patch 6:  avg: 3285.03s, stddev: 38.95
After patch 7:  avg: 3287.32s, stddev: 26.37
After patch 8:  avg: 3295.87s, stddev: 46.24

---

V5: https://lore.kernel.org/linux-mm/[email protected]/
Updates:
- Add shmem_confirm_swap back for Patch 1, and fix xas_nomem handling:
https://lore.kernel.org/linux-mm/CAMgjq7DfPXS4PkpGK-zem2L1gZD0dekbAyHa-CPHjf=eonoFXg@mail.gmail.com/
- Fix typo and comments [ Baolin Wang, Hugh Dickins ]
- Rebase the rest of this series. There is basically no change to follow up patches except trivial conflicts. Only patch 1 is a bit different from before.
- Adding the shmem_confirm_swap back in Patch 1 V6 slowed down shmem swapin by about ~2% compares to V5 but it's still a ~8% gain.

V4: https://lore.kernel.org/linux-mm/[email protected]/
Updates:
- Merge patch 5 into patch 8 to fix a intermediate code error. [ Baolin
Wang ]
-6517755a04ae4d82d1220d690944359f1dbea686 Instead of passing two swap entries, calculate the new order 0 entry
in shmem_swap_alloc_folio, to improve code readability. [ Baolin Wang ]
- Rebase on top of mm-new.

V3: https://lore.kernel.org/linux-mm/[email protected]/
Updates:
- Split and reorganize a few intermediate patches [ Baolin Wang ]
- Fix a duplicated fault issue that may occur in one intermediate patch [ Baolin Wang ]
- Improve variable naming [ Baolin Wang ]
- Fix a wrong error value problem, return proper error value when direct swapin failed.
- No major code change from V3.

V2: https://lore.kernel.org/linux-mm/[email protected]/
Updates:
- Split the clean up patch into 3 individual patches [ Baolin Wang ]
- Fix a code error in the first patch [ Baolin Wang ]
- I found there are some other remaining issue that can be fixed after the clean up so includes these too: fix major fault counter, and clean up the goto labels.

V1: https://lore.kernel.org/linux-mm/[email protected]/
Updates:
- Improve of funtion name and variable names, also commit message [ Kemeng Shi, Dev Jain ]
- Correct Fixes: tag [ Andrew Morton ]
- Collect Reviewed-by.

Two of the patches in this series comes from the swap table series [1], and worth noting that the performance gain of this series is independent to the swap table series, we'll see another bigger performance gain and reduce of memory usage after the swap table series.

I found these issues while trying to split the shmem changes out of the swap table series for easier reviewing, and found several more issues while doing stress tests for performance comparision. Barry also mentioned that CONFIG_TRANSPARENT_HUGEPAGE may have redundant checks [2] and I managed to clean them up properly too.

No issue found with a few days of stress testing.

Kairui Song (8):
mm/shmem, swap: improve cached mTHP handling and fix potential hang mm/shmem, swap: avoid redundant Xarray lookup during swapin mm/shmem, swap: tidy up THP swapin checks
mm/shmem, swap: tidy up swap entry splitting
mm/shmem, swap: never use swap cache and readahead for
SWP_SYNCHRONOUS_IO
mm/shmem, swap: simplify swapin path and result handling mm/shmem, swap: rework swap entry and index calculation for large
swapin
mm/shmem, swap: fix major fault counting

 mm/shmem.c | 275 +++++++++++++++++++++++++++++------------------------
 1 file changed, 152 insertions(+), 123 deletions(-)
Signature · 1 line
2.50.1