Linux Kernel Selftest development
 help / color / mirror / Atom feed
* [PATCH v5 0/3] mm: process/cgroup ksm support
@ 2023-04-06 16:53 Stefan Roesch
       [not found] ` <20230406165339.1017597-2-shr@devkernel.io>
       [not found] ` <20230406165339.1017597-3-shr@devkernel.io>
  0 siblings, 2 replies; 7+ messages in thread
From: Stefan Roesch @ 2023-04-06 16:53 UTC (permalink / raw)
  To: kernel-team
  Cc: shr, linux-mm, riel, mhocko, david, linux-kselftest, linux-doc,
	akpm, hannes

So far KSM can only be enabled by calling madvise for memory regions. To
be able to use KSM for more workloads, KSM needs to have the ability to be
enabled / disabled at the process / cgroup level.

Use case 1:
The madvise call is not available in the programming language. An example for
this are programs with forked workloads using a garbage collected language without
pointers. In such a language madvise cannot be made available.

In addition the addresses of objects get moved around as they are garbage
collected. KSM sharing needs to be enabled "from the outside" for these type of
workloads.

Use case 2:
The same interpreter can also be used for workloads where KSM brings no
benefit or even has overhead. We'd like to be able to enable KSM on a workload
by workload basis.

Use case 3:
With the madvise call sharing opportunities are only enabled for the current
process: it is a workload-local decision. A considerable number of sharing
opportunities may exist across multiple workloads or jobs (if they are part
of the same security domain). Only a higler level entity like a job scheduler
or container can know for certain if its running one or more instances of a
job. That job scheduler however doesn't have the necessary internal workload
knowledge to make targeted madvise calls.

Security concerns:
In previous discussions security concerns have been brought up. The problem is
that an individual workload does not have the knowledge about what else is
running on a machine. Therefore it has to be very conservative in what memory
areas can be shared or not. However, if the system is dedicated to running
multiple jobs within the same security domain, its the job scheduler that has
the knowledge that sharing can be safely enabled and is even desirable.

Performance:
Experiments with using UKSM have shown a capacity increase of around 20%.


1. New options for prctl system command
This patch series adds two new options to the prctl system call. The first
one allows to enable KSM at the process level and the second one to query the
setting.

The setting will be inherited by child processes.

With the above setting, KSM can be enabled for the seed process of a cgroup
and all processes in the cgroup will inherit the setting.

2. Changes to KSM processing
When KSM is enabled at the process level, the KSM code will iterate over all
the VMA's and enable KSM for the eligible VMA's.

When forking a process that has KSM enabled, the setting will be inherited by
the new child process.

In addition when KSM is disabled for a process, KSM will be disabled for the
VMA's where KSM has been enabled.

3. Add general_profit metric
The general_profit metric of KSM is specified in the documentation, but not
calculated. This adds the general profit metric to /sys/kernel/debug/mm/ksm.

4. Add more metrics to ksm_stat
This adds the process profit and ksm type metric to /proc/<pid>/ksm_stat.

5. Add more tests to ksm_tests
This adds an option to specify the merge type to the ksm_tests. This allows to
test madvise and prctl KSM. It also adds a new option to query if prctl KSM has
been enabled. It adds a fork test to verify that the KSM process setting is
inherited by client processes.


Changes:
- V5:
  - When the prctl system call is invoked, mark all compatible VMA
    as mergeable
  - Instead of checcking during scan if VMA is mergeable, mark the VMA
    mergeable when the VMA is created (in case the VMA is compatible)
    - Remove earlier changes, they are no longer necessary
  - Unset the flag MMF_VM_MERGE_ANY in gmap_mark_unmergeable().
  - When unsetting the MMF_VM_MERGE_ANY flag with prctl, only unset the
    flag
  - Remove pages_volatile function (with the simplar general_profit calculation,
    the function is no longer needed)
  - Use simpler formula for calculation of general_profit

