--- linux-2.6.11-rc1/arch/i386/mm/hugetlbpage.c	2005-01-14 12:35:31 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/i386/mm/hugetlbpage.c	2005-01-15 11:27:51 +0100
@@ -46,7 +46,8 @@ static void set_huge_pte(struct mm_struc
 {
 	pte_t entry;
 
-	mm->rss += (HPAGE_SIZE / PAGE_SIZE);
+	// 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-rc1/arch/i386/mm/hugetlbpage.c	2005-01-14 12:35:31 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/i386/mm/hugetlbpage.c	2005-01-15 11:27:51 +0100
@@ -86,7 +87,8 @@ 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);
+		// dst->rss += (HPAGE_SIZE / PAGE_SIZE);
+		vx_rsspages_add(dst, HPAGE_SIZE / PAGE_SIZE);
 		addr += HPAGE_SIZE;
 	}
 	return 0;
--- linux-2.6.11-rc1/arch/i386/mm/hugetlbpage.c	2005-01-14 12:35:31 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/i386/mm/hugetlbpage.c	2005-01-15 11:27:51 +0100
@@ -222,7 +224,8 @@ void unmap_hugepage_range(struct vm_area
 		page = pte_page(pte);
 		put_page(page);
 	}
-	mm->rss -= (end - start) >> PAGE_SHIFT;
+	// mm->rss -= (end - start) >> PAGE_SHIFT;
+	vx_rsspages_sub(mm, (end - start) >> PAGE_SHIFT);
 	flush_tlb_range(vma, start, end);
 }
 
--- linux-2.6.11-rc1/arch/ia64/ia32/binfmt_elf32.c	2005-01-14 12:35:31 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/ia64/ia32/binfmt_elf32.c	2005-01-15 11:27:51 +0100
@@ -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-rc1/arch/ia64/ia32/binfmt_elf32.c	2005-01-14 12:35:31 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/ia64/ia32/binfmt_elf32.c	2005-01-15 11:27:51 +0100
@@ -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-rc1/arch/ia64/ia32/binfmt_elf32.c	2005-01-14 12:35:31 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/ia64/ia32/binfmt_elf32.c	2005-01-15 11:27:51 +0100
@@ -242,7 +244,9 @@ 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);
+		// 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-rc1/arch/ia64/kernel/perfmon.c	2005-01-14 12:35:31 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/ia64/kernel/perfmon.c	2005-01-15 11:27:51 +0100
@@ -2339,7 +2341,8 @@ pfm_smpl_buffer_alloc(struct task_struct
 	 */
 	insert_vm_struct(mm, vma);
 
-	mm->total_vm  += size >> PAGE_SHIFT;
+	// 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-rc1/arch/ia64/mm/fault.c	2005-01-14 12:35:31 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/ia64/mm/fault.c	2005-01-15 11:27:52 +0100
@@ -33,12 +34,19 @@ 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;
+	// 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;
+		// 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-rc1/arch/ia64/mm/hugetlbpage.c	2005-01-14 12:35:31 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/ia64/mm/hugetlbpage.c	2005-01-15 11:27:52 +0100
@@ -73,7 +73,8 @@ set_huge_pte (struct mm_struct *mm, stru
 {
 	pte_t entry;
 
-	mm->rss += (HPAGE_SIZE / PAGE_SIZE);
+	// 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-rc1/arch/ia64/mm/hugetlbpage.c	2005-01-14 12:35:31 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/ia64/mm/hugetlbpage.c	2005-01-15 11:27:52 +0100
@@ -116,7 +117,8 @@ 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);
+		// dst->rss += (HPAGE_SIZE / PAGE_SIZE);
+		vx_rsspages_add(dst, HPAGE_SIZE / PAGE_SIZE);
 		addr += HPAGE_SIZE;
 	}
 	return 0;
--- linux-2.6.11-rc1/arch/ia64/mm/hugetlbpage.c	2005-01-14 12:35:31 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/ia64/mm/hugetlbpage.c	2005-01-15 11:27:52 +0100
@@ -246,7 +248,8 @@ void unmap_hugepage_range(struct vm_area
 		put_page(page);
 		pte_clear(pte);
 	}
-	mm->rss -= (end - start) >> PAGE_SHIFT;
+	// mm->rss -= (end - start) >> PAGE_SHIFT;
+	vx_rsspages_sub(mm, (end - start) >> PAGE_SHIFT);
 	flush_tlb_range(vma, start, end);
 }
 
