mm: Convert remove_mapping() to take a folio

Add kernel-doc and return the number of pages removed in order to
get the statistics right in __invalidate_mapping_pages().
Signed-off-by: default avatarMatthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarMiaohe Lin <linmiaohe@huawei.com>
parent e41c81d0
...@@ -46,8 +46,7 @@ ...@@ -46,8 +46,7 @@
static bool page_cache_pipe_buf_try_steal(struct pipe_inode_info *pipe, static bool page_cache_pipe_buf_try_steal(struct pipe_inode_info *pipe,
struct pipe_buffer *buf) struct pipe_buffer *buf)
{ {
struct page *page = buf->page; struct folio *folio = page_folio(buf->page);
struct folio *folio = page_folio(page);
struct address_space *mapping; struct address_space *mapping;
folio_lock(folio); folio_lock(folio);
...@@ -74,7 +73,7 @@ static bool page_cache_pipe_buf_try_steal(struct pipe_inode_info *pipe, ...@@ -74,7 +73,7 @@ static bool page_cache_pipe_buf_try_steal(struct pipe_inode_info *pipe,
* If we succeeded in removing the mapping, set LRU flag * If we succeeded in removing the mapping, set LRU flag
* and return good. * and return good.
*/ */
if (remove_mapping(mapping, page)) { if (remove_mapping(mapping, folio)) {
buf->flags |= PIPE_BUF_FLAG_LRU; buf->flags |= PIPE_BUF_FLAG_LRU;
return true; return true;
} }
......
...@@ -395,7 +395,7 @@ extern unsigned long mem_cgroup_shrink_node(struct mem_cgroup *mem, ...@@ -395,7 +395,7 @@ extern unsigned long mem_cgroup_shrink_node(struct mem_cgroup *mem,
unsigned long *nr_scanned); unsigned long *nr_scanned);
extern unsigned long shrink_all_memory(unsigned long nr_pages); extern unsigned long shrink_all_memory(unsigned long nr_pages);
extern int vm_swappiness; extern int vm_swappiness;
extern int remove_mapping(struct address_space *mapping, struct page *page); long remove_mapping(struct address_space *mapping, struct folio *folio);
extern unsigned long reclaim_pages(struct list_head *page_list); extern unsigned long reclaim_pages(struct list_head *page_list);
#ifdef CONFIG_NUMA #ifdef CONFIG_NUMA
......
...@@ -294,7 +294,7 @@ int invalidate_inode_page(struct page *page) ...@@ -294,7 +294,7 @@ int invalidate_inode_page(struct page *page)
if (folio_has_private(folio) && !filemap_release_folio(folio, 0)) if (folio_has_private(folio) && !filemap_release_folio(folio, 0))
return 0; return 0;
return remove_mapping(mapping, page); return remove_mapping(mapping, folio);
} }
/** /**
......
...@@ -1335,23 +1335,28 @@ static int __remove_mapping(struct address_space *mapping, struct folio *folio, ...@@ -1335,23 +1335,28 @@ static int __remove_mapping(struct address_space *mapping, struct folio *folio,
return 0; return 0;
} }
/* /**
* Attempt to detach a locked page from its ->mapping. If it is dirty or if * remove_mapping() - Attempt to remove a folio from its mapping.
* someone else has a ref on the page, abort and return 0. If it was * @mapping: The address space.
* successfully detached, return 1. Assumes the caller has a single ref on * @folio: The folio to remove.
* this page. *
* If the folio is dirty, under writeback or if someone else has a ref
* on it, removal will fail.
* Return: The number of pages removed from the mapping. 0 if the folio
* could not be removed.
* Context: The caller should have a single refcount on the folio and
* hold its lock.
*/ */
int remove_mapping(struct address_space *mapping, struct page *page) long remove_mapping(struct address_space *mapping, struct folio *folio)
{ {
struct folio *folio = page_folio(page);
if (__remove_mapping(mapping, folio, false, NULL)) { if (__remove_mapping(mapping, folio, false, NULL)) {
/* /*
* Unfreezing the refcount with 1 rather than 2 effectively * Unfreezing the refcount with 1 effectively
* drops the pagecache ref for us without requiring another * drops the pagecache ref for us without requiring another
* atomic operation. * atomic operation.
*/ */
folio_ref_unfreeze(folio, 1); folio_ref_unfreeze(folio, 1);
return 1; return folio_nr_pages(folio);
} }
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment