From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>, linux-mm@kvack.org
Subject: [PATCH v2 21/57] shmem: Convert shmem_getpage_gfp() to shmem_get_folio_gfp()
Date: Fri, 2 Sep 2022 20:46:17 +0100 [thread overview]
Message-ID: <20220902194653.1739778-22-willy@infradead.org> (raw)
In-Reply-To: <20220902194653.1739778-1-willy@infradead.org>
Add a shmem_getpage_gfp() wrapper for compatibility with current users.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
mm/shmem.c | 70 ++++++++++++++++++++++++++++++++----------------------
1 file changed, 41 insertions(+), 29 deletions(-)
diff --git a/mm/shmem.c b/mm/shmem.c
index b685acd9f149..89536091928f 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -139,17 +139,6 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,
struct folio **foliop, enum sgp_type sgp,
gfp_t gfp, struct vm_area_struct *vma,
vm_fault_t *fault_type);
-static int shmem_getpage_gfp(struct inode *inode, pgoff_t index,
- struct page **pagep, enum sgp_type sgp,
- gfp_t gfp, struct vm_area_struct *vma,
- struct vm_fault *vmf, vm_fault_t *fault_type);
-
-int shmem_getpage(struct inode *inode, pgoff_t index,
- struct page **pagep, enum sgp_type sgp)
-{
- return shmem_getpage_gfp(inode, index, pagep, sgp,
- mapping_gfp_mask(inode->i_mapping), NULL, NULL, NULL);
-}
static inline struct shmem_sb_info *SHMEM_SB(struct super_block *sb)
{
@@ -1595,7 +1584,7 @@ static struct folio *shmem_alloc_and_acct_folio(gfp_t gfp, struct inode *inode,
/*
* When a page is moved from swapcache to shmem filecache (either by the
- * usual swapin of shmem_getpage_gfp(), or by the less common swapoff of
+ * usual swapin of shmem_get_folio_gfp(), or by the less common swapoff of
* shmem_unuse_inode()), it may have been read in earlier from swap, in
* ignorance of the mapping it belongs to. If that mapping has special
* constraints (like the gma500 GEM driver, which requires RAM below 4GB),
@@ -1812,7 +1801,7 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,
}
/*
- * shmem_getpage_gfp - find page in cache, or get from swap, or allocate
+ * shmem_get_folio_gfp - find page in cache, or get from swap, or allocate
*
* If we allocate a new one we do not mark it dirty. That's up to the
* vm. If we swap it in we mark it dirty since we also free the swap
@@ -1821,10 +1810,10 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index,
* vma, vmf, and fault_type are only supplied by shmem_fault:
* otherwise they are NULL.
*/
-static int shmem_getpage_gfp(struct inode *inode, pgoff_t index,
- struct page **pagep, enum sgp_type sgp, gfp_t gfp,
- struct vm_area_struct *vma, struct vm_fault *vmf,
- vm_fault_t *fault_type)
+static int shmem_get_folio_gfp(struct inode *inode, pgoff_t index,
+ struct folio **foliop, enum sgp_type sgp, gfp_t gfp,
+ struct vm_area_struct *vma, struct vm_fault *vmf,
+ vm_fault_t *fault_type)
{
struct address_space *mapping = inode->i_mapping;
struct shmem_inode_info *info = SHMEM_I(inode);
@@ -1864,7 +1853,7 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index,
if (error == -EEXIST)
goto repeat;
- *pagep = &folio->page;
+ *foliop = folio;
return error;
}
@@ -1874,7 +1863,7 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index,
folio_mark_accessed(folio);
if (folio_test_uptodate(folio))
goto out;
- /* fallocated page */
+ /* fallocated folio */
if (sgp != SGP_READ)
goto clear;
folio_unlock(folio);
@@ -1882,10 +1871,10 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index,
}
/*
- * SGP_READ: succeed on hole, with NULL page, letting caller zero.
- * SGP_NOALLOC: fail on hole, with NULL page, letting caller fail.
+ * SGP_READ: succeed on hole, with NULL folio, letting caller zero.
+ * SGP_NOALLOC: fail on hole, with NULL folio, letting caller fail.
*/
- *pagep = NULL;
+ *foliop = NULL;
if (sgp == SGP_READ)
return 0;
if (sgp == SGP_NOALLOC)
@@ -1918,7 +1907,7 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index,
if (error != -ENOSPC)
goto unlock;
/*
- * Try to reclaim some space by splitting a huge page
+ * Try to reclaim some space by splitting a large folio
* beyond i_size on the filesystem.
*/
while (retry--) {
@@ -1954,9 +1943,9 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index,
if (folio_test_pmd_mappable(folio) &&
DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE) <
- hindex + HPAGE_PMD_NR - 1) {
+ folio_next_index(folio) - 1) {
/*
- * Part of the huge page is beyond i_size: subject
+ * Part of the large folio is beyond i_size: subject
* to shrink under memory pressure.
*/
spin_lock(&sbinfo->shrinklist_lock);
@@ -1973,14 +1962,14 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index,
}
/*
- * Let SGP_FALLOC use the SGP_WRITE optimization on a new page.
+ * Let SGP_FALLOC use the SGP_WRITE optimization on a new folio.
*/
if (sgp == SGP_FALLOC)
sgp = SGP_WRITE;
clear:
/*
- * Let SGP_WRITE caller clear ends if write does not fill page;
- * but SGP_FALLOC on a page fallocated earlier must initialize
+ * Let SGP_WRITE caller clear ends if write does not fill folio;
+ * but SGP_FALLOC on a folio fallocated earlier must initialize
* it now, lest undo on failure cancel our earlier guarantee.
*/
if (sgp != SGP_WRITE && !folio_test_uptodate(folio)) {
@@ -2006,7 +1995,7 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index,
goto unlock;
}
out:
- *pagep = folio_page(folio, index - hindex);
+ *foliop = folio;
return 0;
/*
@@ -2036,6 +2025,29 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index,
return error;
}
+static int shmem_getpage_gfp(struct inode *inode, pgoff_t index,
+ struct page **pagep, enum sgp_type sgp,
+ gfp_t gfp, struct vm_area_struct *vma,
+ struct vm_fault *vmf, vm_fault_t *fault_type)
+{
+ struct folio *folio = NULL;
+ int ret = shmem_get_folio_gfp(inode, index, &folio, sgp, gfp, vma,
+ vmf, fault_type);
+
+ if (folio)
+ *pagep = folio_file_page(folio, index);
+ else
+ *pagep = NULL;
+ return ret;
+}
+
+int shmem_getpage(struct inode *inode, pgoff_t index,
+ struct page **pagep, enum sgp_type sgp)
+{
+ return shmem_getpage_gfp(inode, index, pagep, sgp,
+ mapping_gfp_mask(inode->i_mapping), NULL, NULL, NULL);
+}
+
/*
* This is like autoremove_wake_function, but it removes the wait queue
* entry unconditionally - even if something else had already woken the
--
2.35.1
next prev parent reply other threads:[~2022-09-02 19:47 UTC|newest]
Thread overview: 61+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-02 19:45 [PATCH v2 00/57] MM folio changes for 6.1 Matthew Wilcox (Oracle)
2022-09-02 19:45 ` [PATCH v2 01/57] mm/vmscan: Fix a lot of comments Matthew Wilcox (Oracle)
2022-09-02 23:28 ` Andrew Morton
2022-09-02 19:45 ` [PATCH v2 02/57] mm: Add the first tail page to struct folio Matthew Wilcox (Oracle)
2022-09-02 23:28 ` Andrew Morton
2022-09-04 0:44 ` Matthew Wilcox
2022-09-02 19:45 ` [PATCH v2 03/57] mm: Reimplement folio_order() and folio_nr_pages() Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 04/57] mm: Add split_folio() Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 05/57] mm: Add folio_add_lru_vma() Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 06/57] shmem: Convert shmem_writepage() to use a folio throughout Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 07/57] shmem: Convert shmem_delete_from_page_cache() to take a folio Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 08/57] shmem: Convert shmem_replace_page() to use folios throughout Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 09/57] mm/swapfile: Remove page_swapcount() Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 10/57] mm/swapfile: Convert try_to_free_swap() to folio_free_swap() Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 11/57] mm/swap: Convert __read_swap_cache_async() to use a folio Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 12/57] mm/swap: Convert add_to_swap_cache() to take " Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 13/57] mm/swap: Convert put_swap_page() to put_swap_folio() Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 14/57] mm: Convert do_swap_page() to use a folio Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 15/57] mm: Convert do_swap_page()'s swapcache variable to " Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 16/57] memcg: Convert mem_cgroup_swapin_charge_page() to mem_cgroup_swapin_charge_folio() Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 17/57] shmem: Convert shmem_mfill_atomic_pte() to use a folio Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 18/57] shmem: Convert shmem_replace_page() to shmem_replace_folio() Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 19/57] swap: Add swap_cache_get_folio() Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 20/57] shmem: Eliminate struct page from shmem_swapin_folio() Matthew Wilcox (Oracle)
2022-09-02 19:46 ` Matthew Wilcox (Oracle) [this message]
2022-09-02 19:46 ` [PATCH v2 22/57] shmem: Convert shmem_fault() to use shmem_get_folio_gfp() Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 23/57] shmem: Convert shmem_read_mapping_page_gfp() " Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 24/57] shmem: Add shmem_get_folio() Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 25/57] shmem: Convert shmem_get_partial_folio() to use shmem_get_folio() Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 26/57] shmem: Convert shmem_write_begin() " Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 27/57] shmem: Convert shmem_file_read_iter() " Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 28/57] shmem: Convert shmem_fallocate() to use a folio Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 29/57] shmem: Convert shmem_symlink() " Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 30/57] shmem: Convert shmem_get_link() " Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 31/57] khugepaged: Call shmem_get_folio() Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 32/57] userfaultfd: Convert mcontinue_atomic_pte() to use a folio Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 33/57] shmem: Remove shmem_getpage() Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 34/57] swapfile: Convert try_to_unuse() to use a folio Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 35/57] swapfile: Convert __try_to_reclaim_swap() " Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 36/57] swapfile: Convert unuse_pte_range() " Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 37/57] mm: Convert do_swap_page() to use swap_cache_get_folio() Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 38/57] mm: Remove lookup_swap_cache() Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 39/57] swap_state: Convert free_swap_cache() to use a folio Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 40/57] swap: Convert swap_writepage() " Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 41/57] mm: Convert do_wp_page() " Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 42/57] huge_memory: Convert do_huge_pmd_wp_page() " Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 43/57] madvise: Convert madvise_free_pte_range() " Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 44/57] uprobes: Use folios more widely in __replace_page() Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 45/57] ksm: Use a folio in replace_page() Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 46/57] mm: Convert do_swap_page() to use folio_free_swap() Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 47/57] memcg: Convert mem_cgroup_swap_full() to take a folio Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 48/57] mm: Remove try_to_free_swap() Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 49/57] rmap: Convert page_move_anon_rmap() to use a folio Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 50/57] migrate: Convert __unmap_and_move() to use folios Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 51/57] migrate: Convert unmap_and_move_huge_page() " Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 52/57] huge_memory: Convert split_huge_page_to_list() to use a folio Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 53/57] huge_memory: Convert unmap_page() to unmap_folio() Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 54/57] mm: Convert page_get_anon_vma() to folio_get_anon_vma() Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 55/57] rmap: Remove page_unlock_anon_vma_read() Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 56/57] uprobes: Use new_folio in __replace_page() Matthew Wilcox (Oracle)
2022-09-02 19:46 ` [PATCH v2 57/57] mm: Convert lock_page_or_retry() to folio_lock_or_retry() Matthew Wilcox (Oracle)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220902194653.1739778-22-willy@infradead.org \
--to=willy@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox