/* * swapcache pages are stored in the swapper_space radix tree. We want to * get good packing density in that tree, so the index should be dense in * the low-order bits. * * We arrange the `type' and `offset' fields so that `type' is at the six * high-order bits of the swp_entry_t and `offset' is right-aligned in the * remaining bits. Although `type' itself needs only five bits, we allow for * shmem/tmpfs to shift it all up a further one bit: see swp_to_radix_entry(). * * swp_entry_t's are *never* stored anywhere in their arch-dependent format.
*/ #define SWP_TYPE_SHIFT (BITS_PER_XA_VALUE - MAX_SWAPFILES_SHIFT) #define SWP_OFFSET_MASK ((1UL << SWP_TYPE_SHIFT) - 1)
/* * Definitions only for PFN swap entries (see is_pfn_swap_entry()). To * store PFN, we only need SWP_PFN_BITS bits. Each of the pfn swap entries * can use the extra bits to store other information besides PFN.
*/ #ifdef MAX_PHYSMEM_BITS #define SWP_PFN_BITS (MAX_PHYSMEM_BITS - PAGE_SHIFT) #else/* MAX_PHYSMEM_BITS */ #define SWP_PFN_BITS min_t(int, \ sizeof(phys_addr_t) * 8 - PAGE_SHIFT, \
SWP_TYPE_SHIFT) #endif/* MAX_PHYSMEM_BITS */ #define SWP_PFN_MASK (BIT(SWP_PFN_BITS) - 1)
/** * Migration swap entry specific bitfield definitions. Layout: * * |----------+--------------------| * | swp_type | swp_offset | * |----------+--------+-+-+-------| * | | resv |D|A| PFN | * |----------+--------+-+-+-------| * * @SWP_MIG_YOUNG_BIT: Whether the page used to have young bit set (bit A) * @SWP_MIG_DIRTY_BIT: Whether the page used to have dirty bit set (bit D) * * Note: A/D bits will be stored in migration entries iff there're enough * free bits in arch specific swp offset. By default we'll ignore A/D bits * when migrating a page. Please refer to migration_entry_supports_ad() * for more information. If there're more bits besides PFN and A/D bits, * they should be reserved and always be zeros.
*/ #define SWP_MIG_YOUNG_BIT (SWP_PFN_BITS) #define SWP_MIG_DIRTY_BIT (SWP_PFN_BITS + 1) #define SWP_MIG_TOTAL_BITS (SWP_PFN_BITS + 2)
/* Clear all flags but only keep swp_entry_t related information */ staticinline pte_t pte_swp_clear_flags(pte_t pte)
{ if (pte_swp_exclusive(pte))
pte = pte_swp_clear_exclusive(pte); if (pte_swp_soft_dirty(pte))
pte = pte_swp_clear_soft_dirty(pte); if (pte_swp_uffd_wp(pte))
pte = pte_swp_clear_uffd_wp(pte); return pte;
}
/* * Store a type+offset into a swp_entry_t in an arch-independent format
*/ staticinline swp_entry_t swp_entry(unsignedlong type, pgoff_t offset)
{
swp_entry_t ret;
/* * Extract the `type' field from a swp_entry_t. The swp_entry_t is in * arch-independent format
*/ staticinlineunsigned swp_type(swp_entry_t entry)
{ return (entry.val >> SWP_TYPE_SHIFT);
}
/* * Extract the `offset' field from a swp_entry_t. The swp_entry_t is in * arch-independent format
*/ staticinline pgoff_t swp_offset(swp_entry_t entry)
{ return entry.val & SWP_OFFSET_MASK;
}
/* * This should only be called upon a pfn swap entry to get the PFN stored * in the swap entry. Please refers to is_pfn_swap_entry() for definition * of pfn swap entry.
*/ staticinlineunsignedlong swp_offset_pfn(swp_entry_t entry)
{
VM_BUG_ON(!is_pfn_swap_entry(entry)); return swp_offset(entry) & SWP_PFN_MASK;
}
/* check whether a pte points to a swap entry */ staticinlineint is_swap_pte(pte_t pte)
{ return !pte_none(pte) && !pte_present(pte);
}
/* * Convert the arch-dependent pte representation of a swp_entry_t into an * arch-independent swp_entry_t.
*/ staticinline swp_entry_t pte_to_swp_entry(pte_t pte)
{
swp_entry_t arch_entry;
/* * Convert the arch-independent representation of a swp_entry_t into the * arch-dependent pte representation.
*/ staticinline pte_t swp_entry_to_pte(swp_entry_t entry)
{
swp_entry_t arch_entry;
staticinlinebool is_device_private_entry(swp_entry_t entry)
{ int type = swp_type(entry); return type == SWP_DEVICE_READ || type == SWP_DEVICE_WRITE;
}
/* * Returns whether the host has large enough swap offset field to support * carrying over pgtable A/D bits for page migrations. The result is * pretty much arch specific.
*/ staticinlinebool migration_entry_supports_ad(void)
{ #ifdef CONFIG_SWAP return swap_migration_ad_supported; #else/* CONFIG_SWAP */ returnfalse; #endif/* CONFIG_SWAP */
}
staticinlinebool is_migration_entry_young(swp_entry_t entry)
{ if (migration_entry_supports_ad()) return swp_offset(entry) & SWP_MIG_YOUNG; /* Keep the old behavior of aging page after migration */ returnfalse;
}
staticinlinebool is_migration_entry_dirty(swp_entry_t entry)
{ if (migration_entry_supports_ad()) return swp_offset(entry) & SWP_MIG_DIRTY; /* Keep the old behavior of clean page after migration */ returnfalse;
}
#define PTE_MARKER_UFFD_WP BIT(0) /* * "Poisoned" here is meant in the very general sense of "future accesses are * invalid", instead of referring very specifically to hardware memory errors. * This marker is meant to represent any of various different causes of this. * * Note that, when encountered by the faulting logic, PTEs with this marker will * result in VM_FAULT_HWPOISON and thus regardless trigger hardware memory error * logic.
*/ #define PTE_MARKER_POISONED BIT(1) /* * Indicates that, on fault, this PTE will case a SIGSEGV signal to be * sent. This means guard markers behave in effect as if the region were mapped * PROT_NONE, rather than if they were a memory hole or equivalent.
*/ #define PTE_MARKER_GUARD BIT(2) #define PTE_MARKER_MASK (BIT(3) - 1)
/* * This is a special version to check pte_none() just to cover the case when * the pte is a pte marker. It existed because in many cases the pte marker * should be seen as a none pte; it's just that we have stored some information * onto the none pte so it becomes not-none any more. * * It should be used when the pte is file-backed, ram-based and backing * userspace pages, like shmem. It is not needed upon pgtables that do not * support pte markers at all. For example, it's not needed on anonymous * memory, kernel-only memory (including when the system is during-boot), * non-ram based generic file-system. It's fine to be used even there, but the * extra pte marker check will be pure overhead.
*/ staticinlineint pte_none_mostly(pte_t pte)
{ return pte_none(pte) || is_pte_marker(pte);
}
/* * Any use of migration entries may only occur while the * corresponding folio is locked
*/
BUG_ON(is_migration_entry(entry) && !folio_test_locked(folio));
return folio;
}
/* * A pfn swap entry is a special type of swap entry that always has a pfn stored * in the swap offset. They can either be used to represent unaddressable device * memory, to restrict access to a page undergoing migration or to represent a * pfn which has been hwpoisoned and unmapped.
*/ staticinlinebool is_pfn_swap_entry(swp_entry_t entry)
{ /* Make sure the swp offset can always store the needed fields */
BUILD_BUG_ON(SWP_TYPE_SHIFT < SWP_PFN_BITS);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.