Skip to content

Commit 042c4f3

Browse files
author
Matthew Wilcox (Oracle)
committed
mm/truncate: Inline invalidate_complete_page() into its one caller
invalidate_inode_page() is the only caller of invalidate_complete_page() and inlining it reveals that the first check is unnecessary (because we hold the page locked, and we just retrieved the mapping from the page). Actually, it does make a difference, in that tail pages no longer fail at this check, so it's now possible to remove a tail page from a mapping. Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Reviewed-by: John Hubbard <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]>
1 parent 51608e9 commit 042c4f3

File tree

2 files changed

+6
-24
lines changed

2 files changed

+6
-24
lines changed

kernel/futex/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ int get_futex_key(u32 __user *uaddr, bool fshared, union futex_key *key,
302302
* found it, but truncated or holepunched or subjected to
303303
* invalidate_complete_page2 before we got the page lock (also
304304
* cases which we are happy to fail). And we hold a reference,
305-
* so refcount care in invalidate_complete_page's remove_mapping
305+
* so refcount care in invalidate_inode_page's remove_mapping
306306
* prevents drop_caches from setting mapping to NULL beneath us.
307307
*
308308
* The case we do have to guard against is when memory pressure made

mm/truncate.c

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -193,27 +193,6 @@ static void truncate_cleanup_folio(struct folio *folio)
193193
folio_clear_mappedtodisk(folio);
194194
}
195195

196-
/*
197-
* This is for invalidate_mapping_pages(). That function can be called at
198-
* any time, and is not supposed to throw away dirty pages. But pages can
199-
* be marked dirty at any time too, so use remove_mapping which safely
200-
* discards clean, unused pages.
201-
*
202-
* Returns non-zero if the page was successfully invalidated.
203-
*/
204-
static int
205-
invalidate_complete_page(struct address_space *mapping, struct page *page)
206-
{
207-
208-
if (page->mapping != mapping)
209-
return 0;
210-
211-
if (page_has_private(page) && !try_to_release_page(page, 0))
212-
return 0;
213-
214-
return remove_mapping(mapping, page);
215-
}
216-
217196
int truncate_inode_folio(struct address_space *mapping, struct folio *folio)
218197
{
219198
if (folio->mapping != mapping)
@@ -309,7 +288,10 @@ int invalidate_inode_page(struct page *page)
309288
return 0;
310289
if (page_mapped(page))
311290
return 0;
312-
return invalidate_complete_page(mapping, page);
291+
if (page_has_private(page) && !try_to_release_page(page, 0))
292+
return 0;
293+
294+
return remove_mapping(mapping, page);
313295
}
314296

315297
/**
@@ -584,7 +566,7 @@ void invalidate_mapping_pagevec(struct address_space *mapping,
584566
}
585567

586568
/*
587-
* This is like invalidate_complete_page(), except it ignores the page's
569+
* This is like invalidate_inode_page(), except it ignores the page's
588570
* refcount. We do this because invalidate_inode_pages2() needs stronger
589571
* invalidation guarantees, and cannot afford to leave pages behind because
590572
* shrink_page_list() has a temp ref on them, or because they're transiently

0 commit comments

Comments
 (0)