On Mon, Aug 01, 2022 at 11:13:58AM +0800, Huang, Ying wrote: > > +/* > > + * 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. > > + */ > > +static inline unsigned long swp_offset_pfn(swp_entry_t entry) > > +{ > > Is it good to call is_pfn_swap_entry() here for debug that can be > eliminated in the production kernel? Sure, I'll add a VM_BUG_ON() there in the next spin. > > > + return swp_offset(entry) & SWP_PFN_MASK; > > +} > > + > > /* check whether a pte points to a swap entry */ > > static inline int is_swap_pte(pte_t pte) > > { > > @@ -369,7 +387,7 @@ static inline int pte_none_mostly(pte_t pte) > > > > static inline struct page *pfn_swap_entry_to_page(swp_entry_t entry) > > { > > - struct page *p = pfn_to_page(swp_offset(entry)); > > + struct page *p = pfn_to_page(swp_offset_pfn(entry)); > > > > /* > > * Any use of migration entries may only occur while the > > @@ -387,6 +405,9 @@ static inline struct page *pfn_swap_entry_to_page(swp_entry_t entry) > > */ > > static inline bool 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); > > BUILD_BUG_ON(SWP_TYPE_SHIFT <= SWP_PFN_BITS); Logiclaly it's okay to have SWP_TYPE_SHIFT==SWP_PFN_BITS? Thanks, -- Peter Xu