From: Christoph Lameter Mark new anonymous pages mlocked if they are in a mlocked VMA. Avoid putting pages onto the LRU that are allocated in a VMA with VM_LOCKED set. NR_MLOCK will be more accurate. Signed-off-by: Christoph Lameter Signed-off-by: Andrew Morton --- mm/memory.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff -puN mm/memory.c~avoid-putting-new-mlocked-anonymous-pages-on-lru mm/memory.c --- a/mm/memory.c~avoid-putting-new-mlocked-anonymous-pages-on-lru +++ a/mm/memory.c @@ -906,7 +906,16 @@ static void add_anon_page(struct vm_area unsigned long address) { inc_mm_counter(vma->vm_mm, anon_rss); - lru_cache_add_active(page); + if (vma->vm_flags & VM_LOCKED) { + /* + * Page is new and therefore not on the LRU + * so we can directly mark it as mlocked + */ + SetPageMlocked(page); + ClearPageActive(page); + inc_zone_page_state(page, NR_MLOCK); + } else + lru_cache_add_active(page); page_add_new_anon_rmap(page, vma, address); } _