- V4:
  - removing check in prctl for MMF_VM_MERGEABLE in PR_SET_MEMORY_MERGE
    handling
  - Checking for VM_MERGEABLE AND MMF_VM_MERGE_ANY to avoid chaning vm_flags
    - This requires also checking that the vma is compatible. The
      compatibility check is provided by a new helper
    - processes which have set MMF_VM_MERGE_ANY, only need to call the
      helper and not madvise.
  - removed unmerge_vmas function, this function is no longer necessary,
    clearing the MMF_VM_MERGE_ANY bit is sufficient

- V3:
  - folded patch 1 - 6
  - folded patch 7 - 14
  - folded patch 15 - 19
  - Expanded on the use cases in the cover letter
  - Added a section on security concerns to the cover letter

- V2:
  - Added use cases to the cover letter
  - Removed the tracing patch from the patch series and posted it as an
    individual patch
  - Refreshed repo


Stefan Roesch (3):
  mm: add new api to enable ksm per process
  mm: add new KSM process and sysfs knobs
  selftests/mm: add new selftests for KSM

 Documentation/ABI/testing/sysfs-kernel-mm-ksm |   8 +
 Documentation/admin-guide/mm/ksm.rst          |   8 +-
 arch/s390/mm/gmap.c                           |   1 +
 fs/proc/base.c                                |   5 +
 include/linux/ksm.h                           |  36 ++-
 include/linux/sched/coredump.h                |   1 +
 include/uapi/linux/prctl.h                    |   2 +
 kernel/fork.c                                 |   1 +
 kernel/sys.c                                  |  24 ++
 mm/ksm.c                                      | 143 ++++++++--
 mm/mmap.c                                     |   7 +
 tools/include/uapi/linux/prctl.h              |   2 +
 tools/testing/selftests/mm/Makefile           |   2 +-
 tools/testing/selftests/mm/ksm_tests.c        | 254 +++++++++++++++---
 14 files changed, 426 insertions(+), 68 deletions(-)

-- 
2.34.1


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

* Re: [PATCH v5 1/3] mm: add new api to enable ksm per process
       [not found] ` <20230406165339.1017597-2-shr@devkernel.io>
@ 2023-04-06 23:29   ` Andrew Morton
  2023-04-07  4:09     ` Stefan Roesch
  2023-04-11 22:35   ` Matthew Wilcox
  1 sibling, 1 reply; 7+ messages in thread
From: Andrew Morton @ 2023-04-06 23:29 UTC (permalink / raw)
  To: Stefan Roesch
  Cc: kernel-team, linux-mm, riel, mhocko, david, linux-kselftest,
	linux-doc, hannes, Bagas Sanjaya

On Thu,  6 Apr 2023 09:53:37 -0700 Stefan Roesch <shr@devkernel.io> wrote:

> So far KSM can only be enabled by calling madvise for memory regions.  To
> be able to use KSM for more workloads, KSM needs to have the ability to be
> enabled / disabled at the process / cgroup level.
> 
> ...
>
> @@ -53,6 +62,18 @@ void folio_migrate_ksm(struct folio *newfolio, struct folio *folio);
>  
>  #else  /* !CONFIG_KSM */
>  
> +static inline int ksm_add_mm(struct mm_struct *mm)
> +{
> +}

The compiler doesn't like the lack of a return value.

I queued up a patch to simply delete the above function - seems that
ksm_add_mm() has no callers if CONFIG_KSM=n.

The same might be true of the ksm_add_vma()...ksm_exit() stubs also,
Perhaps some kind soul could take a look at whether we can simply clean
those out.


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

* Re: [PATCH v5 1/3] mm: add new api to enable ksm per process
  2023-04-06 23:29   ` [PATCH v5 1/3] mm: add new api to enable ksm per process Andrew Morton
@ 2023-04-07  4:09     ` Stefan Roesch
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Roesch @ 2023-04-07  4:09 UTC (permalink / raw)
  To: Andrew Morton
  Cc: kernel-team, linux-mm, riel, mhocko, david, linux-kselftest,
	linux-doc, hannes, Bagas Sanjaya


