* [PATCH 0/4] Remove FGP_HEAD flag
@ 2022-10-19 18:33 Matthew Wilcox (Oracle)
2022-10-19 18:33 ` [PATCH 1/4] mm/huge_memory: Convert split_huge_pages_in_file() to use a folio Matthew Wilcox (Oracle)
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Matthew Wilcox (Oracle) @ 2022-10-19 18:33 UTC (permalink / raw)
To: Andrew Morton; +Cc: Matthew Wilcox (Oracle), linux-mm
We have just two users left of the FGP_HEAD flag and both of them are
better off; sometimes startlingly so as a result of conversion to use
folios. Tested with a few xfstests runs, which complete successfully
except for new failures induced by updated tooling.
Matthew Wilcox (Oracle) (4):
mm/huge_memory: Convert split_huge_pages_in_file() to use a folio
mm/swap: Convert find_get_incore_page to use folios
mm: Convert find_get_incore_page() to filemap_get_incore_folio()
mm: Remove FGP_HEAD
include/linux/pagemap.h | 5 ++---
mm/folio-compat.c | 2 +-
mm/huge_memory.c | 18 +++++++++---------
mm/memcontrol.c | 12 +++++++++---
mm/mincore.c | 10 +++++-----
mm/swap.h | 8 +++++---
mm/swap_state.c | 28 ++++++++++++++--------------
7 files changed, 45 insertions(+), 38 deletions(-)
--
2.35.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/4] mm/huge_memory: Convert split_huge_pages_in_file() to use a folio
2022-10-19 18:33 [PATCH 0/4] Remove FGP_HEAD flag Matthew Wilcox (Oracle)
@ 2022-10-19 18:33 ` Matthew Wilcox (Oracle)
2022-10-19 18:33 ` [PATCH 2/4] mm/swap: Convert find_get_incore_page to use folios Matthew Wilcox (Oracle)
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Matthew Wilcox (Oracle) @ 2022-10-19 18:33 UTC (permalink / raw)
To: Andrew Morton; +Cc: Matthew Wilcox (Oracle), linux-mm
Removes a number of calls to compound_head() and a call to
pagecache_get_page().
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
mm/huge_memory.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 1cc4a5f4791e..6d9ca4819d68 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -3057,28 +3057,28 @@ static int split_huge_pages_in_file(const char *file_path, pgoff_t off_start,
mapping = candidate->f_mapping;
for (index = off_start; index < off_end; index += nr_pages) {
- struct page *fpage = pagecache_get_page(mapping, index,
- FGP_ENTRY | FGP_HEAD, 0);
+ struct folio *folio = __filemap_get_folio(mapping, index,
+ FGP_ENTRY, 0);
nr_pages = 1;
- if (xa_is_value(fpage) || !fpage)
+ if (xa_is_value(folio) || !folio)
continue;
- if (!is_transparent_hugepage(fpage))
+ if (!folio_test_large(folio))
goto next;
total++;
- nr_pages = thp_nr_pages(fpage);
+ nr_pages = folio_nr_pages(folio);
- if (!trylock_page(fpage))
+ if (!folio_trylock(folio))
goto next;
- if (!split_huge_page(fpage))
+ if (!split_folio(folio))
split++;
- unlock_page(fpage);
+ folio_unlock(folio);
next:
- put_page(fpage);
+ folio_put(folio);
cond_resched();
}
--
2.35.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/4] mm/swap: Convert find_get_incore_page to use folios
2022-10-19 18:33 [PATCH 0/4] Remove FGP_HEAD flag Matthew Wilcox (Oracle)
2022-10-19 18:33 ` [PATCH 1/4] mm/huge_memory: Convert split_huge_pages_in_file() to use a folio Matthew Wilcox (Oracle)
@ 2022-10-19 18:33 ` Matthew Wilcox (Oracle)
2022-10-19 18:33 ` [PATCH 3/4] mm: Convert find_get_incore_page() to filemap_get_incore_folio() Matthew Wilcox (Oracle)
2022-10-19 18:33 ` [PATCH 4/4] mm: Remove FGP_HEAD Matthew Wilcox (Oracle)
3 siblings, 0 replies; 5+ messages in thread
From: Matthew Wilcox (Oracle) @ 2022-10-19 18:33 UTC (permalink / raw)
To: Andrew Morton; +Cc: Matthew Wilcox (Oracle), linux-mm
Eliminates a use of FGP_HEAD and saves 35 bytes of text.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
mm/swap_state.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/mm/swap_state.c b/mm/swap_state.c
index 438d0676c5be..44e3530520e8 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -386,17 +386,14 @@ struct page *find_get_incore_page(struct address_space *mapping, pgoff_t index)
{
swp_entry_t swp;
struct swap_info_struct *si;
- struct page *page = pagecache_get_page(mapping, index,
- FGP_ENTRY | FGP_HEAD, 0);
+ struct folio *folio = __filemap_get_folio(mapping, index, FGP_ENTRY, 0);
- if (!page)
- return page;
- if (!xa_is_value(page))
- return find_subpage(page, index);
+ if (!xa_is_value(folio))
+ goto out;
if (!shmem_mapping(mapping))
return NULL;
- swp = radix_to_swp_entry(page);
+ swp = radix_to_swp_entry(folio);
/* There might be swapin error entries in shmem mapping. */
if (non_swap_entry(swp))
return NULL;
@@ -404,9 +401,13 @@ struct page *find_get_incore_page(struct address_space *mapping, pgoff_t index)
si = get_swap_device(swp);
if (!si)
return NULL;
- page = find_get_page(swap_address_space(swp), swp_offset(swp));
+ index = swp_offset(swp);
+ folio = filemap_get_folio(swap_address_space(swp), index);
put_swap_device(si);
- return page;
+out:
+ if (!folio)
+ return NULL;
+ return folio_file_page(folio, index);
}
struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
--
2.35.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 3/4] mm: Convert find_get_incore_page() to filemap_get_incore_folio()
2022-10-19 18:33 [PATCH 0/4] Remove FGP_HEAD flag Matthew Wilcox (Oracle)
2022-10-19 18:33 ` [PATCH 1/4] mm/huge_memory: Convert split_huge_pages_in_file() to use a folio Matthew Wilcox (Oracle)
2022-10-19 18:33 ` [PATCH 2/4] mm/swap: Convert find_get_incore_page to use folios Matthew Wilcox (Oracle)
@ 2022-10-19 18:33 ` Matthew Wilcox (Oracle)
2022-10-19 18:33 ` [PATCH 4/4] mm: Remove FGP_HEAD Matthew Wilcox (Oracle)
3 siblings, 0 replies; 5+ messages in thread
From: Matthew Wilcox (Oracle) @ 2022-10-19 18:33 UTC (permalink / raw)
To: Andrew Morton; +Cc: Matthew Wilcox (Oracle), linux-mm
Return the containing folio instead of the precise page. One of the
callers wants the folio and the other can do the folio->page conversion
itself. Nets 442 bytes of text size reduction, 478 bytes removed
and 36 bytes added.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
mm/memcontrol.c | 12 +++++++++---
mm/mincore.c | 10 +++++-----
mm/swap.h | 8 +++++---
mm/swap_state.c | 15 +++++++--------
4 files changed, 26 insertions(+), 19 deletions(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 2d8549ae1b30..2e6e8bce1f60 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -5648,15 +5648,21 @@ static struct page *mc_handle_swap_pte(struct vm_area_struct *vma,
static struct page *mc_handle_file_pte(struct vm_area_struct *vma,
unsigned long addr, pte_t ptent)
{
+ unsigned long index;
+ struct folio *folio;
+
if (!vma->vm_file) /* anonymous vma */
return NULL;
if (!(mc.flags & MOVE_FILE))
return NULL;
- /* page is moved even if it's not RSS of this task(page-faulted). */
+ /* folio is moved even if it's not RSS of this task(page-faulted). */
/* shmem/tmpfs may report page out on swap: account for that too. */
- return find_get_incore_page(vma->vm_file->f_mapping,
- linear_page_index(vma, addr));
+ index = linear_page_index(vma, addr);
+ folio = filemap_get_incore_folio(vma->vm_file->f_mapping, index);
+ if (!folio)
+ return NULL;
+ return folio_file_page(folio, index);
}
/**
diff --git a/mm/mincore.c b/mm/mincore.c
index fa200c14185f..7bf2803e03c6 100644
--- a/mm/mincore.c
+++ b/mm/mincore.c
@@ -52,7 +52,7 @@ static int mincore_hugetlb(pte_t *pte, unsigned long hmask, unsigned long addr,
static unsigned char mincore_page(struct address_space *mapping, pgoff_t index)
{
unsigned char present = 0;
- struct page *page;
+ struct folio *folio;
/*
* When tmpfs swaps out a page from a file, any process mapping that
@@ -60,10 +60,10 @@ static unsigned char mincore_page(struct address_space *mapping, pgoff_t index)
* any other file mapping (ie. marked !present and faulted in with
* tmpfs's .fault). So swapped out tmpfs mappings are tested here.
*/
- page = find_get_incore_page(mapping, index);
- if (page) {
- present = PageUptodate(page);
- put_page(page);
+ folio = filemap_get_incore_folio(mapping, index);
+ if (folio) {
+ present = folio_test_uptodate(folio);
+ folio_put(folio);
}
return present;
diff --git a/mm/swap.h b/mm/swap.h
index cc08c459c619..f78065c8ef52 100644
--- a/mm/swap.h
+++ b/mm/swap.h
@@ -41,7 +41,8 @@ void clear_shadow_from_swap_cache(int type, unsigned long begin,
unsigned long end);
struct folio *swap_cache_get_folio(swp_entry_t entry,
struct vm_area_struct *vma, unsigned long addr);
-struct page *find_get_incore_page(struct address_space *mapping, pgoff_t index);
+struct folio *filemap_get_incore_folio(struct address_space *mapping,
+ pgoff_t index);
struct page *read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
struct vm_area_struct *vma,
@@ -105,9 +106,10 @@ static inline struct folio *swap_cache_get_folio(swp_entry_t entry,
}
static inline
-struct page *find_get_incore_page(struct address_space *mapping, pgoff_t index)
+struct folio *filemap_get_incore_folio(struct address_space *mapping,
+ pgoff_t index)
{
- return find_get_page(mapping, index);
+ return filemap_get_folio(mapping, index);
}
static inline bool add_to_swap(struct folio *folio)
diff --git a/mm/swap_state.c b/mm/swap_state.c
index 44e3530520e8..40fe6f23e105 100644
--- a/mm/swap_state.c
+++ b/mm/swap_state.c
@@ -373,16 +373,17 @@ struct folio *swap_cache_get_folio(swp_entry_t entry,
}
/**
- * find_get_incore_page - Find and get a page from the page or swap caches.
+ * filemap_get_incore_folio - Find and get a folio from the page or swap caches.
* @mapping: The address_space to search.
* @index: The page cache index.
*
- * This differs from find_get_page() in that it will also look for the
- * page in the swap cache.
+ * This differs from filemap_get_folio() in that it will also look for the
+ * folio in the swap cache.
*
- * Return: The found page or %NULL.
+ * Return: The found folio or %NULL.
*/
-struct page *find_get_incore_page(struct address_space *mapping, pgoff_t index)
+struct folio *filemap_get_incore_folio(struct address_space *mapping,
+ pgoff_t index)
{
swp_entry_t swp;
struct swap_info_struct *si;
@@ -405,9 +406,7 @@ struct page *find_get_incore_page(struct address_space *mapping, pgoff_t index)
folio = filemap_get_folio(swap_address_space(swp), index);
put_swap_device(si);
out:
- if (!folio)
- return NULL;
- return folio_file_page(folio, index);
+ return folio;
}
struct page *__read_swap_cache_async(swp_entry_t entry, gfp_t gfp_mask,
--
2.35.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 4/4] mm: Remove FGP_HEAD
2022-10-19 18:33 [PATCH 0/4] Remove FGP_HEAD flag Matthew Wilcox (Oracle)
` (2 preceding siblings ...)
2022-10-19 18:33 ` [PATCH 3/4] mm: Convert find_get_incore_page() to filemap_get_incore_folio() Matthew Wilcox (Oracle)
@ 2022-10-19 18:33 ` Matthew Wilcox (Oracle)
3 siblings, 0 replies; 5+ messages in thread
From: Matthew Wilcox (Oracle) @ 2022-10-19 18:33 UTC (permalink / raw)
To: Andrew Morton; +Cc: Matthew Wilcox (Oracle), linux-mm
This is no longer used; all callers have been converted to use folios
instead. Somehow this manages to save 11 bytes of text.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
include/linux/pagemap.h | 5 ++---
mm/folio-compat.c | 2 +-
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index bbccb4044222..f690c979913d 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -504,9 +504,8 @@ pgoff_t page_cache_prev_miss(struct address_space *mapping,
#define FGP_NOFS 0x00000010
#define FGP_NOWAIT 0x00000020
#define FGP_FOR_MMAP 0x00000040
-#define FGP_HEAD 0x00000080
-#define FGP_ENTRY 0x00000100
-#define FGP_STABLE 0x00000200
+#define FGP_ENTRY 0x00000080
+#define FGP_STABLE 0x00000100
struct folio *__filemap_get_folio(struct address_space *mapping, pgoff_t index,
int fgp_flags, gfp_t gfp);
diff --git a/mm/folio-compat.c b/mm/folio-compat.c
index e1e23b4947d7..4eab4e505e85 100644
--- a/mm/folio-compat.c
+++ b/mm/folio-compat.c
@@ -108,7 +108,7 @@ struct page *pagecache_get_page(struct address_space *mapping, pgoff_t index,
struct folio *folio;
folio = __filemap_get_folio(mapping, index, fgp_flags, gfp);
- if ((fgp_flags & FGP_HEAD) || !folio || xa_is_value(folio))
+ if (!folio || xa_is_value(folio))
return &folio->page;
return folio_file_page(folio, index);
}
--
2.35.1
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-10-19 18:33 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-19 18:33 [PATCH 0/4] Remove FGP_HEAD flag Matthew Wilcox (Oracle)
2022-10-19 18:33 ` [PATCH 1/4] mm/huge_memory: Convert split_huge_pages_in_file() to use a folio Matthew Wilcox (Oracle)
2022-10-19 18:33 ` [PATCH 2/4] mm/swap: Convert find_get_incore_page to use folios Matthew Wilcox (Oracle)
2022-10-19 18:33 ` [PATCH 3/4] mm: Convert find_get_incore_page() to filemap_get_incore_folio() Matthew Wilcox (Oracle)
2022-10-19 18:33 ` [PATCH 4/4] mm: Remove FGP_HEAD Matthew Wilcox (Oracle)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox