mm/ksm: remove redundant code in ksm_fork
PATCH 1/1 mm/ksm: remove redundant code in ksm_fork
Since commit 3c6f33b7273a ("mm/ksm: support fork/exec for prctl"), when a child process is forked, the MMF_VM_MERGE_ANY flag will be inherited in mm_init(). So, it's unnecessary to set the flag in ksm_fork().
--- include/linux/ksm.h | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
include/linux/ksm.h +2 -10
@@ -45,16 +45,8 @@ static inline void ksm_might_unmap_zero_page(struct mm_struct *mm, pte_t pte)static inline int ksm_fork (struct mm_struct *mm,struct mm_struct *oldmm) { -int ret; - -if (test_bit (MMF_VM_MERGEABLE , &oldmm->flags)) { - ret =__ksm_enter (mm); -if (ret) -return ret; - } - -if (test_bit (MMF_VM_MERGE_ANY , &oldmm->flags)) -set_bit (MMF_VM_MERGE_ANY , &mm->flags); +if (test_bit (MMF_VM_MERGEABLE , &oldmm->flags)) +return __ksm_enter (mm);return 0 ; }
Signature · 1 line
2.25.1
Andrew Morton
maintainerQuoted 16 lines · On Tue, 2 Apr 2024 10:49:34 +0800 Jinjiang Tu <[email protected]> wrote:
Since commit
3c6f33b7273a("mm/ksm: support fork/exec for prctl"), when a child process is forked, theMMF_VM_MERGE_ANYflag will be inherited inmm_init(). So, it's unnecessary to set the flag inksm_fork()....
include/linux/ksm.h +0
-4@@ -45,16 +45,8 @@ static inline void ksm_might_unmap_zero_page(struct mm_struct *mm, pte_t pte)static inline int ksm_fork (struct mm_struct *mm,struct mm_struct *oldmm) { -int ret; - -if (test_bit (MMF_VM_MERGEABLE , &oldmm->flags)) { - ret =__ksm_enter (mm);
include/linux/ksm.h static inline void ksm_might_unmap_zero_page(struct mm_struct *mm, pte_t pte) · line 51
Quoted 10 lines
include/linux/ksm.h +2
-6-if (ret) -return ret; - } - -if (test_bit (MMF_VM_MERGE_ANY , &oldmm->flags)) -set_bit (MMF_VM_MERGE_ANY , &mm->flags); +if (test_bit (MMF_VM_MERGEABLE , &oldmm->flags)) +return __ksm_enter (mm);return 0 ;
Thanks, I shall queue this up for testing and shall await review input from Stefan and hopefully others.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 35 lines · David Hildenbrand
Quoted 21 lines · Jinjiang Tu
Since commit
3c6f33b7273a("mm/ksm: support fork/exec for prctl"), when a child process is forked, theMMF_VM_MERGE_ANYflag will be inherited inmm_init(). So, it's unnecessary to set the flag inksm_fork().Signed-off-by Jinjiang Tu <[email protected]>---
include/linux/ksm.h| 12 ++----------1 file changed, 2 insertions(+), 10 deletions(-)include/linux/ksm.h +0
-4@@ -45,16 +45,8 @@ static inline void ksm_might_unmap_zero_page(struct mm_struct *mm, pte_t pte) static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm) { - int ret; - - if (test_bit(MMF_VM_MERGEABLE, &oldmm->flags)) { - ret = __ksm_enter(mm);include/linux/ksm.h static inline void · line 51
Quoted 10 lines
include/linux/ksm.h +2
-6- if (ret) - return ret; - } - - if (test_bit(MMF_VM_MERGE_ANY, &oldmm->flags)) - set_bit(MMF_VM_MERGE_ANY, &mm->flags); + if (test_bit(MMF_VM_MERGEABLE, &oldmm->flags)) + return __ksm_enter(mm); return 0; }I *think* this is correct. :)
Quoted 3 lines
Did you run the new
ksm_functional_testsinmm/mm-unstableto make sure they still pass? If soReviewed-by David Hildenbrand <[email protected]>
Sorry for late reply, I was on holiday.
I have run the new ksm_functional_tests and the testcases still pass.