Skip to contentSkip to conversation

mm/ksm: remove redundant code in ksm_fork

PATCH Applied Jinjiang Tu 2 participants 3 messages Apr 2, 2024 – Apr 6, 2024 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index 401348e9f92b..2e61df795803 100644
@@ -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
maintainer
#1 lore raw
Quoted 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, 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 +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]

#3 lore raw
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, 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 +0 -4
index 401348e9f92b..2e61df795803 100644
@@ -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_tests in mm/mm-unstable to make sure they still pass? If so

Sorry for late reply, I was on holiday.

I have run the new ksm_functional_tests and the testcases still pass.