linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Roesch <shr@devkernel.io>
To: David Hildenbrand <david@redhat.com>
Cc: kernel-team@fb.com, linux-mm@kvack.org, riel@surriel.com,
	mhocko@suse.com, linux-kselftest@vger.kernel.org,
	linux-doc@vger.kernel.org, akpm@linux-foundation.org,
	hannes@cmpxchg.org, willy@infradead.org,
	Bagas Sanjaya <bagasdotme@gmail.com>
Subject: Re: [PATCH v7 1/3] mm: add new api to enable ksm per process
Date: Fri, 14 Apr 2023 13:53:15 -0700	[thread overview]
Message-ID: <qvqwcz46gp6j.fsf@devbig1114.prn1.facebook.com> (raw)
In-Reply-To: <d2df2d42-66bd-3b7a-99a1-370cc91906e4@redhat.com>


David Hildenbrand <david@redhat.com> writes:

> Thanks!
>
> In general,
>
> Acked-by: David Hildenbrand <david@redhat.com>
>
> Two nits below, after staring at some other prctl implementations.
>
>> +#define PR_SET_MEMORY_MERGE		67
>> +#define PR_GET_MEMORY_MERGE		68
>>   #endif /* _LINUX_PRCTL_H */
>> diff --git a/kernel/sys.c b/kernel/sys.c
>> index 495cd87d9bf4..8c2e50edeb18 100644
>> --- a/kernel/sys.c
>> +++ b/kernel/sys.c
>> @@ -15,6 +15,7 @@
>>   #include <linux/highuid.h>
>>   #include <linux/fs.h>
>>   #include <linux/kmod.h>
>> +#include <linux/ksm.h>
>>   #include <linux/perf_event.h>
>>   #include <linux/resource.h>
>>   #include <linux/kernel.h>
>> @@ -2661,6 +2662,30 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
>>   	case PR_SET_VMA:
>>   		error = prctl_set_vma(arg2, arg3, arg4, arg5);
>>   		break;
>> +#ifdef CONFIG_KSM
>> +	case PR_SET_MEMORY_MERGE:
>
> Looking at some other code (PR_SET_NO_NEW_PRIVS/ PR_SET_THP_DISABLE) I wonder if
> we also want
>
> if (arg3 || arg4 || arg5)
> 	return -EINVAL;
>
I added the above check. It requires that we always specify all
parameters in the test programs. I also changed them accordingly.

> For PR_GET_MEMORY_MERGE it looks good already.
>
>> +		if (mmap_write_lock_killable(me->mm))
>> +			return -EINTR;
>> +
>> +		if (arg2) {
>> +			error = ksm_enable_merge_any(me->mm);
>> +		} else {
>> +			/*
>> +			 * TODO: we might want disable KSM on all VMAs and
>> +			 * trigger unsharing to completely disable KSM.
>> +			 */
>> +			clear_bit(MMF_VM_MERGE_ANY, &me->mm->flags);
>> +			error = 0;
>> +		}
>> +		mmap_write_unlock(me->mm);
>> +		break;
>> +	case PR_GET_MEMORY_MERGE:
>> +		if (arg2 || arg3 || arg4 || arg5)
>> +			return -EINVAL;
>> +
>> +		error = !!test_bit(MMF_VM_MERGE_ANY, &me->mm->flags);
>> +		break;
>> +#endif
>>   	default:
>>   		error = -EINVAL;
>>   		break;
>
> [...]
>
>> +/**
>> + * ksm_enable_merge_any - Add mm to mm ksm list and enable merging on all
>> + *                        compatible VMA's
>> + *
>> + * @mm:  Pointer to mm
>> + *
>> + * Returns 0 on success, otherwise error code
>> + */
>> +int ksm_enable_merge_any(struct mm_struct *mm)
>> +{
>> +	int err;
>> +
>> +	if (test_bit(MMF_VM_MERGE_ANY, &mm->flags))
>> +		return -EINVAL;
>
>
> I'm curious, why is enabling the prctl() supposed to fail if already enabled?
> (it would not fail if disabling and already disabled)
>

I changed that to not return an error in that case.
>
> For example, PR_SET_THP_DISABLE/PR_SET_NO_NEW_PRIVS doesn't fail if already set.


  reply	other threads:[~2023-04-14 20:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-13 23:31 [PATCH v7 0/3] mm: process/cgroup ksm support Stefan Roesch
2023-04-13 23:31 ` [PATCH v7 1/3] mm: add new api to enable ksm per process Stefan Roesch
2023-04-14 10:24   ` David Hildenbrand
2023-04-14 20:53     ` Stefan Roesch [this message]
2023-04-13 23:31 ` [PATCH v7 2/3] mm: add new KSM process and sysfs knobs Stefan Roesch
2023-04-13 23:31 ` [PATCH v7 3/3] selftests/mm: add new selftests for KSM Stefan Roesch
2023-04-14 14:28   ` David Hildenbrand
2023-04-14 20:54     ` Stefan Roesch
2023-04-17  8:04       ` David Hildenbrand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=qvqwcz46gp6j.fsf@devbig1114.prn1.facebook.com \
    --to=shr@devkernel.io \
    --cc=akpm@linux-foundation.org \
    --cc=bagasdotme@gmail.com \
    --cc=david@redhat.com \
    --cc=hannes@cmpxchg.org \
    --cc=kernel-team@fb.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=riel@surriel.com \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox