Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ksm: replace function unmerge_ksm_pages with break_ksm

Function unmerge_ksm_pages() is unnecessary since now break_ksm() walks an
address range. So replace it with break_ksm().

Link: https://lkml.kernel.org/r/20251105184912.186329-4-pedrodemargomes@gmail.com
Signed-off-by: Pedro Demarchi Gomes <pedrodemargomes@gmail.com>
Suggested-by: David Hildenbrand (Red Hat) <david@kernel.org>
Acked-by: David Hildenbrand (Red Hat) <david@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Pedro Demarchi Gomes and committed by
Andrew Morton
05c3fa9c 5d4939fc

+16 -24
+16 -24
mm/ksm.c
··· 665 665 }; 666 666 667 667 /* 668 + * Though it's very tempting to unmerge rmap_items from stable tree rather 669 + * than check every pte of a given vma, the locking doesn't quite work for 670 + * that - an rmap_item is assigned to the stable tree after inserting ksm 671 + * page and upping mmap_lock. Nor does it fit with the way we skip dup'ing 672 + * rmap_items from parent to child at fork time (so as not to waste time 673 + * if exit comes before the next scan reaches it). 674 + * 675 + * Similarly, although we'd like to remove rmap_items (so updating counts 676 + * and freeing memory) when unmerging an area, it's easier to leave that 677 + * to the next pass of ksmd - consider, for example, how ksmd might be 678 + * in cmp_and_merge_page on one of the rmap_items we would be removing. 679 + * 668 680 * We use break_ksm to break COW on a ksm page by triggering unsharing, 669 681 * such that the ksm page will get replaced by an exclusive anonymous page. 670 682 * ··· 1083 1071 } 1084 1072 } 1085 1073 1086 - /* 1087 - * Though it's very tempting to unmerge rmap_items from stable tree rather 1088 - * than check every pte of a given vma, the locking doesn't quite work for 1089 - * that - an rmap_item is assigned to the stable tree after inserting ksm 1090 - * page and upping mmap_lock. Nor does it fit with the way we skip dup'ing 1091 - * rmap_items from parent to child at fork time (so as not to waste time 1092 - * if exit comes before the next scan reaches it). 1093 - * 1094 - * Similarly, although we'd like to remove rmap_items (so updating counts 1095 - * and freeing memory) when unmerging an area, it's easier to leave that 1096 - * to the next pass of ksmd - consider, for example, how ksmd might be 1097 - * in cmp_and_merge_page on one of the rmap_items we would be removing. 1098 - */ 1099 - static int unmerge_ksm_pages(struct vm_area_struct *vma, 1100 - unsigned long start, unsigned long end, bool lock_vma) 1101 - { 1102 - return break_ksm(vma, start, end, lock_vma); 1103 - } 1104 - 1105 1074 static inline 1106 1075 struct ksm_stable_node *folio_stable_node(const struct folio *folio) 1107 1076 { ··· 1220 1227 for_each_vma(vmi, vma) { 1221 1228 if (!(vma->vm_flags & VM_MERGEABLE) || !vma->anon_vma) 1222 1229 continue; 1223 - err = unmerge_ksm_pages(vma, 1224 - vma->vm_start, vma->vm_end, false); 1230 + err = break_ksm(vma, vma->vm_start, vma->vm_end, false); 1225 1231 if (err) 1226 1232 goto error; 1227 1233 } ··· 2847 2855 return 0; 2848 2856 2849 2857 if (vma->anon_vma) { 2850 - err = unmerge_ksm_pages(vma, vma->vm_start, vma->vm_end, true); 2858 + err = break_ksm(vma, vma->vm_start, vma->vm_end, true); 2851 2859 if (err) 2852 2860 return err; 2853 2861 } ··· 2999 3007 return 0; /* just ignore the advice */ 3000 3008 3001 3009 if (vma->anon_vma) { 3002 - err = unmerge_ksm_pages(vma, start, end, true); 3010 + err = break_ksm(vma, start, end, true); 3003 3011 if (err) 3004 3012 return err; 3005 3013 } ··· 3381 3389 * Prevent ksm_do_scan(), unmerge_and_remove_all_rmap_items() 3382 3390 * and remove_all_stable_nodes() while memory is going offline: 3383 3391 * it is unsafe for them to touch the stable tree at this time. 3384 - * But unmerge_ksm_pages(), rmap lookups and other entry points 3392 + * But break_ksm(), rmap lookups and other entry points 3385 3393 * which do not need the ksm_thread_mutex are all safe. 3386 3394 */ 3387 3395 mutex_lock(&ksm_thread_mutex);