Re: [PATCH v9 16/17] mm: make vma cache SLAB_TYPESAFE_BY_RCU

From: Suren Baghdasaryan
Date: Wed Jan 15 2025 - 16:46:33 EST


On Wed, Jan 15, 2025 at 4:17 AM Wei Yang <richard.weiyang@xxxxxxxxx> wrote:
>
> On Tue, Jan 14, 2025 at 07:15:05PM -0800, Suren Baghdasaryan wrote:
> >On Tue, Jan 14, 2025 at 6:27 PM Wei Yang <richard.weiyang@xxxxxxxxx> wrote:
> >>
> >> On Fri, Jan 10, 2025 at 08:26:03PM -0800, Suren Baghdasaryan wrote:
> >>
> >> >diff --git a/kernel/fork.c b/kernel/fork.c
> >> >index 9d9275783cf8..151b40627c14 100644
> >> >--- a/kernel/fork.c
> >> >+++ b/kernel/fork.c
> >> >@@ -449,6 +449,42 @@ struct vm_area_struct *vm_area_alloc(struct mm_struct *mm)
> >> > return vma;
> >> > }
> >> >
> >> >+static void vm_area_init_from(const struct vm_area_struct *src,
> >> >+ struct vm_area_struct *dest)
> >> >+{
> >> >+ dest->vm_mm = src->vm_mm;
> >> >+ dest->vm_ops = src->vm_ops;
> >> >+ dest->vm_start = src->vm_start;
> >> >+ dest->vm_end = src->vm_end;
> >> >+ dest->anon_vma = src->anon_vma;
> >> >+ dest->vm_pgoff = src->vm_pgoff;
> >> >+ dest->vm_file = src->vm_file;
> >> >+ dest->vm_private_data = src->vm_private_data;
> >> >+ vm_flags_init(dest, src->vm_flags);
> >> >+ memcpy(&dest->vm_page_prot, &src->vm_page_prot,
> >> >+ sizeof(dest->vm_page_prot));
> >> >+ /*
> >> >+ * src->shared.rb may be modified concurrently when called from
> >> >+ * dup_mmap(), but the clone will reinitialize it.
> >> >+ */
> >> >+ data_race(memcpy(&dest->shared, &src->shared, sizeof(dest->shared)));
> >> >+ memcpy(&dest->vm_userfaultfd_ctx, &src->vm_userfaultfd_ctx,
> >> >+ sizeof(dest->vm_userfaultfd_ctx));
> >> >+#ifdef CONFIG_ANON_VMA_NAME
> >> >+ dest->anon_name = src->anon_name;
> >> >+#endif
> >> >+#ifdef CONFIG_SWAP
> >> >+ memcpy(&dest->swap_readahead_info, &src->swap_readahead_info,
> >> >+ sizeof(dest->swap_readahead_info));
> >> >+#endif
> >> >+#ifndef CONFIG_MMU
> >> >+ dest->vm_region = src->vm_region;
> >> >+#endif
> >> >+#ifdef CONFIG_NUMA
> >> >+ dest->vm_policy = src->vm_policy;
> >> >+#endif
> >> >+}
> >>
> >> Would this be difficult to maintain? We should make sure not miss or overwrite
> >> anything.
> >
> >Yeah, it is less maintainable than a simple memcpy() but I did not
> >find a better alternative. I added a warning above the struct
> >vm_area_struct definition to update this function every time we change
> >that structure. Not sure if there is anything else I can do to help
> >with this.
> >
>
> For !PER_VMA_LOCK, maybe we can use memcpy() as usual.
>
> For PER_VMA_LOCK, I just come up the same idea with you:-)

Missed this comment. Yeah, in one of the previous versions I had
different !PER_VMA_LOCK and PER_VMA_LOCK versions of vma_copy() but
David raised a question whether it is worth having two versions. From
performance POV there is no reason for that and it unnecessarily
complicates the code. So, I dropped that in favor of having one
version.

>
> >>
> >> --
> >> Wei Yang
> >> Help you, Help me
>
> --
> Wei Yang
> Help you, Help me