The patch titled Subject: ksm-abstract-the-function-try_to_get_old_rmap_item-v6 has been added to the -mm mm-unstable branch. Its filename is ksm-abstract-the-function-try_to_get_old_rmap_item-v6.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/ksm-abstract-the-function-try_to_get_old_rmap_item-v6.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: xu xin <xu.xin16@xxxxxxxxxx> Subject: ksm-abstract-the-function-try_to_get_old_rmap_item-v6 Date: Fri, 10 Feb 2023 09:16:42 +0800 (CST) modify some comments according to David's suggestions. Link: https://lkml.kernel.org/r/202302100916423431376@xxxxxxxxxx Signed-off-by: xu xin <xu.xin16@xxxxxxxxxx> Reviewed-by: Xiaokai Ran <ran.xiaokai@xxxxxxxxxx> Reviewed-by: Yang Yang <yang.yang29@xxxxxxxxxx> Cc: David Hildenbrand <david@xxxxxxxxxx> Cc: Claudio Imbrenda <imbrenda@xxxxxxxxxxxxx> Cc: Xuexin Jiang <jiang.xuexin@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- --- a/mm/ksm.c~ksm-abstract-the-function-try_to_get_old_rmap_item-v6 +++ a/mm/ksm.c @@ -2218,12 +2218,16 @@ static struct ksm_rmap_item *try_to_get_ { while (*rmap_list) { struct ksm_rmap_item *rmap_item = *rmap_list; + if ((rmap_item->address & PAGE_MASK) == addr) return rmap_item; if (rmap_item->address > addr) break; *rmap_list = rmap_item->rmap_list; - /* Running here indicates it's vma has been UNMERGEABLE */ + /* + * If we end up here, the VMA is MADV_UNMERGEABLE or its page + * is ineligible or discarded, e.g. MADV_DONTNEED. + */ remove_rmap_item_from_tree(rmap_item); free_rmap_item(rmap_item); } @@ -2237,12 +2241,10 @@ static struct ksm_rmap_item *get_next_rm { struct ksm_rmap_item *rmap_item; - /* lookup if we have a old rmap_item matching the addr*/ rmap_item = try_to_get_old_rmap_item(addr, rmap_list); if (rmap_item) return rmap_item; - /* Need to allocate a new rmap_item */ rmap_item = alloc_rmap_item(); if (rmap_item) { /* It has already been zeroed */ _ Patches currently in -mm which might be from xu.xin16@xxxxxxxxxx are ksm-abstract-the-function-try_to_get_old_rmap_item.patch ksm-abstract-the-function-try_to_get_old_rmap_item-v6.patch ksm-support-unsharing-zero-pages-placed-by-ksm.patch ksm-count-all-zero-pages-placed-by-ksm.patch ksm-count-zero-pages-for-each-process.patch ksm-add-zero_pages_sharing-documentation.patch selftest-add-testing-unsharing-and-counting-ksm-zero-page.patch selftest-add-testing-unsharing-and-counting-ksm-zero-page-v6.patch