#include <linux/swapops.h>
#include <linux/slab.h>
#include <linux/init.h>
-#include <linux/acct.h>
#include <linux/rmap.h>
#include <linux/rcupdate.h>
#include <linux/vs_memory.h>
return vma_address(page, vma);
}
+/*
+ * Check that @page is mapped at @address into @mm.
+ *
+ * On success returns with mapped pte and locked mm->page_table_lock.
+ */
+static pte_t *page_check_address(struct page *page, struct mm_struct *mm,
+ unsigned long address)
+{
+ pgd_t *pgd;
+ pud_t *pud;
+ pmd_t *pmd;
+ pte_t *pte;
+
+ /*
+ * We need the page_table_lock to protect us from page faults,
+ * munmap, fork, etc...
+ */
+ spin_lock(&mm->page_table_lock);
+ pgd = pgd_offset(mm, address);
+ if (likely(pgd_present(*pgd))) {
+ pud = pud_offset(pgd, address);
+ if (likely(pud_present(*pud))) {
+ pmd = pmd_offset(pud, address);
+ if (likely(pmd_present(*pmd))) {
+ pte = pte_offset_map(pmd, address);
+ if (likely(pte_present(*pte) &&
+ page_to_pfn(page) == pte_pfn(*pte)))
+ return pte;
+ pte_unmap(pte);
+ }
+ }
+ }
+ spin_unlock(&mm->page_table_lock);
+ return ERR_PTR(-ENOENT);
+}
+
/*
* Subfunctions of page_referenced: page_referenced_one called
* repeatedly from either page_referenced_anon or page_referenced_file.
{
struct mm_struct *mm = vma->vm_mm;
unsigned long address;
- pgd_t *pgd;
- pud_t *pud;
- pmd_t *pmd;
pte_t *pte;
int referenced = 0;
- if (!mm->rss)
+ if (!get_mm_counter(mm, rss))
goto out;
address = vma_address(page, vma);
if (address == -EFAULT)
goto out;
- spin_lock(&mm->page_table_lock);
-
- pgd = pgd_offset(mm, address);
- if (!pgd_present(*pgd))
- goto out_unlock;
-
- pud = pud_offset(pgd, address);
- if (!pud_present(*pud))
- goto out_unlock;
-
- pmd = pmd_offset(pud, address);
- if (!pmd_present(*pmd))
- goto out_unlock;
-
- pte = pte_offset_map(pmd, address);
- if (!pte_present(*pte))
- goto out_unmap;
-
- if (page_to_pfn(page) != pte_pfn(*pte))
- goto out_unmap;
-
- if (ptep_clear_flush_young(vma, address, pte))
- referenced++;
-
- if (mm != current->mm && !ignore_token && has_swap_token(mm))
- referenced++;
+ pte = page_check_address(page, mm, address);
+ if (!IS_ERR(pte)) {
+ if (ptep_clear_flush_young(vma, address, pte))
+ referenced++;
- (*mapcount)--;
+ if (mm != current->mm && !ignore_token && has_swap_token(mm))
+ referenced++;
-out_unmap:
- pte_unmap(pte);
-out_unlock:
- spin_unlock(&mm->page_table_lock);
+ (*mapcount)--;
+ pte_unmap(pte);
+ spin_unlock(&mm->page_table_lock);
+ }
out:
return referenced;
}
BUG_ON(PageReserved(page));
BUG_ON(!anon_vma);
- vx_anonpages_inc(vma->vm_mm);
+ inc_mm_counter(vma->vm_mm, anon_rss);
anon_vma = (void *) anon_vma + PAGE_MAPPING_ANON;
index = (address - vma->vm_start) >> PAGE_SHIFT;
{
struct mm_struct *mm = vma->vm_mm;
unsigned long address;
- pgd_t *pgd;
- pud_t *pud;
- pmd_t *pmd;
pte_t *pte;
pte_t pteval;
int ret = SWAP_AGAIN;
- if (!mm->rss)
+ if (!get_mm_counter(mm, rss))
goto out;
address = vma_address(page, vma);
if (address == -EFAULT)
goto out;
- /*
- * We need the page_table_lock to protect us from page faults,
- * munmap, fork, etc...
- */
- spin_lock(&mm->page_table_lock);
-
- pgd = pgd_offset(mm, address);
- if (!pgd_present(*pgd))
- goto out_unlock;
-
- pud = pud_offset(pgd, address);
- if (!pud_present(*pud))
- goto out_unlock;
-
- pmd = pmd_offset(pud, address);
- if (!pmd_present(*pmd))
- goto out_unlock;
-
- pte = pte_offset_map(pmd, address);
- if (!pte_present(*pte))
- goto out_unmap;
-
- if (page_to_pfn(page) != pte_pfn(*pte))
- goto out_unmap;
+ pte = page_check_address(page, mm, address);
+ if (IS_ERR(pte))
+ goto out;
/*
* If the page is mlock()d, we cannot swap it out.
}
/* Nuke the page table entry. */
- flush_cache_page(vma, address);
+ flush_cache_page(vma, address, page_to_pfn(page));
pteval = ptep_clear_flush(vma, address, pte);
/* Move the dirty bit to the physical page now the pte is gone. */
list_add(&mm->mmlist, &init_mm.mmlist);
spin_unlock(&mmlist_lock);
}
- set_pte(pte, swp_entry_to_pte(entry));
+ set_pte_at(mm, address, pte, swp_entry_to_pte(entry));
BUG_ON(pte_file(*pte));
- vx_anonpages_dec(mm);
+ dec_mm_counter(mm, anon_rss);
}
- vx_rsspages_dec(mm);
- acct_update_integrals();
+ dec_mm_counter(mm, rss);
page_remove_rmap(page);
page_cache_release(page);
out_unmap:
pte_unmap(pte);
-out_unlock:
spin_unlock(&mm->page_table_lock);
out:
return ret;
pgd_t *pgd;
pud_t *pud;
pmd_t *pmd;
- pte_t *pte;
+ pte_t *pte, *original_pte;
pte_t pteval;
struct page *page;
unsigned long address;
if (!pmd_present(*pmd))
goto out_unlock;
- for (pte = pte_offset_map(pmd, address);
+ for (original_pte = pte = pte_offset_map(pmd, address);
address < end; pte++, address += PAGE_SIZE) {
if (!pte_present(*pte))
continue;
/* Nuke the page table entry. */
- flush_cache_page(vma, address);
+ flush_cache_page(vma, address, pfn);
pteval = ptep_clear_flush(vma, address, pte);
/* If nonlinear, store the file page offset in the pte. */
if (page->index != linear_page_index(vma, address))
- set_pte(pte, pgoff_to_pte(page->index));
+ set_pte_at(mm, address, pte, pgoff_to_pte(page->index));
/* Move the dirty bit to the physical page now the pte is gone. */
if (pte_dirty(pteval))
page_remove_rmap(page);
page_cache_release(page);
- acct_update_integrals();
- vx_rsspages_dec(mm);
+ dec_mm_counter(mm, rss);
(*mapcount)--;
}
- pte_unmap(pte);
-
+ pte_unmap(original_pte);
out_unlock:
spin_unlock(&mm->page_table_lock);
}
if (vma->vm_flags & (VM_LOCKED|VM_RESERVED))
continue;
cursor = (unsigned long) vma->vm_private_data;
- while (vma->vm_mm->rss &&
+ while (get_mm_counter(vma->vm_mm, rss) &&
cursor < max_nl_cursor &&
cursor < vma->vm_end - vma->vm_start) {
try_to_unmap_cluster(cursor, &mapcount, vma);
ret = SWAP_SUCCESS;
return ret;
}
+