Index: linux-2.6.16-mm2/mm/mmap.c =================================================================== --- linux-2.6.16-mm2.orig/mm/mmap.c 2006-03-29 19:20:13.000000000 -0800 +++ linux-2.6.16-mm2/mm/mmap.c 2006-03-29 19:20:28.000000000 -0800 @@ -930,6 +930,11 @@ unsigned long do_mmap_pgoff(struct file return -EPERM; vm_flags |= VM_LOCKED; } + if (flags & MAP_DONTMOVE) { + if (!can_do_mlock()) + return -EPERM; + vm_flags |= VM_DONTMOVE | VM_LOCKED; + } /* mlock MCL_FUTURE? */ if (vm_flags & VM_LOCKED) { unsigned long locked, lock_limit; Index: linux-2.6.16-mm2/include/linux/mm.h =================================================================== --- linux-2.6.16-mm2.orig/include/linux/mm.h 2006-03-29 19:20:07.000000000 -0800 +++ linux-2.6.16-mm2/include/linux/mm.h 2006-03-29 19:20:28.000000000 -0800 @@ -167,6 +167,8 @@ extern unsigned int kobjsize(const void #define VM_MAPPED_COPY 0x01000000 /* T if mapped copy of data (nommu mmap) */ #define VM_INSERTPAGE 0x02000000 /* The vma has had "vm_insert_page()" done on it */ +#define VM_DONTMOVE 0x04000000 /* Do not move pages in this vma */ + #ifndef VM_STACK_DEFAULT_FLAGS /* arch can override this */ #define VM_STACK_DEFAULT_FLAGS VM_DATA_DEFAULT_FLAGS #endif Index: linux-2.6.16-mm2/include/asm-generic/mman.h =================================================================== --- linux-2.6.16-mm2.orig/include/asm-generic/mman.h 2006-03-19 21:53:29.000000000 -0800 +++ linux-2.6.16-mm2/include/asm-generic/mman.h 2006-03-29 19:20:28.000000000 -0800 @@ -19,6 +19,7 @@ #define MAP_TYPE 0x0f /* Mask for type of mapping */ #define MAP_FIXED 0x10 /* Interpret addr exactly */ #define MAP_ANONYMOUS 0x20 /* don't use a file */ +#define MAP_DONTMOVE 0x40 /* do not move any pages in there */ #define MS_ASYNC 1 /* sync memory asynchronously */ #define MS_INVALIDATE 2 /* invalidate the caches */ Index: linux-2.6.16-mm2/mm/rmap.c =================================================================== --- linux-2.6.16-mm2.orig/mm/rmap.c 2006-03-29 19:20:13.000000000 -0800 +++ linux-2.6.16-mm2/mm/rmap.c 2006-03-29 19:20:28.000000000 -0800 @@ -600,7 +600,7 @@ static int try_to_unmap_one(struct page * If it's recently referenced (perhaps page_referenced * skipped over this mm) then we should reactivate it. */ - if ((vma->vm_flags & VM_LOCKED) || + if ((vma->vm_flags & (VM_LOCKED|VM_DONTMOVE)) || (ptep_clear_flush_young(vma, address, pte) && !ignore_refs)) { ret = SWAP_FAIL; @@ -788,7 +788,7 @@ static int try_to_unmap_file(struct page list_for_each_entry(vma, &mapping->i_mmap_nonlinear, shared.vm_set.list) { - if (vma->vm_flags & VM_LOCKED) + if (vma->vm_flags & (VM_LOCKED|VM_DONTMOVE)) continue; cursor = (unsigned long) vma->vm_private_data; if (cursor > max_nl_cursor) @@ -822,7 +822,7 @@ static int try_to_unmap_file(struct page do { list_for_each_entry(vma, &mapping->i_mmap_nonlinear, shared.vm_set.list) { - if (vma->vm_flags & VM_LOCKED) + if (vma->vm_flags & (VM_LOCKED|VM_DONTMOVE)) continue; cursor = (unsigned long) vma->vm_private_data; while ( cursor < max_nl_cursor &&