Andrew Morton <akpm@linux-foundation.org> writes:

> On Thu,  6 Apr 2023 09:53:37 -0700 Stefan Roesch <shr@devkernel.io> wrote:
>
>> So far KSM can only be enabled by calling madvise for memory regions.  To
>> be able to use KSM for more workloads, KSM needs to have the ability to be
>> enabled / disabled at the process / cgroup level.
>>
>> ...
>>
>> @@ -53,6 +62,18 @@ void folio_migrate_ksm(struct folio *newfolio, struct folio *folio);
>>
>>  #else  /* !CONFIG_KSM */
>>
>> +static inline int ksm_add_mm(struct mm_struct *mm)
>> +{
>> +}
>
> The compiler doesn't like the lack of a return value.
>
> I queued up a patch to simply delete the above function - seems that
> ksm_add_mm() has no callers if CONFIG_KSM=n.
>
> The same might be true of the ksm_add_vma()...ksm_exit() stubs also,
> Perhaps some kind soul could take a look at whether we can simply clean
> those out.

ksm_add_mm() and ksm_add_vmas() is not needed.
However ksm_add_vma() is required. It is called from mm/mmap.c

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

* Re: [PATCH v5 2/3] mm: add new KSM process and sysfs knobs
       [not found] ` <20230406165339.1017597-3-shr@devkernel.io>
@ 2023-04-11  9:10   ` David Hildenbrand
  2023-04-11 22:29     ` Stefan Roesch
  0 siblings, 1 reply; 7+ messages in thread
From: David Hildenbrand @ 2023-04-11  9:10 UTC (permalink / raw)
  To: Stefan Roesch, kernel-team
  Cc: linux-mm, riel, mhocko, linux-kselftest, linux-doc, akpm, hannes,
	Bagas Sanjaya

On 06.04.23 18:53, Stefan Roesch wrote:
> This adds the general_profit KSM sysfs knob and the process profit metric
> and process merge type knobs to ksm_stat.
> 
> 1) expose general_profit metric
> 
>     The documentation mentions a general profit metric, however this
>     metric is not calculated.  In addition the formula depends on the size
>     of internal structures, which makes it more difficult for an
>     administrator to make the calculation.  Adding the metric for a better
>     user experience.
> 
> 2) document general_profit sysfs knob
> 
> 3) calculate ksm process profit metric
> 
>     The ksm documentation mentions the process profit metric and how to
>     calculate it.  This adds the calculation of the metric.
> 
> 4) add ksm_merge_type() function
> 
>     This adds the ksm_merge_type function.  The function returns the
>     merge type for the process.  For madvise it returns "madvise", for
>     prctl it returns "process" and otherwise it returns "none".

I'm curious, why exactly is this change required in this context? It 
might be sufficient to observe if the prctl is set for a process. If 
not, the ksm stats can reveal whether KSM is still active for that 
process -> madvise.

For your use case, I'd assume it's pretty unnecessary to expose that.

If there is no compelling reason, I'd suggest to drop this and limit 
this patch to exposing the general/per-mm profit, which I can understand 
why it's desirable when fine-tuning a workload.


[...]

> Signed-off-by: Stefan Roesch <shr@devkernel.io>
> Reviewed-by: Bagas Sanjaya <bagasdotme@gmail.com>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Johannes Weiner <hannes@cmpxchg.org>
> Cc: Michal Hocko <mhocko@suse.com>
> Cc: Rik van Riel <riel@surriel.com>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> ---
>   Documentation/ABI/testing/sysfs-kernel-mm-ksm |  8 +++++
>   Documentation/admin-guide/mm/ksm.rst          |  8 ++++-
>   fs/proc/base.c                                |  5 +++
>   include/linux/ksm.h                           |  5 +++
>   mm/ksm.c                                      | 32 +++++++++++++++++++
>   5 files changed, 57 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/ABI/testing/sysfs-kernel-mm-ksm b/Documentation/ABI/testing/sysfs-kernel-mm-ksm
> index d244674a9480..7768e90f7a8f 100644
> --- a/Documentation/ABI/testing/sysfs-kernel-mm-ksm
> +++ b/Documentation/ABI/testing/sysfs-kernel-mm-ksm
> @@ -51,3 +51,11 @@ Description:	Control merging pages across different NUMA nodes.
>   
>   		When it is set to 0 only pages from the same node are merged,
>   		otherwise pages from all nodes can be merged together (default).
> +
> +What:		/sys/kernel/mm/ksm/general_profit
> +Date:		January 2023

^ No

> +KernelVersion:  6.1

^ Outdated

(kind of weird having to come up with the right numbers before getting 
it merged)

[...]

>   
> diff --git a/fs/proc/base.c b/fs/proc/base.c
> index 07463ad4a70a..c74450318e05 100644
> --- a/fs/proc/base.c
> +++ b/fs/proc/base.c
> @@ -96,6 +96,7 @@
>   #include <linux/time_namespace.h>
>   #include <linux/resctrl.h>
>   #include <linux/cn_proc.h>
> +#include <linux/ksm.h>
>   #include <trace/events/oom.h>
>   #include "internal.h"
>   #include "fd.h"
> @@ -3199,6 +3200,7 @@ static int proc_pid_ksm_merging_pages(struct seq_file *m, struct pid_namespace *
>   
>   	return 0;
>   }
> +

^ unrelated change

>   static int proc_pid_ksm_stat(struct seq_file *m, struct pid_namespace *ns,
>   				struct pid *pid, struct task_struct *task)
>   {
> @@ -3208,6 +3210,9 @@ static int proc_pid_ksm_stat(struct seq_file *m, struct pid_namespace *ns,
>   	if (mm) {
>   		seq_printf(m, "ksm_rmap_items %lu\n", mm->ksm_rmap_items);
>   		seq_printf(m, "zero_pages_sharing %lu\n", mm->ksm_zero_pages_sharing);
> +		seq_printf(m, "ksm_merging_pages %lu\n", mm->ksm_merging_pages);
> +		seq_printf(m, "ksm_merge_type %s\n", ksm_merge_type(mm));
> +		seq_printf(m, "ksm_process_profit %ld\n", ksm_process_profit(mm));
>   		mmput(mm);
>   	}
>   
> diff --git a/include/linux/ksm.h b/include/linux/ksm.h
> index c65455bf124c..4c32f9bca723 100644
> --- a/include/linux/ksm.h
> +++ b/include/linux/ksm.h
> @@ -60,6 +60,11 @@ struct page *ksm_might_need_to_copy(struct page *page,
>   void rmap_walk_ksm(struct folio *folio, struct rmap_walk_control *rwc);
>   void folio_migrate_ksm(struct folio *newfolio, struct folio *folio);
>   
> +#ifdef CONFIG_PROC_FS
> +long ksm_process_profit(struct mm_struct *);
> +const char *ksm_merge_type(struct mm_struct *mm);
> +#endif /* CONFIG_PROC_FS */
> +
>   #else  /* !CONFIG_KSM */
>   
>   static inline int ksm_add_mm(struct mm_struct *mm)
> diff --git a/mm/ksm.c b/mm/ksm.c
> index ab95ae0f9def..76b10ff840ac 100644
> --- a/mm/ksm.c
> +++ b/mm/ksm.c
> @@ -3042,6 +3042,25 @@ static void wait_while_offlining(void)
>   }
>   #endif /* CONFIG_MEMORY_HOTREMOVE */
>   
> +#ifdef CONFIG_PROC_FS
> +long ksm_process_profit(struct mm_struct *mm)
> +{
> +	return (long)mm->ksm_merging_pages * PAGE_SIZE -

Do we really need the cast to long? mm->ksm_merging_pages is defined as 
"unsigned long". Just like "ksm_pages_sharing" below.

> +		mm->ksm_rmap_items * sizeof(struct ksm_rmap_item);
> +}
> +
> +/* Return merge type name as string. */
> +const char *ksm_merge_type(struct mm_struct *mm)
> +{
> +	if (test_bit(MMF_VM_MERGE_ANY, &mm->flags))
> +		return "process";
> +	else if (test_bit(MMF_VM_MERGEABLE, &mm->flags))
> +		return "madvise";
> +	else
> +		return "none";
> +}
> +#endif /* CONFIG_PROC_FS */
> +

Apart from these nits, LGTM (again, I don't see why the merge type 
should belong into this patch, and why there is a real need to expose it 
like that).

Acked-by: David Hildenbrand <david@redhat.com>

-- 
Thanks,

David / dhildenb


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

* Re: [PATCH v5 2/3] mm: add new KSM process and sysfs knobs
  2023-04-11  9:10   ` [PATCH v5 2/3] mm: add new KSM process and sysfs knobs David Hildenbrand
