Skip to content

mm/khugepaged: collapse_file() cleanups

Pedro Falcato linux-mm lkml 2 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest8 patches 0 repliesNew
  2. v18 patches 12 repliesSuperseded

Changes in v2 from the cover letter · 17 lines

- Rebased on current mm-core/for-next, which contains a number of fixes to the amazingly simple and awesome collapse_file() function.
- Fix the "bad unlock balance" reported by syzbot ci (syzbot ci, Lorenzo)
- 1/8:
- Fold in v1 5/8 (kerneldoc); new helpers get their kerneldoc in the patch that introduces them. (Lorenzo)
- Group the input fields of collapse_file_state and make end and is_shmem const; is_shmem is now a bool. (Lorenzo)
- Wrap the prepare_collapse_file_folio() declaration to fit in 80 columns. (Lorenzo)
- Keep the original LRU drain behaviour (drain only after a successful shmem_get_folio()) (Lorenzo)
- 2/8: New patch. Turn value entries into NULL before calling prepare_collapse_file_folio().
- 3/8 (v1 2/8):
- Rename collapse_read_folio() to maybe_read_folio(). (Lorenzo)
- Replace the compound condition with an early-return guard. (Lorenzo)
- Comment on why the xa_lock is dropped. (Lorenzo)
- Expand the commit message. (Lorenzo)
- 5/8 (v1 4/8): Drop a duplicate blank line.
- 6/8: Add a commit message, noting that errors before try_to_unmap() no longer call try_to_unmap_flush() themselves.
- 7/8: Explain in the commit message why the refcount and dirty checks don't need the i_pages lock. The flush added by 854e5ff8b3ce now happens at out_putback.
- 8/8: Retitle (drop "fix"), since 854e5ff8b3ce already reworded the comment; drop a stray blank line.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/8mm/khugepaged: separate out windy folio logic from collapse_filemm/khugepaged.c+128 -740 replies
2/8mm/khugepaged: sanitize the folio passed to file folio collapse logicmm/khugepaged.c+21 -40 replies
3/8mm/khugepaged: factor out page cache folio readingmm/khugepaged.c+59 -180 replies
4/8mm/khugepaged: factor out and simplify dirty/writeback handlingmm/khugepaged.c+24 -230 replies
5/8mm/khugepaged: simplify prepare folio locking and exit pathsmm/khugepaged.c+11 -220 replies
6/8mm/khugepaged: hoist isolation into collapse_isolate_folio()mm/khugepaged.c+66 -520 replies
7/8mm/khugepaged: hoist more code into collapse_isolate_folio()mm/khugepaged.c+42 -510 replies
8/8mm/khugepaged: flesh out try_to_unmap_flush() commentmm/khugepaged.c+6 -20 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/8] mm/khugepaged: collapse_file() cleanups

Here are a bunch of cleanups for collapse_file() that attempt to aid code readability and understanding. This is part 1 out of N, and only attempts to address the main collapse loop. The exit path is still a mess but I figure it's much easier to review if I send this batch as-is, versus sending the whole thing.

Tested using the khugepaged shmem and file selftests.

Based on top of latest mm-core/for-next.

Note that some review comments from v1 went unaddressed (Nico's larger restructuring, some small Lorenzo suggestions) for a couple of small reasons. The main one being that I want to get this v2 out before going insane :)) I agreed to work with Nico, and I'll either send out some of his patches as a followup, or he will.

In any case, I'm tired of this function and I hope this kicks off some discussion :)

Cc Baolin Wang <[email protected]>
Cc "Liam R. Howlett" <[email protected]>
Cc Nico Pache <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc Dev Jain <[email protected]>
Cc Barry Song <[email protected]>
Cc Lance Yang <[email protected]>
Cc Usama Arif <[email protected]>
Cc Lorenzo Stoakes <[email protected]>
Cc Kiryl Shutsemau <[email protected]>

Changes in v2:
- Rebased on current mm-core/for-next, which contains a number of fixes to the amazingly simple and awesome collapse_file() function.
- Fix the "bad unlock balance" reported by syzbot ci (syzbot ci, Lorenzo)
- 1/8:
- Fold in v1 5/8 (kerneldoc); new helpers get their kerneldoc in the patch that introduces them. (Lorenzo)
- Group the input fields of collapse_file_state and make end and is_shmem const; is_shmem is now a bool. (Lorenzo)
- Wrap the prepare_collapse_file_folio() declaration to fit in 80 columns. (Lorenzo)
- Keep the original LRU drain behaviour (drain only after a successful shmem_get_folio()) (Lorenzo)
- 2/8: New patch. Turn value entries into NULL before calling prepare_collapse_file_folio().
- 3/8 (v1 2/8):
- Rename collapse_read_folio() to maybe_read_folio(). (Lorenzo)
- Replace the compound condition with an early-return guard. (Lorenzo)
- Comment on why the xa_lock is dropped. (Lorenzo)
- Expand the commit message. (Lorenzo)
- 5/8 (v1 4/8): Drop a duplicate blank line.
- 6/8: Add a commit message, noting that errors before try_to_unmap() no longer call try_to_unmap_flush() themselves.
- 7/8: Explain in the commit message why the refcount and dirty checks don't need the i_pages lock. The flush added by 854e5ff8b3ce now happens at out_putback.
- 8/8: Retitle (drop "fix"), since 854e5ff8b3ce already reworded the comment; drop a stray blank line.

Link to v1: https://lore.kernel.org/all/[email protected]/

Pedro Falcato (8):
mm/khugepaged: separate out windy folio logic from collapse_file mm/khugepaged: sanitize the folio passed to file folio collapse logic mm/khugepaged: factor out page cache folio reading mm/khugepaged: factor out and simplify dirty/writeback handling mm/khugepaged: simplify prepare folio locking and exit paths mm/khugepaged: hoist isolation into collapse_isolate_folio() mm/khugepaged: hoist more code into collapse_isolate_folio() mm/khugepaged: flesh out try_to_unmap_flush() comment

 mm/khugepaged.c | 461 ++++++++++++++++++++++++++++++------------------
 1 file changed, 286 insertions(+), 175 deletions(-)

base-commit: 8d21e3d3faf19f461f6d0380fe8a1f5bdba97f25

Signature · 1 line
2.56.0