Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm, swap: Add infrastructure for saving page metadata on swap

If a processor supports special metadata for a page, for example ADI
version tags on SPARC M7, this metadata must be saved when the page is
swapped out. The same metadata must be restored when the page is swapped
back in. This patch adds two new architecture specific functions -
arch_do_swap_page() to be called when a page is swapped in, and
arch_unmap_one() to be called when a page is being unmapped for swap
out. These architecture hooks allow page metadata to be saved if the
architecture supports it.

Signed-off-by: Khalid Aziz <khalid.aziz@oracle.com>
Cc: Khalid Aziz <khalid@gonehiking.org>
Acked-by: Jerome Marchand <jmarchan@redhat.com>
Reviewed-by: Anthony Yznaga <anthony.yznaga@oracle.com>
Acked-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Khalid Aziz and committed by
David S. Miller
ca827d55 d84bb709

+51
+36
include/asm-generic/pgtable.h
··· 400 400 #endif /* CONFIG_TRANSPARENT_HUGEPAGE */ 401 401 #endif 402 402 403 + #ifndef __HAVE_ARCH_DO_SWAP_PAGE 404 + /* 405 + * Some architectures support metadata associated with a page. When a 406 + * page is being swapped out, this metadata must be saved so it can be 407 + * restored when the page is swapped back in. SPARC M7 and newer 408 + * processors support an ADI (Application Data Integrity) tag for the 409 + * page as metadata for the page. arch_do_swap_page() can restore this 410 + * metadata when a page is swapped back in. 411 + */ 412 + static inline void arch_do_swap_page(struct mm_struct *mm, 413 + struct vm_area_struct *vma, 414 + unsigned long addr, 415 + pte_t pte, pte_t oldpte) 416 + { 417 + 418 + } 419 + #endif 420 + 421 + #ifndef __HAVE_ARCH_UNMAP_ONE 422 + /* 423 + * Some architectures support metadata associated with a page. When a 424 + * page is being swapped out, this metadata must be saved so it can be 425 + * restored when the page is swapped back in. SPARC M7 and newer 426 + * processors support an ADI (Application Data Integrity) tag for the 427 + * page as metadata for the page. arch_unmap_one() can save this 428 + * metadata on a swap-out of a page. 429 + */ 430 + static inline int arch_unmap_one(struct mm_struct *mm, 431 + struct vm_area_struct *vma, 432 + unsigned long addr, 433 + pte_t orig_pte) 434 + { 435 + return 0; 436 + } 437 + #endif 438 + 403 439 #ifndef __HAVE_ARCH_PGD_OFFSET_GATE 404 440 #define pgd_offset_gate(mm, addr) pgd_offset(mm, addr) 405 441 #endif
+1
mm/memory.c
··· 3053 3053 if (pte_swp_soft_dirty(vmf->orig_pte)) 3054 3054 pte = pte_mksoft_dirty(pte); 3055 3055 set_pte_at(vma->vm_mm, vmf->address, vmf->pte, pte); 3056 + arch_do_swap_page(vma->vm_mm, vma, vmf->address, pte, vmf->orig_pte); 3056 3057 vmf->orig_pte = pte; 3057 3058 3058 3059 /* ksm created a completely new copy */
+14
mm/rmap.c
··· 1497 1497 (flags & (TTU_MIGRATION|TTU_SPLIT_FREEZE))) { 1498 1498 swp_entry_t entry; 1499 1499 pte_t swp_pte; 1500 + 1501 + if (arch_unmap_one(mm, vma, address, pteval) < 0) { 1502 + set_pte_at(mm, address, pvmw.pte, pteval); 1503 + ret = false; 1504 + page_vma_mapped_walk_done(&pvmw); 1505 + break; 1506 + } 1507 + 1500 1508 /* 1501 1509 * Store the pfn of the page in a special migration 1502 1510 * pte. do_swap_page() will wait until the migration ··· 1559 1551 } 1560 1552 1561 1553 if (swap_duplicate(entry) < 0) { 1554 + set_pte_at(mm, address, pvmw.pte, pteval); 1555 + ret = false; 1556 + page_vma_mapped_walk_done(&pvmw); 1557 + break; 1558 + } 1559 + if (arch_unmap_one(mm, vma, address, pteval) < 0) { 1562 1560 set_pte_at(mm, address, pvmw.pte, pteval); 1563 1561 ret = false; 1564 1562 page_vma_mapped_walk_done(&pvmw);