--- linux-2.6.11-rc1/arch/m68k/atari/stram.c	2004-08-14 12:55:48 +0200
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/m68k/atari/stram.c	2005-01-15 11:27:52 +0100
@@ -635,7 +635,8 @@ 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;
+	// ++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-rc1/arch/mips/kernel/irixelf.c	2005-01-14 12:35:41 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/mips/kernel/irixelf.c	2005-01-15 12:17:14 +0100
@@ -684,7 +684,8 @@ 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;
+	// 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-rc1/arch/mips/kernel/sysirix.c	2004-12-25 01:54:46 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/mips/kernel/sysirix.c	2005-01-15 11:27:52 +0100
@@ -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-rc1/arch/ppc64/mm/hugetlbpage.c	2005-01-14 12:35:42 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/ppc64/mm/hugetlbpage.c	2005-01-15 11:27:52 +0100
@@ -153,7 +153,8 @@ static void set_huge_pte(struct mm_struc
 {
 	pte_t entry;
 
-	mm->rss += (HPAGE_SIZE / PAGE_SIZE);
+	// 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-rc1/arch/ppc64/mm/hugetlbpage.c	2005-01-14 12:35:42 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/ppc64/mm/hugetlbpage.c	2005-01-15 11:27:52 +0100
@@ -311,7 +312,8 @@ int copy_hugetlb_page_range(struct mm_st
 		
 		ptepage = pte_page(entry);
 		get_page(ptepage);
-		dst->rss += (HPAGE_SIZE / PAGE_SIZE);
+		// 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-rc1/arch/ppc64/mm/hugetlbpage.c	2005-01-14 12:35:42 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/ppc64/mm/hugetlbpage.c	2005-01-15 11:27:52 +0100
@@ -421,7 +423,8 @@ void unmap_hugepage_range(struct vm_area
 
 		put_page(page);
 	}
-	mm->rss -= (end - start) >> PAGE_SHIFT;
+	// mm->rss -= (end - start) >> PAGE_SHIFT;
+	vx_rsspages_sub(mm, (end - start) >> PAGE_SHIFT);
 	flush_tlb_pending();
 }
 
--- linux-2.6.11-rc1/arch/sh/mm/hugetlbpage.c	2004-08-14 12:55:33 +0200
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/sh/mm/hugetlbpage.c	2005-01-15 11:27:52 +0100
@@ -62,7 +62,8 @@ static void set_huge_pte(struct mm_struc
 	unsigned long i;
 	pte_t entry;
 
-	mm->rss += (HPAGE_SIZE / PAGE_SIZE);
+	// 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-rc1/arch/sh/mm/hugetlbpage.c	2004-08-14 12:55:33 +0200
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/sh/mm/hugetlbpage.c	2005-01-15 11:27:52 +0100
@@ -115,7 +116,8 @@ int copy_hugetlb_page_range(struct mm_st
 			pte_val(entry) += PAGE_SIZE;
 			dst_pte++;
 		}
-		dst->rss += (HPAGE_SIZE / PAGE_SIZE);
+		// dst->rss += (HPAGE_SIZE / PAGE_SIZE);
+		vx_rsspages_add(dst, HPAGE_SIZE / PAGE_SIZE);
 		addr += HPAGE_SIZE;
 	}
 	return 0;
--- linux-2.6.11-rc1/arch/sh/mm/hugetlbpage.c	2004-08-14 12:55:33 +0200
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/sh/mm/hugetlbpage.c	2005-01-15 11:27:52 +0100
@@ -206,7 +208,8 @@ void unmap_hugepage_range(struct vm_area
 			pte++;
 		}
 	}
-	mm->rss -= (end - start) >> PAGE_SHIFT;
+	// mm->rss -= (end - start) >> PAGE_SHIFT;
+	vx_rsspages_sub(mm, (end - start) >> PAGE_SHIFT);
 	flush_tlb_range(vma, start, end);
 }
 
--- linux-2.6.11-rc1/arch/sh64/mm/hugetlbpage.c	2004-08-14 12:55:10 +0200
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/sh64/mm/hugetlbpage.c	2005-01-15 11:27:52 +0100
@@ -62,8 +62,8 @@ static void set_huge_pte(struct mm_struc
 	unsigned long i;
 	pte_t entry;
 
-	mm->rss += (HPAGE_SIZE / PAGE_SIZE);
-
+	// 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-rc1/arch/sh64/mm/hugetlbpage.c	2004-08-14 12:55:10 +0200
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/sh64/mm/hugetlbpage.c	2005-01-15 11:27:52 +0100
@@ -115,7 +115,8 @@ int copy_hugetlb_page_range(struct mm_st
 			pte_val(entry) += PAGE_SIZE;
 			dst_pte++;
 		}
-		dst->rss += (HPAGE_SIZE / PAGE_SIZE);
+		// dst->rss += (HPAGE_SIZE / PAGE_SIZE);
+		vx_rsspages_add(dst, HPAGE_SIZE / PAGE_SIZE);
 		addr += HPAGE_SIZE;
 	}
 	return 0;
--- linux-2.6.11-rc1/arch/sh64/mm/hugetlbpage.c	2004-08-14 12:55:10 +0200
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/sh64/mm/hugetlbpage.c	2005-01-15 11:27:52 +0100
@@ -206,7 +207,8 @@ void unmap_hugepage_range(struct vm_area
 			pte++;
 		}
 	}
-	mm->rss -= (end - start) >> PAGE_SHIFT;
+	// mm->rss -= (end - start) >> PAGE_SHIFT;
+	vx_rsspages_sub(mm, (end - start) >> PAGE_SHIFT);
 	flush_tlb_range(vma, start, end);
 }
 
--- linux-2.6.11-rc1/arch/sparc64/kernel/binfmt_aout32.c	2005-01-14 12:35:43 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/sparc64/kernel/binfmt_aout32.c	2005-01-15 11:27:52 +0100
@@ -239,7 +240,8 @@ static int load_aout32_binary(struct lin
 	current->mm->brk = ex.a_bss +
 		(current->mm->start_brk = N_BSSADDR(ex));
 
-	current->mm->rss = 0;
+	// 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-rc1/arch/sparc64/mm/hugetlbpage.c	2004-08-14 12:55:47 +0200
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/sparc64/mm/hugetlbpage.c	2005-01-15 11:27:52 +0100
@@ -59,7 +59,8 @@ static void set_huge_pte(struct mm_struc
 	unsigned long i;
 	pte_t entry;
 
-	mm->rss += (HPAGE_SIZE / PAGE_SIZE);
+	// 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-rc1/arch/sparc64/mm/hugetlbpage.c	2004-08-14 12:55:47 +0200
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/sparc64/mm/hugetlbpage.c	2005-01-15 11:27:52 +0100
@@ -112,7 +113,8 @@ int copy_hugetlb_page_range(struct mm_st
 			pte_val(entry) += PAGE_SIZE;
 			dst_pte++;
 		}
-		dst->rss += (HPAGE_SIZE / PAGE_SIZE);
+		// dst->rss += (HPAGE_SIZE / PAGE_SIZE);
+		vx_rsspages_add(dst, HPAGE_SIZE / PAGE_SIZE);
 		addr += HPAGE_SIZE;
 	}
 	return 0;
--- linux-2.6.11-rc1/arch/sparc64/mm/hugetlbpage.c	2004-08-14 12:55:47 +0200
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/sparc64/mm/hugetlbpage.c	2005-01-15 11:27:52 +0100
@@ -203,7 +205,8 @@ void unmap_hugepage_range(struct vm_area
 			pte++;
 		}
 	}
-	mm->rss -= (end - start) >> PAGE_SHIFT;
+	// mm->rss -= (end - start) >> PAGE_SHIFT;
+	vx_rsspages_sub(mm, (end - start) >> PAGE_SHIFT);
 	flush_tlb_range(vma, start, end);
 }
 
