Skip to content

mm, THP, swap: Delay splitting THP after swapped out

Huang, Ying linux-mm linux-nvdimm lkml nvdimm 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest13 patches 4 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/13mm, THP, swap: Support to clear swap cache flag for THP swapped outmm/swapfile.c+25 -70 replies
2/13mm, THP, swap: Support to reclaim swap space for THP swapped outinclude/linux/swap.h mm/swapfile.c+72 -70 replies
3/13mm, THP, swap: Make reuse_swap_page() works for THP swapped outinclude/linux/swap.h mm/huge_memory.c mm/memory.c +1 more+113 -150 replies
4/13mm, THP, swap: Don't allocate huge cluster for file backed swap devicemm/swapfile.c+4 -30 replies
5/13block, THP: Make block_device_operations.rw_page support THPdrivers/block/brd.c drivers/block/zram/zram_drv.c drivers/nvdimm/btt.c +1 more+41 -132 replies
6/13block: Increase BIO_MAX_PAGES to PMD size if THP_SWAP enabledinclude/linux/bio.h+8 -02 replies
7/13mm, THP, swap: Support to write THP to swap device as a wholeinclude/linux/page-flags.h include/linux/vm_event_item.h mm/page_io.c +1 more+20 -70 replies
8/13mm, THP, swap: Support to split THP for THP swapped outinclude/linux/swap.h mm/huge_memory.c mm/swapfile.c+33 -10 replies
9/13memcg, THP, swap: Support move mem cgroup charge for THP swapped outmm/memcontrol.c+5 -20 replies
10/13memcg, THP, swap: Avoid to duplicated charge THP in swap cachemm/memcontrol.c+1 -10 replies
11/13memcg, THP, swap: Make mem_cgroup_swapout() support THPmm/memcontrol.c+15 -80 replies
12/13mm, THP, swap: Delay splitting THP after swapped outmm/vmscan.c+52 -430 replies
13/13mm, THP, swap: Add THP swapping out fallback countinginclude/linux/vm_event_item.h mm/vmscan.c mm/vmstat.c+5 -00 replies

Reviews trailers per patch

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

PatchRoss Zwisler
1/13
2/13
3/13
4/13
5/13R-b
6/13
7/13
8/13
9/13
10/13
11/13
12/13
13/13

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

Read the v1 thread

Cover letter [PATCH -mm 00/13] mm, THP, swap: Delay splitting THP after swapped out

From: Huang Ying <[email protected]>

Hi, Andrew, could you help me to check whether the overall design is reasonable?

Hi, Johannes and Minchan, Thanks a lot for your review to the first step of the THP swap optimization! Could you help me to review the second step in this patchset?

Hi, Hugh, Shaohua, Minchan and Rik, could you help me to review the swap part of the patchset? Especially [01/13], [02/13], [03/13], [04/13], [07/13], [12/13], and [13/13].

Hi, Andrea and Kirill, could you help me to review the THP part of the patchset? Especially [01/13], [03/13], [08/13], [09/13], [10/13], [12/13].

Hi, Jens and Shaohua, could you help me to review the block part of the patchset? Especially [05/13], [06/13], and [07/13].

Hi, Johannes, Michal, could you help me to review the cgroup part of the patchset? Especially [09/13], [10/13], and [11/13].

And for all, Any comment is welcome!

This is the second step of THP (Transparent Huge Page) swap optimization. In the first step, the splitting huge page is delayed from almost the first step of swapping out to after allocating the swap space for the THP and adding the THP into the swap cache. In the second step, the splitting is delayed further to after the swapping out finished. The plan is to delay splitting THP step by step, finally avoid splitting THP for the THP swapping out and swap out/in the THP as a whole.

In the patchset, more operations for the anonymous THP reclaiming, such as TLB flushing, writing the THP to the swap device, removing the THP from the swap cache are batched. So that the performance of anonymous THP swapping out are improved.

This patchset is based on the 5/18 head of mmotm/master.

During the development, the following scenarios/code paths have been checked,

- swap out/in
- swap off
- write protect page fault
- madvise_free
- process exit
- split huge page

Please let me know if I missed something.

With the patchset, the swap out throughput improves 42% (from about 5.81GB/s to about 8.25GB/s) in the vm-scalability swap-w-seq test case with 16 processes. At the same time, the IPI (reflect TLB flushing) reduced about 78.9%. The test is done on a Xeon E5 v3 system. The swap device used is a RAM simulated PMEM (persistent memory) device. To test the sequential swapping out, the test case creates 8 processes, which sequentially allocate and write to the anonymous pages until the RAM and part of the swap device is used up.

Below is the part of the cover letter for the first step patchset of THP swap optimization which applies to all steps.

----------------------------------------------------------------->

Recently, the performance of the storage devices improved so fast that we cannot saturate the disk bandwidth with single logical CPU when do page swap out even on a high-end server machine. Because the performance of the storage device improved faster than that of single logical CPU. And it seems that the trend will not change in the near future. On the other hand, the THP becomes more and more popular because of increased memory size. So it becomes necessary to optimize THP swap performance.

The advantages of the THP swap support include:

- Batch the swap operations for the THP to reduce TLB flushing and lock acquiring/releasing, including allocating/freeing the swap space, adding/deleting to/from the swap cache, and writing/reading the swap space, etc. This will help improve the performance of the THP swap.

- The THP swap space read/write will be 2M sequential IO. It is particularly helpful for the swap read, which are usually 4k random IO. This will improve the performance of the THP swap too.

- It will help the memory fragmentation, especially when the THP is heavily used by the applications. The 2M continuous pages will be free up after THP swapping out.

- It will improve the THP utilization on the system with the swap turned on. Because the speed for khugepaged to collapse the normal pages into the THP is quite slow. After the THP is split during the swapping out, it will take quite long time for the normal pages to collapse back into the THP after being swapped in. The high THP utilization helps the efficiency of the page based memory management too.

There are some concerns regarding THP swap in, mainly because possible enlarged read/write IO size (for swap in/out) may put more overhead on the storage device. To deal with that, the THP swap in should be turned on only when necessary. For example, it can be selected via "always/never/madvise" logic, to be turned on globally, turned off globally, or turned on only for VMA with MADV_HUGEPAGE, etc.

Best Regards,
Huang, Ying

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>