Commit 45961722f8e30ceab9d135b1ddc0947d53aef7c3

Authored by Konstantin Weitz
Committed by Martin Schwidefsky
1 parent 53e857f308

mm: add support for discard of unused ptes

In a virtualized environment and given an appropriate interface the guest
can mark pages as unused while they are free (for the s390 implementation
see git commit 45e576b1c3d00206 "guest page hinting light"). For the host
the unused state is a property of the pte.

This patch adds the primitive 'pte_unused' and code to the host swap out
handler so that pages marked as unused by all mappers are not swapped out
but discarded instead, thus saving one IO for swap out and potentially
another one for swap in.

[ Martin Schwidefsky: patch reordering and simplification ]

Signed-off-by: Konstantin Weitz <konstantin.weitz@gmail.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>

Showing 2 changed files with 23 additions and 0 deletions Side-by-side Diff

include/asm-generic/pgtable.h
... ... @@ -193,6 +193,19 @@
193 193 }
194 194 #endif
195 195  
  196 +#ifndef __HAVE_ARCH_PTE_UNUSED
  197 +/*
  198 + * Some architectures provide facilities to virtualization guests
  199 + * so that they can flag allocated pages as unused. This allows the
  200 + * host to transparently reclaim unused pages. This function returns
  201 + * whether the pte's page is unused.
  202 + */
  203 +static inline int pte_unused(pte_t pte)
  204 +{
  205 + return 0;
  206 +}
  207 +#endif
  208 +
196 209 #ifndef __HAVE_ARCH_PMD_SAME
197 210 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
198 211 static inline int pmd_same(pmd_t pmd_a, pmd_t pmd_b)
... ... @@ -1165,6 +1165,16 @@
1165 1165 }
1166 1166 set_pte_at(mm, address, pte,
1167 1167 swp_entry_to_pte(make_hwpoison_entry(page)));
  1168 + } else if (pte_unused(pteval)) {
  1169 + /*
  1170 + * The guest indicated that the page content is of no
  1171 + * interest anymore. Simply discard the pte, vmscan
  1172 + * will take care of the rest.
  1173 + */
  1174 + if (PageAnon(page))
  1175 + dec_mm_counter(mm, MM_ANONPAGES);
  1176 + else
  1177 + dec_mm_counter(mm, MM_FILEPAGES);
1168 1178 } else if (PageAnon(page)) {
1169 1179 swp_entry_t entry = { .val = page_private(page) };
1170 1180 pte_t swp_pte;