--- linux-2.6.11-rc1/arch/x86_64/ia32/ia32_aout.c	2005-01-14 12:35:43 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/x86_64/ia32/ia32_aout.c	2005-01-15 11:27:52 +0100
@@ -311,7 +312,8 @@ 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;
+	// 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-rc1/arch/x86_64/ia32/ia32_binfmt.c	2005-01-14 12:35:43 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/x86_64/ia32/ia32_binfmt.c	2005-01-15 11:27:52 +0100
@@ -332,7 +332,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-rc1/arch/x86_64/ia32/ia32_binfmt.c	2005-01-14 12:35:43 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/x86_64/ia32/ia32_binfmt.c	2005-01-15 11:27:52 +0100
@@ -349,7 +349,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-rc1/arch/x86_64/ia32/ia32_binfmt.c	2005-01-14 12:35:43 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/arch/x86_64/ia32/ia32_binfmt.c	2005-01-15 11:27:52 +0100
@@ -374,7 +377,9 @@ 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);
+		// 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-rc1/fs/binfmt_aout.c	2005-01-14 12:35:55 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/fs/binfmt_aout.c	2005-01-15 11:27:52 +0100
@@ -314,7 +315,8 @@ 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;
+	// 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-rc1/fs/binfmt_elf.c	2005-01-14 12:35:55 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/fs/binfmt_elf.c	2005-01-15 11:27:52 +0100
@@ -738,7 +739,8 @@ 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;
+	// 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-rc1/fs/binfmt_elf_fdpic.c	2005-01-14 12:35:55 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/fs/binfmt_elf_fdpic.c	2005-01-15 17:57:08 +0100
@@ -299,7 +299,8 @@ 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;
+	// 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-rc1/fs/binfmt_flat.c	2004-12-25 01:55:19 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/fs/binfmt_flat.c	2005-01-15 11:27:52 +0100
@@ -650,7 +651,8 @@ 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;
+		// current->mm->rss = 0;
+		vx_rsspages_sub(current->mm, current->mm->rss);
 	}
 
 	if (flags & FLAT_FLAG_KTRACE)
