linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/ksm: remove redundant code in ksm_fork
@ 2024-04-02  2:49 Jinjiang Tu
  2024-04-04  1:45 ` Andrew Morton
       [not found] ` <cddc0d26-5163-462e-bb9e-7fd87aacad37@redhat.com>
  0 siblings, 2 replies; 3+ messages in thread
From: Jinjiang Tu @ 2024-04-02  2:49 UTC (permalink / raw)
  To: akpm, david, shr, hannes, riel, wangkefeng.wang, sunnanyong, linux-mm
  Cc: tujinjiang

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().

Signed-off-by: Jinjiang Tu <tujinjiang@huawei.com>
---
 include/linux/ksm.h | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/include/linux/ksm.h b/include/linux/ksm.h
index 401348e9f92b..2e61df795803 100644
--- a/include/linux/ksm.h
+++ b/include/linux/ksm.h
@@ -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;
 }
-- 
2.25.1



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/ksm: remove redundant code in ksm_fork
  2024-04-02  2:49 [PATCH] mm/ksm: remove redundant code in ksm_fork Jinjiang Tu
@ 2024-04-04  1:45 ` Andrew Morton
       [not found] ` <cddc0d26-5163-462e-bb9e-7fd87aacad37@redhat.com>
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Morton @ 2024-04-04  1:45 UTC (permalink / raw)
  To: Jinjiang Tu
  Cc: david, shr, hannes, riel, wangkefeng.wang, sunnanyong, linux-mm

On Tue, 2 Apr 2024 10:49:34 +0800 Jinjiang Tu <tujinjiang@huawei.com> 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().
> 
> ...
>
> --- a/include/linux/ksm.h
> +++ b/include/linux/ksm.h
> @@ -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;

Thanks, I shall queue this up for testing and shall await review input
from Stefan and hopefully others.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/ksm: remove redundant code in ksm_fork
       [not found] ` <cddc0d26-5163-462e-bb9e-7fd87aacad37@redhat.com>
@ 2024-04-06 23:37   ` Jinjiang Tu
  0 siblings, 0 replies; 3+ messages in thread
From: Jinjiang Tu @ 2024-04-06 23:37 UTC (permalink / raw)
  To: David Hildenbrand, akpm, shr, hannes, riel, wangkefeng.wang,
	sunnanyong, linux-mm


在 2024/4/4 23:34, David Hildenbrand 写道:
> On 02.04.24 04:49, Jinjiang Tu 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().
>>
>> Signed-off-by: Jinjiang Tu <tujinjiang@huawei.com>
>> ---
>>   include/linux/ksm.h | 12 ++----------
>>   1 file changed, 2 insertions(+), 10 deletions(-)
>>
>> diff --git a/include/linux/ksm.h b/include/linux/ksm.h
>> index 401348e9f92b..2e61df795803 100644
>> --- a/include/linux/ksm.h
>> +++ b/include/linux/ksm.h
>> @@ -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;
>>   }
>
> I *think* this is correct. :)
>
> Did you run the new ksm_functional_tests in mm/mm-unstable to make 
> sure they still pass? If so
>
> Reviewed-by: David Hildenbrand <david@redhat.com>

Sorry for late reply, I was on holiday.

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




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-06 23:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-02  2:49 [PATCH] mm/ksm: remove redundant code in ksm_fork Jinjiang Tu
2024-04-04  1:45 ` Andrew Morton
     [not found] ` <cddc0d26-5163-462e-bb9e-7fd87aacad37@redhat.com>
2024-04-06 23:37   ` Jinjiang Tu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox