mirror of
https://github.com/torvalds/linux.git
synced 2024-10-23 05:30:55 +00:00
filemap: Convert filemap_create_page to folio
This is all internal to filemap and saves 100 bytes of text. Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: William Kucharski <william.kucharski@oracle.com>
This commit is contained in:
parent
9d427b4eb4
commit
a5d4ad0985
39
mm/filemap.c
39
mm/filemap.c
|
@ -2475,47 +2475,48 @@ unlock_mapping:
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int filemap_create_page(struct file *file,
|
static int filemap_create_folio(struct file *file,
|
||||||
struct address_space *mapping, pgoff_t index,
|
struct address_space *mapping, pgoff_t index,
|
||||||
struct pagevec *pvec)
|
struct pagevec *pvec)
|
||||||
{
|
{
|
||||||
struct page *page;
|
struct folio *folio;
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
page = page_cache_alloc(mapping);
|
folio = filemap_alloc_folio(mapping_gfp_mask(mapping), 0);
|
||||||
if (!page)
|
if (!folio)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Protect against truncate / hole punch. Grabbing invalidate_lock here
|
* Protect against truncate / hole punch. Grabbing invalidate_lock
|
||||||
* assures we cannot instantiate and bring uptodate new pagecache pages
|
* here assures we cannot instantiate and bring uptodate new
|
||||||
* after evicting page cache during truncate and before actually
|
* pagecache folios after evicting page cache during truncate
|
||||||
* freeing blocks. Note that we could release invalidate_lock after
|
* and before actually freeing blocks. Note that we could
|
||||||
* inserting the page into page cache as the locked page would then be
|
* release invalidate_lock after inserting the folio into
|
||||||
* enough to synchronize with hole punching. But there are code paths
|
* the page cache as the locked folio would then be enough to
|
||||||
* such as filemap_update_page() filling in partially uptodate pages or
|
* synchronize with hole punching. But there are code paths
|
||||||
* ->readpages() that need to hold invalidate_lock while mapping blocks
|
* such as filemap_update_page() filling in partially uptodate
|
||||||
* for IO so let's hold the lock here as well to keep locking rules
|
* pages or ->readpages() that need to hold invalidate_lock
|
||||||
* simple.
|
* while mapping blocks for IO so let's hold the lock here as
|
||||||
|
* well to keep locking rules simple.
|
||||||
*/
|
*/
|
||||||
filemap_invalidate_lock_shared(mapping);
|
filemap_invalidate_lock_shared(mapping);
|
||||||
error = add_to_page_cache_lru(page, mapping, index,
|
error = filemap_add_folio(mapping, folio, index,
|
||||||
mapping_gfp_constraint(mapping, GFP_KERNEL));
|
mapping_gfp_constraint(mapping, GFP_KERNEL));
|
||||||
if (error == -EEXIST)
|
if (error == -EEXIST)
|
||||||
error = AOP_TRUNCATED_PAGE;
|
error = AOP_TRUNCATED_PAGE;
|
||||||
if (error)
|
if (error)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
error = filemap_read_folio(file, mapping, page_folio(page));
|
error = filemap_read_folio(file, mapping, folio);
|
||||||
if (error)
|
if (error)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
filemap_invalidate_unlock_shared(mapping);
|
filemap_invalidate_unlock_shared(mapping);
|
||||||
pagevec_add(pvec, page);
|
pagevec_add(pvec, &folio->page);
|
||||||
return 0;
|
return 0;
|
||||||
error:
|
error:
|
||||||
filemap_invalidate_unlock_shared(mapping);
|
filemap_invalidate_unlock_shared(mapping);
|
||||||
put_page(page);
|
folio_put(folio);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2557,7 +2558,7 @@ retry:
|
||||||
if (!pagevec_count(pvec)) {
|
if (!pagevec_count(pvec)) {
|
||||||
if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_WAITQ))
|
if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_WAITQ))
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
err = filemap_create_page(filp, mapping,
|
err = filemap_create_folio(filp, mapping,
|
||||||
iocb->ki_pos >> PAGE_SHIFT, pvec);
|
iocb->ki_pos >> PAGE_SHIFT, pvec);
|
||||||
if (err == AOP_TRUNCATED_PAGE)
|
if (err == AOP_TRUNCATED_PAGE)
|
||||||
goto retry;
|
goto retry;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user