@ 2023-04-11 22:29     ` Stefan Roesch
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Roesch @ 2023-04-11 22:29 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: kernel-team, linux-mm, riel, mhocko, linux-kselftest, linux-doc,
	akpm, hannes, Bagas Sanjaya


David Hildenbrand <david@redhat.com> writes:

> On 06.04.23 18:53, Stefan Roesch wrote:
>> This adds the general_profit KSM sysfs knob and the process profit metric
>> and process merge type knobs to ksm_stat.
>> 1) expose general_profit metric
>>     The documentation mentions a general profit metric, however this
>>     metric is not calculated.  In addition the formula depends on the size
>>     of internal structures, which makes it more difficult for an
>>     administrator to make the calculation.  Adding the metric for a better
>>     user experience.
>> 2) document general_profit sysfs knob
>> 3) calculate ksm process profit metric
>>     The ksm documentation mentions the process profit metric and how to
>>     calculate it.  This adds the calculation of the metric.
>> 4) add ksm_merge_type() function
>>     This adds the ksm_merge_type function.  The function returns the
>>     merge type for the process.  For madvise it returns "madvise", for
>>     prctl it returns "process" and otherwise it returns "none".
>
> I'm curious, why exactly is this change required in this context? It might be
> sufficient to observe if the prctl is set for a process. If not, the ksm stats
> can reveal whether KSM is still active for that process -> madvise.
>
> For your use case, I'd assume it's pretty unnecessary to expose that.
>
> If there is no compelling reason, I'd suggest to drop this and limit this patch
> to exposing the general/per-mm profit, which I can understand why it's desirable
> when fine-tuning a workload.
>
>
> [...]
>

In the next version, the ksm_merge_type function() is removed.

>
>> Signed-off-by: Stefan Roesch <shr@devkernel.io>
>> Reviewed-by: Bagas Sanjaya <bagasdotme@gmail.com>
>> Cc: David Hildenbrand <david@redhat.com>
>> Cc: Johannes Weiner <hannes@cmpxchg.org>
>> Cc: Michal Hocko <mhocko@suse.com>
>> Cc: Rik van Riel <riel@surriel.com>
>> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
>> ---
>>   Documentation/ABI/testing/sysfs-kernel-mm-ksm |  8 +++++
>>   Documentation/admin-guide/mm/ksm.rst          |  8 ++++-
>>   fs/proc/base.c                                |  5 +++
>>   include/linux/ksm.h                           |  5 +++
>>   mm/ksm.c                                      | 32 +++++++++++++++++++
>>   5 files changed, 57 insertions(+), 1 deletion(-)
>> diff --git a/Documentation/ABI/testing/sysfs-kernel-mm-ksm
>> b/Documentation/ABI/testing/sysfs-kernel-mm-ksm
>> index d244674a9480..7768e90f7a8f 100644
>> --- a/Documentation/ABI/testing/sysfs-kernel-mm-ksm
>> +++ b/Documentation/ABI/testing/sysfs-kernel-mm-ksm
>> @@ -51,3 +51,11 @@ Description:	Control merging pages across different NUMA nodes.
>>     		When it is set to 0 only pages from the same node are merged,
>>   		otherwise pages from all nodes can be merged together (default).
>> +
>> +What:		/sys/kernel/mm/ksm/general_profit
>> +Date:		January 2023
>
> ^ N
>
Updated in the next version.

>> +KernelVersion:  6.1
>
> ^ Outdated
>
Updated in the next version.

> (kind of weird having to come up with the right numbers before getting it
> merged)
>
> [...]
>
>>   diff --git a/fs/proc/base.c b/fs/proc/base.c
>> index 07463ad4a70a..c74450318e05 100644
>> --- a/fs/proc/base.c
>> +++ b/fs/proc/base.c
>> @@ -96,6 +96,7 @@
>>   #include <linux/time_namespace.h>
>>   #include <linux/resctrl.h>
>>   #include <linux/cn_proc.h>
>> +#include <linux/ksm.h>
>>   #include <trace/events/oom.h>
>>   #include "internal.h"
>>   #include "fd.h"
>> @@ -3199,6 +3200,7 @@ static int proc_pid_ksm_merging_pages(struct seq_file *m, struct pid_namespace *
>>     	return 0;
>>   }
>> +
>
> ^ unrelated change
>

Fixed in the next version.

>>   static int proc_pid_ksm_stat(struct seq_file *m, struct pid_namespace *ns,
>>   				struct pid *pid, struct task_struct *task)
>>   {
>> @@ -3208,6 +3210,9 @@ static int proc_pid_ksm_stat(struct seq_file *m, struct pid_namespace *ns,
>>   	if (mm) {
>>   		seq_printf(m, "ksm_rmap_items %lu\n", mm->ksm_rmap_items);
>>   		seq_printf(m, "zero_pages_sharing %lu\n", mm->ksm_zero_pages_sharing);
>> +		seq_printf(m, "ksm_merging_pages %lu\n", mm->ksm_merging_pages);
>> +		seq_printf(m, "ksm_merge_type %s\n", ksm_merge_type(mm));
>> +		seq_printf(m, "ksm_process_profit %ld\n", ksm_process_profit(mm));
>>   		mmput(mm);
>>   	}
>>   diff --git a/include/linux/ksm.h b/include/linux/ksm.h
>> index c65455bf124c..4c32f9bca723 100644
>> --- a/include/linux/ksm.h
>> +++ b/include/linux/ksm.h
>> @@ -60,6 +60,11 @@ struct page *ksm_might_need_to_copy(struct page *page,
>>   void rmap_walk_ksm(struct folio *folio, struct rmap_walk_control *rwc);
>>   void folio_migrate_ksm(struct folio *newfolio, struct folio *folio);
>>   +#ifdef CONFIG_PROC_FS
>> +long ksm_process_profit(struct mm_struct *);
>> +const char *ksm_merge_type(struct mm_struct *mm);
>> +#endif /* CONFIG_PROC_FS */
>> +
>>   #else  /* !CONFIG_KSM */
>>     static inline int ksm_add_mm(struct mm_struct *mm)
>> diff --git a/mm/ksm.c b/mm/ksm.c
>> index ab95ae0f9def..76b10ff840ac 100644
>> --- a/mm/ksm.c
>> +++ b/mm/ksm.c
>> @@ -3042,6 +3042,25 @@ static void wait_while_offlining(void)
>>   }
>>   #endif /* CONFIG_MEMORY_HOTREMOVE */
>>   +#ifdef CONFIG_PROC_FS
>> +long ksm_process_profit(struct mm_struct *mm)
>> +{
>> +	return (long)mm->ksm_merging_pages * PAGE_SIZE -
>
> Do we really need the cast to long? mm->ksm_merging_pages is defined as
> "unsigned long". Just like "ksm_pages_sharing" below.
>

Removed the cast in the next version.

>> +		mm->ksm_rmap_items * sizeof(struct ksm_rmap_item);
>> +}
>> +
>> +/* Return merge type name as string. */
>> +const char *ksm_merge_type(struct mm_struct *mm)
>> +{
>> +	if (test_bit(MMF_VM_MERGE_ANY, &mm->flags))
>> +		return "process";
>> +	else if (test_bit(MMF_VM_MERGEABLE, &mm->flags))
>> +		return "madvise";
>> +	else
>> +		return "none";
>> +}
>> +#endif /* CONFIG_PROC_FS */
>> +
>
> Apart from these nits, LGTM (again, I don't see why the merge type should belong
> into this patch, and why there is a real need to expose it like that).
>
> Acked-by: David Hildenbrand <david@redhat.com>

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

* Re: [PATCH v5 1/3] mm: add new api to enable ksm per process
       [not found] ` <20230406165339.1017597-2-shr@devkernel.io>
  2023-04-06 23:29   ` [PATCH v5 1/3] mm: add new api to enable ksm per process Andrew Morton
@ 2023-04-11 22:35   ` Matthew Wilcox
  2023-04-11 23:03     ` Stefan Roesch
  1 sibling, 1 reply; 7+ messages in thread
From: Matthew Wilcox @ 2023-04-11 22:35 UTC (permalink / raw)
  To: Stefan Roesch
  Cc: kernel-team, linux-mm, riel, mhocko, david, linux-kselftest,
	linux-doc, akpm, hannes, Bagas Sanjaya

On Thu, Apr 06, 2023 at 09:53:37AM -0700, Stefan Roesch wrote:
> +	case PR_SET_MEMORY_MERGE:
> +		if (mmap_write_lock_killable(me->mm))
> +			return -EINTR;
> +
> +		if (arg2) {
> +			int err = ksm_add_mm(me->mm);
> +			if (err)
> +				return err;

You'll return to userspace with the mutex held, no?

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

* Re: [PATCH v5 1/3] mm: add new api to enable ksm per process
  2023-04-11 22:35   ` Matthew Wilcox
