Re: [RFC PATCH 2/6] mm: clone3: Add CLONE_COW_PGTABLE flag

Christophe Leroy
2022-05-20T14:13:31Z

Le 19/05/2022 à 20:31, Chih-En Lin a écrit :
> Add CLONE_COW_PGTABLE flag to support clone3() system call to enable the
> Copy-On-Write (COW) mechanism on the page table.

Is that really something we want the user to decide ? Isn't it an
internal stuff that should be transparent for users ?

As far as I know, there is no way today to decide whether you want COW
or not for main memory. Why should there be a choice for the COW of page
tables ?

>
> Signed-off-by: Chih-En Lin <shiyn.lin@gmail.com>
> ---
> include/uapi/linux/sched.h | 1 +
> kernel/fork.c | 6 +++++-
> 2 files changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/include/uapi/linux/sched.h b/include/uapi/linux/sched.h
> index 3bac0a8ceab2..3b92ff589e0f 100644
> --- a/include/uapi/linux/sched.h
> +++ b/include/uapi/linux/sched.h
> @@ -36,6 +36,7 @@
> /* Flags for the clone3() syscall. */
> #define CLONE_CLEAR_SIGHAND 0x100000000ULL /* Clear any signal handler and reset to SIG_DFL. */
> #define CLONE_INTO_CGROUP 0x200000000ULL /* Clone into a specific cgroup given the right permissions. */
> +#define CLONE_COW_PGTABLE 0x400000000ULL /* Copy-On-Write for page table */
>
> /*
> * cloning flags intersect with CSIGNAL so can be used with unshare and clone3
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 35a3beff140b..08cf95201333 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -2636,6 +2636,9 @@ pid_t kernel_clone(struct kernel_clone_args *args)
> trace = 0;
> }
>
> + if (clone_flags & CLONE_COW_PGTABLE)
> + set_bit(MMF_COW_PGTABLE, &current->mm->flags);
> +
> p = copy_process(NULL, trace, NUMA_NO_NODE, args);
> add_latent_entropy();
>
> @@ -2860,7 +2863,8 @@ static bool clone3_args_valid(struct kernel_clone_args *kargs)
> {
> /* Verify that no unknown flags are passed along. */
> if (kargs->flags &
> - ~(CLONE_LEGACY_FLAGS | CLONE_CLEAR_SIGHAND | CLONE_INTO_CGROUP))
> + ~(CLONE_LEGACY_FLAGS | CLONE_CLEAR_SIGHAND | CLONE_INTO_CGROUP |
> + CLONE_COW_PGTABLE))
> return false;
>
> /*
> --
> 2.36.1
>