rmap 10 add anonmm rmap
Subsystems (5)
PATCH 11/57 rmap 10 add anonmm rmap
From: Hugh Dickins <[email protected]>
Hugh's anonmm object-based reverse mapping scheme for anonymous pages. We have not yet decided whether to adopt this scheme, or Andrea's more advanced anon_vma scheme. anonmm is easier for me to merge quickly, to replace the pte_chain rmap taken out in the previous patch; a patch to install Andrea's anon_vma will follow in due course.
Why build up and tear down chains of pte pointers for anonymous pages, when a page can only appear at one particular address, in a restricted group of mms that might share it? (Except: see next patch on mremap.)
Introduce struct anonmm per mm to track anonymous pages, all forks from one exec sharing the same bundle of linked anonmms. Anonymous pages originate in one mm, but may be forked into another mm of the bundle later on. Callouts from fork.c to allocate, dup and exit the anonmm structure private to rmap.c.
From: Hugh Dickins <[email protected]>
Two concurrent exits (of the last two mms sharing the anonhd). First exit_rmap brings anonhd->count down to 2, gets preempted (at the spin_unlock) by second, which brings anonhd->count down to 1, sees it's 1 and frees the anonhd (without making any change to anonhd->count itself), cpu goes on to do something new which reallocates the old anonhd as a new struct anonmm (probably not a head, in which case count will start at 1), first resumes after the spin_unlock and sees anonhd->count 1, frees "anonhd" again, it's used for something else, a later exit_rmap list_del finds list corrupt.
---
25-akpm/include/linux/rmap.h | 13 ++ 25-akpm/include/linux/sched.h | 1 25-akpm/kernel/fork.c | 18 ++- 25-akpm/mm/rmap.c | 239 +++++++++++++++++++++++++++++++++++++++++- 4 files changed, 266 insertions(+), 5 deletions(-)
include/linux/rmap.h renamed from include/linux/rmap.h~rmap-10-add-anonmm-rmap +13 -0
@@ -35,6 +35,14 @@ static inline void page_dup_rmap(struct }/* +* Called from kernel/fork.c to manage anonymous memory +*/ +void init_rmap (void ); +int exec_rmap (struct mm_struct *); +int dup_rmap (struct mm_struct *,struct mm_struct *oldmm); +void exit_rmap (struct mm_struct *); + +/* * Called from mm/vmscan.c to handle paging out */ int fastcall page_referenced(struct page *);
@@ -42,6 +50,11 @@ int fastcall try_to_unmap(struct page *)#else /* !CONFIG_MMU */ +#define init_rmap () do {} while (0) +#define exec_rmap (mm) (0) +#define dup_rmap (mm, oldmm) (0) +#define exit_rmap (mm) do {} while (0) +#define page_referenced (page) TestClearPageReferenced(page)#define try_to_unmap (page) SWAP_FAIL
include/linux/sched.h renamed from include/linux/sched.h~rmap-10-add-anonmm-rmap +1 -0
@@ -207,6 +207,7 @@ struct mm_struct {* together off init_mm.mmlist, and are protected * by mmlist_lock */ +struct anonmm *anonmm;/* For rmap to track anon mem */ unsigned long start_code, end_code, start_data, end_data;unsigned long start_brk, brk, start_stack;
kernel/fork.c renamed from kernel/fork.c~rmap-10-add-anonmm-rmap +16 -2
@@ -34,6 +34,7 @@#include <linux/ptrace.h> #include <linux/mount.h> #include <linux/audit.h> +#include <linux/rmap.h> #include <asm/pgtable.h> #include <asm/pgalloc.h>
@@ -419,9 +420,14 @@ struct mm_struct * mm_alloc(void) mm =allocate_mm ();if (mm) {memset (mm,0 ,sizeof (*mm)); -return mm_init (mm); + mm =mm_init (mm); +if (mm &&exec_rmap (mm)) { +mm_free_pgd (mm); +free_mm (mm); + mm =NULL ; + } } -return NULL ; +return mm; }/*
@@ -448,6 +454,7 @@ void mmput(struct mm_struct *mm)spin_unlock (&mmlist_lock);exit_aio (mm);exit_mmap (mm); +exit_rmap (mm);mmdrop (mm); } }
@@ -551,6 +558,12 @@ static int copy_mm(unsigned long clone_fif (!mm_init (mm)) goto fail_nomem; +if (dup_rmap (mm, oldmm)) { +mm_free_pgd (mm); +free_mm (mm); + goto fail_nomem; + } +if (init_new_context (tsk,mm)) goto fail_nocontext;
@@ -1262,4 +1275,5 @@ void __init proc_caches_init(void) mm_cachep =kmem_cache_create ("mm_struct" ,sizeof (struct mm_struct ),0 ,SLAB_HWCACHE_ALIGN |SLAB_PANIC ,NULL ,NULL ); +init_rmap (); }
mm/rmap.c renamed from mm/rmap.c~rmap-10-add-anonmm-rmap +236 -3
285 lines not on this page · raw message
_
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>