Message ID | 20240111111239.2453282-2-wangkefeng.wang@huawei.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | mm: convert mm counter to take a folio | expand |
On Thu, Jan 11, 2024 at 07:12:32PM +0800, Kefeng Wang wrote: > Introduce a new pfn_swap_entry_to_folio(), it is similar to > pfn_swap_entry_to_page(), but return a folio, which allow us > to completely replace the struct page variables with struct > folio variables. I have the exact same patch in my tree except I called it pfn_swap_entry_folio(). I also noted: Thanks to the compound_head() hidden inside PageLocked(), this saves a call to compound_head() over calling page_folio(pfn_swap_entry_to_page()) > Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
On Thu, Jan 11, 2024 at 02:37:41PM +0000, Matthew Wilcox wrote: > On Thu, Jan 11, 2024 at 07:12:32PM +0800, Kefeng Wang wrote: > > Introduce a new pfn_swap_entry_to_folio(), it is similar to > > pfn_swap_entry_to_page(), but return a folio, which allow us > > to completely replace the struct page variables with struct > > folio variables. > > I have the exact same patch in my tree except I called it > pfn_swap_entry_folio(). I also noted: > > Thanks to the compound_head() hidden inside PageLocked(), this saves a > call to compound_head() over calling page_folio(pfn_swap_entry_to_page()) > > > Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> > > Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org> Oh, and I converted a couple of callers ... migration_entry_wait_on_locked and change_huge_pmd. Those should probably be added to this patch.
On 2024/1/11 22:39, Matthew Wilcox wrote: > On Thu, Jan 11, 2024 at 02:37:41PM +0000, Matthew Wilcox wrote: >> On Thu, Jan 11, 2024 at 07:12:32PM +0800, Kefeng Wang wrote: >>> Introduce a new pfn_swap_entry_to_folio(), it is similar to >>> pfn_swap_entry_to_page(), but return a folio, which allow us >>> to completely replace the struct page variables with struct >>> folio variables. >> >> I have the exact same patch in my tree except I called it >> pfn_swap_entry_folio(). I also noted: >> >> Thanks to the compound_head() hidden inside PageLocked(), this saves a >> call to compound_head() over calling page_folio(pfn_swap_entry_to_page()) >> >>> Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> >> >> Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org> > > Oh, and I converted a couple of callers ... > migration_entry_wait_on_locked and change_huge_pmd. Those should > probably be added to this patch. > Thanks for your update, and all above conversion in your v3, and I check more callers, eg, hugetlb_change_protection,break_ksm_pmd_entry could be converted too, but we could send separate patch.
diff --git a/include/linux/swapops.h b/include/linux/swapops.h index bff1e8d97de0..85cb84e4be95 100644 --- a/include/linux/swapops.h +++ b/include/linux/swapops.h @@ -468,6 +468,19 @@ static inline struct page *pfn_swap_entry_to_page(swp_entry_t entry) return p; } +static inline struct folio *pfn_swap_entry_to_folio(swp_entry_t entry) +{ + struct folio *folio = pfn_folio(swp_offset_pfn(entry)); + + /* + * 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 are used to represent unaddressable device memory
Introduce a new pfn_swap_entry_to_folio(), it is similar to pfn_swap_entry_to_page(), but return a folio, which allow us to completely replace the struct page variables with struct folio variables. Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com> --- include/linux/swapops.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)