* [f2fs-dev] [PATCH 01/10] filemap: Add filemap_get_folios()
2022-06-05 19:38 [f2fs-dev] [PATCH 00/10] Convert to filemap_get_folios() Matthew Wilcox (Oracle)
@ 2022-06-05 19:38 ` Matthew Wilcox (Oracle)
2022-06-08 8:00 ` Christoph Hellwig
2022-06-05 19:38 ` [f2fs-dev] [PATCH 02/10] buffer: Convert clean_bdev_aliases() to use filemap_get_folios() Matthew Wilcox (Oracle)
` (9 subsequent siblings)
10 siblings, 1 reply; 33+ messages in thread
From: Matthew Wilcox (Oracle) @ 2022-06-05 19:38 UTC (permalink / raw)
To: linux-fsdevel
Cc: linux-nilfs, linux-kernel, Matthew Wilcox (Oracle),
linux-f2fs-devel, linux-mm, linux-ext4
This is the equivalent of find_get_pages() but fills a folio_batch
instead of an array of pages.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
include/linux/pagemap.h | 2 ++
mm/filemap.c | 55 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 57 insertions(+)
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 5555689ea809..50e57b2d845f 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -718,6 +718,8 @@ static inline struct page *find_subpage(struct page *head, pgoff_t index)
return head + (index & (thp_nr_pages(head) - 1));
}
+unsigned filemap_get_folios(struct address_space *mapping, pgoff_t *start,
+ pgoff_t end, struct folio_batch *fbatch);
unsigned find_get_pages_range(struct address_space *mapping, pgoff_t *start,
pgoff_t end, unsigned int nr_pages,
struct page **pages);
diff --git a/mm/filemap.c b/mm/filemap.c
index 1e66eea98a7e..ea4145b7a84c 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2127,6 +2127,61 @@ unsigned find_lock_entries(struct address_space *mapping, pgoff_t start,
return folio_batch_count(fbatch);
}
+/**
+ * filemap_get_folios - Get a batch of folios
+ * @mapping: The address_space to search
+ * @start: The starting page index
+ * @end: The final page index (inclusive)
+ * @fbatch: The batch to fill.
+ *
+ * Search for and return a batch of folios in the mapping starting at
+ * index @start and up to index @end (inclusive). The folios are returned
+ * in @fbatch with an elevated reference count.
+ *
+ * The first folio may start before @start; if it does, it will contain
+ * @start. The final folio may extend beyond @end; if it does, it will
+ * contain @end. The folios have ascending indices. There may be gaps
+ * between the folios if there are indices which have no folio in the
+ * page cache. If folios are added to or removed from the page cache
+ * while this is running, they may or may not be found by this call.
+ *
+ * Return: The number of folios which were found.
+ * We also update @start to index the next folio for the traversal.
+ */
+unsigned filemap_get_folios(struct address_space *mapping, pgoff_t *start,
+ pgoff_t end, struct folio_batch *fbatch)
+{
+ XA_STATE(xas, &mapping->i_pages, *start);
+ struct folio *folio;
+
+ rcu_read_lock();
+ while ((folio = find_get_entry(&xas, end, XA_PRESENT)) != NULL) {
+ /* Skip over shadow, swap and DAX entries */
+ if (xa_is_value(folio))
+ continue;
+ if (!folio_batch_add(fbatch, folio)) {
+ *start = folio->index + folio_nr_pages(folio);
+ goto out;
+ }
+ }
+
+ /*
+ * We come here when there is no page beyond @end. We take care to not
+ * overflow the index @start as it confuses some of the callers. This
+ * breaks the iteration when there is a page at index -1 but that is
+ * already broken anyway.
+ */
+ if (end == (pgoff_t)-1)
+ *start = (pgoff_t)-1;
+ else
+ *start = end + 1;
+out:
+ rcu_read_unlock();
+
+ return folio_batch_count(fbatch);
+}
+EXPORT_SYMBOL(filemap_get_folios);
+
static inline
bool folio_more_pages(struct folio *folio, pgoff_t index, pgoff_t max)
{
--
2.35.1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 33+ messages in thread* [f2fs-dev] [PATCH 02/10] buffer: Convert clean_bdev_aliases() to use filemap_get_folios()
2022-06-05 19:38 [f2fs-dev] [PATCH 00/10] Convert to filemap_get_folios() Matthew Wilcox (Oracle)
2022-06-05 19:38 ` [f2fs-dev] [PATCH 01/10] filemap: Add filemap_get_folios() Matthew Wilcox (Oracle)
@ 2022-06-05 19:38 ` Matthew Wilcox (Oracle)
2022-06-08 8:01 ` Christoph Hellwig
2022-06-05 19:38 ` [f2fs-dev] [PATCH 03/10] ext4: Convert mpage_release_unused_pages() " Matthew Wilcox (Oracle)
` (8 subsequent siblings)
10 siblings, 1 reply; 33+ messages in thread
From: Matthew Wilcox (Oracle) @ 2022-06-05 19:38 UTC (permalink / raw)
To: linux-fsdevel
Cc: linux-nilfs, linux-kernel, Matthew Wilcox (Oracle),
linux-f2fs-devel, linux-mm, linux-ext4
Use a folio throughout this function.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
fs/buffer.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/fs/buffer.c b/fs/buffer.c
index 898c7f301b1b..276769d3715a 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -1604,7 +1604,7 @@ void clean_bdev_aliases(struct block_device *bdev, sector_t block, sector_t len)
{
struct inode *bd_inode = bdev->bd_inode;
struct address_space *bd_mapping = bd_inode->i_mapping;
- struct pagevec pvec;
+ struct folio_batch fbatch;
pgoff_t index = block >> (PAGE_SHIFT - bd_inode->i_blkbits);
pgoff_t end;
int i, count;
@@ -1612,24 +1612,24 @@ void clean_bdev_aliases(struct block_device *bdev, sector_t block, sector_t len)
struct buffer_head *head;
end = (block + len - 1) >> (PAGE_SHIFT - bd_inode->i_blkbits);
- pagevec_init(&pvec);
- while (pagevec_lookup_range(&pvec, bd_mapping, &index, end)) {
- count = pagevec_count(&pvec);
+ folio_batch_init(&fbatch);
+ while (filemap_get_folios(bd_mapping, &index, end, &fbatch)) {
+ count = folio_batch_count(&fbatch);
for (i = 0; i < count; i++) {
- struct page *page = pvec.pages[i];
+ struct folio *folio = fbatch.folios[i];
- if (!page_has_buffers(page))
+ if (!folio_buffers(folio))
continue;
/*
- * We use page lock instead of bd_mapping->private_lock
+ * We use folio lock instead of bd_mapping->private_lock
* to pin buffers here since we can afford to sleep and
* it scales better than a global spinlock lock.
*/
- lock_page(page);
- /* Recheck when the page is locked which pins bhs */
- if (!page_has_buffers(page))
+ folio_lock(folio);
+ /* Recheck when the folio is locked which pins bhs */
+ head = folio_buffers(folio);
+ if (!head)
goto unlock_page;
- head = page_buffers(page);
bh = head;
do {
if (!buffer_mapped(bh) || (bh->b_blocknr < block))
@@ -1643,9 +1643,9 @@ void clean_bdev_aliases(struct block_device *bdev, sector_t block, sector_t len)
bh = bh->b_this_page;
} while (bh != head);
unlock_page:
- unlock_page(page);
+ folio_unlock(folio);
}
- pagevec_release(&pvec);
+ folio_batch_release(&fbatch);
cond_resched();
/* End of range already reached? */
if (index > end || !index)
--
2.35.1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 33+ messages in thread* [f2fs-dev] [PATCH 03/10] ext4: Convert mpage_release_unused_pages() to use filemap_get_folios()
2022-06-05 19:38 [f2fs-dev] [PATCH 00/10] Convert to filemap_get_folios() Matthew Wilcox (Oracle)
2022-06-05 19:38 ` [f2fs-dev] [PATCH 01/10] filemap: Add filemap_get_folios() Matthew Wilcox (Oracle)
2022-06-05 19:38 ` [f2fs-dev] [PATCH 02/10] buffer: Convert clean_bdev_aliases() to use filemap_get_folios() Matthew Wilcox (Oracle)
@ 2022-06-05 19:38 ` Matthew Wilcox (Oracle)
2022-06-08 8:02 ` Christoph Hellwig
2022-06-05 19:38 ` [f2fs-dev] [PATCH 04/10] ext4: Convert mpage_map_and_submit_buffers() " Matthew Wilcox (Oracle)
` (7 subsequent siblings)
10 siblings, 1 reply; 33+ messages in thread
From: Matthew Wilcox (Oracle) @ 2022-06-05 19:38 UTC (permalink / raw)
To: linux-fsdevel
Cc: linux-nilfs, linux-kernel, Matthew Wilcox (Oracle),
linux-f2fs-devel, linux-mm, linux-ext4
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>
---
fs/ext4/inode.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 3dce7d058985..32a7f5e024d6 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -1554,9 +1554,9 @@ struct mpage_da_data {
static void mpage_release_unused_pages(struct mpage_da_data *mpd,
bool invalidate)
{
- int nr_pages, i;
+ unsigned nr, i;
pgoff_t index, end;
- struct pagevec pvec;
+ struct folio_batch fbatch;
struct inode *inode = mpd->inode;
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);
}
- pagevec_init(&pvec);
+ folio_batch_init(&fbatch);
while (index <= end) {
- nr_pages = pagevec_lookup_range(&pvec, mapping, &index, end);
- if (nr_pages == 0)
+ nr = filemap_get_folios(mapping, &index, end, &fbatch);
+ if (nr == 0)
break;
- for (i = 0; i < nr_pages; i++) {
- struct page *page = pvec.pages[i];
- struct folio *folio = page_folio(page);
+ for (i = 0; i < nr; i++) {
+ struct folio *folio = fbatch.folios[i];
+ 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_writeback(folio));
if (invalidate) {
@@ -1594,7 +1597,7 @@ static void mpage_release_unused_pages(struct mpage_da_data *mpd,
}
folio_unlock(folio);
}
- pagevec_release(&pvec);
+ folio_batch_release(&fbatch);
}
}
--
2.35.1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 33+ messages in thread* Re: [f2fs-dev] [PATCH 03/10] ext4: Convert mpage_release_unused_pages() to use filemap_get_folios()
2022-06-05 19:38 ` [f2fs-dev] [PATCH 03/10] ext4: Convert mpage_release_unused_pages() " Matthew Wilcox (Oracle)
@ 2022-06-08 8:02 ` Christoph Hellwig
2022-06-08 16:02 ` Matthew Wilcox
0 siblings, 1 reply; 33+ messages in thread
From: Christoph Hellwig @ 2022-06-08 8:02 UTC (permalink / raw)
To: Matthew Wilcox (Oracle)
Cc: linux-nilfs, linux-kernel, linux-f2fs-devel, linux-mm,
linux-fsdevel, linux-ext4
On Sun, Jun 05, 2022 at 08:38:47PM +0100, Matthew Wilcox (Oracle) wrote:
> 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.
It's never going to be larger for ext4, is it? But either way,
those precautions looks fine.
Reviewed-by: Christoph Hellwig <hch@lst.de>
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [f2fs-dev] [PATCH 03/10] ext4: Convert mpage_release_unused_pages() to use filemap_get_folios()
2022-06-08 8:02 ` Christoph Hellwig
@ 2022-06-08 16:02 ` Matthew Wilcox
2022-06-09 3:55 ` Christoph Hellwig
0 siblings, 1 reply; 33+ messages in thread
From: Matthew Wilcox @ 2022-06-08 16:02 UTC (permalink / raw)
To: Christoph Hellwig
Cc: linux-nilfs, linux-kernel, linux-f2fs-devel, linux-mm,
linux-fsdevel, linux-ext4
On Wed, Jun 08, 2022 at 01:02:22AM -0700, Christoph Hellwig wrote:
> On Sun, Jun 05, 2022 at 08:38:47PM +0100, Matthew Wilcox (Oracle) wrote:
> > 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.
>
> It's never going to be larger for ext4, is it? But either way,
> those precautions looks fine.
I don't want to say "never". Today, it's not, but if ext4 ever does
gain support for large folios, then this is a precaution it will need
to take. I'm trying not to leave traps when I do conversions.
> Reviewed-by: Christoph Hellwig <hch@lst.de>
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [f2fs-dev] [PATCH 03/10] ext4: Convert mpage_release_unused_pages() to use filemap_get_folios()
2022-06-08 16:02 ` Matthew Wilcox
@ 2022-06-09 3:55 ` Christoph Hellwig
0 siblings, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2022-06-09 3:55 UTC (permalink / raw)
To: Matthew Wilcox
Cc: linux-nilfs, linux-kernel, linux-f2fs-devel, Christoph Hellwig,
linux-mm, linux-fsdevel, linux-ext4
On Wed, Jun 08, 2022 at 05:02:40PM +0100, Matthew Wilcox wrote:
> On Wed, Jun 08, 2022 at 01:02:22AM -0700, Christoph Hellwig wrote:
> > On Sun, Jun 05, 2022 at 08:38:47PM +0100, Matthew Wilcox (Oracle) wrote:
> > > 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.
> >
> > It's never going to be larger for ext4, is it? But either way,
> > those precautions looks fine.
>
> I don't want to say "never". Today, it's not, but if ext4 ever does
> gain support for large folios, then this is a precaution it will need
> to take. I'm trying not to leave traps when I do conversions.
FYI, this wasn't an objection to the patch, just a hint that the commit
log could spell this out a bit better.
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 33+ messages in thread
* [f2fs-dev] [PATCH 04/10] ext4: Convert mpage_map_and_submit_buffers() to use filemap_get_folios()
2022-06-05 19:38 [f2fs-dev] [PATCH 00/10] Convert to filemap_get_folios() Matthew Wilcox (Oracle)
` (2 preceding siblings ...)
2022-06-05 19:38 ` [f2fs-dev] [PATCH 03/10] ext4: Convert mpage_release_unused_pages() " Matthew Wilcox (Oracle)
@ 2022-06-05 19:38 ` Matthew Wilcox (Oracle)
2022-06-08 8:03 ` Christoph Hellwig
2022-06-05 19:38 ` [f2fs-dev] [PATCH 05/10] f2fs: Convert f2fs_invalidate_compress_pages() " Matthew Wilcox (Oracle)
` (6 subsequent siblings)
10 siblings, 1 reply; 33+ messages in thread
From: Matthew Wilcox (Oracle) @ 2022-06-05 19:38 UTC (permalink / raw)
To: linux-fsdevel
Cc: linux-nilfs, linux-kernel, Matthew Wilcox (Oracle),
linux-f2fs-devel, linux-mm, linux-ext4
The called functions all use pages, so just convert back to a page.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
fs/ext4/inode.c | 19 +++++++++----------
1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 32a7f5e024d6..1aaea53e67b5 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -2314,8 +2314,8 @@ static int mpage_process_page(struct mpage_da_data *mpd, struct page *page,
*/
static int mpage_map_and_submit_buffers(struct mpage_da_data *mpd)
{
- struct pagevec pvec;
- int nr_pages, i;
+ struct folio_batch fbatch;
+ unsigned nr, i;
struct inode *inode = mpd->inode;
int bpp_bits = PAGE_SHIFT - inode->i_blkbits;
pgoff_t start, end;
@@ -2329,14 +2329,13 @@ static int mpage_map_and_submit_buffers(struct mpage_da_data *mpd)
lblk = start << bpp_bits;
pblock = mpd->map.m_pblk;
- pagevec_init(&pvec);
+ folio_batch_init(&fbatch);
while (start <= end) {
- nr_pages = pagevec_lookup_range(&pvec, inode->i_mapping,
- &start, end);
- if (nr_pages == 0)
+ nr = filemap_get_folios(inode->i_mapping, &start, end, &fbatch);
+ if (nr == 0)
break;
- for (i = 0; i < nr_pages; i++) {
- struct page *page = pvec.pages[i];
+ for (i = 0; i < nr; i++) {
+ struct page *page = &fbatch.folios[i]->page;
err = mpage_process_page(mpd, page, &lblk, &pblock,
&map_bh);
@@ -2352,14 +2351,14 @@ static int mpage_map_and_submit_buffers(struct mpage_da_data *mpd)
if (err < 0)
goto out;
}
- pagevec_release(&pvec);
+ folio_batch_release(&fbatch);
}
/* Extent fully mapped and matches with page boundary. We are done. */
mpd->map.m_len = 0;
mpd->map.m_flags = 0;
return 0;
out:
- pagevec_release(&pvec);
+ folio_batch_release(&fbatch);
return err;
}
--
2.35.1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 33+ messages in thread* Re: [f2fs-dev] [PATCH 04/10] ext4: Convert mpage_map_and_submit_buffers() to use filemap_get_folios()
2022-06-05 19:38 ` [f2fs-dev] [PATCH 04/10] ext4: Convert mpage_map_and_submit_buffers() " Matthew Wilcox (Oracle)
@ 2022-06-08 8:03 ` Christoph Hellwig
0 siblings, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2022-06-08 8:03 UTC (permalink / raw)
To: Matthew Wilcox (Oracle)
Cc: linux-nilfs, linux-kernel, linux-f2fs-devel, linux-mm,
linux-fsdevel, linux-ext4
On Sun, Jun 05, 2022 at 08:38:48PM +0100, Matthew Wilcox (Oracle) wrote:
> The called functions all use pages, so just convert back to a page.
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 33+ messages in thread
* [f2fs-dev] [PATCH 05/10] f2fs: Convert f2fs_invalidate_compress_pages() to use filemap_get_folios()
2022-06-05 19:38 [f2fs-dev] [PATCH 00/10] Convert to filemap_get_folios() Matthew Wilcox (Oracle)
` (3 preceding siblings ...)
2022-06-05 19:38 ` [f2fs-dev] [PATCH 04/10] ext4: Convert mpage_map_and_submit_buffers() " Matthew Wilcox (Oracle)
@ 2022-06-05 19:38 ` Matthew Wilcox (Oracle)
2022-06-08 8:03 ` Christoph Hellwig
2022-06-15 8:14 ` Chao Yu
2022-06-05 19:38 ` [f2fs-dev] [PATCH 06/10] hugetlbfs: Convert remove_inode_hugepages() " Matthew Wilcox (Oracle)
` (5 subsequent siblings)
10 siblings, 2 replies; 33+ messages in thread
From: Matthew Wilcox (Oracle) @ 2022-06-05 19:38 UTC (permalink / raw)
To: linux-fsdevel
Cc: linux-nilfs, linux-kernel, Matthew Wilcox (Oracle),
linux-f2fs-devel, linux-mm, linux-ext4
Convert this function to use folios throughout.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
fs/f2fs/compress.c | 35 +++++++++++++++--------------------
1 file changed, 15 insertions(+), 20 deletions(-)
diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c
index 24824cd96f36..009e6c519e98 100644
--- a/fs/f2fs/compress.c
+++ b/fs/f2fs/compress.c
@@ -1832,45 +1832,40 @@ bool f2fs_load_compressed_page(struct f2fs_sb_info *sbi, struct page *page,
void f2fs_invalidate_compress_pages(struct f2fs_sb_info *sbi, nid_t ino)
{
struct address_space *mapping = sbi->compress_inode->i_mapping;
- struct pagevec pvec;
+ struct folio_batch fbatch;
pgoff_t index = 0;
pgoff_t end = MAX_BLKADDR(sbi);
if (!mapping->nrpages)
return;
- pagevec_init(&pvec);
+ folio_batch_init(&fbatch);
do {
- unsigned int nr_pages;
- int i;
+ unsigned int nr, i;
- nr_pages = pagevec_lookup_range(&pvec, mapping,
- &index, end - 1);
- if (!nr_pages)
+ nr = filemap_get_folios(mapping, &index, end - 1, &fbatch);
+ if (!nr)
break;
- for (i = 0; i < nr_pages; i++) {
- struct page *page = pvec.pages[i];
-
- if (page->index > end)
- break;
+ for (i = 0; i < nr; i++) {
+ struct folio *folio = fbatch.folios[i];
- lock_page(page);
- if (page->mapping != mapping) {
- unlock_page(page);
+ folio_lock(folio);
+ if (folio->mapping != mapping) {
+ folio_unlock(folio);
continue;
}
- if (ino != get_page_private_data(page)) {
- unlock_page(page);
+ if (ino != get_page_private_data(&folio->page)) {
+ folio_unlock(folio);
continue;
}
- generic_error_remove_page(mapping, page);
- unlock_page(page);
+ generic_error_remove_page(mapping, &folio->page);
+ folio_unlock(folio);
}
- pagevec_release(&pvec);
+ folio_batch_release(&fbatch);
cond_resched();
} while (index < end);
}
--
2.35.1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 33+ messages in thread* Re: [f2fs-dev] [PATCH 05/10] f2fs: Convert f2fs_invalidate_compress_pages() to use filemap_get_folios()
2022-06-05 19:38 ` [f2fs-dev] [PATCH 05/10] f2fs: Convert f2fs_invalidate_compress_pages() " Matthew Wilcox (Oracle)
@ 2022-06-08 8:03 ` Christoph Hellwig
2022-06-15 8:14 ` Chao Yu
1 sibling, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2022-06-08 8:03 UTC (permalink / raw)
To: Matthew Wilcox (Oracle)
Cc: linux-nilfs, linux-kernel, linux-f2fs-devel, linux-mm,
linux-fsdevel, linux-ext4
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [f2fs-dev] [PATCH 05/10] f2fs: Convert f2fs_invalidate_compress_pages() to use filemap_get_folios()
2022-06-05 19:38 ` [f2fs-dev] [PATCH 05/10] f2fs: Convert f2fs_invalidate_compress_pages() " Matthew Wilcox (Oracle)
2022-06-08 8:03 ` Christoph Hellwig
@ 2022-06-15 8:14 ` Chao Yu
1 sibling, 0 replies; 33+ messages in thread
From: Chao Yu @ 2022-06-15 8:14 UTC (permalink / raw)
To: Matthew Wilcox (Oracle), linux-fsdevel
Cc: linux-mm, linux-ext4, linux-nilfs, linux-kernel, linux-f2fs-devel
On 2022/6/6 3:38, Matthew Wilcox (Oracle) wrote:
> Convert this function to use folios throughout.
>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Acked-by: Chao Yu <chao@kernel.org>
Thanks,
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 33+ messages in thread
* [f2fs-dev] [PATCH 06/10] hugetlbfs: Convert remove_inode_hugepages() to use filemap_get_folios()
2022-06-05 19:38 [f2fs-dev] [PATCH 00/10] Convert to filemap_get_folios() Matthew Wilcox (Oracle)
` (4 preceding siblings ...)
2022-06-05 19:38 ` [f2fs-dev] [PATCH 05/10] f2fs: Convert f2fs_invalidate_compress_pages() " Matthew Wilcox (Oracle)
@ 2022-06-05 19:38 ` Matthew Wilcox (Oracle)
2022-06-08 8:04 ` Christoph Hellwig
2022-06-10 15:52 ` Sumanth Korikkar
2022-06-05 19:38 ` [f2fs-dev] [PATCH 07/10] nilfs2: Convert nilfs_copy_back_pages() " Matthew Wilcox (Oracle)
` (4 subsequent siblings)
10 siblings, 2 replies; 33+ messages in thread
From: Matthew Wilcox (Oracle) @ 2022-06-05 19:38 UTC (permalink / raw)
To: linux-fsdevel
Cc: linux-nilfs, linux-kernel, Matthew Wilcox (Oracle),
linux-f2fs-devel, linux-mm, linux-ext4
Use folios throughout this function. That removes the last caller of
huge_pagevec_release(), so delete that too.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
fs/hugetlbfs/inode.c | 44 ++++++++++++++------------------------------
1 file changed, 14 insertions(+), 30 deletions(-)
diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
index ae2524480f23..14d33f725e05 100644
--- a/fs/hugetlbfs/inode.c
+++ b/fs/hugetlbfs/inode.c
@@ -108,16 +108,6 @@ static inline void hugetlb_drop_vma_policy(struct vm_area_struct *vma)
}
#endif
-static void huge_pagevec_release(struct pagevec *pvec)
-{
- int i;
-
- for (i = 0; i < pagevec_count(pvec); ++i)
- put_page(pvec->pages[i]);
-
- pagevec_reinit(pvec);
-}
-
/*
* Mask used when checking the page offset value passed in via system
* calls. This value will be converted to a loff_t which is signed.
@@ -480,25 +470,19 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,
struct address_space *mapping = &inode->i_data;
const pgoff_t start = lstart >> huge_page_shift(h);
const pgoff_t end = lend >> huge_page_shift(h);
- struct pagevec pvec;
+ struct folio_batch fbatch;
pgoff_t next, index;
int i, freed = 0;
bool truncate_op = (lend == LLONG_MAX);
- pagevec_init(&pvec);
+ folio_batch_init(&fbatch);
next = start;
- while (next < end) {
- /*
- * When no more pages are found, we are done.
- */
- if (!pagevec_lookup_range(&pvec, mapping, &next, end - 1))
- break;
-
- for (i = 0; i < pagevec_count(&pvec); ++i) {
- struct page *page = pvec.pages[i];
+ while (filemap_get_folios(mapping, &next, end - 1, &fbatch)) {
+ for (i = 0; i < folio_batch_count(&fbatch); ++i) {
+ struct folio *folio = fbatch.folios[i];
u32 hash = 0;
- index = page->index;
+ index = folio->index;
if (!truncate_op) {
/*
* Only need to hold the fault mutex in the
@@ -511,15 +495,15 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,
}
/*
- * If page is mapped, it was faulted in after being
+ * If folio is mapped, it was faulted in after being
* unmapped in caller. Unmap (again) now after taking
* the fault mutex. The mutex will prevent faults
- * until we finish removing the page.
+ * until we finish removing the folio.
*
* This race can only happen in the hole punch case.
* Getting here in a truncate operation is a bug.
*/
- if (unlikely(page_mapped(page))) {
+ if (unlikely(folio_mapped(folio))) {
BUG_ON(truncate_op);
mutex_unlock(&hugetlb_fault_mutex_table[hash]);
@@ -532,7 +516,7 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,
i_mmap_unlock_write(mapping);
}
- lock_page(page);
+ folio_lock(folio);
/*
* We must free the huge page and remove from page
* cache (remove_huge_page) BEFORE removing the
@@ -542,8 +526,8 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,
* the subpool and global reserve usage count can need
* to be adjusted.
*/
- VM_BUG_ON(HPageRestoreReserve(page));
- remove_huge_page(page);
+ VM_BUG_ON(HPageRestoreReserve(&folio->page));
+ remove_huge_page(&folio->page);
freed++;
if (!truncate_op) {
if (unlikely(hugetlb_unreserve_pages(inode,
@@ -551,11 +535,11 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,
hugetlb_fix_reserve_counts(inode);
}
- unlock_page(page);
+ folio_unlock(folio);
if (!truncate_op)
mutex_unlock(&hugetlb_fault_mutex_table[hash]);
}
- huge_pagevec_release(&pvec);
+ folio_batch_release(&fbatch);
cond_resched();
}
--
2.35.1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 33+ messages in thread* Re: [f2fs-dev] [PATCH 06/10] hugetlbfs: Convert remove_inode_hugepages() to use filemap_get_folios()
2022-06-05 19:38 ` [f2fs-dev] [PATCH 06/10] hugetlbfs: Convert remove_inode_hugepages() " Matthew Wilcox (Oracle)
@ 2022-06-08 8:04 ` Christoph Hellwig
2022-06-10 15:52 ` Sumanth Korikkar
1 sibling, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2022-06-08 8:04 UTC (permalink / raw)
To: Matthew Wilcox (Oracle)
Cc: linux-nilfs, linux-kernel, linux-f2fs-devel, linux-mm,
linux-fsdevel, linux-ext4
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [f2fs-dev] [PATCH 06/10] hugetlbfs: Convert remove_inode_hugepages() to use filemap_get_folios()
2022-06-05 19:38 ` [f2fs-dev] [PATCH 06/10] hugetlbfs: Convert remove_inode_hugepages() " Matthew Wilcox (Oracle)
2022-06-08 8:04 ` Christoph Hellwig
@ 2022-06-10 15:52 ` Sumanth Korikkar
2022-06-10 18:35 ` Gerald Schaefer
2022-06-10 21:17 ` Matthew Wilcox
1 sibling, 2 replies; 33+ messages in thread
From: Sumanth Korikkar @ 2022-06-10 15:52 UTC (permalink / raw)
To: willy
Cc: linux-nilfs, gor, Sumanth Korikkar, linux-kernel,
linux-f2fs-devel, linux-mm, linux-fsdevel, gerald.schaefer,
linux-ext4, agordeev
Hi,
The kernel crashes with the following backtrace on linux-next:
[ 203.304451] kernel BUG at fs/inode.c:612!
[ 203.304466] invalid opcode: 0000 [#1] PREEMPT SMP PTI
[ 203.305215] CPU: 0 PID: 868 Comm: alloc-instantia Not tainted 5.19.0-rc1-next-20220609 #256
[ 203.305563] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.14.0-6.fc35 04/01/2014
[ 203.305922] RIP: 0010:clear_inode+0x6e/0x80
[ 203.306139] Code: 00 a8 20 74 29 a8 40 75 27 48 8b 93 18 01 00 00 48 8d 83 18 01 00 00 48 39 c2 75 16 48 c7 83 98 00 00 00 60 00 00 00 5b 5d c3 <0f> 0b 0f 0b 0f 0b 0f 0b 0f 0b 0f 1f 84 00 00 00 00 00 0f 1f 44 00
[ 203.306827] RSP: 0018:ffffa49dc07cbde8 EFLAGS: 00010002
[ 203.307074] RAX: 0000000000000000 RBX: ffff8bf4cecc4010 RCX: 0000000000069600
[ 203.307380] RDX: 0000000000000001 RSI: ffffffff929b5b2b RDI: 0000000000000000
[ 203.307715] RBP: ffff8bf4cecc4180 R08: 000003fffffffffe R09: ffffffffffffffc0
[ 203.307988] R10: ffff8bf4ca515ec8 R11: ffffa49dc07cbc68 R12: ffff8bf4cecc4118
[ 203.308256] R13: ffff8bf4cf029a80 R14: ffff8bf4cb2ce900 R15: ffff8bf4c79b8848
[ 203.308591] FS: 0000000000000000(0000) GS:ffff8bf533000000(0000) knlGS:0000000000000000
[ 203.309033] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 203.309327] CR2: 00007fadbf5d3838 CR3: 000000016520c000 CR4: 00000000000006f0
[ 203.309661] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[ 203.309997] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
[ 203.310330] Call Trace:
[ 203.310534] <TASK>
[ 203.310733] evict+0xc3/0x1c0
[ 203.310956] __dentry_kill+0xd6/0x170
[ 203.311196] dput+0x144/0x2e0
[ 203.311416] __fput+0xdb/0x240
[ 203.311634] task_work_run+0x5c/0x90
[ 203.311876] do_exit+0x317/0xa80
[ 203.312104] do_group_exit+0x2d/0x90
[ 203.312337] __x64_sys_exit_group+0x14/0x20
[ 203.312599] do_syscall_64+0x3b/0x90
[ 203.312816] entry_SYSCALL_64_after_hwframe+0x46/0xb0
[ 203.313064] RIP: 0033:0x7fadbf4f2711
[ 203.313275] Code: Unable to access opcode bytes at RIP 0x7fadbf4f26e7.
[ 203.313559] RSP: 002b:00007fff6b0e0458 EFLAGS: 00000246 ORIG_RAX: 00000000000000e7
[ 203.313932] RAX: ffffffffffffffda RBX: 00007fadbf5cf9e0 RCX: 00007fadbf4f2711
[ 203.314228] RDX: 000000000000003c RSI: 00000000000000e7 RDI: 0000000000000000
[ 203.314523] RBP: 0000000000000000 R08: ffffffffffffff80 R09: 0000000000000000
[ 203.314821] R10: 00007fadbf3dffa8 R11: 0000000000000246 R12: 00007fadbf5cf9e0
[ 203.315120] R13: 0000000000000000 R14: 00007fadbf5d4ee8 R15: 00007fadbf5d4f00
[ 203.315431] </TASK>
[ 203.315606] Modules linked in: zram zsmalloc xfs libcrc32c
[ 203.315875] ---[ end trace 0000000000000000 ]---
[ 203.315876] RIP: 0010:clear_inode+0x6e/0x80
[ 203.315878] Code: 00 a8 20 74 29 a8 40 75 27 48 8b 93 18 01 00 00 48 8d 83 18 01 00 00 48 39 c2 75 16 48 c7 83 98 00 00 00 60 00 00 00 5b 5d c3 <0f> 0b 0f 0b 0f 0b 0f 0b 0f 0b 0f 1f 84 00 00 00 00 00 0f 1f 44 00
[ 203.315879] RSP: 0018:ffffa49dc07cbde8 EFLAGS: 00010002
[ 203.315880] RAX: 0000000000000000 RBX: ffff8bf4cecc4010 RCX: 0000000000069600
[ 203.315881] RDX: 0000000000000001 RSI: ffffffff929b5b2b RDI: 0000000000000000
[ 203.315881] RBP: ffff8bf4cecc4180 R08: 000003fffffffffe R09: ffffffffffffffc0
[ 203.315882] R10: ffff8bf4ca515ec8 R11: ffffa49dc07cbc68 R12: ffff8bf4cecc4118
[ 203.315883] R13: ffff8bf4cf029a80 R14: ffff8bf4cb2ce900 R15: ffff8bf4c79b8848
[ 203.315884] FS: 0000000000000000(0000) GS:ffff8bf533000000(0000) knlGS:0000000000000000
[ 203.315886] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 203.315887] CR2: 00007fadbf5d3838 CR3: 000000016520c000 CR4: 00000000000006f0
[ 203.315887] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
[ 203.315888] DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
[ 203.315889] note: alloc-instantia[868] exited with preempt_count 1
[ 203.315890] Fixing recursive fault but reboot is needed!
[ 203.315892] BUG: scheduling while atomic: alloc-instantia/868/0x00000000
[ 203.315893] Modules linked in: zram zsmalloc xfs libcrc32c
[ 203.315894] Preemption disabled at:
[ 203.315895] [<0000000000000000>] 0x0
[ 203.315896] CPU: 0 PID: 868 Comm: alloc-instantia Tainted: G D 5.19.0-rc1-next-20220609 #256
[ 203.315898] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.14.0-6.fc35 04/01/2014
[ 203.315898] Call Trace:
[ 203.315900] <TASK>
[ 203.315901] dump_stack_lvl+0x34/0x44
[ 203.315905] __schedule_bug.cold+0x7d/0x8b
[ 203.315907] __schedule+0x624/0x700
[ 203.315908] ? _printk+0x58/0x6f
[ 203.315911] do_task_dead+0x3f/0x50
[ 203.315913] make_task_dead.cold+0x51/0xab
[ 203.315914] rewind_stack_and_make_dead+0x17/0x17
[ 203.315917] RIP: 0033:0x7fadbf4f2711
[ 203.315918] Code: Unable to access opcode bytes at RIP 0x7fadbf4f26e7.
[ 203.315918] RSP: 002b:00007fff6b0e0458 EFLAGS: 00000246 ORIG_RAX: 00000000000000e7
[ 203.315919] RAX: ffffffffffffffda RBX: 00007fadbf5cf9e0 RCX: 00007fadbf4f2711
[ 203.315920] RDX: 000000000000003c RSI: 00000000000000e7 RDI: 0000000000000000
[ 203.315921] RBP: 0000000000000000 R08: ffffffffffffff80 R09: 0000000000000000
[ 203.315921] R10: 00007fadbf3dffa8 R11: 0000000000000246 R12: 00007fadbf5cf9e0
[ 203.315922] R13: 0000000000000000 R14: 00007fadbf5d4ee8 R15: 00007fadbf5d4f00
[ 203.315924] </TASK>
* Bisected the crash to this commit.
To reproduce:
* clone libhugetlbfs:
* Execute, PATH=$PATH:"obj64/" LD_LIBRARY_PATH=../obj64/ alloc-instantiate-race shared
Crashes on both s390 and x86.
Thanks
--
Sumanth
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [f2fs-dev] [PATCH 06/10] hugetlbfs: Convert remove_inode_hugepages() to use filemap_get_folios()
2022-06-10 15:52 ` Sumanth Korikkar
@ 2022-06-10 18:35 ` Gerald Schaefer
2022-06-10 21:17 ` Matthew Wilcox
1 sibling, 0 replies; 33+ messages in thread
From: Gerald Schaefer @ 2022-06-10 18:35 UTC (permalink / raw)
To: willy
Cc: linux-s390, linux-nilfs, gor, linux-kernel, linux-f2fs-devel,
linux-mm, linux-fsdevel, Sumanth Korikkar, linux-ext4, agordeev
On Fri, 10 Jun 2022 17:52:05 +0200
Sumanth Korikkar <sumanthk@linux.ibm.com> wrote:
[...]
>
> * Bisected the crash to this commit.
>
> To reproduce:
> * clone libhugetlbfs:
> * Execute, PATH=$PATH:"obj64/" LD_LIBRARY_PATH=../obj64/ alloc-instantiate-race shared
>
> Crashes on both s390 and x86.
FWIW, not really able to understand the code changes, so I added some
printks to track the state of inode->i_data.nrpages during
remove_inode_hugepages().
Before this commit, we enter with nrpages = 99, and leave with nrpages = 0.
With this commit we enter with nrpages = 99, and leave with nrpages = 84
(i.e. 99 - PAGEVEC_SIZE), resulting in the BUG later in fs/inode.c:612.
The difference seems to be that with this commit, the outer
while(filemap_get_folios) loop is only traversed once, while before
the corresponding while(pagevec_lookup_range) loop was repeated until
nrpages reached 0 (in steps of 15 == PAGEVEC_SIZE for the inner loop).
Both before and after the commit, the pagevec_count / folio_batch_count
for the inner loop starts with 15, but before the pagevec_lookup_range()
also increased &next in steps of 15, while now the filemap_get_folios()
moved &next from 0 to 270 in one step, while still only returning
15 as folio_batch_count for the inner loop. I assume the next index
of 270 is then too big to find any other folios, so it stops after the
first iteration, even though only 15 pages have been processed yet with
remove_huge_page(&folio->page).
I guess it is either wrong to return 15 as folio_batch_count (although
it seems that would be the maximum possible value), or it is wrong to
advance &next by 270 instead of 15.
Hope that makes any sense, and might be of help for debugging, to someone
more familiar with this code.
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [f2fs-dev] [PATCH 06/10] hugetlbfs: Convert remove_inode_hugepages() to use filemap_get_folios()
2022-06-10 15:52 ` Sumanth Korikkar
2022-06-10 18:35 ` Gerald Schaefer
@ 2022-06-10 21:17 ` Matthew Wilcox
2022-06-10 21:56 ` Mike Kravetz
2022-06-13 6:56 ` Sumanth Korikkar
1 sibling, 2 replies; 33+ messages in thread
From: Matthew Wilcox @ 2022-06-10 21:17 UTC (permalink / raw)
To: Sumanth Korikkar
Cc: linux-nilfs, gor, linux-kernel, linux-f2fs-devel, linux-mm,
linux-fsdevel, gerald.schaefer, linux-ext4, agordeev
On Fri, Jun 10, 2022 at 05:52:05PM +0200, Sumanth Korikkar wrote:
> To reproduce:
> * clone libhugetlbfs:
> * Execute, PATH=$PATH:"obj64/" LD_LIBRARY_PATH=../obj64/ alloc-instantiate-race shared
... it's a lot harder to set up hugetlb than that ...
anyway, i figured it out without being able to run the reproducer.
Can you try this?
diff --git a/mm/filemap.c b/mm/filemap.c
index a30587f2e598..8ef861297ffb 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2160,7 +2160,11 @@ unsigned filemap_get_folios(struct address_space *mapping, pgoff_t *start,
if (xa_is_value(folio))
continue;
if (!folio_batch_add(fbatch, folio)) {
- *start = folio->index + folio_nr_pages(folio);
+ unsigned long nr = folio_nr_pages(folio);
+
+ if (folio_test_hugetlb(folio))
+ nr = 1;
+ *start = folio->index + nr;
goto out;
}
}
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 33+ messages in thread* Re: [f2fs-dev] [PATCH 06/10] hugetlbfs: Convert remove_inode_hugepages() to use filemap_get_folios()
2022-06-10 21:17 ` Matthew Wilcox
@ 2022-06-10 21:56 ` Mike Kravetz
2022-06-13 6:56 ` Sumanth Korikkar
1 sibling, 0 replies; 33+ messages in thread
From: Mike Kravetz @ 2022-06-10 21:56 UTC (permalink / raw)
To: Matthew Wilcox, Sumanth Korikkar
Cc: linux-nilfs, gor, linux-kernel, linux-f2fs-devel, linux-mm,
linux-fsdevel, gerald.schaefer, linux-ext4, agordeev
On 6/10/22 14:17, Matthew Wilcox wrote:
> On Fri, Jun 10, 2022 at 05:52:05PM +0200, Sumanth Korikkar wrote:
>> To reproduce:
>> * clone libhugetlbfs:
>> * Execute, PATH=$PATH:"obj64/" LD_LIBRARY_PATH=../obj64/ alloc-instantiate-race shared
>
> ... it's a lot harder to set up hugetlb than that ...
>
> anyway, i figured it out without being able to run the reproducer.
>
> Can you try this?
I can confirm that libhugetlbfs tests do not trigger the BUG with the
below change.
--
Mike Kravetz
>
> diff --git a/mm/filemap.c b/mm/filemap.c
> index a30587f2e598..8ef861297ffb 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -2160,7 +2160,11 @@ unsigned filemap_get_folios(struct address_space *mapping, pgoff_t *start,
> if (xa_is_value(folio))
> continue;
> if (!folio_batch_add(fbatch, folio)) {
> - *start = folio->index + folio_nr_pages(folio);
> + unsigned long nr = folio_nr_pages(folio);
> +
> + if (folio_test_hugetlb(folio))
> + nr = 1;
> + *start = folio->index + nr;
> goto out;
> }
> }
>
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 33+ messages in thread* Re: [f2fs-dev] [PATCH 06/10] hugetlbfs: Convert remove_inode_hugepages() to use filemap_get_folios()
2022-06-10 21:17 ` Matthew Wilcox
2022-06-10 21:56 ` Mike Kravetz
@ 2022-06-13 6:56 ` Sumanth Korikkar
1 sibling, 0 replies; 33+ messages in thread
From: Sumanth Korikkar @ 2022-06-13 6:56 UTC (permalink / raw)
To: Matthew Wilcox
Cc: linux-nilfs, gor, linux-kernel, linux-f2fs-devel, linux-mm,
linux-fsdevel, gerald.schaefer, linux-ext4, agordeev
On Fri, Jun 10, 2022 at 10:17:36PM +0100, Matthew Wilcox wrote:
> On Fri, Jun 10, 2022 at 05:52:05PM +0200, Sumanth Korikkar wrote:
> > To reproduce:
> > * clone libhugetlbfs:
> > * Execute, PATH=$PATH:"obj64/" LD_LIBRARY_PATH=../obj64/ alloc-instantiate-race shared
>
> ... it's a lot harder to set up hugetlb than that ...
>
> anyway, i figured it out without being able to run the reproducer.
>
> Can you try this?
>
> diff --git a/mm/filemap.c b/mm/filemap.c
> index a30587f2e598..8ef861297ffb 100644
> --- a/mm/filemap.c
> +++ b/mm/filemap.c
> @@ -2160,7 +2160,11 @@ unsigned filemap_get_folios(struct address_space *mapping, pgoff_t *start,
> if (xa_is_value(folio))
> continue;
> if (!folio_batch_add(fbatch, folio)) {
> - *start = folio->index + folio_nr_pages(folio);
> + unsigned long nr = folio_nr_pages(folio);
> +
> + if (folio_test_hugetlb(folio))
> + nr = 1;
> + *start = folio->index + nr;
> goto out;
> }
> }
Yes, With the patch, The above tests works fine.
--
Thanks,
Sumanth
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 33+ messages in thread
* [f2fs-dev] [PATCH 07/10] nilfs2: Convert nilfs_copy_back_pages() to use filemap_get_folios()
2022-06-05 19:38 [f2fs-dev] [PATCH 00/10] Convert to filemap_get_folios() Matthew Wilcox (Oracle)
` (5 preceding siblings ...)
2022-06-05 19:38 ` [f2fs-dev] [PATCH 06/10] hugetlbfs: Convert remove_inode_hugepages() " Matthew Wilcox (Oracle)
@ 2022-06-05 19:38 ` Matthew Wilcox (Oracle)
2022-06-07 16:10 ` Ryusuke Konishi
2022-06-08 8:04 ` Christoph Hellwig
2022-06-05 19:38 ` [f2fs-dev] [PATCH 08/10] vmscan: Add check_move_unevictable_folios() Matthew Wilcox (Oracle)
` (3 subsequent siblings)
10 siblings, 2 replies; 33+ messages in thread
From: Matthew Wilcox (Oracle) @ 2022-06-05 19:38 UTC (permalink / raw)
To: linux-fsdevel
Cc: linux-nilfs, linux-kernel, Matthew Wilcox (Oracle),
linux-f2fs-devel, linux-mm, linux-ext4
Use folios throughout.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
fs/nilfs2/page.c | 60 ++++++++++++++++++++++++------------------------
1 file changed, 30 insertions(+), 30 deletions(-)
diff --git a/fs/nilfs2/page.c b/fs/nilfs2/page.c
index a8e88cc38e16..3267e96c256c 100644
--- a/fs/nilfs2/page.c
+++ b/fs/nilfs2/page.c
@@ -294,57 +294,57 @@ int nilfs_copy_dirty_pages(struct address_space *dmap,
void nilfs_copy_back_pages(struct address_space *dmap,
struct address_space *smap)
{
- struct pagevec pvec;
+ struct folio_batch fbatch;
unsigned int i, n;
- pgoff_t index = 0;
+ pgoff_t start = 0;
- pagevec_init(&pvec);
+ folio_batch_init(&fbatch);
repeat:
- n = pagevec_lookup(&pvec, smap, &index);
+ n = filemap_get_folios(smap, &start, ~0UL, &fbatch);
if (!n)
return;
- for (i = 0; i < pagevec_count(&pvec); i++) {
- struct page *page = pvec.pages[i], *dpage;
- pgoff_t offset = page->index;
-
- lock_page(page);
- dpage = find_lock_page(dmap, offset);
- if (dpage) {
- /* overwrite existing page in the destination cache */
- WARN_ON(PageDirty(dpage));
- nilfs_copy_page(dpage, page, 0);
- unlock_page(dpage);
- put_page(dpage);
- /* Do we not need to remove page from smap here? */
+ for (i = 0; i < folio_batch_count(&fbatch); i++) {
+ struct folio *folio = fbatch.folios[i], *dfolio;
+ pgoff_t index = folio->index;
+
+ folio_lock(folio);
+ dfolio = filemap_lock_folio(dmap, index);
+ if (dfolio) {
+ /* overwrite existing folio in the destination cache */
+ WARN_ON(folio_test_dirty(dfolio));
+ nilfs_copy_page(&dfolio->page, &folio->page, 0);
+ folio_unlock(dfolio);
+ folio_put(dfolio);
+ /* Do we not need to remove folio from smap here? */
} else {
- struct page *p;
+ struct folio *f;
- /* move the page to the destination cache */
+ /* move the folio to the destination cache */
xa_lock_irq(&smap->i_pages);
- p = __xa_erase(&smap->i_pages, offset);
- WARN_ON(page != p);
+ f = __xa_erase(&smap->i_pages, index);
+ WARN_ON(folio != f);
smap->nrpages--;
xa_unlock_irq(&smap->i_pages);
xa_lock_irq(&dmap->i_pages);
- p = __xa_store(&dmap->i_pages, offset, page, GFP_NOFS);
- if (unlikely(p)) {
+ f = __xa_store(&dmap->i_pages, index, folio, GFP_NOFS);
+ if (unlikely(f)) {
/* Probably -ENOMEM */
- page->mapping = NULL;
- put_page(page);
+ folio->mapping = NULL;
+ folio_put(folio);
} else {
- page->mapping = dmap;
+ folio->mapping = dmap;
dmap->nrpages++;
- if (PageDirty(page))
- __xa_set_mark(&dmap->i_pages, offset,
+ if (folio_test_dirty(folio))
+ __xa_set_mark(&dmap->i_pages, index,
PAGECACHE_TAG_DIRTY);
}
xa_unlock_irq(&dmap->i_pages);
}
- unlock_page(page);
+ folio_unlock(folio);
}
- pagevec_release(&pvec);
+ folio_batch_release(&fbatch);
cond_resched();
goto repeat;
--
2.35.1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 33+ messages in thread* Re: [f2fs-dev] [PATCH 07/10] nilfs2: Convert nilfs_copy_back_pages() to use filemap_get_folios()
2022-06-05 19:38 ` [f2fs-dev] [PATCH 07/10] nilfs2: Convert nilfs_copy_back_pages() " Matthew Wilcox (Oracle)
@ 2022-06-07 16:10 ` Ryusuke Konishi
2022-06-08 8:04 ` Christoph Hellwig
1 sibling, 0 replies; 33+ messages in thread
From: Ryusuke Konishi @ 2022-06-07 16:10 UTC (permalink / raw)
To: Matthew Wilcox (Oracle)
Cc: linux-nilfs, LKML, linux-f2fs-devel, Linux MM, linux-fsdevel,
linux-ext4
On Mon, Jun 6, 2022 at 1:00 PM Matthew Wilcox (Oracle) wrote:
>
> Use folios throughout.
>
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> ---
> fs/nilfs2/page.c | 60 ++++++++++++++++++++++++------------------------
> 1 file changed, 30 insertions(+), 30 deletions(-)
Throughout, looks good to me. Thank you so much for your great work.
Acked-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Ryusuke Konishi
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [f2fs-dev] [PATCH 07/10] nilfs2: Convert nilfs_copy_back_pages() to use filemap_get_folios()
2022-06-05 19:38 ` [f2fs-dev] [PATCH 07/10] nilfs2: Convert nilfs_copy_back_pages() " Matthew Wilcox (Oracle)
2022-06-07 16:10 ` Ryusuke Konishi
@ 2022-06-08 8:04 ` Christoph Hellwig
1 sibling, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2022-06-08 8:04 UTC (permalink / raw)
To: Matthew Wilcox (Oracle)
Cc: linux-nilfs, linux-kernel, linux-f2fs-devel, linux-mm,
linux-fsdevel, linux-ext4
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 33+ messages in thread
* [f2fs-dev] [PATCH 08/10] vmscan: Add check_move_unevictable_folios()
2022-06-05 19:38 [f2fs-dev] [PATCH 00/10] Convert to filemap_get_folios() Matthew Wilcox (Oracle)
` (6 preceding siblings ...)
2022-06-05 19:38 ` [f2fs-dev] [PATCH 07/10] nilfs2: Convert nilfs_copy_back_pages() " Matthew Wilcox (Oracle)
@ 2022-06-05 19:38 ` Matthew Wilcox (Oracle)
2022-06-08 8:07 ` Christoph Hellwig
2022-06-05 19:38 ` [f2fs-dev] [PATCH 09/10] shmem: Convert shmem_unlock_mapping() to use filemap_get_folios() Matthew Wilcox (Oracle)
` (2 subsequent siblings)
10 siblings, 1 reply; 33+ messages in thread
From: Matthew Wilcox (Oracle) @ 2022-06-05 19:38 UTC (permalink / raw)
To: linux-fsdevel
Cc: linux-nilfs, linux-kernel, Matthew Wilcox (Oracle),
linux-f2fs-devel, linux-mm, linux-ext4
Change the guts of check_move_unevictable_pages() over to use folios
and add check_move_unevictable_pages() as a wrapper.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
include/linux/swap.h | 3 ++-
mm/vmscan.c | 55 ++++++++++++++++++++++++++------------------
2 files changed, 35 insertions(+), 23 deletions(-)
diff --git a/include/linux/swap.h b/include/linux/swap.h
index 0c0fed1b348f..8672a7123ccd 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -438,7 +438,8 @@ static inline bool node_reclaim_enabled(void)
return node_reclaim_mode & (RECLAIM_ZONE|RECLAIM_WRITE|RECLAIM_UNMAP);
}
-extern void check_move_unevictable_pages(struct pagevec *pvec);
+void check_move_unevictable_folios(struct folio_batch *fbatch);
+void check_move_unevictable_pages(struct pagevec *pvec);
extern void kswapd_run(int nid);
extern void kswapd_stop(int nid);
diff --git a/mm/vmscan.c b/mm/vmscan.c
index f7d9a683e3a7..5222c5ad600a 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -4790,45 +4790,56 @@ int node_reclaim(struct pglist_data *pgdat, gfp_t gfp_mask, unsigned int order)
}
#endif
+void check_move_unevictable_pages(struct pagevec *pvec)
+{
+ struct folio_batch fbatch;
+ unsigned i;
+
+ for (i = 0; i < pvec->nr; i++) {
+ struct page *page = pvec->pages[i];
+
+ if (PageTransTail(page))
+ continue;
+ folio_batch_add(&fbatch, page_folio(page));
+ }
+ check_move_unevictable_folios(&fbatch);
+}
+EXPORT_SYMBOL_GPL(check_move_unevictable_pages);
+
/**
- * check_move_unevictable_pages - check pages for evictability and move to
- * appropriate zone lru list
- * @pvec: pagevec with lru pages to check
+ * check_move_unevictable_folios - Move evictable folios to appropriate zone
+ * lru list
+ * @fbatch: Batch of lru folios to check.
*
- * Checks pages for evictability, if an evictable page is in the unevictable
+ * Checks folios for evictability, if an evictable folio is in the unevictable
* lru list, moves it to the appropriate evictable lru list. This function
- * should be only used for lru pages.
+ * should be only used for lru folios.
*/
-void check_move_unevictable_pages(struct pagevec *pvec)
+void check_move_unevictable_folios(struct folio_batch *fbatch)
{
struct lruvec *lruvec = NULL;
int pgscanned = 0;
int pgrescued = 0;
int i;
- for (i = 0; i < pvec->nr; i++) {
- struct page *page = pvec->pages[i];
- struct folio *folio = page_folio(page);
- int nr_pages;
-
- if (PageTransTail(page))
- continue;
+ for (i = 0; i < fbatch->nr; i++) {
+ struct folio *folio = fbatch->folios[i];
+ int nr_pages = folio_nr_pages(folio);
- nr_pages = thp_nr_pages(page);
pgscanned += nr_pages;
- /* block memcg migration during page moving between lru */
- if (!TestClearPageLRU(page))
+ /* block memcg migration while the folio moves between lrus */
+ if (!folio_test_clear_lru(folio))
continue;
lruvec = folio_lruvec_relock_irq(folio, lruvec);
- if (page_evictable(page) && PageUnevictable(page)) {
- del_page_from_lru_list(page, lruvec);
- ClearPageUnevictable(page);
- add_page_to_lru_list(page, lruvec);
+ if (folio_evictable(folio) && folio_test_unevictable(folio)) {
+ lruvec_del_folio(lruvec, folio);
+ folio_clear_unevictable(folio);
+ lruvec_add_folio(lruvec, folio);
pgrescued += nr_pages;
}
- SetPageLRU(page);
+ folio_set_lru(folio);
}
if (lruvec) {
@@ -4839,4 +4850,4 @@ void check_move_unevictable_pages(struct pagevec *pvec)
count_vm_events(UNEVICTABLE_PGSCANNED, pgscanned);
}
}
-EXPORT_SYMBOL_GPL(check_move_unevictable_pages);
+EXPORT_SYMBOL_GPL(check_move_unevictable_folios);
--
2.35.1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 33+ messages in thread* Re: [f2fs-dev] [PATCH 08/10] vmscan: Add check_move_unevictable_folios()
2022-06-05 19:38 ` [f2fs-dev] [PATCH 08/10] vmscan: Add check_move_unevictable_folios() Matthew Wilcox (Oracle)
@ 2022-06-08 8:07 ` Christoph Hellwig
2022-06-08 16:32 ` Matthew Wilcox
0 siblings, 1 reply; 33+ messages in thread
From: Christoph Hellwig @ 2022-06-08 8:07 UTC (permalink / raw)
To: Matthew Wilcox (Oracle)
Cc: linux-nilfs, linux-kernel, linux-f2fs-devel, linux-mm,
linux-fsdevel, linux-ext4
On Sun, Jun 05, 2022 at 08:38:52PM +0100, Matthew Wilcox (Oracle) wrote:
> Change the guts of check_move_unevictable_pages() over to use folios
> and add check_move_unevictable_pages() as a wrapper.
The changes here look fine, but please also add patches for converting
the two callers (which looks mostly trivial to me).
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [f2fs-dev] [PATCH 08/10] vmscan: Add check_move_unevictable_folios()
2022-06-08 8:07 ` Christoph Hellwig
@ 2022-06-08 16:32 ` Matthew Wilcox
2022-06-09 3:56 ` Christoph Hellwig
0 siblings, 1 reply; 33+ messages in thread
From: Matthew Wilcox @ 2022-06-08 16:32 UTC (permalink / raw)
To: Christoph Hellwig
Cc: linux-nilfs, linux-kernel, linux-f2fs-devel, linux-mm,
linux-fsdevel, linux-ext4
On Wed, Jun 08, 2022 at 01:07:32AM -0700, Christoph Hellwig wrote:
> On Sun, Jun 05, 2022 at 08:38:52PM +0100, Matthew Wilcox (Oracle) wrote:
> > Change the guts of check_move_unevictable_pages() over to use folios
> > and add check_move_unevictable_pages() as a wrapper.
>
> The changes here look fine, but please also add patches for converting
> the two callers (which looks mostly trivial to me).
I do want to get rid of pagevecs entirely, but that conversion isn't
going to happen in time for the next merge window. for_each_sgt_page()
is a little intimidating.
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 33+ messages in thread
* Re: [f2fs-dev] [PATCH 08/10] vmscan: Add check_move_unevictable_folios()
2022-06-08 16:32 ` Matthew Wilcox
@ 2022-06-09 3:56 ` Christoph Hellwig
0 siblings, 0 replies; 33+ messages in thread
From: Christoph Hellwig @ 2022-06-09 3:56 UTC (permalink / raw)
To: Matthew Wilcox
Cc: linux-nilfs, linux-kernel, linux-f2fs-devel, Christoph Hellwig,
linux-mm, linux-fsdevel, linux-ext4
On Wed, Jun 08, 2022 at 05:32:34PM +0100, Matthew Wilcox wrote:
> On Wed, Jun 08, 2022 at 01:07:32AM -0700, Christoph Hellwig wrote:
> > On Sun, Jun 05, 2022 at 08:38:52PM +0100, Matthew Wilcox (Oracle) wrote:
> > > Change the guts of check_move_unevictable_pages() over to use folios
> > > and add check_move_unevictable_pages() as a wrapper.
> >
> > The changes here look fine, but please also add patches for converting
> > the two callers (which looks mostly trivial to me).
>
> I do want to get rid of pagevecs entirely, but that conversion isn't
> going to happen in time for the next merge window. for_each_sgt_page()
> is a little intimidating.
for_each_sgt_page, just like other creative scatterlist abuse in the gpu
code is a beast. But, instead of doing a for_each_sgt_page to add
pages to the pagevec and then do a loop over the pagevec to add to
the folio batch it should be pretty trivial to just cut out the
middle man.
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 33+ messages in thread
* [f2fs-dev] [PATCH 09/10] shmem: Convert shmem_unlock_mapping() to use filemap_get_folios()
2022-06-05 19:38 [f2fs-dev] [PATCH 00/10] Convert to filemap_get_folios() Matthew Wilcox (Oracle)
` (7 preceding siblings ...)
2022-06-05 19:38 ` [f2fs-dev] [PATCH 08/10] vmscan: Add check_move_unevictable_folios() Matthew Wilcox (Oracle)
@ 2022-06-05 19:38 ` Matthew Wilcox (Oracle)
2022-06-08 8:08 ` Christoph Hellwig
2022-06-05 19:38 ` [f2fs-dev] [PATCH 10/10] filemap: Remove find_get_pages_range() and associated functions Matthew Wilcox (Oracle)
2022-06-07 11:37 ` [f2fs-dev] [PATCH 00/10] Convert to filemap_get_folios() Christian Brauner
10 siblings, 1 reply; 33+ messages in thread
From: Matthew Wilcox (Oracle) @ 2022-06-05 19:38 UTC (permalink / raw)
To: linux-fsdevel
Cc: linux-nilfs, linux-kernel, Matthew Wilcox (Oracle),
linux-f2fs-devel, linux-mm, linux-ext4
This is a straightforward conversion.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
mm/shmem.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/mm/shmem.c b/mm/shmem.c
index 60fdfc0208fd..313ae7df59d8 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -867,18 +867,17 @@ unsigned long shmem_swap_usage(struct vm_area_struct *vma)
*/
void shmem_unlock_mapping(struct address_space *mapping)
{
- struct pagevec pvec;
+ struct folio_batch fbatch;
pgoff_t index = 0;
- pagevec_init(&pvec);
+ folio_batch_init(&fbatch);
/*
* Minor point, but we might as well stop if someone else SHM_LOCKs it.
*/
- while (!mapping_unevictable(mapping)) {
- if (!pagevec_lookup(&pvec, mapping, &index))
- break;
- check_move_unevictable_pages(&pvec);
- pagevec_release(&pvec);
+ while (!mapping_unevictable(mapping) &&
+ filemap_get_folios(mapping, &index, ~0UL, &fbatch)) {
+ check_move_unevictable_folios(&fbatch);
+ folio_batch_release(&fbatch);
cond_resched();
}
}
--
2.35.1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 33+ messages in thread* [f2fs-dev] [PATCH 10/10] filemap: Remove find_get_pages_range() and associated functions
2022-06-05 19:38 [f2fs-dev] [PATCH 00/10] Convert to filemap_get_folios() Matthew Wilcox (Oracle)
` (8 preceding siblings ...)
2022-06-05 19:38 ` [f2fs-dev] [PATCH 09/10] shmem: Convert shmem_unlock_mapping() to use filemap_get_folios() Matthew Wilcox (Oracle)
@ 2022-06-05 19:38 ` Matthew Wilcox (Oracle)
2022-06-08 8:08 ` Christoph Hellwig
2022-06-07 11:37 ` [f2fs-dev] [PATCH 00/10] Convert to filemap_get_folios() Christian Brauner
10 siblings, 1 reply; 33+ messages in thread
From: Matthew Wilcox (Oracle) @ 2022-06-05 19:38 UTC (permalink / raw)
To: linux-fsdevel
Cc: linux-nilfs, linux-kernel, Matthew Wilcox (Oracle),
linux-f2fs-devel, linux-mm, linux-ext4
All callers of find_get_pages_range(), pagevec_lookup_range() and
pagevec_lookup() have now been removed.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
include/linux/pagemap.h | 3 --
include/linux/pagevec.h | 10 ------
mm/filemap.c | 67 -----------------------------------------
mm/swap.c | 29 ------------------
4 files changed, 109 deletions(-)
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 50e57b2d845f..1caccb9f99aa 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -720,9 +720,6 @@ static inline struct page *find_subpage(struct page *head, pgoff_t index)
unsigned filemap_get_folios(struct address_space *mapping, pgoff_t *start,
pgoff_t end, struct folio_batch *fbatch);
-unsigned find_get_pages_range(struct address_space *mapping, pgoff_t *start,
- pgoff_t end, unsigned int nr_pages,
- struct page **pages);
unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t start,
unsigned int nr_pages, struct page **pages);
unsigned find_get_pages_range_tag(struct address_space *mapping, pgoff_t *index,
diff --git a/include/linux/pagevec.h b/include/linux/pagevec.h
index 67b1246f136b..6649154a2115 100644
--- a/include/linux/pagevec.h
+++ b/include/linux/pagevec.h
@@ -27,16 +27,6 @@ struct pagevec {
void __pagevec_release(struct pagevec *pvec);
void __pagevec_lru_add(struct pagevec *pvec);
-unsigned pagevec_lookup_range(struct pagevec *pvec,
- struct address_space *mapping,
- pgoff_t *start, pgoff_t end);
-static inline unsigned pagevec_lookup(struct pagevec *pvec,
- struct address_space *mapping,
- pgoff_t *start)
-{
- return pagevec_lookup_range(pvec, mapping, start, (pgoff_t)-1);
-}
-
unsigned pagevec_lookup_range_tag(struct pagevec *pvec,
struct address_space *mapping, pgoff_t *index, pgoff_t end,
xa_mark_t tag);
diff --git a/mm/filemap.c b/mm/filemap.c
index ea4145b7a84c..340ccb37f6b6 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -2192,73 +2192,6 @@ bool folio_more_pages(struct folio *folio, pgoff_t index, pgoff_t max)
return index < folio->index + folio_nr_pages(folio) - 1;
}
-/**
- * find_get_pages_range - gang pagecache lookup
- * @mapping: The address_space to search
- * @start: The starting page index
- * @end: The final page index (inclusive)
- * @nr_pages: The maximum number of pages
- * @pages: Where the resulting pages are placed
- *
- * find_get_pages_range() will search for and return a group of up to @nr_pages
- * pages in the mapping starting at index @start and up to index @end
- * (inclusive). The pages are placed at @pages. find_get_pages_range() takes
- * a reference against the returned pages.
- *
- * The search returns a group of mapping-contiguous pages with ascending
- * indexes. There may be holes in the indices due to not-present pages.
- * We also update @start to index the next page for the traversal.
- *
- * Return: the number of pages which were found. If this number is
- * smaller than @nr_pages, the end of specified range has been
- * reached.
- */
-unsigned find_get_pages_range(struct address_space *mapping, pgoff_t *start,
- pgoff_t end, unsigned int nr_pages,
- struct page **pages)
-{
- XA_STATE(xas, &mapping->i_pages, *start);
- struct folio *folio;
- unsigned ret = 0;
-
- if (unlikely(!nr_pages))
- return 0;
-
- rcu_read_lock();
- while ((folio = find_get_entry(&xas, end, XA_PRESENT))) {
- /* Skip over shadow, swap and DAX entries */
- if (xa_is_value(folio))
- continue;
-
-again:
- pages[ret] = folio_file_page(folio, xas.xa_index);
- if (++ret == nr_pages) {
- *start = xas.xa_index + 1;
- goto out;
- }
- if (folio_more_pages(folio, xas.xa_index, end)) {
- xas.xa_index++;
- folio_ref_inc(folio);
- goto again;
- }
- }
-
- /*
- * We come here when there is no page beyond @end. We take care to not
- * overflow the index @start as it confuses some of the callers. This
- * breaks the iteration when there is a page at index -1 but that is
- * already broken anyway.
- */
- if (end == (pgoff_t)-1)
- *start = (pgoff_t)-1;
- else
- *start = end + 1;
-out:
- rcu_read_unlock();
-
- return ret;
-}
-
/**
* find_get_pages_contig - gang contiguous pagecache lookup
* @mapping: The address_space to search
diff --git a/mm/swap.c b/mm/swap.c
index f3922a96b2e9..f65e284247b2 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -1086,35 +1086,6 @@ void folio_batch_remove_exceptionals(struct folio_batch *fbatch)
fbatch->nr = j;
}
-/**
- * pagevec_lookup_range - gang pagecache lookup
- * @pvec: Where the resulting pages are placed
- * @mapping: The address_space to search
- * @start: The starting page index
- * @end: The final page index
- *
- * pagevec_lookup_range() will search for & return a group of up to PAGEVEC_SIZE
- * pages in the mapping starting from index @start and upto index @end
- * (inclusive). The pages are placed in @pvec. pagevec_lookup() takes a
- * reference against the pages in @pvec.
- *
- * The search returns a group of mapping-contiguous pages with ascending
- * indexes. There may be holes in the indices due to not-present pages. We
- * also update @start to index the next page for the traversal.
- *
- * pagevec_lookup_range() returns the number of pages which were found. If this
- * number is smaller than PAGEVEC_SIZE, the end of specified range has been
- * reached.
- */
-unsigned pagevec_lookup_range(struct pagevec *pvec,
- struct address_space *mapping, pgoff_t *start, pgoff_t end)
-{
- pvec->nr = find_get_pages_range(mapping, start, end, PAGEVEC_SIZE,
- pvec->pages);
- return pagevec_count(pvec);
-}
-EXPORT_SYMBOL(pagevec_lookup_range);
-
unsigned pagevec_lookup_range_tag(struct pagevec *pvec,
struct address_space *mapping, pgoff_t *index, pgoff_t end,
xa_mark_t tag)
--
2.35.1
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply related [flat|nested] 33+ messages in thread* Re: [f2fs-dev] [PATCH 00/10] Convert to filemap_get_folios()
2022-06-05 19:38 [f2fs-dev] [PATCH 00/10] Convert to filemap_get_folios() Matthew Wilcox (Oracle)
` (9 preceding siblings ...)
2022-06-05 19:38 ` [f2fs-dev] [PATCH 10/10] filemap: Remove find_get_pages_range() and associated functions Matthew Wilcox (Oracle)
@ 2022-06-07 11:37 ` Christian Brauner
10 siblings, 0 replies; 33+ messages in thread
From: Christian Brauner @ 2022-06-07 11:37 UTC (permalink / raw)
To: Matthew Wilcox (Oracle)
Cc: linux-nilfs, linux-kernel, linux-f2fs-devel, linux-mm,
linux-fsdevel, linux-ext4
On Sun, Jun 05, 2022 at 08:38:44PM +0100, Matthew Wilcox wrote:
> This patch series removes find_get_pages_range(), pagevec_lookup()
> and pagevec_lookup_range(), converting all callers to use the new
> filemap_get_folios(). I've only run xfstests over ext4 ... some other
> testing might be appropriate.
>
> Matthew Wilcox (Oracle) (10):
> filemap: Add filemap_get_folios()
> buffer: Convert clean_bdev_aliases() to use filemap_get_folios()
> ext4: Convert mpage_release_unused_pages() to use filemap_get_folios()
> ext4: Convert mpage_map_and_submit_buffers() to use
> filemap_get_folios()
> f2fs: Convert f2fs_invalidate_compress_pages() to use
> filemap_get_folios()
> hugetlbfs: Convert remove_inode_hugepages() to use
> filemap_get_folios()
> nilfs2: Convert nilfs_copy_back_pages() to use filemap_get_folios()
> vmscan: Add check_move_unevictable_folios()
> shmem: Convert shmem_unlock_mapping() to use filemap_get_folios()
> filemap: Remove find_get_pages_range() and associated functions
>
> fs/buffer.c | 26 +++++++--------
> fs/ext4/inode.c | 40 ++++++++++++-----------
> fs/f2fs/compress.c | 35 +++++++++-----------
> fs/hugetlbfs/inode.c | 44 ++++++++-----------------
> fs/nilfs2/page.c | 60 +++++++++++++++++-----------------
> include/linux/pagemap.h | 5 ++-
> include/linux/pagevec.h | 10 ------
> include/linux/swap.h | 3 +-
> mm/filemap.c | 72 +++++++++++++++++------------------------
> mm/shmem.c | 13 ++++----
> mm/swap.c | 29 -----------------
> mm/vmscan.c | 55 ++++++++++++++++++-------------
> 12 files changed, 166 insertions(+), 226 deletions(-)
The conversion seems fairly straightforward, so looks good to me.
Acked-by: Christian Brauner (Microsoft) <brauner@kernel.org>
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
^ permalink raw reply [flat|nested] 33+ messages in thread