2006-09-27 02:50:01 -06:00
|
|
|
#ifndef _LINUX_MM_TYPES_H
|
|
|
|
#define _LINUX_MM_TYPES_H
|
|
|
|
|
2007-10-17 00:30:12 -06:00
|
|
|
#include <linux/auxvec.h>
|
2006-09-27 02:50:01 -06:00
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/threads.h>
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/spinlock.h>
|
2007-10-16 02:24:43 -06:00
|
|
|
#include <linux/prio_tree.h>
|
|
|
|
#include <linux/rbtree.h>
|
|
|
|
#include <linux/rwsem.h>
|
|
|
|
#include <linux/completion.h>
|
mmu-notifiers: core
With KVM/GFP/XPMEM there isn't just the primary CPU MMU pointing to pages.
There are secondary MMUs (with secondary sptes and secondary tlbs) too.
sptes in the kvm case are shadow pagetables, but when I say spte in
mmu-notifier context, I mean "secondary pte". In GRU case there's no
actual secondary pte and there's only a secondary tlb because the GRU
secondary MMU has no knowledge about sptes and every secondary tlb miss
event in the MMU always generates a page fault that has to be resolved by
the CPU (this is not the case of KVM where the a secondary tlb miss will
walk sptes in hardware and it will refill the secondary tlb transparently
to software if the corresponding spte is present). The same way
zap_page_range has to invalidate the pte before freeing the page, the spte
(and secondary tlb) must also be invalidated before any page is freed and
reused.
Currently we take a page_count pin on every page mapped by sptes, but that
means the pages can't be swapped whenever they're mapped by any spte
because they're part of the guest working set. Furthermore a spte unmap
event can immediately lead to a page to be freed when the pin is released
(so requiring the same complex and relatively slow tlb_gather smp safe
logic we have in zap_page_range and that can be avoided completely if the
spte unmap event doesn't require an unpin of the page previously mapped in
the secondary MMU).
The mmu notifiers allow kvm/GRU/XPMEM to attach to the tsk->mm and know
when the VM is swapping or freeing or doing anything on the primary MMU so
that the secondary MMU code can drop sptes before the pages are freed,
avoiding all page pinning and allowing 100% reliable swapping of guest
physical address space. Furthermore it avoids the code that teardown the
mappings of the secondary MMU, to implement a logic like tlb_gather in
zap_page_range that would require many IPI to flush other cpu tlbs, for
each fixed number of spte unmapped.
To make an example: if what happens on the primary MMU is a protection
downgrade (from writeable to wrprotect) the secondary MMU mappings will be
invalidated, and the next secondary-mmu-page-fault will call
get_user_pages and trigger a do_wp_page through get_user_pages if it
called get_user_pages with write=1, and it'll re-establishing an updated
spte or secondary-tlb-mapping on the copied page. Or it will setup a
readonly spte or readonly tlb mapping if it's a guest-read, if it calls
get_user_pages with write=0. This is just an example.
This allows to map any page pointed by any pte (and in turn visible in the
primary CPU MMU), into a secondary MMU (be it a pure tlb like GRU, or an
full MMU with both sptes and secondary-tlb like the shadow-pagetable layer
with kvm), or a remote DMA in software like XPMEM (hence needing of
schedule in XPMEM code to send the invalidate to the remote node, while no
need to schedule in kvm/gru as it's an immediate event like invalidating
primary-mmu pte).
At least for KVM without this patch it's impossible to swap guests
reliably. And having this feature and removing the page pin allows
several other optimizations that simplify life considerably.
Dependencies:
1) mm_take_all_locks() to register the mmu notifier when the whole VM
isn't doing anything with "mm". This allows mmu notifier users to keep
track if the VM is in the middle of the invalidate_range_begin/end
critical section with an atomic counter incraese in range_begin and
decreased in range_end. No secondary MMU page fault is allowed to map
any spte or secondary tlb reference, while the VM is in the middle of
range_begin/end as any page returned by get_user_pages in that critical
section could later immediately be freed without any further
->invalidate_page notification (invalidate_range_begin/end works on
ranges and ->invalidate_page isn't called immediately before freeing
the page). To stop all page freeing and pagetable overwrites the
mmap_sem must be taken in write mode and all other anon_vma/i_mmap
locks must be taken too.
2) It'd be a waste to add branches in the VM if nobody could possibly
run KVM/GRU/XPMEM on the kernel, so mmu notifiers will only enabled if
CONFIG_KVM=m/y. In the current kernel kvm won't yet take advantage of
mmu notifiers, but this already allows to compile a KVM external module
against a kernel with mmu notifiers enabled and from the next pull from
kvm.git we'll start using them. And GRU/XPMEM will also be able to
continue the development by enabling KVM=m in their config, until they
submit all GRU/XPMEM GPLv2 code to the mainline kernel. Then they can
also enable MMU_NOTIFIERS in the same way KVM does it (even if KVM=n).
This guarantees nobody selects MMU_NOTIFIER=y if KVM and GRU and XPMEM
are all =n.
The mmu_notifier_register call can fail because mm_take_all_locks may be
interrupted by a signal and return -EINTR. Because mmu_notifier_reigster
is used when a driver startup, a failure can be gracefully handled. Here
an example of the change applied to kvm to register the mmu notifiers.
Usually when a driver startups other allocations are required anyway and
-ENOMEM failure paths exists already.
struct kvm *kvm_arch_create_vm(void)
{
struct kvm *kvm = kzalloc(sizeof(struct kvm), GFP_KERNEL);
+ int err;
if (!kvm)
return ERR_PTR(-ENOMEM);
INIT_LIST_HEAD(&kvm->arch.active_mmu_pages);
+ kvm->arch.mmu_notifier.ops = &kvm_mmu_notifier_ops;
+ err = mmu_notifier_register(&kvm->arch.mmu_notifier, current->mm);
+ if (err) {
+ kfree(kvm);
+ return ERR_PTR(err);
+ }
+
return kvm;
}
mmu_notifier_unregister returns void and it's reliable.
The patch also adds a few needed but missing includes that would prevent
kernel to compile after these changes on non-x86 archs (x86 didn't need
them by luck).
[akpm@linux-foundation.org: coding-style fixes]
[akpm@linux-foundation.org: fix mm/filemap_xip.c build]
[akpm@linux-foundation.org: fix mm/mmu_notifier.c build]
Signed-off-by: Andrea Arcangeli <andrea@qumranet.com>
Signed-off-by: Nick Piggin <npiggin@suse.de>
Signed-off-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Jack Steiner <steiner@sgi.com>
Cc: Robin Holt <holt@sgi.com>
Cc: Nick Piggin <npiggin@suse.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Kanoj Sarcar <kanojsarcar@yahoo.com>
Cc: Roland Dreier <rdreier@cisco.com>
Cc: Steve Wise <swise@opengridcomputing.com>
Cc: Avi Kivity <avi@qumranet.com>
Cc: Hugh Dickins <hugh@veritas.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Anthony Liguori <aliguori@us.ibm.com>
Cc: Chris Wright <chrisw@redhat.com>
Cc: Marcelo Tosatti <marcelo@kvack.org>
Cc: Eric Dumazet <dada1@cosmosbay.com>
Cc: "Paul E. McKenney" <paulmck@us.ibm.com>
Cc: Izik Eidus <izike@qumranet.com>
Cc: Anthony Liguori <aliguori@us.ibm.com>
Cc: Rik van Riel <riel@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-07-28 16:46:29 -06:00
|
|
|
#include <linux/cpumask.h>
|
2009-03-31 16:23:17 -06:00
|
|
|
#include <linux/page-debug-flags.h>
|
2007-10-16 02:24:43 -06:00
|
|
|
#include <asm/page.h>
|
|
|
|
#include <asm/mmu.h>
|
2006-09-27 02:50:01 -06:00
|
|
|
|
2007-10-17 00:30:12 -06:00
|
|
|
#ifndef AT_VECTOR_SIZE_ARCH
|
|
|
|
#define AT_VECTOR_SIZE_ARCH 0
|
|
|
|
#endif
|
|
|
|
#define AT_VECTOR_SIZE (2*(AT_VECTOR_SIZE_ARCH + AT_VECTOR_SIZE_BASE + 1))
|
|
|
|
|
2006-09-27 02:50:01 -06:00
|
|
|
struct address_space;
|
|
|
|
|
2008-09-09 16:43:22 -06:00
|
|
|
#define USE_SPLIT_PTLOCKS (NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS)
|
|
|
|
|
|
|
|
#if USE_SPLIT_PTLOCKS
|
2007-10-16 02:24:43 -06:00
|
|
|
typedef atomic_long_t mm_counter_t;
|
2008-09-09 16:43:22 -06:00
|
|
|
#else /* !USE_SPLIT_PTLOCKS */
|
2007-10-16 02:24:43 -06:00
|
|
|
typedef unsigned long mm_counter_t;
|
2008-09-09 16:43:22 -06:00
|
|
|
#endif /* !USE_SPLIT_PTLOCKS */
|
2007-10-16 02:24:43 -06:00
|
|
|
|
2006-09-27 02:50:01 -06:00
|
|
|
/*
|
|
|
|
* Each physical page in the system has a struct page associated with
|
|
|
|
* it to keep track of whatever it is we are using the page for at the
|
|
|
|
* moment. Note that we have no way to track which tasks are using
|
|
|
|
* a page, though if it is a pagecache page, rmap structures can tell us
|
|
|
|
* who is mapping it.
|
|
|
|
*/
|
|
|
|
struct page {
|
|
|
|
unsigned long flags; /* Atomic flags, some possibly
|
|
|
|
* updated asynchronously */
|
|
|
|
atomic_t _count; /* Usage count, see below. */
|
2007-05-06 15:49:36 -06:00
|
|
|
union {
|
|
|
|
atomic_t _mapcount; /* Count of ptes mapped in mms,
|
2006-09-27 02:50:01 -06:00
|
|
|
* to show when page is mapped
|
|
|
|
* & limit reverse map searches.
|
|
|
|
*/
|
2008-04-14 10:11:30 -06:00
|
|
|
struct { /* SLUB */
|
|
|
|
u16 inuse;
|
|
|
|
u16 objects;
|
|
|
|
};
|
2007-05-06 15:49:36 -06:00
|
|
|
};
|
2006-09-27 02:50:01 -06:00
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
unsigned long private; /* Mapping-private opaque data:
|
|
|
|
* usually used for buffer_heads
|
|
|
|
* if PagePrivate set; used for
|
|
|
|
* swp_entry_t if PageSwapCache;
|
|
|
|
* indicates order in the buddy
|
|
|
|
* system if PG_buddy is set.
|
|
|
|
*/
|
|
|
|
struct address_space *mapping; /* If low bit clear, points to
|
|
|
|
* inode address_space, or NULL.
|
|
|
|
* If page mapped as anonymous
|
|
|
|
* memory, low bit is set, and
|
|
|
|
* it points to anon_vma object:
|
|
|
|
* see PAGE_MAPPING_ANON below.
|
|
|
|
*/
|
|
|
|
};
|
2008-09-09 16:43:22 -06:00
|
|
|
#if USE_SPLIT_PTLOCKS
|
2006-09-27 02:50:01 -06:00
|
|
|
spinlock_t ptl;
|
|
|
|
#endif
|
2008-03-01 14:40:44 -07:00
|
|
|
struct kmem_cache *slab; /* SLUB: Pointer to slab */
|
2007-10-16 02:26:06 -06:00
|
|
|
struct page *first_page; /* Compound tail pages */
|
2007-05-06 15:49:36 -06:00
|
|
|
};
|
|
|
|
union {
|
|
|
|
pgoff_t index; /* Our offset within mapping. */
|
2007-05-10 04:15:16 -06:00
|
|
|
void *freelist; /* SLUB: freelist req. slab lock */
|
2006-09-27 02:50:01 -06:00
|
|
|
};
|
|
|
|
struct list_head lru; /* Pageout list, eg. active_list
|
|
|
|
* protected by zone->lru_lock !
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* On machines where all RAM is mapped into kernel address space,
|
|
|
|
* we can simply calculate the virtual address. On machines with
|
|
|
|
* highmem some memory is mapped into kernel virtual memory
|
|
|
|
* dynamically, so we need a place to store that address.
|
|
|
|
* Note that this field could be 16 bits on x86 ... ;)
|
|
|
|
*
|
|
|
|
* Architectures with slow multiplication can define
|
|
|
|
* WANT_PAGE_VIRTUAL in asm/page.h
|
|
|
|
*/
|
|
|
|
#if defined(WANT_PAGE_VIRTUAL)
|
|
|
|
void *virtual; /* Kernel virtual address (NULL if
|
|
|
|
not kmapped, ie. highmem) */
|
|
|
|
#endif /* WANT_PAGE_VIRTUAL */
|
2009-04-02 17:56:30 -06:00
|
|
|
#ifdef CONFIG_WANT_PAGE_DEBUG_FLAGS
|
|
|
|
unsigned long debug_flags; /* Use atomic bitops on this */
|
|
|
|
#endif
|
2008-04-03 16:51:41 -06:00
|
|
|
|
|
|
|
#ifdef CONFIG_KMEMCHECK
|
|
|
|
/*
|
|
|
|
* kmemcheck wants to track the status of each byte in a page; this
|
|
|
|
* is a pointer to such a status block. NULL if not tracked.
|
|
|
|
*/
|
|
|
|
void *shadow;
|
|
|
|
#endif
|
2006-09-27 02:50:01 -06:00
|
|
|
};
|
|
|
|
|
2009-01-08 05:04:47 -07:00
|
|
|
/*
|
|
|
|
* A region containing a mapping of a non-memory backed file under NOMMU
|
|
|
|
* conditions. These are held in a global tree and are pinned by the VMAs that
|
|
|
|
* map parts of them.
|
|
|
|
*/
|
|
|
|
struct vm_region {
|
|
|
|
struct rb_node vm_rb; /* link in global region tree */
|
|
|
|
unsigned long vm_flags; /* VMA vm_flags */
|
|
|
|
unsigned long vm_start; /* start address of region */
|
|
|
|
unsigned long vm_end; /* region initialised to here */
|
2009-01-08 05:04:47 -07:00
|
|
|
unsigned long vm_top; /* region allocated to here */
|
2009-01-08 05:04:47 -07:00
|
|
|
unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */
|
|
|
|
struct file *vm_file; /* the backing file or NULL */
|
|
|
|
|
|
|
|
atomic_t vm_usage; /* region usage count */
|
|
|
|
};
|
|
|
|
|
2007-10-16 02:24:43 -06:00
|
|
|
/*
|
|
|
|
* This struct defines a memory VMM memory area. There is one of these
|
|
|
|
* per VM-area/task. A VM area is any part of the process virtual memory
|
|
|
|
* space that has a special rule for the page-fault handlers (ie a shared
|
|
|
|
* library, the executable area etc).
|
|
|
|
*/
|
|
|
|
struct vm_area_struct {
|
|
|
|
struct mm_struct * vm_mm; /* The address space we belong to. */
|
|
|
|
unsigned long vm_start; /* Our start address within vm_mm. */
|
|
|
|
unsigned long vm_end; /* The first byte after our end address
|
|
|
|
within vm_mm. */
|
|
|
|
|
|
|
|
/* linked list of VM areas per task, sorted by address */
|
|
|
|
struct vm_area_struct *vm_next;
|
|
|
|
|
|
|
|
pgprot_t vm_page_prot; /* Access permissions of this VMA. */
|
2008-08-16 04:07:21 -06:00
|
|
|
unsigned long vm_flags; /* Flags, see mm.h. */
|
2007-10-16 02:24:43 -06:00
|
|
|
|
|
|
|
struct rb_node vm_rb;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For areas with an address space and backing store,
|
|
|
|
* linkage into the address_space->i_mmap prio tree, or
|
|
|
|
* linkage to the list of like vmas hanging off its node, or
|
|
|
|
* linkage of vma in the address_space->i_mmap_nonlinear list.
|
|
|
|
*/
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
struct list_head list;
|
|
|
|
void *parent; /* aligns with prio_tree_node parent */
|
|
|
|
struct vm_area_struct *head;
|
|
|
|
} vm_set;
|
|
|
|
|
|
|
|
struct raw_prio_tree_node prio_tree_node;
|
|
|
|
} shared;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A file's MAP_PRIVATE vma can be in both i_mmap tree and anon_vma
|
|
|
|
* list, after a COW of one of the file pages. A MAP_SHARED vma
|
|
|
|
* can only be in the i_mmap tree. An anonymous MAP_PRIVATE, stack
|
|
|
|
* or brk vma (with NULL file) can only be in an anon_vma list.
|
|
|
|
*/
|
|
|
|
struct list_head anon_vma_node; /* Serialized by anon_vma->lock */
|
|
|
|
struct anon_vma *anon_vma; /* Serialized by page_table_lock */
|
|
|
|
|
|
|
|
/* Function pointers to deal with this struct. */
|
2009-09-27 12:29:37 -06:00
|
|
|
const struct vm_operations_struct *vm_ops;
|
2007-10-16 02:24:43 -06:00
|
|
|
|
|
|
|
/* Information about our backing store: */
|
|
|
|
unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE
|
|
|
|
units, *not* PAGE_CACHE_SIZE */
|
|
|
|
struct file * vm_file; /* File we map to (can be NULL). */
|
|
|
|
void * vm_private_data; /* was vm_pte (shared mem) */
|
|
|
|
unsigned long vm_truncate_count;/* truncate_count or restart_addr */
|
|
|
|
|
|
|
|
#ifndef CONFIG_MMU
|
2009-01-08 05:04:47 -07:00
|
|
|
struct vm_region *vm_region; /* NOMMU mapping region */
|
2007-10-16 02:24:43 -06:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NUMA
|
|
|
|
struct mempolicy *vm_policy; /* NUMA policy for the VMA */
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2008-07-25 02:47:44 -06:00
|
|
|
struct core_thread {
|
|
|
|
struct task_struct *task;
|
|
|
|
struct core_thread *next;
|
|
|
|
};
|
|
|
|
|
2008-07-25 02:47:41 -06:00
|
|
|
struct core_state {
|
2008-07-25 02:47:42 -06:00
|
|
|
atomic_t nr_threads;
|
2008-07-25 02:47:44 -06:00
|
|
|
struct core_thread dumper;
|
2008-07-25 02:47:41 -06:00
|
|
|
struct completion startup;
|
|
|
|
};
|
|
|
|
|
2007-10-16 02:24:43 -06:00
|
|
|
struct mm_struct {
|
|
|
|
struct vm_area_struct * mmap; /* list of VMAs */
|
|
|
|
struct rb_root mm_rb;
|
|
|
|
struct vm_area_struct * mmap_cache; /* last find_vma result */
|
|
|
|
unsigned long (*get_unmapped_area) (struct file *filp,
|
|
|
|
unsigned long addr, unsigned long len,
|
|
|
|
unsigned long pgoff, unsigned long flags);
|
|
|
|
void (*unmap_area) (struct mm_struct *mm, unsigned long addr);
|
|
|
|
unsigned long mmap_base; /* base of mmap area */
|
|
|
|
unsigned long task_size; /* size of task vm space */
|
|
|
|
unsigned long cached_hole_size; /* if non-zero, the largest hole below free_area_cache */
|
|
|
|
unsigned long free_area_cache; /* first hole of size cached_hole_size or larger */
|
|
|
|
pgd_t * pgd;
|
|
|
|
atomic_t mm_users; /* How many users with user space? */
|
|
|
|
atomic_t mm_count; /* How many references to "struct mm_struct" (users count as 1) */
|
|
|
|
int map_count; /* number of VMAs */
|
|
|
|
struct rw_semaphore mmap_sem;
|
|
|
|
spinlock_t page_table_lock; /* Protects page tables and some counters */
|
|
|
|
|
|
|
|
struct list_head mmlist; /* List of maybe swapped mm's. These are globally strung
|
|
|
|
* together off init_mm.mmlist, and are protected
|
|
|
|
* by mmlist_lock
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Special counters, in some configurations protected by the
|
|
|
|
* page_table_lock, in other configurations by being atomic.
|
|
|
|
*/
|
|
|
|
mm_counter_t _file_rss;
|
|
|
|
mm_counter_t _anon_rss;
|
|
|
|
|
|
|
|
unsigned long hiwater_rss; /* High-watermark of RSS usage */
|
|
|
|
unsigned long hiwater_vm; /* High-water virtual memory usage */
|
|
|
|
|
|
|
|
unsigned long total_vm, locked_vm, shared_vm, exec_vm;
|
|
|
|
unsigned long stack_vm, reserved_vm, def_flags, nr_ptes;
|
|
|
|
unsigned long start_code, end_code, start_data, end_data;
|
|
|
|
unsigned long start_brk, brk, start_stack;
|
|
|
|
unsigned long arg_start, arg_end, env_start, env_end;
|
|
|
|
|
|
|
|
unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
|
|
|
|
|
2009-09-23 16:57:41 -06:00
|
|
|
struct linux_binfmt *binfmt;
|
|
|
|
|
2007-10-16 02:24:43 -06:00
|
|
|
cpumask_t cpu_vm_mask;
|
|
|
|
|
|
|
|
/* Architecture-specific MM context */
|
|
|
|
mm_context_t context;
|
|
|
|
|
|
|
|
/* Swap token stuff */
|
|
|
|
/*
|
|
|
|
* Last value of global fault stamp as seen by this process.
|
|
|
|
* In other words, this value gives an indication of how long
|
|
|
|
* it has been since this task got the token.
|
|
|
|
* Look at mm/thrash.c
|
|
|
|
*/
|
|
|
|
unsigned int faultstamp;
|
|
|
|
unsigned int token_priority;
|
|
|
|
unsigned int last_interval;
|
|
|
|
|
|
|
|
unsigned long flags; /* Must use atomic bitops to access the bits */
|
|
|
|
|
2008-07-25 02:47:46 -06:00
|
|
|
struct core_state *core_state; /* coredumping support */
|
2009-09-23 16:57:32 -06:00
|
|
|
#ifdef CONFIG_AIO
|
2008-12-09 00:11:22 -07:00
|
|
|
spinlock_t ioctx_lock;
|
|
|
|
struct hlist_head ioctx_list;
|
2009-09-23 16:57:32 -06:00
|
|
|
#endif
|
cgroups: add an owner to the mm_struct
Remove the mem_cgroup member from mm_struct and instead adds an owner.
This approach was suggested by Paul Menage. The advantage of this approach
is that, once the mm->owner is known, using the subsystem id, the cgroup
can be determined. It also allows several control groups that are
virtually grouped by mm_struct, to exist independent of the memory
controller i.e., without adding mem_cgroup's for each controller, to
mm_struct.
A new config option CONFIG_MM_OWNER is added and the memory resource
controller selects this config option.
This patch also adds cgroup callbacks to notify subsystems when mm->owner
changes. The mm_cgroup_changed callback is called with the task_lock() of
the new task held and is called just prior to changing the mm->owner.
I am indebted to Paul Menage for the several reviews of this patchset and
helping me make it lighter and simpler.
This patch was tested on a powerpc box, it was compiled with both the
MM_OWNER config turned on and off.
After the thread group leader exits, it's moved to init_css_state by
cgroup_exit(), thus all future charges from runnings threads would be
redirected to the init_css_set's subsystem.
Signed-off-by: Balbir Singh <balbir@linux.vnet.ibm.com>
Cc: Pavel Emelianov <xemul@openvz.org>
Cc: Hugh Dickins <hugh@veritas.com>
Cc: Sudhir Kumar <skumar@linux.vnet.ibm.com>
Cc: YAMAMOTO Takashi <yamamoto@valinux.co.jp>
Cc: Hirokazu Takahashi <taka@valinux.co.jp>
Cc: David Rientjes <rientjes@google.com>,
Cc: Balbir Singh <balbir@linux.vnet.ibm.com>
Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Acked-by: Pekka Enberg <penberg@cs.helsinki.fi>
Reviewed-by: Paul Menage <menage@google.com>
Cc: Oleg Nesterov <oleg@tv-sign.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-04-29 02:00:16 -06:00
|
|
|
#ifdef CONFIG_MM_OWNER
|
2008-05-12 15:02:31 -06:00
|
|
|
/*
|
|
|
|
* "owner" points to a task that is regarded as the canonical
|
|
|
|
* user/owner of this mm. All of the following must be true in
|
|
|
|
* order for it to be changed:
|
|
|
|
*
|
|
|
|
* current == mm->owner
|
|
|
|
* current->mm != mm
|
|
|
|
* new_owner->mm == mm
|
|
|
|
* new_owner->alloc_lock is held
|
|
|
|
*/
|
|
|
|
struct task_struct *owner;
|
2008-02-07 01:13:51 -07:00
|
|
|
#endif
|
2008-04-29 02:01:36 -06:00
|
|
|
|
|
|
|
#ifdef CONFIG_PROC_FS
|
|
|
|
/* store ref to file /proc/<pid>/exe symlink points to */
|
|
|
|
struct file *exe_file;
|
|
|
|
unsigned long num_exe_file_vmas;
|
|
|
|
#endif
|
mmu-notifiers: core
With KVM/GFP/XPMEM there isn't just the primary CPU MMU pointing to pages.
There are secondary MMUs (with secondary sptes and secondary tlbs) too.
sptes in the kvm case are shadow pagetables, but when I say spte in
mmu-notifier context, I mean "secondary pte". In GRU case there's no
actual secondary pte and there's only a secondary tlb because the GRU
secondary MMU has no knowledge about sptes and every secondary tlb miss
event in the MMU always generates a page fault that has to be resolved by
the CPU (this is not the case of KVM where the a secondary tlb miss will
walk sptes in hardware and it will refill the secondary tlb transparently
to software if the corresponding spte is present). The same way
zap_page_range has to invalidate the pte before freeing the page, the spte
(and secondary tlb) must also be invalidated before any page is freed and
reused.
Currently we take a page_count pin on every page mapped by sptes, but that
means the pages can't be swapped whenever they're mapped by any spte
because they're part of the guest working set. Furthermore a spte unmap
event can immediately lead to a page to be freed when the pin is released
(so requiring the same complex and relatively slow tlb_gather smp safe
logic we have in zap_page_range and that can be avoided completely if the
spte unmap event doesn't require an unpin of the page previously mapped in
the secondary MMU).
The mmu notifiers allow kvm/GRU/XPMEM to attach to the tsk->mm and know
when the VM is swapping or freeing or doing anything on the primary MMU so
that the secondary MMU code can drop sptes before the pages are freed,
avoiding all page pinning and allowing 100% reliable swapping of guest
physical address space. Furthermore it avoids the code that teardown the
mappings of the secondary MMU, to implement a logic like tlb_gather in
zap_page_range that would require many IPI to flush other cpu tlbs, for
each fixed number of spte unmapped.
To make an example: if what happens on the primary MMU is a protection
downgrade (from writeable to wrprotect) the secondary MMU mappings will be
invalidated, and the next secondary-mmu-page-fault will call
get_user_pages and trigger a do_wp_page through get_user_pages if it
called get_user_pages with write=1, and it'll re-establishing an updated
spte or secondary-tlb-mapping on the copied page. Or it will setup a
readonly spte or readonly tlb mapping if it's a guest-read, if it calls
get_user_pages with write=0. This is just an example.
This allows to map any page pointed by any pte (and in turn visible in the
primary CPU MMU), into a secondary MMU (be it a pure tlb like GRU, or an
full MMU with both sptes and secondary-tlb like the shadow-pagetable layer
with kvm), or a remote DMA in software like XPMEM (hence needing of
schedule in XPMEM code to send the invalidate to the remote node, while no
need to schedule in kvm/gru as it's an immediate event like invalidating
primary-mmu pte).
At least for KVM without this patch it's impossible to swap guests
reliably. And having this feature and removing the page pin allows
several other optimizations that simplify life considerably.
Dependencies:
1) mm_take_all_locks() to register the mmu notifier when the whole VM
isn't doing anything with "mm". This allows mmu notifier users to keep
track if the VM is in the middle of the invalidate_range_begin/end
critical section with an atomic counter incraese in range_begin and
decreased in range_end. No secondary MMU page fault is allowed to map
any spte or secondary tlb reference, while the VM is in the middle of
range_begin/end as any page returned by get_user_pages in that critical
section could later immediately be freed without any further
->invalidate_page notification (invalidate_range_begin/end works on
ranges and ->invalidate_page isn't called immediately before freeing
the page). To stop all page freeing and pagetable overwrites the
mmap_sem must be taken in write mode and all other anon_vma/i_mmap
locks must be taken too.
2) It'd be a waste to add branches in the VM if nobody could possibly
run KVM/GRU/XPMEM on the kernel, so mmu notifiers will only enabled if
CONFIG_KVM=m/y. In the current kernel kvm won't yet take advantage of
mmu notifiers, but this already allows to compile a KVM external module
against a kernel with mmu notifiers enabled and from the next pull from
kvm.git we'll start using them. And GRU/XPMEM will also be able to
continue the development by enabling KVM=m in their config, until they
submit all GRU/XPMEM GPLv2 code to the mainline kernel. Then they can
also enable MMU_NOTIFIERS in the same way KVM does it (even if KVM=n).
This guarantees nobody selects MMU_NOTIFIER=y if KVM and GRU and XPMEM
are all =n.
The mmu_notifier_register call can fail because mm_take_all_locks may be
interrupted by a signal and return -EINTR. Because mmu_notifier_reigster
is used when a driver startup, a failure can be gracefully handled. Here
an example of the change applied to kvm to register the mmu notifiers.
Usually when a driver startups other allocations are required anyway and
-ENOMEM failure paths exists already.
struct kvm *kvm_arch_create_vm(void)
{
struct kvm *kvm = kzalloc(sizeof(struct kvm), GFP_KERNEL);
+ int err;
if (!kvm)
return ERR_PTR(-ENOMEM);
INIT_LIST_HEAD(&kvm->arch.active_mmu_pages);
+ kvm->arch.mmu_notifier.ops = &kvm_mmu_notifier_ops;
+ err = mmu_notifier_register(&kvm->arch.mmu_notifier, current->mm);
+ if (err) {
+ kfree(kvm);
+ return ERR_PTR(err);
+ }
+
return kvm;
}
mmu_notifier_unregister returns void and it's reliable.
The patch also adds a few needed but missing includes that would prevent
kernel to compile after these changes on non-x86 archs (x86 didn't need
them by luck).
[akpm@linux-foundation.org: coding-style fixes]
[akpm@linux-foundation.org: fix mm/filemap_xip.c build]
[akpm@linux-foundation.org: fix mm/mmu_notifier.c build]
Signed-off-by: Andrea Arcangeli <andrea@qumranet.com>
Signed-off-by: Nick Piggin <npiggin@suse.de>
Signed-off-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Jack Steiner <steiner@sgi.com>
Cc: Robin Holt <holt@sgi.com>
Cc: Nick Piggin <npiggin@suse.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Kanoj Sarcar <kanojsarcar@yahoo.com>
Cc: Roland Dreier <rdreier@cisco.com>
Cc: Steve Wise <swise@opengridcomputing.com>
Cc: Avi Kivity <avi@qumranet.com>
Cc: Hugh Dickins <hugh@veritas.com>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Anthony Liguori <aliguori@us.ibm.com>
Cc: Chris Wright <chrisw@redhat.com>
Cc: Marcelo Tosatti <marcelo@kvack.org>
Cc: Eric Dumazet <dada1@cosmosbay.com>
Cc: "Paul E. McKenney" <paulmck@us.ibm.com>
Cc: Izik Eidus <izike@qumranet.com>
Cc: Anthony Liguori <aliguori@us.ibm.com>
Cc: Rik van Riel <riel@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-07-28 16:46:29 -06:00
|
|
|
#ifdef CONFIG_MMU_NOTIFIER
|
|
|
|
struct mmu_notifier_mm *mmu_notifier_mm;
|
|
|
|
#endif
|
2007-10-16 02:24:43 -06:00
|
|
|
};
|
|
|
|
|
2009-03-12 14:35:44 -06:00
|
|
|
/* Future-safe accessor for struct mm_struct's cpu_vm_mask. */
|
|
|
|
#define mm_cpumask(mm) (&(mm)->cpu_vm_mask)
|
|
|
|
|
2006-09-27 02:50:01 -06:00
|
|
|
#endif /* _LINUX_MM_TYPES_H */
|