--- linux-2.6.11-rc1/fs/binfmt_som.c	2005-01-14 12:35:55 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/fs/binfmt_som.c	2005-01-15 11:27:52 +0100
@@ -259,7 +260,8 @@ load_som_binary(struct linux_binprm * bp
 	create_som_tables(bprm);
 
 	current->mm->start_stack = bprm->p;
-	current->mm->rss = 0;
+	// 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-rc1/fs/exec.c	2005-01-14 12:35:55 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/fs/exec.c	2005-01-15 12:34:38 +0100
@@ -326,7 +327,8 @@ void install_arg_page(struct vm_area_str
 		pte_unmap(pte);
 		goto out;
 	}
-	mm->rss++;
+	// 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-rc1/fs/exec.c	2005-01-14 12:35:55 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/fs/exec.c	2005-01-15 12:34:38 +0100
@@ -416,7 +418,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-rc1/fs/exec.c	2005-01-14 12:35:55 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/fs/exec.c	2005-01-15 12:34:38 +0100
@@ -449,7 +452,9 @@ 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);
+		// 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-rc1/include/asm-arm/tlb.h	2004-08-14 12:54:47 +0200
+++ linux-2.6.11-rc1-vs1.9.4-rc2/include/asm-arm/tlb.h	2005-01-15 11:27:52 +0100
@@ -58,7 +58,8 @@ tlb_finish_mmu(struct mmu_gather *tlb, u
 
 	if (rss < freed)
 		freed = rss;
-	mm->rss = rss - freed;
+	// mm->rss = rss - freed;
+	vx_rsspages_sub(mm, freed);
 
 	if (freed) {
 		flush_tlb_mm(mm);
--- linux-2.6.11-rc1/include/asm-arm26/tlb.h	2005-01-14 12:35:56 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/include/asm-arm26/tlb.h	2005-01-15 11:27:52 +0100
@@ -41,7 +41,8 @@ tlb_finish_mmu(struct mmu_gather *tlb, u
 
         if (rss < freed)
                 freed = rss;
-        mm->rss = rss - freed;
+	// mm->rss = rss - freed;
+	vx_rsspages_sub(mm, freed);
 
         if (freed) {
                 flush_tlb_mm(mm);
--- linux-2.6.11-rc1/include/asm-generic/tlb.h	2005-01-14 12:35:56 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/include/asm-generic/tlb.h	2005-01-15 11:27:52 +0100
@@ -92,7 +93,8 @@ tlb_finish_mmu(struct mmu_gather *tlb, u
 
 	if (rss < freed)
 		freed = rss;
-	mm->rss = rss - freed;
+	// 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-rc1/include/asm-ia64/tlb.h	2005-01-14 12:35:57 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/include/asm-ia64/tlb.h	2005-01-15 11:27:52 +0100
@@ -165,7 +166,8 @@ tlb_finish_mmu (struct mmu_gather *tlb, 
 
 	if (rss < freed)
 		freed = rss;
-	mm->rss = rss - freed;
+	// 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-rc1/include/asm-sparc64/tlb.h	2004-08-14 12:55:48 +0200
+++ linux-2.6.11-rc1-vs1.9.4-rc2/include/asm-sparc64/tlb.h	2005-01-15 11:27:52 +0100
@@ -84,7 +86,8 @@ static inline void tlb_finish_mmu(struct
 
 	if (rss < freed)
 		freed = rss;
-	mm->rss = rss - freed;
+	// mm->rss = rss - freed;
+	vx_rsspages_sub(mm, freed);
 
 	tlb_flush_mmu(mp);
 
--- linux-2.6.11-rc1/include/linux/sched.h	2005-01-14 12:35:58 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/include/linux/sched.h	2005-01-15 11:27:52 +0100
@@ -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-rc1/kernel/fork.c	2005-01-14 12:36:00 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/kernel/fork.c	2005-01-15 12:42:27 +0100
@@ -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-rc1/kernel/fork.c	2005-01-14 12:36:00 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/kernel/fork.c	2005-01-15 12:42:27 +0100
@@ -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-rc1/kernel/fork.c	2005-01-14 12:36:00 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/kernel/fork.c	2005-01-15 12:42:27 +0100
@@ -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-rc1/mm/fremap.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/fremap.c	2005-01-15 12:55:07 +0100
@@ -39,7 +40,8 @@ static inline void zap_pte(struct mm_str
 					set_page_dirty(page);
 				page_remove_rmap(page);
 				page_cache_release(page);
-				mm->rss--;
+				// mm->rss--;
+				vx_rsspages_dec(mm);
 			}
 		}
 	} else {
--- linux-2.6.11-rc1/mm/fremap.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/fremap.c	2005-01-15 12:55:07 +0100
@@ -67,6 +69,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-rc1/mm/fremap.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/fremap.c	2005-01-15 12:55:07 +0100
@@ -92,7 +97,8 @@ int install_page(struct mm_struct *mm, s
 
 	zap_pte(mm, vma, addr, pte);
 
-	mm->rss++;
+	// 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-rc1/mm/memory.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/memory.c	2005-01-15 14:08:58 +0100
@@ -324,7 +324,8 @@ copy_one_pte(struct mm_struct *dst_mm,  
 		pte = pte_mkclean(pte);
 	pte = pte_mkold(pte);
 	get_page(page);
-	dst_mm->rss++;
+	// dst_mm->rss++;
+	vx_rsspages_inc(dst_mm);
 	if (PageAnon(page))
 		dst_mm->anon_rss++;
 	set_pte(dst_pte, pte);
--- linux-2.6.11-rc1/mm/memory.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/memory.c	2005-01-15 14:08:58 +0100
@@ -1343,7 +1344,8 @@ static int do_wp_page(struct mm_struct *
 		if (PageAnon(old_page))
 			mm->anon_rss--;
 		if (PageReserved(old_page)) {
-			++mm->rss;
+			// ++mm->rss;
+			vx_rsspages_inc(mm);
 			acct_update_integrals();
 			update_mem_hiwater();
 		} else
--- linux-2.6.11-rc1/mm/memory.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/memory.c	2005-01-15 14:08:58 +0100
@@ -1717,6 +1719,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-rc1/mm/memory.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/memory.c	2005-01-15 14:08:58 +0100
@@ -1741,7 +1747,8 @@ static int do_swap_page(struct mm_struct
 	if (vm_swap_full())
 		remove_exclusive_swap_page(page);
 
-	mm->rss++;
+	// mm->rss++;
+	vx_rsspages_inc(mm);
 	acct_update_integrals();
 	update_mem_hiwater();
 
--- linux-2.6.11-rc1/mm/memory.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/memory.c	2005-01-15 14:08:58 +0100
@@ -1795,6 +1802,9 @@ do_anonymous_page(struct mm_struct *mm, 
 
 		if (unlikely(anon_vma_prepare(vma)))
 			goto no_mem;
+		if (!vx_rsspages_avail(mm, 1))
+			goto no_mem;
+
 		page = alloc_page_vma(GFP_HIGHUSER, vma, addr);
 		if (!page)
 			goto no_mem;
--- linux-2.6.11-rc1/mm/memory.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/memory.c	2005-01-15 14:08:58 +0100
@@ -1809,7 +1819,8 @@ do_anonymous_page(struct mm_struct *mm, 
 			spin_unlock(&mm->page_table_lock);
 			goto out;
 		}
-		mm->rss++;
+		// mm->rss++;
+		vx_rsspages_inc(mm);
 		acct_update_integrals();
 		update_mem_hiwater();
 		entry = maybe_mkwrite(pte_mkdirty(mk_pte(page,
--- linux-2.6.11-rc1/mm/memory.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/memory.c	2005-01-15 14:08:58 +0100
@@ -1874,6 +1885,8 @@ retry:
 		return VM_FAULT_SIGBUS;
 	if (new_page == NOPAGE_OOM)
 		return VM_FAULT_OOM;
+	if (!vx_rsspages_avail(mm, 1))
+		return VM_FAULT_OOM;
 
 	/*
 	 * Should we do an early C-O-W break?
--- linux-2.6.11-rc1/mm/memory.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/memory.c	2005-01-15 14:08:58 +0100
@@ -1919,7 +1932,8 @@ retry:
 	/* Only go through if we didn't race with anybody else... */
 	if (pte_none(*page_table)) {
 		if (!PageReserved(new_page))
-			++mm->rss;
+			// ++mm->rss;
+			vx_rsspages_inc(mm);
 		acct_update_integrals();
 		update_mem_hiwater();
 
--- linux-2.6.11-rc1/mm/mlock.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/mlock.c	2005-01-15 11:27:52 +0100
@@ -51,7 +52,8 @@ static int mlock_fixup(struct vm_area_st
 			ret = make_pages_present(start, end);
 	}
 
-	vma->vm_mm->locked_vm -= pages;
+	// vma->vm_mm->locked_vm -= pages;
+	vx_vmlocked_sub(vma->vm_mm, pages);
 out:
 	return ret;
 }
--- linux-2.6.11-rc1/mm/mlock.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/mlock.c	2005-01-15 11:27:52 +0100
@@ -103,7 +105,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-rc1/mm/mlock.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/mlock.c	2005-01-15 11:27:52 +0100
@@ -114,8 +116,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-rc1/mm/mlock.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/mlock.c	2005-01-15 11:27:52 +0100
@@ -123,6 +127,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-rc1/mm/mlock.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/mlock.c	2005-01-15 11:27:52 +0100
@@ -182,6 +187,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-rc1/mm/mmap.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/mmap.c	2005-01-15 14:37:39 +0100
@@ -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-rc1/mm/mmap.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/mmap.c	2005-01-15 14:37:39 +0100
@@ -1109,10 +1113,12 @@ munmap_back:
 		kmem_cache_free(vm_area_cachep, vma);
 	}
 out:	
-	mm->total_vm += len >> PAGE_SHIFT;
+	// 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;
+		// 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-rc1/mm/mmap.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/mmap.c	2005-01-15 14:37:39 +0100
@@ -1451,6 +1457,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-rc1/mm/mmap.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/mmap.c	2005-01-15 14:37:39 +0100
@@ -1459,9 +1468,11 @@ static int acct_stack_growth(struct vm_a
 		return -ENOMEM;
 
 	/* Ok, everything looks good - let it rip */
-	mm->total_vm += grow;
+	// mm->total_vm += grow;
+	vx_vmpages_add(mm, grow);
 	if (vma->vm_flags & VM_LOCKED)
-		mm->locked_vm += grow;
+		// 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-rc1/mm/mmap.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/mmap.c	2005-01-15 14:37:39 +0100
@@ -1651,9 +1662,12 @@ static void unmap_vma(struct mm_struct *
 {
 	size_t len = area->vm_end - area->vm_start;
 
-	area->vm_mm->total_vm -= len >> PAGE_SHIFT;
+	// 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;
+		// 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-rc1/mm/mmap.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/mmap.c	2005-01-15 14:37:39 +0100
@@ -1888,6 +1902,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-rc1/mm/mmap.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/mmap.c	2005-01-15 14:37:39 +0100
@@ -1909,7 +1925,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-rc1/mm/mmap.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/mmap.c	2005-01-15 14:37:39 +0100
@@ -1937,9 +1954,11 @@ 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;
+	// mm->total_vm += len >> PAGE_SHIFT;
+	vx_vmpages_add(mm, len >> PAGE_SHIFT);
 	if (flags & VM_LOCKED) {
-		mm->locked_vm += len >> PAGE_SHIFT;
+		// 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-rc1/mm/mmap.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/mmap.c	2005-01-15 14:37:39 +0100
@@ -1975,9 +1994,12 @@ 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;
+	// mm->rss = 0;
+	vx_rsspages_sub(mm, mm->rss);
+	// mm->total_vm = 0;
+	vx_vmpages_sub(mm, mm->total_vm);
+	// mm->locked_vm = 0;
+	vx_vmlocked_sub(mm, mm->locked_vm);
 
 	spin_unlock(&mm->page_table_lock);
 
--- linux-2.6.11-rc1/mm/mremap.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/mremap.c	2005-01-15 11:27:52 +0100
@@ -246,10 +247,12 @@ static unsigned long move_vma(struct vm_
 			vma->vm_next->vm_flags |= VM_ACCOUNT;
 	}
 
-	mm->total_vm += new_len >> PAGE_SHIFT;
+	// 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;
+		// 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-rc1/mm/mremap.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/mremap.c	2005-01-15 11:27:52 +0100
@@ -358,11 +361,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-rc1/mm/mremap.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/mremap.c	2005-01-15 11:27:52 +0100
@@ -386,11 +396,13 @@ 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;
+			// 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;
+				// 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-rc1/mm/nommu.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/nommu.c	2005-01-15 15:36:28 +0100
@@ -686,7 +686,8 @@ unsigned long do_mmap_pgoff(struct file 
 	realalloc += kobjsize(vma);
 	askedalloc += sizeof(*vma);
 
-	current->mm->total_vm += len >> PAGE_SHIFT;
+	// current->mm->total_vm += len >> PAGE_SHIFT;
+	vx_vmpages_add(current->mm, len >> PAGE_SHIFT);
 
 	add_nommu_vma(vma);
  shared:
--- linux-2.6.11-rc1/mm/nommu.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/nommu.c	2005-01-15 15:36:28 +0100
@@ -805,7 +806,8 @@ int do_munmap(struct mm_struct *mm, unsi
 	realalloc -= kobjsize(vml);
 	askedalloc -= sizeof(*vml);
 	kfree(vml);
-	mm->total_vm -= len >> PAGE_SHIFT;
+	// mm->total_vm -= len >> PAGE_SHIFT;
+	vx_vmpages_sub(mm, len >> PAGE_SHIFT);
 
 #ifdef DEBUG
 	show_process_blocks();
--- linux-2.6.11-rc1/mm/nommu.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/nommu.c	2005-01-15 15:36:28 +0100
@@ -824,7 +826,8 @@ void exit_mmap(struct mm_struct * mm)
 		printk("Exit_mmap:\n");
 #endif
 
-		mm->total_vm = 0;
+		// 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-rc1/mm/oom_kill.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/oom_kill.c	2005-01-15 11:27:52 +0100
@@ -55,6 +55,7 @@ static unsigned long badness(struct task
 	 * The memory size of the process is the basis for the badness.
 	 */
 	points = p->mm->total_vm;
+	/* FIXME add vserver badness ;) */
 
 	/*
 	 * CPU time is in tens of seconds and run time is in thousands
--- linux-2.6.11-rc1/mm/rmap.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/rmap.c	2005-01-15 15:42:32 +0100
@@ -599,7 +600,8 @@ static int try_to_unmap_one(struct page 
 		mm->anon_rss--;
 	}
 
-	mm->rss--;
+	// mm->rss--;
+	vx_rsspages_dec(mm);
 	acct_update_integrals();
 	page_remove_rmap(page);
 	page_cache_release(page);
--- linux-2.6.11-rc1/mm/rmap.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/rmap.c	2005-01-15 15:42:32 +0100
@@ -706,7 +708,8 @@ static void try_to_unmap_cluster(unsigne
 		page_remove_rmap(page);
 		page_cache_release(page);
 		acct_update_integrals();
-		mm->rss--;
+		// mm->rss--;
+		vx_rsspages_dec(mm);
 		(*mapcount)--;
 	}
 
--- linux-2.6.11-rc1/mm/swapfile.c	2005-01-14 12:36:01 +0100
+++ linux-2.6.11-rc1-vs1.9.4-rc2/mm/swapfile.c	2005-01-15 11:27:52 +0100
@@ -432,7 +433,8 @@ 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++;
+	// 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);
