static inline swp_entry_t pte_to_swp_entry(pte_t pte) {

swp_entry_t arch_entry;

return swp_entry(_swp_type(arch_entry), _swp_offset(arch_entry));

Conversion is performed in two steps. Starting with a page table entry that — as explained in Chapter 4 — is represented by an instance of data type pte_t, the data it contains are converted to an architecture-dependent swap_entry_t.

Even if the same data type is used in the processor-specific representation and in the architecture-independent memory model, the way in which the bits are distributed generally differs in the two variants.

_pte_to_swp_entry is an architecture-dependent function that is defined in the CPU-specific include file

<asm-arch/pgtable.h>. It gives the kernel the opportunity to extract the processor-specific information in the page table. On many architectures, this can be achieved by means of a simple typecast that does not change the content of the page table entry — just for a change, even the Sparc processors, which are otherwise somewhat eccentric in this respect, do not call for anything special here.

In the second step, the information contained in the newly created swap_entry_t instance is converted to the architecture-independent format, where usually a number of bits are devoted to management tasks, for instance, to mark the identifier as swap entry in contrast to regular page table entries. The kernel is again reliant on the help of the processor-specific code. All systems must feature the_swp_type and

_swp_offset functions (note the leading underscores that are absent in the architecture-independent versions) that extract the type and offset from the machine-specific format and return the information in the general format, which is then put together by swp_entry to create a new swap_entry_t.

The number of bits used to address swap space locations in the architecture-independent format of a swap entry will in general be larger than in the architecture-specific format. Because architectures are not required to define the number of bits used for a swap offset in a constant visible to the public, the kernel needs to employ a little trick to find the maximally addressable swap offset:

maxpages = swp_offset(pte_to_swp_entry(swp_entry_to_pte(swp_entry(0,~0UL)))) - 1;

swp_entry(0, 0UL) specifies a swap offset with all bits set. The conversion to a page table entry and then back to an architecture-independent format guarantees that only valid bits survive. The largest addressable swap page number is obtained by picking the swap offset from the result.

Continue reading here: Mmswapstatec

Was this article helpful?

0 0