Commit 175ad0cb authored by Linus Torvalds's avatar Linus Torvalds Committed by Greg Kroah-Hartman

mm: get rid of vmacache_flush_all() entirely

commit 7a9cdebd upstream.

Jann Horn points out that the vmacache_flush_all() function is not only
potentially expensive, it's buggy too.  It also happens to be entirely
unnecessary, because the sequence number overflow case can be avoided by
simply making the sequence number be 64-bit.  That doesn't even grow the
data structures in question, because the other adjacent fields are
already 64-bit.

So simplify the whole thing by just making the sequence number overflow
case go away entirely, which gets rid of all the complications and makes
the code faster too.  Win-win.

[ Oleg Nesterov points out that the VMACACHE_FULL_FLUSHES statistics
  also just goes away entirely with this ]
Reported-by: default avatarJann Horn <>
Suggested-by: default avatarWill Deacon <>
Acked-by: default avatarDavidlohr Bueso <>
Cc: Oleg Nesterov <>
Signed-off-by: default avatarLinus Torvalds <>
Signed-off-by: default avatarGreg Kroah-Hartman <>
parent 39998fd5
......@@ -340,7 +340,7 @@ struct kioctx_table;
struct mm_struct {
struct vm_area_struct *mmap; /* list of VMAs */
struct rb_root mm_rb;
u32 vmacache_seqnum; /* per-thread vmacache */
u64 vmacache_seqnum; /* per-thread vmacache */
unsigned long (*get_unmapped_area) (struct file *filp,
unsigned long addr, unsigned long len,
......@@ -32,7 +32,7 @@
struct vmacache {
u32 seqnum;
u64 seqnum;
struct vm_area_struct *vmas[VMACACHE_SIZE];
......@@ -105,7 +105,6 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT,
......@@ -16,7 +16,6 @@ static inline void vmacache_flush(struct task_struct *tsk)
memset(tsk->vmacache.vmas, 0, sizeof(tsk->vmacache.vmas));
extern void vmacache_flush_all(struct mm_struct *mm);
extern void vmacache_update(unsigned long addr, struct vm_area_struct *newvma);
extern struct vm_area_struct *vmacache_find(struct mm_struct *mm,
unsigned long addr);
......@@ -30,10 +29,6 @@ extern struct vm_area_struct *vmacache_find_exact(struct mm_struct *mm,
static inline void vmacache_invalidate(struct mm_struct *mm)
/* deal with overflows */
if (unlikely(mm->vmacache_seqnum == 0))
#endif /* __LINUX_VMACACHE_H */
......@@ -114,7 +114,7 @@ EXPORT_SYMBOL(dump_vma);
void dump_mm(const struct mm_struct *mm)
pr_emerg("mm %px mmap %px seqnum %d task_size %lu\n"
pr_emerg("mm %px mmap %px seqnum %llu task_size %lu\n"
"get_unmapped_area %px\n"
......@@ -142,7 +142,7 @@ void dump_mm(const struct mm_struct *mm)
"tlb_flush_pending %d\n"
"def_flags: %#lx(%pGv)\n",
mm, mm->mmap, mm->vmacache_seqnum, mm->task_size,
mm, mm->mmap, (long long) mm->vmacache_seqnum, mm->task_size,
......@@ -7,44 +7,6 @@
#include <linux/mm.h>
#include <linux/vmacache.h>
* Flush vma caches for threads that share a given mm.
* The operation is safe because the caller holds the mmap_sem
* exclusively and other threads accessing the vma cache will
* have mmap_sem held at least for read, so no extra locking
* is required to maintain the vma cache.
void vmacache_flush_all(struct mm_struct *mm)
struct task_struct *g, *p;
* Single threaded tasks need not iterate the entire
* list of process. We can avoid the flushing as well
* since the mm's seqnum was increased and don't have
* to worry about other threads' seqnum. Current's
* flush will occur upon the next lookup.
if (atomic_read(&mm->mm_users) == 1)
for_each_process_thread(g, p) {
* Only flush the vmacache pointers as the
* mm seqnum is already set and curr's will
* be set upon invalidation when the next
* lookup is done.
if (mm == p->mm)
* This task may be accessing a foreign mm via (for example)
* get_user_pages()->find_vma(). The vmacache is task-local and this
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment