Skip to content

Commit f747059

Browse files
Matthew Wilcox (Oracle)akpm00
authored andcommitted
mm: convert page_to_pgoff() to page_pgoff()
Patch series "page->index removals in mm", v2. As part of shrinking struct page, we need to stop using page->index. This patchset gets rid of most of the remaining references to page->index in mm, as well as increasing the number of functions which take a const folio/page pointer. It shrinks the text segment of mm by a few hundred bytes in my test config, probably mostly from removing calls to compound_head() in page_to_pgoff(). This patch (of 7): Change the function signature to pass in the folio as all three callers have it. This removes a reference to page->index, which we're trying to get rid of. And add kernel-doc. Link: https://lkml.kernel.org/r/20241005200121.3231142-1-willy@infradead.org Link: https://lkml.kernel.org/r/20241005200121.3231142-2-willy@infradead.org Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent e664c2c commit f747059

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

include/linux/mm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1895,7 +1895,7 @@ static inline unsigned long page_to_section(const struct page *page)
18951895
*
18961896
* Return: The Page Frame Number of the first page in the folio.
18971897
*/
1898-
static inline unsigned long folio_pfn(struct folio *folio)
1898+
static inline unsigned long folio_pfn(const struct folio *folio)
18991899
{
19001900
return page_to_pfn(&folio->page);
19011901
}

include/linux/pagemap.h

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,22 +1011,25 @@ static inline struct folio *read_mapping_folio(struct address_space *mapping,
10111011
return read_cache_folio(mapping, index, NULL, file);
10121012
}
10131013

1014-
/*
1015-
* Get the offset in PAGE_SIZE (even for hugetlb pages).
1014+
/**
1015+
* page_pgoff - Calculate the logical page offset of this page.
1016+
* @folio: The folio containing this page.
1017+
* @page: The page which we need the offset of.
1018+
*
1019+
* For file pages, this is the offset from the beginning of the file
1020+
* in units of PAGE_SIZE. For anonymous pages, this is the offset from
1021+
* the beginning of the anon_vma in units of PAGE_SIZE. This will
1022+
* return nonsense for KSM pages.
1023+
*
1024+
* Context: Caller must have a reference on the folio or otherwise
1025+
* prevent it from being split or freed.
1026+
*
1027+
* Return: The offset in units of PAGE_SIZE.
10161028
*/
1017-
static inline pgoff_t page_to_pgoff(struct page *page)
1029+
static inline pgoff_t page_pgoff(const struct folio *folio,
1030+
const struct page *page)
10181031
{
1019-
struct page *head;
1020-
1021-
if (likely(!PageTransTail(page)))
1022-
return page->index;
1023-
1024-
head = compound_head(page);
1025-
/*
1026-
* We don't initialize ->index for tail pages: calculate based on
1027-
* head page
1028-
*/
1029-
return head->index + page - head;
1032+
return folio->index + folio_page_idx(folio, page);
10301033
}
10311034

10321035
/*

mm/memory-failure.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ static void collect_procs_anon(struct folio *folio, struct page *page,
617617
if (av == NULL) /* Not actually mapped anymore */
618618
return;
619619

620-
pgoff = page_to_pgoff(page);
620+
pgoff = page_pgoff(folio, page);
621621
rcu_read_lock();
622622
for_each_process(tsk) {
623623
struct vm_area_struct *vma;
@@ -653,7 +653,7 @@ static void collect_procs_file(struct folio *folio, struct page *page,
653653

654654
i_mmap_lock_read(mapping);
655655
rcu_read_lock();
656-
pgoff = page_to_pgoff(page);
656+
pgoff = page_pgoff(folio, page);
657657
for_each_process(tsk) {
658658
struct task_struct *t = task_early_kill(tsk, force_early);
659659
unsigned long addr;

mm/rmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,7 @@ static void __page_check_anon_rmap(struct folio *folio, struct page *page,
12761276
*/
12771277
VM_BUG_ON_FOLIO(folio_anon_vma(folio)->root != vma->anon_vma->root,
12781278
folio);
1279-
VM_BUG_ON_PAGE(page_to_pgoff(page) != linear_page_index(vma, address),
1279+
VM_BUG_ON_PAGE(page_pgoff(folio, page) != linear_page_index(vma, address),
12801280
page);
12811281
}
12821282

0 commit comments

Comments
 (0)