Skip to content

Commit

Permalink
nilfs2: Convert nilfs_find_uncommited_extent() to use filemap_get_fol…
Browse files Browse the repository at this point in the history
…ios_contig()

Converted function to use folios throughout. This is in preparation for
the removal of find_get_pages_contig(). Now also supports large folios.

Also cleaned up an unnecessary if statement - pvec.pages[0]->index > index
will always evaluate to false, and filemap_get_folios_contig() returns 0 if
there is no folio found at index.

Signed-off-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
  • Loading branch information
VMoola authored and intel-lab-lkp committed Aug 15, 2022
1 parent 45331ba commit ce19663
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions fs/nilfs2/page.c
Expand Up @@ -480,41 +480,38 @@ unsigned long nilfs_find_uncommitted_extent(struct inode *inode,
sector_t start_blk,
sector_t *blkoff)
{
unsigned int i;
unsigned int i, nr;
pgoff_t index;
unsigned int nblocks_in_page;
unsigned long length = 0;
sector_t b;
struct pagevec pvec;
struct page *page;
struct folio_batch fbatch;
struct folio *folio;

if (inode->i_mapping->nrpages == 0)
return 0;

index = start_blk >> (PAGE_SHIFT - inode->i_blkbits);
nblocks_in_page = 1U << (PAGE_SHIFT - inode->i_blkbits);

pagevec_init(&pvec);
folio_batch_init(&fbatch);

repeat:
pvec.nr = find_get_pages_contig(inode->i_mapping, index, PAGEVEC_SIZE,
pvec.pages);
if (pvec.nr == 0)
nr = filemap_get_folios_contig(inode->i_mapping, &index, ULONG_MAX,
&fbatch);
if (nr == 0)
return length;

if (length > 0 && pvec.pages[0]->index > index)
goto out;

b = pvec.pages[0]->index << (PAGE_SHIFT - inode->i_blkbits);
b = fbatch.folios[0]->index << (PAGE_SHIFT - inode->i_blkbits);
i = 0;
do {
page = pvec.pages[i];
folio = fbatch.folios[i];

lock_page(page);
if (page_has_buffers(page)) {
folio_lock(folio);
if (folio_buffers(folio)) {
struct buffer_head *bh, *head;

bh = head = page_buffers(page);
bh = head = folio_buffers(folio);
do {
if (b < start_blk)
continue;
Expand All @@ -532,18 +529,17 @@ unsigned long nilfs_find_uncommitted_extent(struct inode *inode,

b += nblocks_in_page;
}
unlock_page(page);
folio_unlock(folio);

} while (++i < pagevec_count(&pvec));
} while (++i < nr);

index = page->index + 1;
pagevec_release(&pvec);
folio_batch_release(&fbatch);
cond_resched();
goto repeat;

out_locked:
unlock_page(page);
folio_unlock(folio);
out:
pagevec_release(&pvec);
folio_batch_release(&fbatch);
return length;
}

0 comments on commit ce19663

Please sign in to comment.