Skip to content

Commit

Permalink
mm: rcu safe vma freeing
Browse files Browse the repository at this point in the history
This prepares for speculative page faults looking up and copying vmas
under protection of an rcu read lock, instead of the usual mmap read lock.

Note - it might also be feasible to just use SLAB_TYPESAFE_BY_RCU when
creating the vm_area_cachep, but that's probably too subtle to consider here.

Signed-off-by: Michel Lespinasse <michel@lespinasse.org>
  • Loading branch information
lespinasse authored and intel-lab-lkp committed Jan 28, 2022
1 parent 397714e commit e070569
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
16 changes: 11 additions & 5 deletions include/linux/mm_types.h
Expand Up @@ -374,12 +374,18 @@ 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, vm_end;

/* linked list of VM areas per task, sorted by address */
struct vm_area_struct *vm_next, *vm_prev;
/* linked list of VMAs per task, sorted by address */
struct vm_area_struct *vm_next, *vm_prev;
};
#ifdef CONFIG_SPECULATIVE_PAGE_FAULT
struct rcu_head vm_rcu; /* Used for deferred freeing. */
#endif
};

struct rb_node vm_rb;

Expand Down
13 changes: 13 additions & 0 deletions kernel/fork.c
Expand Up @@ -371,10 +371,23 @@ struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig)
return new;
}

#ifdef CONFIG_SPECULATIVE_PAGE_FAULT
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_vma_anon_name(vma);
#ifdef CONFIG_SPECULATIVE_PAGE_FAULT
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)
Expand Down

0 comments on commit e070569

Please sign in to comment.