--- linux-2.6.11.11/arch/i386/mm/hugetlbpage.c	2005-03-02 12:38:20 +0100
+++ linux-2.6.11.11-vs2.0-rc3/arch/i386/mm/hugetlbpage.c	2005-06-01 14:34:17 +0200
@@ -46,7 +46,7 @@ static void set_huge_pte(struct mm_struc
 {
 	pte_t entry;
 
-	mm->rss += (HPAGE_SIZE / PAGE_SIZE);
+	vx_rsspages_add(mm, HPAGE_SIZE / PAGE_SIZE);
 	if (write_access) {
 		entry =
 		    pte_mkwrite(pte_mkdirty(mk_pte(page, vma->vm_page_prot)));
--- linux-2.6.11.11/arch/i386/mm/hugetlbpage.c	2005-03-02 12:38:20 +0100
+++ linux-2.6.11.11-vs2.0-rc3/arch/i386/mm/hugetlbpage.c	2005-06-01 14:34:17 +0200
@@ -86,7 +86,7 @@ int copy_hugetlb_page_range(struct mm_st
 		ptepage = pte_page(entry);
 		get_page(ptepage);
 		set_pte(dst_pte, entry);
-		dst->rss += (HPAGE_SIZE / PAGE_SIZE);
+		vx_rsspages_add(dst, HPAGE_SIZE / PAGE_SIZE);
 		addr += HPAGE_SIZE;
 	}
 	return 0;
--- linux-2.6.11.11/arch/i386/mm/hugetlbpage.c	2005-03-02 12:38:20 +0100
+++ linux-2.6.11.11-vs2.0-rc3/arch/i386/mm/hugetlbpage.c	2005-06-01 14:34:17 +0200
@@ -222,7 +222,7 @@ void unmap_hugepage_range(struct vm_area
 		page = pte_page(pte);
 		put_page(page);
 	}
-	mm->rss -= (end - start) >> PAGE_SHIFT;
+	vx_rsspages_sub(mm, (end - start) >> PAGE_SHIFT);
 	flush_tlb_range(vma, start, end);
 }
 
--- linux-2.6.11.11/arch/ia64/ia32/binfmt_elf32.c	2005-03-02 12:38:21 +0100
+++ linux-2.6.11.11-vs2.0-rc3/arch/ia64/ia32/binfmt_elf32.c	2005-06-01 14:34:17 +0200
@@ -199,7 +199,7 @@ ia64_elf32_init (struct pt_regs *regs)
 int
 ia32_setup_arg_pages (struct linux_binprm *bprm, int executable_stack)
 {
-	unsigned long stack_base;
+	unsigned long stack_base, grow;
 	struct vm_area_struct *mpnt;
 	struct mm_struct *mm = current->mm;
 	int i, ret;
--- linux-2.6.11.11/arch/ia64/ia32/binfmt_elf32.c	2005-03-02 12:38:21 +0100
+++ linux-2.6.11.11-vs2.0-rc3/arch/ia64/ia32/binfmt_elf32.c	2005-06-01 14:34:17 +0200
@@ -216,8 +216,10 @@ ia32_setup_arg_pages (struct linux_binpr
 	if (!mpnt)
 		return -ENOMEM;
 
-	if (security_vm_enough_memory((IA32_STACK_TOP - (PAGE_MASK & (unsigned long) bprm->p))
-				      >> PAGE_SHIFT)) {
+	grow = (IA32_STACK_TOP - (PAGE_MASK & (unsigned long) bprm->p))
+		>> PAGE_SHIFT;
+	if (security_vm_enough_memory(grow) ||
+		!vx_vmpages_avail(mm, grow)) {
 		kmem_cache_free(vm_area_cachep, mpnt);
 		return -ENOMEM;
 	}
--- linux-2.6.11.11/arch/ia64/ia32/binfmt_elf32.c	2005-03-02 12:38:21 +0100
+++ linux-2.6.11.11-vs2.0-rc3/arch/ia64/ia32/binfmt_elf32.c	2005-06-01 14:34:17 +0200
@@ -242,7 +244,8 @@ ia32_setup_arg_pages (struct linux_binpr
 			kmem_cache_free(vm_area_cachep, mpnt);
 			return ret;
 		}
-		current->mm->stack_vm = current->mm->total_vm = vma_pages(mpnt);
+		vx_vmpages_sub(current->mm, current->mm->total_vm - vma_pages(mpnt));
+		current->mm->stack_vm = current->mm->total_vm;
 	}
 
 	for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
--- linux-2.6.11.11/arch/ia64/kernel/perfmon.c	2005-03-02 12:38:21 +0100
+++ linux-2.6.11.11-vs2.0-rc3/arch/ia64/kernel/perfmon.c	2005-06-01 14:34:17 +0200
@@ -2339,7 +2341,7 @@ pfm_smpl_buffer_alloc(struct task_struct
 	 */
 	insert_vm_struct(mm, vma);
 
-	mm->total_vm  += size >> PAGE_SHIFT;
+	vx_vmpages_add(mm, size >> PAGE_SHIFT);
 	vm_stat_account(vma);
 	up_write(&task->mm->mmap_sem);
 
--- linux-2.6.11.11/arch/ia64/mm/fault.c	2005-03-02 12:38:21 +0100
+++ linux-2.6.11.11-vs2.0-rc3/arch/ia64/mm/fault.c	2005-06-01 14:34:17 +0200
@@ -33,12 +34,17 @@ expand_backing_store (struct vm_area_str
 
 	grow = PAGE_SIZE >> PAGE_SHIFT;
 	if (address - vma->vm_start > current->signal->rlim[RLIMIT_STACK].rlim_cur
-	    || (((vma->vm_mm->total_vm + grow) << PAGE_SHIFT) > current->signal->rlim[RLIMIT_AS].rlim_cur))
+	    || (((vma->vm_mm->total_vm + grow) << PAGE_SHIFT) >
+		current->signal->rlim[RLIMIT_AS].rlim_cur))
+		return -ENOMEM;
+	if (!vx_vmpages_avail(vma->vm_mm, grow) ||
+		((vma->vm_flags & VM_LOCKED) &&
+		!vx_vmlocked_avail(vma->vm_mm, grow)))
 		return -ENOMEM;
 	vma->vm_end += PAGE_SIZE;
-	vma->vm_mm->total_vm += grow;
+	vx_vmpages_add(vma->vm_mm, grow);
 	if (vma->vm_flags & VM_LOCKED)
-		vma->vm_mm->locked_vm += grow;
+		vx_vmlocked_add(vma->vm_mm, grow);
 	__vm_stat_account(vma->vm_mm, vma->vm_flags, vma->vm_file, grow);
 	return 0;
 }
--- linux-2.6.11.11/arch/ia64/mm/hugetlbpage.c	2005-03-02 12:38:21 +0100
+++ linux-2.6.11.11-vs2.0-rc3/arch/ia64/mm/hugetlbpage.c	2005-06-01 14:34:17 +0200
@@ -73,7 +73,7 @@ set_huge_pte (struct mm_struct *mm, stru
 {
 	pte_t entry;
 
-	mm->rss += (HPAGE_SIZE / PAGE_SIZE);
+	vx_rsspages_add(mm, HPAGE_SIZE / PAGE_SIZE);
 	if (write_access) {
 		entry =
 		    pte_mkwrite(pte_mkdirty(mk_pte(page, vma->vm_page_prot)));
--- linux-2.6.11.11/arch/ia64/mm/hugetlbpage.c	2005-03-02 12:38:21 +0100
+++ linux-2.6.11.11-vs2.0-rc3/arch/ia64/mm/hugetlbpage.c	2005-06-01 14:34:17 +0200
@@ -116,7 +116,7 @@ int copy_hugetlb_page_range(struct mm_st
 		ptepage = pte_page(entry);
 		get_page(ptepage);
 		set_pte(dst_pte, entry);
-		dst->rss += (HPAGE_SIZE / PAGE_SIZE);
+		vx_rsspages_add(dst, HPAGE_SIZE / PAGE_SIZE);
 		addr += HPAGE_SIZE;
 	}
 	return 0;
--- linux-2.6.11.11/arch/ia64/mm/hugetlbpage.c	2005-03-02 12:38:21 +0100
+++ linux-2.6.11.11-vs2.0-rc3/arch/ia64/mm/hugetlbpage.c	2005-06-01 14:34:17 +0200
@@ -246,7 +246,7 @@ void unmap_hugepage_range(struct vm_area
 		put_page(page);
 		pte_clear(pte);
 	}
-	mm->rss -= (end - start) >> PAGE_SHIFT;
+	vx_rsspages_sub(mm, (end - start) >> PAGE_SHIFT);
 	flush_tlb_range(vma, start, end);
 }
 
--- linux-2.6.11.11/arch/m68k/atari/stram.c	2005-03-02 12:38:21 +0100
+++ linux-2.6.11.11-vs2.0-rc3/arch/m68k/atari/stram.c	2005-06-01 14:34:17 +0200
@@ -635,7 +635,7 @@ static inline void unswap_pte(struct vm_
 	set_pte(dir, pte_mkdirty(mk_pte(page, vma->vm_page_prot)));
 	swap_free(entry);
 	get_page(page);
-	++vma->vm_mm->rss;
+	vx_rsspages_inc(vma->vm_mm);
 }
 
 static inline void unswap_pmd(struct vm_area_struct * vma, pmd_t *dir,
--- linux-2.6.11.11/arch/mips/kernel/irixelf.c	2005-03-02 12:38:22 +0100
+++ linux-2.6.11.11-vs2.0-rc3/arch/mips/kernel/irixelf.c	2005-06-01 14:34:17 +0200
@@ -692,7 +692,7 @@ static int load_irix_binary(struct linux
 	/* Do this so that we can load the interpreter, if need be.  We will
 	 * change some of these later.
 	 */
-	current->mm->rss = 0;
+	vx_rsspages_sub(current->mm, current->mm->rss);
 	setup_arg_pages(bprm, STACK_TOP, EXSTACK_DEFAULT);
 	current->mm->start_stack = bprm->p;
 
--- linux-2.6.11.11/arch/mips/kernel/sysirix.c	2005-03-02 12:38:22 +0100
+++ linux-2.6.11.11-vs2.0-rc3/arch/mips/kernel/sysirix.c	2005-06-01 14:34:17 +0200
@@ -582,7 +583,8 @@ asmlinkage int irix_brk(unsigned long br
 	/*
 	 * Check if we have enough memory..
 	 */
-	if (security_vm_enough_memory((newbrk-oldbrk) >> PAGE_SHIFT)) {
+	if (security_vm_enough_memory((newbrk-oldbrk) >> PAGE_SHIFT) ||
+		!vx_vmpages_avail(mm, (newbrk-oldbrk) >> PAGE_SHIFT)) {
 		ret = -ENOMEM;
 		goto out;
 	}
--- linux-2.6.11.11/arch/ppc64/mm/hugetlbpage.c	2005-03-02 12:38:24 +0100
+++ linux-2.6.11.11-vs2.0-rc3/arch/ppc64/mm/hugetlbpage.c	2005-06-01 14:34:17 +0200
@@ -153,7 +153,7 @@ static void set_huge_pte(struct mm_struc
 {
 	pte_t entry;
 
-	mm->rss += (HPAGE_SIZE / PAGE_SIZE);
+	vx_rsspages_add(mm, HPAGE_SIZE / PAGE_SIZE);
 	if (write_access) {
 		entry =
 		    pte_mkwrite(pte_mkdirty(mk_pte(page, vma->vm_page_prot)));
--- linux-2.6.11.11/arch/ppc64/mm/hugetlbpage.c	2005-03-02 12:38:24 +0100
+++ linux-2.6.11.11-vs2.0-rc3/arch/ppc64/mm/hugetlbpage.c	2005-06-01 14:34:17 +0200
@@ -315,7 +315,7 @@ int copy_hugetlb_page_range(struct mm_st
 		
 		ptepage = pte_page(entry);
 		get_page(ptepage);
-		dst->rss += (HPAGE_SIZE / PAGE_SIZE);
+		vx_rsspages_add(dst, HPAGE_SIZE / PAGE_SIZE);
 		set_pte(dst_pte, entry);
 
 		addr += HPAGE_SIZE;
--- linux-2.6.11.11/arch/ppc64/mm/hugetlbpage.c	2005-03-02 12:38:24 +0100
+++ linux-2.6.11.11-vs2.0-rc3/arch/ppc64/mm/hugetlbpage.c	2005-06-01 14:34:17 +0200
@@ -425,7 +425,7 @@ void unmap_hugepage_range(struct vm_area
 
 		put_page(page);
 	}
-	mm->rss -= (end - start) >> PAGE_SHIFT;
+	vx_rsspages_sub(mm, (end - start) >> PAGE_SHIFT);
 	flush_tlb_pending();
 }
 
--- linux-2.6.11.11/arch/sh/mm/hugetlbpage.c	2004-08-14 12:55:33 +0200
+++ linux-2.6.11.11-vs2.0-rc3/arch/sh/mm/hugetlbpage.c	2005-06-01 14:34:17 +0200
@@ -62,7 +62,7 @@ static void set_huge_pte(struct mm_struc
 	unsigned long i;
 	pte_t entry;
 
-	mm->rss += (HPAGE_SIZE / PAGE_SIZE);
+	vx_rsspages_add(mm, HPAGE_SIZE / PAGE_SIZE);
 
 	if (write_access)
 		entry = pte_mkwrite(pte_mkdirty(mk_pte(page,
--- linux-2.6.11.11/arch/sh/mm/hugetlbpage.c	2004-08-14 12:55:33 +0200
+++ linux-2.6.11.11-vs2.0-rc3/arch/sh/mm/hugetlbpage.c	2005-06-01 14:34:17 +0200
@@ -115,7 +115,7 @@ int copy_hugetlb_page_range(struct mm_st
 			pte_val(entry) += PAGE_SIZE;
 			dst_pte++;
 		}
-		dst->rss += (HPAGE_SIZE / PAGE_SIZE);
+		vx_rsspages_add(dst, HPAGE_SIZE / PAGE_SIZE);
 		addr += HPAGE_SIZE;
 	}
 	return 0;
--- linux-2.6.11.11/arch/sh/mm/hugetlbpage.c	2004-08-14 12:55:33 +0200
+++ linux-2.6.11.11-vs2.0-rc3/arch/sh/mm/hugetlbpage.c	2005-06-01 14:34:17 +0200
@@ -206,7 +206,7 @@ void unmap_hugepage_range(struct vm_area
 			pte++;
 		}
 	}
-	mm->rss -= (end - start) >> PAGE_SHIFT;
+	vx_rsspages_sub(mm, (end - start) >> PAGE_SHIFT);
 	flush_tlb_range(vma, start, end);
 }
 
--- linux-2.6.11.11/arch/sh64/mm/hugetlbpage.c	2004-08-14 12:55:10 +0200
+++ linux-2.6.11.11-vs2.0-rc3/arch/sh64/mm/hugetlbpage.c	2005-06-01 14:34:17 +0200
@@ -62,8 +62,7 @@ static void set_huge_pte(struct mm_struc
 	unsigned long i;
 	pte_t entry;
 
-	mm->rss += (HPAGE_SIZE / PAGE_SIZE);
-
+	vx_rsspages_add(mm, HPAGE_SIZE / PAGE_SIZE);
 	if (write_access)
 		entry = pte_mkwrite(pte_mkdirty(mk_pte(page,
 						       vma->vm_page_prot)));
--- linux-2.6.11.11/arch/sh64/mm/hugetlbpage.c	2004-08-14 12:55:10 +0200
+++ linux-2.6.11.11-vs2.0-rc3/arch/sh64/mm/hugetlbpage.c	2005-06-01 14:34:17 +0200
@@ -115,7 +114,7 @@ int copy_hugetlb_page_range(struct mm_st
 			pte_val(entry) += PAGE_SIZE;
 			dst_pte++;
 		}
-		dst->rss += (HPAGE_SIZE / PAGE_SIZE);
+		vx_rsspages_add(dst, HPAGE_SIZE / PAGE_SIZE);
 		addr += HPAGE_SIZE;
 	}
 	return 0;
--- linux-2.6.11.11/arch/sh64/mm/hugetlbpage.c	2004-08-14 12:55:10 +0200
+++ linux-2.6.11.11-vs2.0-rc3/arch/sh64/mm/hugetlbpage.c	2005-06-01 14:34:17 +0200
@@ -206,7 +205,7 @@ void unmap_hugepage_range(struct vm_area
 			pte++;
 		}
 	}
-	mm->rss -= (end - start) >> PAGE_SHIFT;
+	vx_rsspages_sub(mm, (end - start) >> PAGE_SHIFT);
 	flush_tlb_range(vma, start, end);
 }
 
--- linux-2.6.11.11/arch/sparc64/kernel/binfmt_aout32.c	2005-03-02 12:38:25 +0100
+++ linux-2.6.11.11-vs2.0-rc3/arch/sparc64/kernel/binfmt_aout32.c	2005-06-01 14:34:17 +0200
@@ -241,7 +242,7 @@ static int load_aout32_binary(struct lin
 	current->mm->brk = ex.a_bss +
 		(current->mm->start_brk = N_BSSADDR(ex));
 
-	current->mm->rss = 0;
+	vx_rsspages_sub(current->mm, current->mm->rss);
 	current->mm->mmap = NULL;
 	compute_creds(bprm);
  	current->flags &= ~PF_FORKNOEXEC;
--- linux-2.6.11.11/arch/sparc64/mm/hugetlbpage.c	2005-03-02 12:38:26 +0100
+++ linux-2.6.11.11-vs2.0-rc3/arch/sparc64/mm/hugetlbpage.c	2005-06-01 14:34:17 +0200
@@ -67,7 +67,7 @@ static void set_huge_pte(struct mm_struc
 	unsigned long i;
 	pte_t entry;
 
-	mm->rss += (HPAGE_SIZE / PAGE_SIZE);
+	vx_rsspages_add(mm, HPAGE_SIZE / PAGE_SIZE);
 
 	if (write_access)
 		entry = pte_mkwrite(pte_mkdirty(mk_pte(page,
--- linux-2.6.11.11/arch/sparc64/mm/hugetlbpage.c	2005-03-02 12:38:26 +0100
+++ linux-2.6.11.11-vs2.0-rc3/arch/sparc64/mm/hugetlbpage.c	2005-06-01 14:34:17 +0200
@@ -120,7 +120,7 @@ int copy_hugetlb_page_range(struct mm_st
 			pte_val(entry) += PAGE_SIZE;
 			dst_pte++;
 		}
-		dst->rss += (HPAGE_SIZE / PAGE_SIZE);
+		vx_rsspages_add(dst, HPAGE_SIZE / PAGE_SIZE);
 		addr += HPAGE_SIZE;
 	}
 	return 0;
--- linux-2.6.11.11/arch/sparc64/mm/hugetlbpage.c	2005-03-02 12:38:26 +0100
+++ linux-2.6.11.11-vs2.0-rc3/arch/sparc64/mm/hugetlbpage.c	2005-06-01 14:34:17 +0200
@@ -211,7 +211,7 @@ void unmap_hugepage_range(struct vm_area
 			pte++;
 		}
 	}
-	mm->rss -= (end - start) >> PAGE_SHIFT;
+	vx_rsspages_sub(mm, (end - start) >> PAGE_SHIFT);
 	flush_tlb_range(vma, start, end);
 }
 
--- linux-2.6.11.11/arch/x86_64/ia32/ia32_aout.c	2005-03-02 12:38:27 +0100
+++ linux-2.6.11.11-vs2.0-rc3/arch/x86_64/ia32/ia32_aout.c	2005-06-01 14:34:17 +0200
@@ -313,7 +314,7 @@ static int load_aout_binary(struct linux
 		(current->mm->start_brk = N_BSSADDR(ex));
 	current->mm->free_area_cache = TASK_UNMAPPED_BASE;
 
-	current->mm->rss = 0;
+	vx_rsspages_sub(current->mm, current->mm->rss);
 	current->mm->mmap = NULL;
 	compute_creds(bprm);
  	current->flags &= ~PF_FORKNOEXEC;
--- linux-2.6.11.11/arch/x86_64/ia32/ia32_binfmt.c	2005-03-02 12:38:27 +0100
+++ linux-2.6.11.11-vs2.0-rc3/arch/x86_64/ia32/ia32_binfmt.c	2005-06-01 14:34:17 +0200
@@ -336,7 +336,7 @@ static void elf32_init(struct pt_regs *r
 
 int setup_arg_pages(struct linux_binprm *bprm, unsigned long stack_top, int executable_stack)
 {
-	unsigned long stack_base;
+	unsigned long stack_base, grow;
 	struct vm_area_struct *mpnt;
 	struct mm_struct *mm = current->mm;
 	int i, ret;
--- linux-2.6.11.11/arch/x86_64/ia32/ia32_binfmt.c	2005-03-02 12:38:27 +0100
+++ linux-2.6.11.11-vs2.0-rc3/arch/x86_64/ia32/ia32_binfmt.c	2005-06-01 14:34:17 +0200
@@ -353,7 +353,10 @@ int setup_arg_pages(struct linux_binprm 
 	if (!mpnt) 
 		return -ENOMEM; 
 	
-	if (security_vm_enough_memory((IA32_STACK_TOP - (PAGE_MASK & (unsigned long) bprm->p))>>PAGE_SHIFT)) {
+	grow = (IA32_STACK_TOP - (PAGE_MASK & (unsigned long) bprm->p))
+		>> PAGE_SHIFT;
+	if (security_vm_enough_memory(grow) ||
+		!vx_vmpages_avail(mm, grow)) {
 		kmem_cache_free(vm_area_cachep, mpnt);
 		return -ENOMEM;
 	}
--- linux-2.6.11.11/arch/x86_64/ia32/ia32_binfmt.c	2005-03-02 12:38:27 +0100
+++ linux-2.6.11.11-vs2.0-rc3/arch/x86_64/ia32/ia32_binfmt.c	2005-06-01 14:34:17 +0200
@@ -378,7 +381,8 @@ int setup_arg_pages(struct linux_binprm 
 			kmem_cache_free(vm_area_cachep, mpnt);
 			return ret;
 		}
-		mm->stack_vm = mm->total_vm = vma_pages(mpnt);
+		vx_vmpages_sub(mm, mm->total_vm - vma_pages(mpnt));
+		mm->stack_vm = mm->total_vm;
 	} 
 
 	for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
--- linux-2.6.11.11/fs/binfmt_aout.c	2005-03-02 12:38:43 +0100
+++ linux-2.6.11.11-vs2.0-rc3/fs/binfmt_aout.c	2005-06-01 14:34:17 +0200
@@ -317,7 +318,7 @@ static int load_aout_binary(struct linux
 		(current->mm->start_brk = N_BSSADDR(ex));
 	current->mm->free_area_cache = current->mm->mmap_base;
 
-	current->mm->rss = 0;
+	vx_rsspages_sub(current->mm, current->mm->rss);
 	current->mm->mmap = NULL;
 	compute_creds(bprm);
  	current->flags &= ~PF_FORKNOEXEC;
--- linux-2.6.11.11/fs/binfmt_elf.c	2005-06-01 14:30:24 +0200
+++ linux-2.6.11.11-vs2.0-rc3/fs/binfmt_elf.c	2005-06-01 14:34:17 +0200
@@ -764,7 +765,7 @@ static int load_elf_binary(struct linux_
 
 	/* Do this so that we can load the interpreter, if need be.  We will
 	   change some of these later */
-	current->mm->rss = 0;
+	vx_rsspages_sub(current->mm, current->mm->rss);
 	current->mm->free_area_cache = current->mm->mmap_base;
 	retval = setup_arg_pages(bprm, STACK_TOP, executable_stack);
 	if (retval < 0) {
--- linux-2.6.11.11/fs/binfmt_elf_fdpic.c	2005-03-02 12:38:43 +0100
+++ linux-2.6.11.11-vs2.0-rc3/fs/binfmt_elf_fdpic.c	2005-06-01 14:34:17 +0200
@@ -299,7 +299,7 @@ static int load_elf_fdpic_binary(struct 
 	/* do this so that we can load the interpreter, if need be
 	 * - we will change some of these later
 	 */
-	current->mm->rss = 0;
+	vx_rsspages_sub(current->mm, current->mm->rss);
 
 #ifdef CONFIG_MMU
 	retval = setup_arg_pages(bprm, current->mm->start_stack, executable_stack);
--- linux-2.6.11.11/fs/binfmt_flat.c	2004-12-25 01:55:19 +0100
+++ linux-2.6.11.11-vs2.0-rc3/fs/binfmt_flat.c	2005-06-01 14:34:17 +0200
@@ -650,7 +651,7 @@ static int load_flat_file(struct linux_b
 		current->mm->start_brk = datapos + data_len + bss_len;
 		current->mm->brk = (current->mm->start_brk + 3) & ~3;
 		current->mm->context.end_brk = memp + ksize((void *) memp) - stack_len;
-		current->mm->rss = 0;
+		vx_rsspages_sub(current->mm, current->mm->rss);
 	}
 
 	if (flags & FLAT_FLAG_KTRACE)
--- linux-2.6.11.11/fs/binfmt_som.c	2005-03-02 12:38:43 +0100
+++ linux-2.6.11.11-vs2.0-rc3/fs/binfmt_som.c	2005-06-01 14:34:17 +0200
@@ -259,7 +260,7 @@ load_som_binary(struct linux_binprm * bp
 	create_som_tables(bprm);
 
 	current->mm->start_stack = bprm->p;
-	current->mm->rss = 0;
+	vx_rsspages_sub(current->mm, current->mm->rss);
 
 #if 0
 	printk("(start_brk) %08lx\n" , (unsigned long) current->mm->start_brk);
--- linux-2.6.11.11/fs/exec.c	2005-06-01 14:30:24 +0200
+++ linux-2.6.11.11-vs2.0-rc3/fs/exec.c	2005-06-01 14:34:17 +0200
@@ -326,7 +327,7 @@ void install_arg_page(struct vm_area_str
 		pte_unmap(pte);
 		goto out;
 	}
-	mm->rss++;
+	vx_rsspages_inc(mm);
 	lru_cache_add_active(page);
 	set_pte(pte, pte_mkdirty(pte_mkwrite(mk_pte(
 					page, vma->vm_page_prot))));
--- linux-2.6.11.11/fs/exec.c	2005-06-01 14:30:24 +0200
+++ linux-2.6.11.11-vs2.0-rc3/fs/exec.c	2005-06-01 14:34:17 +0200
@@ -416,7 +417,8 @@ int setup_arg_pages(struct linux_binprm 
 	if (!mpnt)
 		return -ENOMEM;
 
-	if (security_vm_enough_memory(arg_size >> PAGE_SHIFT)) {
+	if (security_vm_enough_memory(arg_size >> PAGE_SHIFT) ||
+		!vx_vmpages_avail(mm, arg_size >> PAGE_SHIFT)) {
 		kmem_cache_free(vm_area_cachep, mpnt);
 		return -ENOMEM;
 	}
--- linux-2.6.11.11/fs/exec.c	2005-06-01 14:30:24 +0200
+++ linux-2.6.11.11-vs2.0-rc3/fs/exec.c	2005-06-01 14:34:17 +0200
@@ -449,7 +451,8 @@ int setup_arg_pages(struct linux_binprm 
 			kmem_cache_free(vm_area_cachep, mpnt);
 			return ret;
 		}
-		mm->stack_vm = mm->total_vm = vma_pages(mpnt);
+		vx_vmpages_sub(mm, mm->total_vm - vma_pages(mpnt));
+		mm->stack_vm = mm->total_vm;
 	}
 
 	for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
--- linux-2.6.11.11/include/asm-arm/tlb.h	2005-03-02 12:38:47 +0100
+++ linux-2.6.11.11-vs2.0-rc3/include/asm-arm/tlb.h	2005-06-01 14:34:17 +0200
@@ -58,7 +59,7 @@ tlb_finish_mmu(struct mmu_gather *tlb, u
 
 	if (rss < freed)
 		freed = rss;
-	mm->rss = rss - freed;
+	vx_rsspages_sub(mm, freed);
 
 	if (freed) {
 		flush_tlb_mm(mm);
--- linux-2.6.11.11/include/asm-arm26/tlb.h	2005-03-02 12:38:47 +0100
+++ linux-2.6.11.11-vs2.0-rc3/include/asm-arm26/tlb.h	2005-06-01 14:34:17 +0200
@@ -41,7 +42,7 @@ tlb_finish_mmu(struct mmu_gather *tlb, u
 
         if (rss < freed)
                 freed = rss;
-        mm->rss = rss - freed;
+	vx_rsspages_sub(mm, freed);
 
         if (freed) {
                 flush_tlb_mm(mm);
--- linux-2.6.11.11/include/asm-generic/tlb.h	2005-03-02 12:38:47 +0100
+++ linux-2.6.11.11-vs2.0-rc3/include/asm-generic/tlb.h	2005-06-01 14:34:17 +0200
@@ -92,7 +93,7 @@ tlb_finish_mmu(struct mmu_gather *tlb, u
 
 	if (rss < freed)
 		freed = rss;
-	mm->rss = rss - freed;
+	vx_rsspages_sub(mm, freed);
 	tlb_flush_mmu(tlb, start, end);
 
 	/* keep the page table cache within bounds */
--- linux-2.6.11.11/include/asm-ia64/tlb.h	2005-03-02 12:38:50 +0100
+++ linux-2.6.11.11-vs2.0-rc3/include/asm-ia64/tlb.h	2005-06-01 14:34:17 +0200
@@ -165,7 +166,7 @@ tlb_finish_mmu (struct mmu_gather *tlb, 
 
 	if (rss < freed)
 		freed = rss;
-	mm->rss = rss - freed;
+	vx_rsspages_sub(mm, freed);
 	/*
 	 * Note: tlb->nr may be 0 at this point, so we can't rely on tlb->start_addr and
 	 * tlb->end_addr.
--- linux-2.6.11.11/include/asm-sparc64/tlb.h	2005-03-02 12:38:52 +0100
+++ linux-2.6.11.11-vs2.0-rc3/include/asm-sparc64/tlb.h	2005-06-01 14:34:17 +0200
@@ -84,7 +86,7 @@ static inline void tlb_finish_mmu(struct
 
 	if (rss < freed)
 		freed = rss;
-	mm->rss = rss - freed;
+	vx_rsspages_sub(mm, freed);
 
 	tlb_flush_mmu(mp);
 
--- linux-2.6.11.11/include/linux/sched.h	2005-03-02 12:38:53 +0100
+++ linux-2.6.11.11-vs2.0-rc3/include/linux/sched.h	2005-06-01 14:34:17 +0200
@@ -239,6 +241,7 @@ struct mm_struct {
 
 	/* Architecture-specific MM context */
 	mm_context_t context;
+	struct vx_info *mm_vx_info;
 
 	/* Token based thrashing protection. */
 	unsigned long swap_token_time;
--- linux-2.6.11.11/kernel/fork.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/kernel/fork.c	2005-06-01 14:34:17 +0200
@@ -304,6 +309,7 @@ static struct mm_struct * mm_init(struct
 
 	if (likely(!mm_alloc_pgd(mm))) {
 		mm->def_flags = 0;
+		set_vx_info(&mm->mm_vx_info, current->vx_info);
 		return mm;
 	}
 	free_mm(mm);
--- linux-2.6.11.11/kernel/fork.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/kernel/fork.c	2005-06-01 14:34:17 +0200
@@ -335,6 +341,7 @@ void fastcall __mmdrop(struct mm_struct 
 	BUG_ON(mm == &init_mm);
 	mm_free_pgd(mm);
 	destroy_context(mm);
+	clr_vx_info(&mm->mm_vx_info);
 	free_mm(mm);
 }
 
--- linux-2.6.11.11/kernel/fork.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/kernel/fork.c	2005-06-01 14:34:17 +0200
@@ -461,6 +468,7 @@ static int copy_mm(unsigned long clone_f
 
 	/* Copy the current MM stuff.. */
 	memcpy(mm, oldmm, sizeof(*mm));
+	mm->mm_vx_info = NULL;
 	if (!mm_init(mm))
 		goto fail_nomem;
 
--- linux-2.6.11.11/kernel/fork.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/kernel/fork.c	2005-06-01 14:34:17 +0200
@@ -489,6 +497,7 @@ fail_nocontext:
 	 * If init_new_context() failed, we cannot use mmput() to free the mm
 	 * because it calls destroy_context()
 	 */
+	clr_vx_info(&mm->mm_vx_info);
 	mm_free_pgd(mm);
 	free_mm(mm);
 	return retval;
--- linux-2.6.11.11/kernel/fork.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/kernel/fork.c	2005-06-01 14:34:17 +0200
@@ -821,12 +834,30 @@ static task_t *copy_process(unsigned lon
 	if (!p)
 		goto fork_out;
 
+	init_vx_info(&p->vx_info, current->vx_info);
+	init_nx_info(&p->nx_info, current->nx_info);
+
+	/* check vserver memory */
+	if (p->mm && !(clone_flags & CLONE_VM)) {
+		if (vx_vmpages_avail(p->mm, p->mm->total_vm))
+			vx_pages_add(p->mm->mm_vx_info, RLIMIT_AS, p->mm->total_vm);
+		else
+			goto bad_fork_free;
+	}
+	if (p->mm && vx_flags(VXF_FORK_RSS, 0)) {
+		if (!vx_rsspages_avail(p->mm, p->mm->rss))
+			goto bad_fork_cleanup_vm;
+	}
+
 	retval = -EAGAIN;
+	if (!vx_nproc_avail(1))
+		goto bad_fork_cleanup_vm;
+
 	if (atomic_read(&p->user->processes) >=
 			p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
 		if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
 				p->user != &root_user)
-			goto bad_fork_free;
+			goto bad_fork_cleanup_vm;
 	}
 
 	atomic_inc(&p->user->__count);
--- linux-2.6.11.11/kernel/fork.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/kernel/fork.c	2005-06-01 14:34:17 +0200
@@ -1075,6 +1118,9 @@ bad_fork_cleanup_count:
 	put_group_info(p->group_info);
 	atomic_dec(&p->user->processes);
 	free_uid(p->user);
+bad_fork_cleanup_vm:
+	if (p->mm && !(clone_flags & CLONE_VM))
+		vx_pages_sub(p->mm->mm_vx_info, RLIMIT_AS, p->mm->total_vm);
 bad_fork_free:
 	free_task(p);
 	goto fork_out;
--- linux-2.6.11.11/mm/fremap.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/fremap.c	2005-06-01 14:34:17 +0200
@@ -39,7 +40,7 @@ static inline void zap_pte(struct mm_str
 					set_page_dirty(page);
 				page_remove_rmap(page);
 				page_cache_release(page);
-				mm->rss--;
+				vx_rsspages_dec(mm);
 			}
 		}
 	} else {
--- linux-2.6.11.11/mm/fremap.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/fremap.c	2005-06-01 14:34:17 +0200
@@ -67,6 +68,9 @@ int install_page(struct mm_struct *mm, s
 
 	pgd = pgd_offset(mm, addr);
 	spin_lock(&mm->page_table_lock);
+
+	if (!vx_rsspages_avail(mm, 1))
+		goto err_unlock;
 	
 	pud = pud_alloc(mm, pgd, addr);
 	if (!pud)
--- linux-2.6.11.11/mm/fremap.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/fremap.c	2005-06-01 14:34:17 +0200
@@ -92,7 +96,7 @@ int install_page(struct mm_struct *mm, s
 
 	zap_pte(mm, vma, addr, pte);
 
-	mm->rss++;
+	vx_rsspages_inc(mm);
 	flush_icache_page(vma, page);
 	set_pte(pte, mk_pte(page, prot));
 	page_add_file_rmap(page);
--- linux-2.6.11.11/mm/memory.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/memory.c	2005-06-01 14:34:17 +0200
@@ -313,9 +313,9 @@ copy_one_pte(struct mm_struct *dst_mm,  
 		pte = pte_mkclean(pte);
 	pte = pte_mkold(pte);
 	get_page(page);
-	dst_mm->rss++;
+	vx_rsspages_inc(dst_mm);
 	if (PageAnon(page))
-		dst_mm->anon_rss++;
+		vx_anonpages_inc(dst_mm);
 	set_pte(dst_pte, pte);
 	page_dup_rmap(page);
 }
--- linux-2.6.11.11/mm/memory.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/memory.c	2005-06-01 14:34:17 +0200
@@ -513,7 +513,7 @@ static void zap_pte_range(struct mmu_gat
 			if (pte_dirty(pte))
 				set_page_dirty(page);
 			if (PageAnon(page))
-				tlb->mm->anon_rss--;
+				vx_anonpages_dec(tlb->mm);
 			else if (pte_young(pte))
 				mark_page_accessed(page);
 			tlb->freed++;
--- linux-2.6.11.11/mm/memory.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/memory.c	2005-06-01 14:34:17 +0200
@@ -1337,9 +1337,9 @@ static int do_wp_page(struct mm_struct *
 	page_table = pte_offset_map(pmd, address);
 	if (likely(pte_same(*page_table, pte))) {
 		if (PageAnon(old_page))
-			mm->anon_rss--;
+			vx_anonpages_dec(mm);
 		if (PageReserved(old_page)) {
-			++mm->rss;
+			vx_rsspages_inc(mm);
 			acct_update_integrals();
 			update_mem_hiwater();
 		} else
--- linux-2.6.11.11/mm/memory.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/memory.c	2005-06-01 14:34:17 +0200
@@ -1722,6 +1722,10 @@ static int do_swap_page(struct mm_struct
 		grab_swap_token();
 	}
 
+	if (!vx_rsspages_avail(mm, 1)) {
+		ret = VM_FAULT_OOM;
+		goto out;
+	}
 	mark_page_accessed(page);
 	lock_page(page);
 
--- linux-2.6.11.11/mm/memory.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/memory.c	2005-06-01 14:34:17 +0200
@@ -1746,7 +1750,7 @@ static int do_swap_page(struct mm_struct
 	if (vm_swap_full())
 		remove_exclusive_swap_page(page);
 
-	mm->rss++;
+	vx_rsspages_inc(mm);
 	acct_update_integrals();
 	update_mem_hiwater();
 
--- linux-2.6.11.11/mm/memory.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/memory.c	2005-06-01 14:34:17 +0200
@@ -1798,6 +1802,8 @@ do_anonymous_page(struct mm_struct *mm, 
 		pte_unmap(page_table);
 		spin_unlock(&mm->page_table_lock);
 
+		if (!vx_rsspages_avail(mm, 1))
+			goto no_mem;
 		if (unlikely(anon_vma_prepare(vma)))
 			goto no_mem;
 		page = alloc_zeroed_user_highpage(vma, addr);
--- linux-2.6.11.11/mm/memory.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/memory.c	2005-06-01 14:34:17 +0200
@@ -1813,7 +1819,7 @@ do_anonymous_page(struct mm_struct *mm, 
 			spin_unlock(&mm->page_table_lock);
 			goto out;
 		}
-		mm->rss++;
+		vx_rsspages_inc(mm);
 		acct_update_integrals();
 		update_mem_hiwater();
 		entry = maybe_mkwrite(pte_mkdirty(mk_pte(page,
--- linux-2.6.11.11/mm/memory.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/memory.c	2005-06-01 14:34:17 +0200
@@ -1872,6 +1878,9 @@ do_no_page(struct mm_struct *mm, struct 
 	}
 retry:
 	cond_resched();
+	/* FIXME: is that check useful here? */
+	if (!vx_rsspages_avail(mm, 1))
+		return VM_FAULT_OOM;
 	new_page = vma->vm_ops->nopage(vma, address & PAGE_MASK, &ret);
 	/*
 	 * No smp_rmb is needed here as long as there's a full
--- linux-2.6.11.11/mm/memory.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/memory.c	2005-06-01 14:34:17 +0200
@@ -1931,7 +1940,7 @@ retry:
 	/* Only go through if we didn't race with anybody else... */
 	if (pte_none(*page_table)) {
 		if (!PageReserved(new_page))
-			++mm->rss;
+			vx_rsspages_inc(mm);
 		acct_update_integrals();
 		update_mem_hiwater();
 
--- linux-2.6.11.11/mm/mlock.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/mlock.c	2005-06-01 14:34:17 +0200
@@ -49,7 +50,7 @@ static int mlock_fixup(struct vm_area_st
 			ret = make_pages_present(start, end);
 	}
 
-	vma->vm_mm->locked_vm -= pages;
+	vx_vmlocked_sub(vma->vm_mm, pages);
 out:
 	if (ret == -ENOMEM)
 		ret = -EAGAIN;
--- linux-2.6.11.11/mm/mlock.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/mlock.c	2005-06-01 14:34:17 +0200
@@ -103,7 +104,7 @@ static int do_mlock(unsigned long start,
 
 asmlinkage long sys_mlock(unsigned long start, size_t len)
 {
-	unsigned long locked;
+	unsigned long locked, grow;
 	unsigned long lock_limit;
 	int error = -ENOMEM;
 
--- linux-2.6.11.11/mm/mlock.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/mlock.c	2005-06-01 14:34:17 +0200
@@ -114,8 +115,10 @@ asmlinkage long sys_mlock(unsigned long 
 	len = PAGE_ALIGN(len + (start & ~PAGE_MASK));
 	start &= PAGE_MASK;
 
-	locked = len >> PAGE_SHIFT;
-	locked += current->mm->locked_vm;
+	grow = len >> PAGE_SHIFT;
+	if (!vx_vmlocked_avail(current->mm, grow))
+		goto out;
+	locked = current->mm->locked_vm + grow;
 
 	lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
 	lock_limit >>= PAGE_SHIFT;
--- linux-2.6.11.11/mm/mlock.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/mlock.c	2005-06-01 14:34:17 +0200
@@ -123,6 +126,7 @@ asmlinkage long sys_mlock(unsigned long 
 	/* check against resource limits */
 	if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
 		error = do_mlock(start, len, 1);
+out:
 	up_write(&current->mm->mmap_sem);
 	return error;
 }
--- linux-2.6.11.11/mm/mlock.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/mlock.c	2005-06-01 14:34:17 +0200
@@ -182,6 +186,8 @@ asmlinkage long sys_mlockall(int flags)
 	lock_limit >>= PAGE_SHIFT;
 
 	ret = -ENOMEM;
+	if (!vx_vmlocked_avail(current->mm, current->mm->total_vm))
+		goto out;
 	if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
 	    capable(CAP_IPC_LOCK))
 		ret = do_mlockall(flags);
--- linux-2.6.11.11/mm/mmap.c	2005-06-01 14:30:24 +0200
+++ linux-2.6.11.11-vs2.0-rc3/mm/mmap.c	2005-06-01 14:34:17 +0200
@@ -1010,6 +1010,10 @@ munmap_back:
 	    > current->signal->rlim[RLIMIT_AS].rlim_cur)
 		return -ENOMEM;
 
+	/* check context space, maybe only Private writable mapping? */
+	if (!vx_vmpages_avail(mm, len >> PAGE_SHIFT))
+		return -ENOMEM;
+
 	if (accountable && (!(flags & MAP_NORESERVE) ||
 			    sysctl_overcommit_memory == OVERCOMMIT_NEVER)) {
 		if (vm_flags & VM_SHARED) {
--- linux-2.6.11.11/mm/mmap.c	2005-06-01 14:30:24 +0200
+++ linux-2.6.11.11-vs2.0-rc3/mm/mmap.c	2005-06-01 14:34:17 +0200
@@ -1109,10 +1113,10 @@ munmap_back:
 		kmem_cache_free(vm_area_cachep, vma);
 	}
 out:	
-	mm->total_vm += len >> PAGE_SHIFT;
+	vx_vmpages_add(mm, len >> PAGE_SHIFT);
 	__vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
 	if (vm_flags & VM_LOCKED) {
-		mm->locked_vm += len >> PAGE_SHIFT;
+		vx_vmlocked_add(mm, len >> PAGE_SHIFT);
 		make_pages_present(addr, addr + len);
 	}
 	if (flags & MAP_POPULATE) {
--- linux-2.6.11.11/mm/mmap.c	2005-06-01 14:30:24 +0200
+++ linux-2.6.11.11-vs2.0-rc3/mm/mmap.c	2005-06-01 14:34:17 +0200
@@ -1454,6 +1458,9 @@ static int acct_stack_growth(struct vm_a
 			return -ENOMEM;
 	}
 
+	if (!vx_vmpages_avail(vma->vm_mm, grow))
+		return -ENOMEM;
+
 	/*
 	 * Overcommit..  This must be the final test, as it will
 	 * update security statistics.
--- linux-2.6.11.11/mm/mmap.c	2005-06-01 14:30:24 +0200
+++ linux-2.6.11.11-vs2.0-rc3/mm/mmap.c	2005-06-01 14:34:17 +0200
@@ -1462,9 +1469,9 @@ static int acct_stack_growth(struct vm_a
 		return -ENOMEM;
 
 	/* Ok, everything looks good - let it rip */
-	mm->total_vm += grow;
+	vx_vmpages_add(mm, grow);
 	if (vma->vm_flags & VM_LOCKED)
-		mm->locked_vm += grow;
+		vx_vmlocked_add(mm, grow);
 	__vm_stat_account(mm, vma->vm_flags, vma->vm_file, grow);
 	acct_update_integrals();
 	update_mem_hiwater();
--- linux-2.6.11.11/mm/mmap.c	2005-06-01 14:30:24 +0200
+++ linux-2.6.11.11-vs2.0-rc3/mm/mmap.c	2005-06-01 14:34:17 +0200
@@ -1666,9 +1673,10 @@ static void unmap_vma(struct mm_struct *
 {
 	size_t len = area->vm_end - area->vm_start;
 
-	area->vm_mm->total_vm -= len >> PAGE_SHIFT;
+	vx_vmpages_sub(area->vm_mm, len >> PAGE_SHIFT);
+
 	if (area->vm_flags & VM_LOCKED)
-		area->vm_mm->locked_vm -= len >> PAGE_SHIFT;
+		vx_vmlocked_sub(area->vm_mm, len >> PAGE_SHIFT);
 	vm_stat_unaccount(area);
 	area->vm_mm->unmap_area(area);
 	remove_vm_struct(area);
--- linux-2.6.11.11/mm/mmap.c	2005-06-01 14:30:24 +0200
+++ linux-2.6.11.11-vs2.0-rc3/mm/mmap.c	2005-06-01 14:34:17 +0200
@@ -1911,6 +1919,8 @@ unsigned long do_brk(unsigned long addr,
 		locked += len;
 		if (locked > lock_limit && !capable(CAP_IPC_LOCK))
 			return -EAGAIN;
+		if (!vx_vmlocked_avail(mm, len >> PAGE_SHIFT))
+			return -ENOMEM;
 	}
 
 	/*
--- linux-2.6.11.11/mm/mmap.c	2005-06-01 14:30:24 +0200
+++ linux-2.6.11.11-vs2.0-rc3/mm/mmap.c	2005-06-01 14:34:17 +0200
@@ -1938,7 +1948,8 @@ unsigned long do_brk(unsigned long addr,
 	if (mm->map_count > sysctl_max_map_count)
 		return -ENOMEM;
 
-	if (security_vm_enough_memory(len >> PAGE_SHIFT))
+	if (security_vm_enough_memory(len >> PAGE_SHIFT) ||
+		!vx_vmpages_avail(mm, len >> PAGE_SHIFT))
 		return -ENOMEM;
 
 	flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
--- linux-2.6.11.11/mm/mmap.c	2005-06-01 14:30:24 +0200
+++ linux-2.6.11.11-vs2.0-rc3/mm/mmap.c	2005-06-01 14:34:17 +0200
@@ -1966,9 +1977,9 @@ unsigned long do_brk(unsigned long addr,
 	vma->vm_page_prot = protection_map[flags & 0x0f];
 	vma_link(mm, vma, prev, rb_link, rb_parent);
 out:
-	mm->total_vm += len >> PAGE_SHIFT;
+	vx_vmpages_add(mm, len >> PAGE_SHIFT);
 	if (flags & VM_LOCKED) {
-		mm->locked_vm += len >> PAGE_SHIFT;
+		vx_vmlocked_add(mm, len >> PAGE_SHIFT);
 		make_pages_present(addr, addr + len);
 	}
 	acct_update_integrals();
--- linux-2.6.11.11/mm/mmap.c	2005-06-01 14:30:24 +0200
+++ linux-2.6.11.11-vs2.0-rc3/mm/mmap.c	2005-06-01 14:34:17 +0200
@@ -2003,9 +2014,9 @@ void exit_mmap(struct mm_struct *mm)
 	vma = mm->mmap;
 	mm->mmap = mm->mmap_cache = NULL;
 	mm->mm_rb = RB_ROOT;
-	mm->rss = 0;
-	mm->total_vm = 0;
-	mm->locked_vm = 0;
+	vx_rsspages_sub(mm, mm->rss);
+	vx_vmpages_sub(mm, mm->total_vm);
+	vx_vmlocked_sub(mm, mm->locked_vm);
 
 	spin_unlock(&mm->page_table_lock);
 
--- linux-2.6.11.11/mm/mremap.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/mremap.c	2005-06-01 14:34:17 +0200
@@ -246,10 +247,10 @@ static unsigned long move_vma(struct vm_
 			vma->vm_next->vm_flags |= VM_ACCOUNT;
 	}
 
-	mm->total_vm += new_len >> PAGE_SHIFT;
+	vx_vmpages_add(mm, new_len >> PAGE_SHIFT);
 	__vm_stat_account(mm, vma->vm_flags, vma->vm_file, new_len>>PAGE_SHIFT);
 	if (vm_flags & VM_LOCKED) {
-		mm->locked_vm += new_len >> PAGE_SHIFT;
+		vx_vmlocked_add(mm, new_len >> PAGE_SHIFT);
 		if (new_len > old_len)
 			make_pages_present(new_addr + old_len,
 					   new_addr + new_len);
--- linux-2.6.11.11/mm/mremap.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/mremap.c	2005-06-01 14:34:17 +0200
@@ -358,11 +359,18 @@ unsigned long do_mremap(unsigned long ad
 		ret = -EAGAIN;
 		if (locked > lock_limit && !capable(CAP_IPC_LOCK))
 			goto out;
+		ret = -ENOMEM;
+		if (!vx_vmlocked_avail(current->mm,
+			(new_len - old_len) >> PAGE_SHIFT))
+			goto out;
 	}
 	ret = -ENOMEM;
 	if ((current->mm->total_vm << PAGE_SHIFT) + (new_len - old_len)
 	    > current->signal->rlim[RLIMIT_AS].rlim_cur)
 		goto out;
+	/* check context space, maybe only Private writable mapping? */
+	if (!vx_vmpages_avail(current->mm, (new_len - old_len) >> PAGE_SHIFT))
+		goto out;
 
 	if (vma->vm_flags & VM_ACCOUNT) {
 		charged = (new_len - old_len) >> PAGE_SHIFT;
--- linux-2.6.11.11/mm/mremap.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/mremap.c	2005-06-01 14:34:17 +0200
@@ -386,11 +394,11 @@ unsigned long do_mremap(unsigned long ad
 			vma_adjust(vma, vma->vm_start,
 				addr + new_len, vma->vm_pgoff, NULL);
 
-			current->mm->total_vm += pages;
+			vx_vmpages_add(current->mm, pages);
 			__vm_stat_account(vma->vm_mm, vma->vm_flags,
 							vma->vm_file, pages);
 			if (vma->vm_flags & VM_LOCKED) {
-				current->mm->locked_vm += pages;
+				vx_vmlocked_add(vma->vm_mm, pages);
 				make_pages_present(addr + old_len,
 						   addr + new_len);
 			}
--- linux-2.6.11.11/mm/nommu.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/nommu.c	2005-06-01 14:34:17 +0200
@@ -694,7 +694,7 @@ unsigned long do_mmap_pgoff(struct file 
 	realalloc += kobjsize(vma);
 	askedalloc += sizeof(*vma);
 
-	current->mm->total_vm += len >> PAGE_SHIFT;
+	vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
 
 	add_nommu_vma(vma);
  shared:
--- linux-2.6.11.11/mm/nommu.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/nommu.c	2005-06-01 14:34:17 +0200
@@ -813,7 +813,7 @@ int do_munmap(struct mm_struct *mm, unsi
 	realalloc -= kobjsize(vml);
 	askedalloc -= sizeof(*vml);
 	kfree(vml);
-	mm->total_vm -= len >> PAGE_SHIFT;
+	vx_vmpages_sub(mm, len >> PAGE_SHIFT);
 
 #ifdef DEBUG
 	show_process_blocks();
--- linux-2.6.11.11/mm/nommu.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/nommu.c	2005-06-01 14:34:17 +0200
@@ -832,7 +832,7 @@ void exit_mmap(struct mm_struct * mm)
 		printk("Exit_mmap:\n");
 #endif
 
-		mm->total_vm = 0;
+		vx_vmpages_sub(mm, mm->total_vm);
 
 		while ((tmp = mm->context.vmlist)) {
 			mm->context.vmlist = tmp->next;
--- linux-2.6.11.11/mm/oom_kill.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/oom_kill.c	2005-06-01 14:34:17 +0200
@@ -54,6 +54,7 @@ unsigned long badness(struct task_struct
 	 * The memory size of the process is the basis for the badness.
 	 */
 	points = p->mm->total_vm;
+	/* FIXME add vserver badness ;) */
 
 	/*
 	 * Processes which fork a lot of child processes are likely
--- linux-2.6.11.11/mm/rmap.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/rmap.c	2005-06-01 14:34:17 +0200
@@ -437,7 +438,7 @@ void page_add_anon_rmap(struct page *pag
 	BUG_ON(PageReserved(page));
 	BUG_ON(!anon_vma);
 
-	vma->vm_mm->anon_rss++;
+	vx_anonpages_inc(vma->vm_mm);
 
 	anon_vma = (void *) anon_vma + PAGE_MAPPING_ANON;
 	index = (address - vma->vm_start) >> PAGE_SHIFT;
--- linux-2.6.11.11/mm/rmap.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/rmap.c	2005-06-01 14:34:17 +0200
@@ -596,10 +597,10 @@ static int try_to_unmap_one(struct page 
 		}
 		set_pte(pte, swp_entry_to_pte(entry));
 		BUG_ON(pte_file(*pte));
-		mm->anon_rss--;
+		vx_anonpages_dec(mm);
 	}
 
-	mm->rss--;
+	vx_rsspages_dec(mm);
 	acct_update_integrals();
 	page_remove_rmap(page);
 	page_cache_release(page);
--- linux-2.6.11.11/mm/rmap.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/rmap.c	2005-06-01 14:34:17 +0200
@@ -706,7 +707,7 @@ static void try_to_unmap_cluster(unsigne
 		page_remove_rmap(page);
 		page_cache_release(page);
 		acct_update_integrals();
-		mm->rss--;
+		vx_rsspages_dec(mm);
 		(*mapcount)--;
 	}
 
--- linux-2.6.11.11/mm/swapfile.c	2005-03-02 12:39:08 +0100
+++ linux-2.6.11.11-vs2.0-rc3/mm/swapfile.c	2005-06-01 14:34:17 +0200
@@ -432,7 +433,7 @@ static void
 unuse_pte(struct vm_area_struct *vma, unsigned long address, pte_t *dir,
 	swp_entry_t entry, struct page *page)
 {
-	vma->vm_mm->rss++;
+	vx_rsspages_inc(vma->vm_mm);
 	get_page(page);
 	set_pte(dir, pte_mkold(mk_pte(page, vma->vm_page_prot)));
 	page_add_anon_rmap(page, vma, address);
