]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm: rcu safe VMA freeing
authorMichel Lespinasse <michel@lespinasse.org>
Tue, 25 Jan 2022 01:43:54 +0000 (17:43 -0800)
committerSuren Baghdasaryan <surenb@google.com>
Wed, 23 Nov 2022 02:09:43 +0000 (02:09 +0000)
This prepares for page faults handling under VMA lock, looking up VMAs
under protection of an rcu read lock, instead of the usual mmap read lock.

Signed-off-by: Michel Lespinasse <michel@lespinasse.org>
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
include/linux/mm_types.h
kernel/fork.c

index 500e536796ca4ade1721e1ca82f4b09926e3c8a4..eba3987b22d8ad8166c45105f9ac5961a80d14ab 100644 (file)
@@ -444,9 +444,16 @@ struct anon_vma_name {
 struct vm_area_struct {
        /* The first cache line has the info for VMA tree walking. */
 
-       unsigned long vm_start;         /* Our start address within vm_mm. */
-       unsigned long vm_end;           /* The first byte after our end address
-                                          within vm_mm. */
+       union {
+               struct {
+                       /* VMA covers [vm_start; vm_end) addresses within mm */
+                       unsigned long vm_start;
+                       unsigned long vm_end;
+               };
+#ifdef CONFIG_PER_VMA_LOCK
+               struct rcu_head vm_rcu; /* Used for deferred freeing. */
+#endif
+       };
 
        struct mm_struct *vm_mm;        /* The address space we belong to. */
 
index f8ce1fc21378502272081b2911d91e4040656d60..a4993ac1613b4ace33f1ec6d8e83d9f2a616546b 100644 (file)
@@ -479,10 +479,23 @@ struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig)
        return new;
 }
 
+#ifdef CONFIG_PER_VMA_LOCK
+static void __vm_area_free(struct rcu_head *head)
+{
+       struct vm_area_struct *vma = container_of(head, struct vm_area_struct,
+                                                 vm_rcu);
+       kmem_cache_free(vm_area_cachep, vma);
+}
+#endif
+
 void vm_area_free(struct vm_area_struct *vma)
 {
        free_anon_vma_name(vma);
+#ifdef CONFIG_PER_VMA_LOCK
+       call_rcu(&vma->vm_rcu, __vm_area_free);
+#else
        kmem_cache_free(vm_area_cachep, vma);
+#endif
 }
 
 static void account_kernel_stack(struct task_struct *tsk, int account)