@ 2023-04-11 23:03     ` Stefan Roesch
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Roesch @ 2023-04-11 23:03 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: kernel-team, linux-mm, riel, mhocko, david, linux-kselftest,
	linux-doc, akpm, hannes, Bagas Sanjaya


Matthew Wilcox <willy@infradead.org> writes:

> On Thu, Apr 06, 2023 at 09:53:37AM -0700, Stefan Roesch wrote:
>> +	case PR_SET_MEMORY_MERGE:
>> +		if (mmap_write_lock_killable(me->mm))
>> +			return -EINTR;
>> +
>> +		if (arg2) {
>> +			int err = ksm_add_mm(me->mm);
>> +			if (err)
>> +				return err;
>
> You'll return to userspace with the mutex held, no?
>

Thanks for catching this, I'll fix it in the next version.

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

end of thread, other threads:[~2023-04-11 23:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-06 16:53 [PATCH v5 0/3] mm: process/cgroup ksm support Stefan Roesch
     [not found] ` <20230406165339.1017597-2-shr@devkernel.io>
2023-04-06 23:29   ` [PATCH v5 1/3] mm: add new api to enable ksm per process Andrew Morton
2023-04-07  4:09     ` Stefan Roesch
2023-04-11 22:35   ` Matthew Wilcox
2023-04-11 23:03     ` Stefan Roesch
     [not found] ` <20230406165339.1017597-3-shr@devkernel.io>
2023-04-11  9:10   ` [PATCH v5 2/3] mm: add new KSM process and sysfs knobs David Hildenbrand
2023-04-11 22:29     ` Stefan Roesch

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