ext4: Convert mpage_release_unused_pages() to use filemap_get_folios()
If the folio is large, it may overlap the beginning or end of the unused range. If it does, we need to avoid invalidating it. Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Acked-by: Christian Brauner (Microsoft) <brauner@kernel.org>
This commit is contained in:
parent
9e0b6f31ba
commit
fb5a5be05f
@ -1554,9 +1554,9 @@ struct mpage_da_data {
|
|||||||
static void mpage_release_unused_pages(struct mpage_da_data *mpd,
|
static void mpage_release_unused_pages(struct mpage_da_data *mpd,
|
||||||
bool invalidate)
|
bool invalidate)
|
||||||
{
|
{
|
||||||
int nr_pages, i;
|
unsigned nr, i;
|
||||||
pgoff_t index, end;
|
pgoff_t index, end;
|
||||||
struct pagevec pvec;
|
struct folio_batch fbatch;
|
||||||
struct inode *inode = mpd->inode;
|
struct inode *inode = mpd->inode;
|
||||||
struct address_space *mapping = inode->i_mapping;
|
struct address_space *mapping = inode->i_mapping;
|
||||||
|
|
||||||
@ -1574,15 +1574,18 @@ static void mpage_release_unused_pages(struct mpage_da_data *mpd,
|
|||||||
ext4_es_remove_extent(inode, start, last - start + 1);
|
ext4_es_remove_extent(inode, start, last - start + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
pagevec_init(&pvec);
|
folio_batch_init(&fbatch);
|
||||||
while (index <= end) {
|
while (index <= end) {
|
||||||
nr_pages = pagevec_lookup_range(&pvec, mapping, &index, end);
|
nr = filemap_get_folios(mapping, &index, end, &fbatch);
|
||||||
if (nr_pages == 0)
|
if (nr == 0)
|
||||||
break;
|
break;
|
||||||
for (i = 0; i < nr_pages; i++) {
|
for (i = 0; i < nr; i++) {
|
||||||
struct page *page = pvec.pages[i];
|
struct folio *folio = fbatch.folios[i];
|
||||||
struct folio *folio = page_folio(page);
|
|
||||||
|
|
||||||
|
if (folio->index < mpd->first_page)
|
||||||
|
continue;
|
||||||
|
if (folio->index + folio_nr_pages(folio) - 1 > end)
|
||||||
|
continue;
|
||||||
BUG_ON(!folio_test_locked(folio));
|
BUG_ON(!folio_test_locked(folio));
|
||||||
BUG_ON(folio_test_writeback(folio));
|
BUG_ON(folio_test_writeback(folio));
|
||||||
if (invalidate) {
|
if (invalidate) {
|
||||||
@ -1594,7 +1597,7 @@ static void mpage_release_unused_pages(struct mpage_da_data *mpd,
|
|||||||
}
|
}
|
||||||
folio_unlock(folio);
|
folio_unlock(folio);
|
||||||
}
|
}
|
||||||
pagevec_release(&pvec);
|
folio_batch_release(&fbatch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user