Skip to content

Commit 4596172

Browse files
konne88Martin Schwidefsky
authored andcommitted
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 45e576b "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>
1 parent 53e857f commit 4596172

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

‎include/asm-generic/pgtable.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,19 @@ static inline int pte_same(pte_t pte_a, pte_t pte_b)
193193
}
194194
#endif
195195

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+
196209
#ifndef __HAVE_ARCH_PMD_SAME
197210
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
198211
static inline int pmd_same(pmd_t pmd_a, pmd_t pmd_b)

‎mm/rmap.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,16 @@ int try_to_unmap_one(struct page *page, struct vm_area_struct *vma,
11651165
}
11661166
set_pte_at(mm, address, pte,
11671167
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);
11681178
} else if (PageAnon(page)) {
11691179
swp_entry_t entry = { .val = page_private(page) };
11701180
pte_t swp_pte;

0 commit comments

Comments
 (0)