v3
2026-08-21
清理并解除 folio 分割限制 · v3
重构 THP folio split 系列:修复 swap cache 检查,拆分匿名/文件 folio 逻辑并集中处理加锁、unmap/remap。
原始补丁链接
子 Patch(18)
1/18
mm/swap: fix off-by-one in swap cache replace sanity check
修复__swap_cache_replace_folio()调试检查的off-by-one:while (ci_off++ < ci_end)跳过首项且越界读,改用do-while避免非均匀split时误报。
2/18
mm/huge_memory: fix rejection of swap cache folios with a mapping
修复swap cache folio带mapping时split错误路径:原先在冻结和计数器递减后才拒绝且不还原,改为在folio_check_splittable提前返回-EBUSY,避免folio卡死和计数失衡。
3/18
mm/huge_memory: invert folio_ref_freeze() check to reduce indentation
反转__folio_freeze_and_split_unmapped()中folio_ref_freeze()失败检查,失败提前返回,减少成功路径缩进,无功能变化,为后续拆分helper做准备。
4/18
mm/huge_memory: split the routine for splitting anon and file folio
将__folio_freeze_and_split_unmapped()拆分为anon/file两个helper,各自独立演进;并引入安全的sub-folio迭代helper,避免split后子folio中途释放问题。
5/18
mm/huge_memory: rename __split_unmapped_folio() to __split_frozen_folio()
将__split_unmapped_folio()重命名为__split_frozen_folio(),强调该函数依赖冻结引用计数而非unmap状态,避免误导。
6/18
mm/huge_memory: consolidate irq and locking for folio split
将folio split的irq/锁管理下放到各helper,file路径改用xas_lock_irq(),anon保留local_irq_disable(),删除冗余xas_reset(),为后续清理做准备。
7/18
mm/huge_memory: move EOF trimming into the file split helper
将EOF裁剪逻辑移入file split helper,自行计算边界,删除调用者传递的@end和nr_shmem_dropped参数,简化接口。
8/18
mm/huge_memory: move unmap and remap into the split helpers
From: Kairui Song kasong@tencent.com To prepare for further cleanup, move the unmap/remap handling from __folio_split() into the split helpers. Only anon folios need to be remapped, so remap_page(
9/18
mm/huge_memory: move anon_vma and filemap management into split helpers
From: Kairui Song kasong@tencent.com Only anon split needs vma info, and only file split needs the filemap handling. Move the related code into separate helpers so they are genuinely more self-cont
10/18
mm/huge_memory: move memcg switch into the file split helper
将memcg切换移入file split helper,使xarray节点分配正确计入folio的memcg;anon路径无需计费,__folio_split()不再需要memcg处理。
11/18
mm/huge_memory: allow splitting mappingless swap cache folios
From: Kairui Song kasong@tencent.com Lift the restriction that kept swap cache folios without a mapping from being split. All the underlying infrastructure is sound against that with a few more tw
12/18
mm/huge_memory: add kerneldoc for the split helpers
From: Kairui Song kasong@tencent.com Document __folio_split_unmap_and_freeze() and __folio_split_unmap_and_freeze_file(), and rename the file split helper’s definition to match its call site. Sign
13/18
mm/huge_memory: drop the unused do_lru argument of the file split helper
From: Kairui Song kasong@tencent.com The only caller of __folio_split_unmap_and_freeze_file() always passes do_lru as true, so the argument and the branches gated on it are dead code. Drop it. Si
14/18
mm/huge_memory: clean up after-split folio freeing in __folio_split
From: Kairui Song kasong@tencent.com Replace free_folio_and_swap_cache() with an explicit folio_free_swap() and folio_put() in the after-split loop. free_folio_and_swap_cache() unlocks the folio,
15/18
mm/huge_memory: lift order-0 restriction for swapcache split
解除swapcache folio只能order-0 split的旧限制;现基于swap table cluster锁可替换任意order子folio,除order-1因anon不支持。
16/18
mm/huge_memory: clarify supported split orders in comment
From: Kairui Song kasong@tencent.com The doc comment for __split_huge_page_to_list_to_order() needs an update: only order 1 is rejected for anon and swapcache folios, matching the new_order == 1 ch
17/18
mm/huge_memory: count only swap cache refs in anon folio split
From: Kairui Song kasong@tencent.com Only _folio_freeze_split_unmap() sees anon folios and swap cache folios now. The file split helper only handles page cache folios, which hold exactly folio_nr
18/18
mm/huge_memory: drop the redundant mapping argument of __split_frozen_folio
From: Kairui Song kasong@tencent.com The mapping parameter only served as a non-NULL check to detect whether page cache entries need updating. The xa_state pointer conveys exactly the same informa