Skip to contentSkip to conversation

Convert to filemap_get_folios_contig()

PATCH Superseded Vishal Moola (Oracle) 3 participants 11 messages Aug 15, 2022 – Aug 16, 2022

Subsystems (5)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Convert to filemap_get_folios_contig()

This patch series replaces find_get_pages_contig() with filemap_get_folios_contig(). I've run xfstests on btrfs. I've also tested the ramfs changes. I ran some xfstests on nilfs2, and its seemingly fine although more testing may be beneficial.

Vishal Moola (Oracle) (7):
filemap: Add filemap_get_folios_contig()
btrfs: Convert __process_pages_contig() to use
filemap_get_folios_contig()
btrfs: Convert end_compressed_writeback() to use filemap_get_folios()
btrfs: Convert process_page_range() to use filemap_get_folios_contig()
nilfs2: Convert nilfs_find_uncommited_extent() to use
filemap_get_folios_contig()
ramfs: Convert ramfs_nommu_get_unmapped_area() to use
filemap_get_folios_contig()
filemap: Remove find_get_pages_contig()

 fs/btrfs/compression.c           | 26 ++++++------
 fs/btrfs/extent_io.c             | 33 +++++++--------
 fs/btrfs/subpage.c               |  2 +-
 fs/btrfs/tests/extent-io-tests.c | 31 +++++++-------
 fs/nilfs2/page.c                 | 38 ++++++++---------
 fs/ramfs/file-nommu.c            | 50 ++++++++++++----------
 include/linux/pagemap.h          |  4 +-
 mm/filemap.c                     | 71 +++++++++++++++++++-------------
 8 files changed, 134 insertions(+), 121 deletions(-)
Signature · 1 line
2.36.1
#1 lore raw

PATCH 1/7 filemap: Add filemap_get_folios_contig()

This function is meant to replace find_get_pages_contig().

Unlike find_get_pages_contig(), filemap_get_folios_contig() no longer takes in a target number of pages to find - It returns up to 15 contiguous folios.

To be more consistent with filemap_get_folios(), filemap_get_folios_contig() now also updates the start index passed in, and takes an end index.

---
 include/linux/pagemap.h |  2 ++
 mm/filemap.c            | 73 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+)
include/linux/pagemap.h +2 -0
index 0178b2040ea3..8689c32d628b 100644
@@ -718,6 +718,8 @@ 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 filemap_get_folios_contig(struct address_space *mapping,
+		pgoff_t *start, pgoff_t end, struct folio_batch *fbatch);
 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,
mm/filemap.c +73 -0

79 lines not on this page · raw message

Signature · 1 line
2.36.1
#2 lore raw

PATCH 2/7 btrfs: Convert __process_pages_contig() to use filemap_get_folios_contig()

In reply to Vishal Moola (Oracle)

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

Since we may receive more than nr_pages pages, nr_pages may underflow. Since nr_pages > 0 is equivalent to index <= end_index, we replaced it with this check instead.

---
 fs/btrfs/extent_io.c | 33 +++++++++++++++------------------
 1 file changed, 15 insertions(+), 18 deletions(-)
fs/btrfs/extent_io.c +15 -18
index bfae67c593c5..2c2f0e281014 100644
@@ -1900,9 +1900,8 @@ static int __process_pages_contig(struct address_space *mapping,
 	pgoff_t start_index = start >> PAGE_SHIFT;
 	pgoff_t end_index = end >> PAGE_SHIFT;
 	pgoff_t index = start_index;
-	unsigned long nr_pages = end_index - start_index + 1;
 	unsigned long pages_processed = 0;
-	struct page *pages[16];
+	struct folio_batch fbatch;
 	int err = 0;
 	int i;
 
@@ -1911,16 +1910,17 @@ static int __process_pages_contig(struct address_space *mapping,
 		ASSERT(processed_end && *processed_end == start);
 	}
 
-	if ((page_ops & PAGE_SET_ERROR) && nr_pages > 0)
+	if ((page_ops & PAGE_SET_ERROR) && start_index <= end_index)
 		mapping_set_error(mapping, -EIO);
 
-	while (nr_pages > 0) {
-		int found_pages;
+	folio_batch_init(&fbatch);
+	while (index <= end_index) {
+		int found_folios;
+
+		found_folios = filemap_get_folios_contig(mapping, &index,
+				end_index, &fbatch);
 
-		found_pages = find_get_pages_contig(mapping, index,
-				     min_t(unsigned long,
-				     nr_pages, ARRAY_SIZE(pages)), pages);
-		if (found_pages == 0) {
+		if (found_folios == 0) {
 			/*
 			 * Only if we're going to lock these pages, we can find
 			 * nothing at @index.
@@ -1930,23 +1930,20 @@ static int __process_pages_contig(struct address_space *mapping,
 			goto out;
 		}
 
-		for (i = 0; i < found_pages; i++) {
+		for (i = 0; i < found_folios; i++) {
 			int process_ret;
-
+			struct folio *folio = fbatch.folios[i];
 			process_ret = process_one_page(fs_info, mapping,
-					pages[i], locked_page, page_ops,
+					&folio->page, locked_page, page_ops,
 					start, end);
 			if (process_ret < 0) {
-				for (; i < found_pages; i++)
-					put_page(pages[i]);
 				err = -EAGAIN;
+				folio_batch_release(&fbatch);
 				goto out;
 			}
-			put_page(pages[i]);
-			pages_processed++;
+			pages_processed += folio_nr_pages(folio);
 		}
-		nr_pages -= found_pages;
-		index += found_pages;
+		folio_batch_release(&fbatch);
 		cond_resched();
 	}
 out:
Signature · 1 line
2.36.1
#3 lore raw

PATCH 3/7 btrfs: Convert end_compressed_writeback() to use filemap_get_folios()

In reply to Vishal Moola (Oracle)

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

Since we may receive more than nr_pages pages, nr_pages may underflow. Since nr_pages > 0 is equivalent to index <= end_index, we replaced it with this check instead.

Also this function does not care about the pages being contiguous so we can just use filemap_get_folios() to be more efficient.

---
 fs/btrfs/compression.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)
fs/btrfs/compression.c +12 -14
index e84d22c5c6a8..d4ebef60b3ce 100644
@@ -8,6 +8,7 @@
 #include <linux/file.h>
 #include <linux/fs.h>
 #include <linux/pagemap.h>
+#include <linux/pagevec.h>
 #include <linux/highmem.h>
 #include <linux/kthread.h>
 #include <linux/time.h>
@@ -222,8 +223,7 @@ static noinline void end_compressed_writeback(struct inode *inode,
 	struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
 	unsigned long index = cb->start >> PAGE_SHIFT;
 	unsigned long end_index = (cb->start + cb->len - 1) >> PAGE_SHIFT;
-	struct page *pages[16];
-	unsigned long nr_pages = end_index - index + 1;
+	struct folio_batch fbatch;
 	const int errno = blk_status_to_errno(cb->status);
 	int i;
 	int ret;
@@ -231,24 +231,22 @@ static noinline void end_compressed_writeback(struct inode *inode,
 	if (errno)
 		mapping_set_error(inode->i_mapping, errno);
 
-	while (nr_pages > 0) {
-		ret = find_get_pages_contig(inode->i_mapping, index,
-				     min_t(unsigned long,
-				     nr_pages, ARRAY_SIZE(pages)), pages);
+	folio_batch_init(&fbatch);
+	while (index <= end_index) {
+		ret = filemap_get_folios(inode->i_mapping, &index, end_index,
+				&fbatch);
+
 		if (ret == 0) {
-			nr_pages -= 1;
-			index += 1;
-			continue;
+			return;
 		}
 		for (i = 0; i < ret; i++) {
+			struct folio *folio = fbatch.folios[i];
 			if (errno)
-				SetPageError(pages[i]);
-			btrfs_page_clamp_clear_writeback(fs_info, pages[i],
+				folio_set_error(folio);
+			btrfs_page_clamp_clear_writeback(fs_info, &folio->page,
 							 cb->start, cb->len);
-			put_page(pages[i]);
 		}
-		nr_pages -= ret;
-		index += ret;
+		folio_batch_release(&fbatch);
 	}
 	/* the inode may be gone now */
 }
Signature · 1 line
2.36.1
#4 lore raw

PATCH 4/7 btrfs: Convert process_page_range() to use filemap_get_folios_contig()

In reply to Vishal Moola (Oracle)

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

Since we may receive more than nr_pages pages, nr_pages may underflow. Since nr_pages > 0 is equivalent to index <= end_index, we replaced it with this check instead.

Also minor comment renaming for consistency in subpage.

---
 fs/btrfs/subpage.c               |  2 +-
 fs/btrfs/tests/extent-io-tests.c | 31 ++++++++++++++++---------------
 2 files changed, 17 insertions(+), 16 deletions(-)
fs/btrfs/subpage.c +1 -1
index 6fc2b77ae5c3..9a176af847d7 100644
@@ -337,7 +337,7 @@ bool btrfs_subpage_end_and_test_writer(const struct btrfs_fs_info *fs_info,
  *
  * Even with 0 returned, the page still need extra check to make sure
  * it's really the correct page, as the caller is using
- * find_get_pages_contig(), which can race with page invalidating.
+ * filemap_get_folios_contig(), which can race with page invalidating.
  */
 int btrfs_page_start_writer_lock(const struct btrfs_fs_info *fs_info,
 		struct page *page, u64 start, u32 len)
fs/btrfs/tests/extent-io-tests.c +16 -15
index a232b15b8021..530073868916 100644
@@ -4,6 +4,7 @@
  */
 
 #include <linux/pagemap.h>
+#include <linux/pagevec.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/sizes.h>
@@ -20,39 +21,39 @@ static noinline int process_page_range(struct inode *inode, u64 start, u64 end,
 				       unsigned long flags)
 {
 	int ret;
-	struct page *pages[16];
+	struct folio_batch fbatch;
 	unsigned long index = start >> PAGE_SHIFT;
 	unsigned long end_index = end >> PAGE_SHIFT;
-	unsigned long nr_pages = end_index - index + 1;
 	int i;
 	int count = 0;
 	int loops = 0;
 
-	while (nr_pages > 0) {
-		ret = find_get_pages_contig(inode->i_mapping, index,
-				     min_t(unsigned long, nr_pages,
-				     ARRAY_SIZE(pages)), pages);
+	folio_batch_init(&fbatch);
+
+	while (index <= end_index) {
+		ret = filemap_get_folios_contig(inode->i_mapping, &index,
+				end_index, &fbatch);
 		for (i = 0; i < ret; i++) {
+			struct folio *folio = fbatch.folios[i];
 			if (flags & PROCESS_TEST_LOCKED &&
-			    !PageLocked(pages[i]))
+			    !folio_test_locked(folio))
 				count++;
-			if (flags & PROCESS_UNLOCK && PageLocked(pages[i]))
-				unlock_page(pages[i]);
-			put_page(pages[i]);
+			if (flags & PROCESS_UNLOCK && folio_test_locked(folio))
+				folio_unlock(folio);
 			if (flags & PROCESS_RELEASE)
-				put_page(pages[i]);
+				folio_put(folio);
 		}
-		nr_pages -= ret;
-		index += ret;
+		folio_batch_release(&fbatch);
 		cond_resched();
 		loops++;
 		if (loops > 100000) {
 			printk(KERN_ERR
-		"stuck in a loop, start %llu, end %llu, nr_pages %lu, ret %d\n",
-				start, end, nr_pages, ret);
+		"stuck in a loop, start %llu, end %llu, ret %d\n",
+				start, end, ret);
 			break;
 		}
 	}
+
 	return count;
 }
 
Signature · 1 line
2.36.1
#5 lore raw

PATCH 5/7 nilfs2: Convert nilfs_find_uncommited_extent() to use filemap_get_folios_contig()

In reply to Vishal Moola (Oracle)

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.

---
 fs/nilfs2/page.c | 38 +++++++++++++++++---------------------
 1 file changed, 17 insertions(+), 21 deletions(-)
fs/nilfs2/page.c +17 -21
index 3267e96c256c..40cc8eb0bc8e 100644
@@ -480,13 +480,13 @@ 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;
@@ -494,27 +494,24 @@ unsigned long nilfs_find_uncommitted_extent(struct inode *inode,
 	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;
@@ -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;
 }
Signature · 1 line
2.36.1
#6 lore raw

Re: [PATCH 5/7] nilfs2: Convert nilfs_find_uncommited_extent() to use filemap_get_folios_contig()

Thank you for the patch! Perhaps something to improve:

Hi "Vishal,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.0-rc1 next-20220815]
[cannot apply to kdave/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Vishal-Moola-Oracle/Convert-to-filemap_get_folios_contig/20220816-025830
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 568035b01cfb107af8d2e4bd2fb9aea22cf5b868
config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20220816/[email protected]/config)
compiler: gcc-11 (Debian 11.3.0-5) 11.3.0
reproduce (this is a W=1 build):
        # https://github.com/intel-lab-lkp/linux/commit/ce1966344933bbe10010035cd25f23ec7dd76914
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Vishal-Moola-Oracle/Convert-to-filemap_get_folios_contig/20220816-025830
        git checkout ce1966344933bbe10010035cd25f23ec7dd76914
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash fs/nilfs2/

If you fix the issue, kindly add following tag where applicable

All warnings (new ones prefixed by >>):

fs/nilfs2/page.c: In function 'nilfs_find_uncommitted_extent':

>> fs/nilfs2/page.c:542:1: warning: label 'out' defined but not used [-Wunused-label]
     542 | out:
         | ^~~

vim +/out +542 fs/nilfs2/page.c

622daaff0a8975 Ryusuke Konishi       2010-12-26  466  
622daaff0a8975 Ryusuke Konishi       2010-12-26  467  /**
622daaff0a8975 Ryusuke Konishi       2010-12-26  468   * nilfs_find_uncommitted_extent - find extent of uncommitted data
622daaff0a8975 Ryusuke Konishi       2010-12-26  469   * @inode: inode
622daaff0a8975 Ryusuke Konishi       2010-12-26  470   * @start_blk: start block offset (in)
622daaff0a8975 Ryusuke Konishi       2010-12-26  471   * @blkoff: start offset of the found extent (out)
622daaff0a8975 Ryusuke Konishi       2010-12-26  472   *
622daaff0a8975 Ryusuke Konishi       2010-12-26  473   * This function searches an extent of buffers marked "delayed" which
622daaff0a8975 Ryusuke Konishi       2010-12-26  474   * starts from a block offset equal to or larger than @start_blk.  If
622daaff0a8975 Ryusuke Konishi       2010-12-26  475   * such an extent was found, this will store the start offset in
622daaff0a8975 Ryusuke Konishi       2010-12-26  476   * @blkoff and return its length in blocks.  Otherwise, zero is
622daaff0a8975 Ryusuke Konishi       2010-12-26  477   * returned.
622daaff0a8975 Ryusuke Konishi       2010-12-26  478   */
622daaff0a8975 Ryusuke Konishi       2010-12-26  479  unsigned long nilfs_find_uncommitted_extent(struct inode *inode,
622daaff0a8975 Ryusuke Konishi       2010-12-26  480  					    sector_t start_blk,
622daaff0a8975 Ryusuke Konishi       2010-12-26  481  					    sector_t *blkoff)
622daaff0a8975 Ryusuke Konishi       2010-12-26  482  {
ce1966344933bb Vishal Moola (Oracle  2022-08-15  483) 	unsigned int i, nr;
622daaff0a8975 Ryusuke Konishi       2010-12-26  484  	pgoff_t index;
622daaff0a8975 Ryusuke Konishi       2010-12-26  485  	unsigned int nblocks_in_page;
622daaff0a8975 Ryusuke Konishi       2010-12-26  486  	unsigned long length = 0;
622daaff0a8975 Ryusuke Konishi       2010-12-26  487  	sector_t b;
ce1966344933bb Vishal Moola (Oracle  2022-08-15  488) 	struct folio_batch fbatch;
ce1966344933bb Vishal Moola (Oracle  2022-08-15  489) 	struct folio *folio;
622daaff0a8975 Ryusuke Konishi       2010-12-26  490  
622daaff0a8975 Ryusuke Konishi       2010-12-26  491  	if (inode->i_mapping->nrpages == 0)
622daaff0a8975 Ryusuke Konishi       2010-12-26  492  		return 0;
622daaff0a8975 Ryusuke Konishi       2010-12-26  493  
09cbfeaf1a5a67 Kirill A. Shutemov    2016-04-01  494  	index = start_blk >> (PAGE_SHIFT - inode->i_blkbits);
09cbfeaf1a5a67 Kirill A. Shutemov    2016-04-01  495  	nblocks_in_page = 1U << (PAGE_SHIFT - inode->i_blkbits);
622daaff0a8975 Ryusuke Konishi       2010-12-26  496  
ce1966344933bb Vishal Moola (Oracle  2022-08-15  497) 	folio_batch_init(&fbatch);
622daaff0a8975 Ryusuke Konishi       2010-12-26  498  
622daaff0a8975 Ryusuke Konishi       2010-12-26  499  repeat:
ce1966344933bb Vishal Moola (Oracle  2022-08-15  500) 	nr = filemap_get_folios_contig(inode->i_mapping, &index, ULONG_MAX,
ce1966344933bb Vishal Moola (Oracle  2022-08-15  501) 			&fbatch);
ce1966344933bb Vishal Moola (Oracle  2022-08-15  502) 	if (nr == 0)
622daaff0a8975 Ryusuke Konishi       2010-12-26  503  		return length;
622daaff0a8975 Ryusuke Konishi       2010-12-26  504  
ce1966344933bb Vishal Moola (Oracle  2022-08-15  505) 	b = fbatch.folios[0]->index << (PAGE_SHIFT - inode->i_blkbits);
622daaff0a8975 Ryusuke Konishi       2010-12-26  506  	i = 0;
622daaff0a8975 Ryusuke Konishi       2010-12-26  507  	do {
ce1966344933bb Vishal Moola (Oracle  2022-08-15  508) 		folio = fbatch.folios[i];
622daaff0a8975 Ryusuke Konishi       2010-12-26  509  
ce1966344933bb Vishal Moola (Oracle  2022-08-15  510) 		folio_lock(folio);
ce1966344933bb Vishal Moola (Oracle  2022-08-15  511) 		if (folio_buffers(folio)) {
622daaff0a8975 Ryusuke Konishi       2010-12-26  512  			struct buffer_head *bh, *head;
622daaff0a8975 Ryusuke Konishi       2010-12-26  513  
ce1966344933bb Vishal Moola (Oracle  2022-08-15  514) 			bh = head = folio_buffers(folio);
622daaff0a8975 Ryusuke Konishi       2010-12-26  515  			do {
622daaff0a8975 Ryusuke Konishi       2010-12-26  516  				if (b < start_blk)
622daaff0a8975 Ryusuke Konishi       2010-12-26  517  					continue;
622daaff0a8975 Ryusuke Konishi       2010-12-26  518  				if (buffer_delay(bh)) {
622daaff0a8975 Ryusuke Konishi       2010-12-26  519  					if (length == 0)
622daaff0a8975 Ryusuke Konishi       2010-12-26  520  						*blkoff = b;
622daaff0a8975 Ryusuke Konishi       2010-12-26  521  					length++;
622daaff0a8975 Ryusuke Konishi       2010-12-26  522  				} else if (length > 0) {
622daaff0a8975 Ryusuke Konishi       2010-12-26  523  					goto out_locked;
622daaff0a8975 Ryusuke Konishi       2010-12-26  524  				}
622daaff0a8975 Ryusuke Konishi       2010-12-26  525  			} while (++b, bh = bh->b_this_page, bh != head);
622daaff0a8975 Ryusuke Konishi       2010-12-26  526  		} else {
622daaff0a8975 Ryusuke Konishi       2010-12-26  527  			if (length > 0)
622daaff0a8975 Ryusuke Konishi       2010-12-26  528  				goto out_locked;
622daaff0a8975 Ryusuke Konishi       2010-12-26  529  
622daaff0a8975 Ryusuke Konishi       2010-12-26  530  			b += nblocks_in_page;
622daaff0a8975 Ryusuke Konishi       2010-12-26  531  		}
ce1966344933bb Vishal Moola (Oracle  2022-08-15  532) 		folio_unlock(folio);
622daaff0a8975 Ryusuke Konishi       2010-12-26  533  
ce1966344933bb Vishal Moola (Oracle  2022-08-15  534) 	} while (++i < nr);
622daaff0a8975 Ryusuke Konishi       2010-12-26  535  
ce1966344933bb Vishal Moola (Oracle  2022-08-15  536) 	folio_batch_release(&fbatch);
622daaff0a8975 Ryusuke Konishi       2010-12-26  537  	cond_resched();
622daaff0a8975 Ryusuke Konishi       2010-12-26  538  	goto repeat;
622daaff0a8975 Ryusuke Konishi       2010-12-26  539  
622daaff0a8975 Ryusuke Konishi       2010-12-26  540  out_locked:
ce1966344933bb Vishal Moola (Oracle  2022-08-15  541) 	folio_unlock(folio);
622daaff0a8975 Ryusuke Konishi       2010-12-26 @542  out:
Signature · 2 lines
0-DAY CI Kernel Test Service
https://01.org/lkp
#7 lore raw

Re: [PATCH 5/7] nilfs2: Convert nilfs_find_uncommited_extent() to use filemap_get_folios_contig()

In reply to Vishal Moola (Oracle)
Thank you for the patch! Perhaps something to improve:

Hi "Vishal,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.0-rc1 next-20220815]
[cannot apply to kdave/for-next konis-nilfs2/upstream]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Vishal-Moola-Oracle/Convert-to-filemap_get_folios_contig/20220816-025830
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 568035b01cfb107af8d2e4bd2fb9aea22cf5b868
config: s390-randconfig-r044-20220815 (https://download.01.org/0day-ci/archive/20220816/202208161010.5ZmABhnS-lkp-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org/config)
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 6afcc4a459ead8809a0d6d9b4bf7b64bcc13582b)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install s390 cross compiling tool for clang build
# apt-get install binutils-s390x-linux-gnu
# https://github.com/intel-lab-lkp/linux/commit/ce1966344933bbe10010035cd25f23ec7dd76914
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Vishal-Moola-Oracle/Convert-to-filemap_get_folios_contig/20220816-025830 git checkout ce1966344933bbe10010035cd25f23ec7dd76914
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=s390 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable

All warnings (new ones prefixed by >>):

>> fs/nilfs2/page.c:542:1: warning: unused label 'out' [-Wunused-label]

out:
^~~~
1 warning generated.

vim +/out +542 fs/nilfs2/page.c

622daaff0a8975 Ryusuke Konishi       2010-12-26  466  
622daaff0a8975 Ryusuke Konishi       2010-12-26  467  /**
622daaff0a8975 Ryusuke Konishi       2010-12-26  468   * nilfs_find_uncommitted_extent - find extent of uncommitted data
622daaff0a8975 Ryusuke Konishi       2010-12-26  469   * @inode: inode
622daaff0a8975 Ryusuke Konishi       2010-12-26  470   * @start_blk: start block offset (in)
622daaff0a8975 Ryusuke Konishi       2010-12-26  471   * @blkoff: start offset of the found extent (out)
622daaff0a8975 Ryusuke Konishi       2010-12-26  472   *
622daaff0a8975 Ryusuke Konishi       2010-12-26  473   * This function searches an extent of buffers marked "delayed" which
622daaff0a8975 Ryusuke Konishi       2010-12-26  474   * starts from a block offset equal to or larger than @start_blk.  If
622daaff0a8975 Ryusuke Konishi       2010-12-26  475   * such an extent was found, this will store the start offset in
622daaff0a8975 Ryusuke Konishi       2010-12-26  476   * @blkoff and return its length in blocks.  Otherwise, zero is
622daaff0a8975 Ryusuke Konishi       2010-12-26  477   * returned.
622daaff0a8975 Ryusuke Konishi       2010-12-26  478   */
622daaff0a8975 Ryusuke Konishi       2010-12-26  479  unsigned long nilfs_find_uncommitted_extent(struct inode *inode,
622daaff0a8975 Ryusuke Konishi       2010-12-26  480  					    sector_t start_blk,
622daaff0a8975 Ryusuke Konishi       2010-12-26  481  					    sector_t *blkoff)
622daaff0a8975 Ryusuke Konishi       2010-12-26  482  {
ce1966344933bb Vishal Moola (Oracle  2022-08-15  483) 	unsigned int i, nr;
622daaff0a8975 Ryusuke Konishi       2010-12-26  484  	pgoff_t index;
622daaff0a8975 Ryusuke Konishi       2010-12-26  485  	unsigned int nblocks_in_page;
622daaff0a8975 Ryusuke Konishi       2010-12-26  486  	unsigned long length = 0;
622daaff0a8975 Ryusuke Konishi       2010-12-26  487  	sector_t b;
ce1966344933bb Vishal Moola (Oracle  2022-08-15  488) 	struct folio_batch fbatch;
ce1966344933bb Vishal Moola (Oracle  2022-08-15  489) 	struct folio *folio;
622daaff0a8975 Ryusuke Konishi       2010-12-26  490  
622daaff0a8975 Ryusuke Konishi       2010-12-26  491  	if (inode->i_mapping->nrpages == 0)
622daaff0a8975 Ryusuke Konishi       2010-12-26  492  		return 0;
622daaff0a8975 Ryusuke Konishi       2010-12-26  493  
09cbfeaf1a5a67 Kirill A. Shutemov    2016-04-01  494  	index = start_blk >> (PAGE_SHIFT - inode->i_blkbits);
09cbfeaf1a5a67 Kirill A. Shutemov    2016-04-01  495  	nblocks_in_page = 1U << (PAGE_SHIFT - inode->i_blkbits);
622daaff0a8975 Ryusuke Konishi       2010-12-26  496  
ce1966344933bb Vishal Moola (Oracle  2022-08-15  497) 	folio_batch_init(&fbatch);
622daaff0a8975 Ryusuke Konishi       2010-12-26  498  
622daaff0a8975 Ryusuke Konishi       2010-12-26  499  repeat:
ce1966344933bb Vishal Moola (Oracle  2022-08-15  500) 	nr = filemap_get_folios_contig(inode->i_mapping, &index, ULONG_MAX,
ce1966344933bb Vishal Moola (Oracle  2022-08-15  501) 			&fbatch);
ce1966344933bb Vishal Moola (Oracle  2022-08-15  502) 	if (nr == 0)
622daaff0a8975 Ryusuke Konishi       2010-12-26  503  		return length;
622daaff0a8975 Ryusuke Konishi       2010-12-26  504  
ce1966344933bb Vishal Moola (Oracle  2022-08-15  505) 	b = fbatch.folios[0]->index << (PAGE_SHIFT - inode->i_blkbits);
622daaff0a8975 Ryusuke Konishi       2010-12-26  506  	i = 0;
622daaff0a8975 Ryusuke Konishi       2010-12-26  507  	do {
ce1966344933bb Vishal Moola (Oracle  2022-08-15  508) 		folio = fbatch.folios[i];
622daaff0a8975 Ryusuke Konishi       2010-12-26  509  
ce1966344933bb Vishal Moola (Oracle  2022-08-15  510) 		folio_lock(folio);
ce1966344933bb Vishal Moola (Oracle  2022-08-15  511) 		if (folio_buffers(folio)) {
622daaff0a8975 Ryusuke Konishi       2010-12-26  512  			struct buffer_head *bh, *head;
622daaff0a8975 Ryusuke Konishi       2010-12-26  513  
ce1966344933bb Vishal Moola (Oracle  2022-08-15  514) 			bh = head = folio_buffers(folio);
622daaff0a8975 Ryusuke Konishi       2010-12-26  515  			do {
622daaff0a8975 Ryusuke Konishi       2010-12-26  516  				if (b < start_blk)
622daaff0a8975 Ryusuke Konishi       2010-12-26  517  					continue;
622daaff0a8975 Ryusuke Konishi       2010-12-26  518  				if (buffer_delay(bh)) {
622daaff0a8975 Ryusuke Konishi       2010-12-26  519  					if (length == 0)
622daaff0a8975 Ryusuke Konishi       2010-12-26  520  						*blkoff = b;
622daaff0a8975 Ryusuke Konishi       2010-12-26  521  					length++;
622daaff0a8975 Ryusuke Konishi       2010-12-26  522  				} else if (length > 0) {
622daaff0a8975 Ryusuke Konishi       2010-12-26  523  					goto out_locked;
622daaff0a8975 Ryusuke Konishi       2010-12-26  524  				}
622daaff0a8975 Ryusuke Konishi       2010-12-26  525  			} while (++b, bh = bh->b_this_page, bh != head);
622daaff0a8975 Ryusuke Konishi       2010-12-26  526  		} else {
622daaff0a8975 Ryusuke Konishi       2010-12-26  527  			if (length > 0)
622daaff0a8975 Ryusuke Konishi       2010-12-26  528  				goto out_locked;
622daaff0a8975 Ryusuke Konishi       2010-12-26  529  
622daaff0a8975 Ryusuke Konishi       2010-12-26  530  			b += nblocks_in_page;
622daaff0a8975 Ryusuke Konishi       2010-12-26  531  		}
ce1966344933bb Vishal Moola (Oracle  2022-08-15  532) 		folio_unlock(folio);
622daaff0a8975 Ryusuke Konishi       2010-12-26  533  
ce1966344933bb Vishal Moola (Oracle  2022-08-15  534) 	} while (++i < nr);
622daaff0a8975 Ryusuke Konishi       2010-12-26  535  
ce1966344933bb Vishal Moola (Oracle  2022-08-15  536) 	folio_batch_release(&fbatch);
622daaff0a8975 Ryusuke Konishi       2010-12-26  537  	cond_resched();
622daaff0a8975 Ryusuke Konishi       2010-12-26  538  	goto repeat;
622daaff0a8975 Ryusuke Konishi       2010-12-26  539  
622daaff0a8975 Ryusuke Konishi       2010-12-26  540  out_locked:
ce1966344933bb Vishal Moola (Oracle  2022-08-15  541) 	folio_unlock(folio);
622daaff0a8975 Ryusuke Konishi       2010-12-26 @542  out:
Signature · 2 lines
0-DAY CI Kernel Test Service
https://01.org/lkp
#8 lore raw

PATCH 6/7 ramfs: Convert ramfs_nommu_get_unmapped_area() to use filemap_get_folios_contig()

In reply to Vishal Moola (Oracle)

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

The initial version of this function set the page_address to be returned after finishing all the checks. Since folio_batches have a maximum of 15 folios, the function had to be modified to support getting and checking up to lpages, 15 pages at a time while still returning the initial page address. Now the function sets ret as soon as the first batch arrives, and updates it only if a check fails.

The physical adjacency check utilizes the page frame numbers. The page frame number of each folio must be nr_pages away from the first folio.

---
 fs/ramfs/file-nommu.c | 50 +++++++++++++++++++++++++------------------
 1 file changed, 29 insertions(+), 21 deletions(-)
fs/ramfs/file-nommu.c +29 -21
index ba3525ccc27e..81817f301e17 100644
@@ -203,9 +203,9 @@ static unsigned long ramfs_nommu_get_unmapped_area(struct file *file,
 					    unsigned long addr, unsigned long len,
 					    unsigned long pgoff, unsigned long flags)
 {
-	unsigned long maxpages, lpages, nr, loop, ret;
+	unsigned long maxpages, lpages, nr, loop, ret, nr_pages, pfn;
 	struct inode *inode = file_inode(file);
-	struct page **pages = NULL, **ptr, *page;
+	struct folio_batch fbatch;
 	loff_t isize;
 
 	/* the mapping mustn't extend beyond the EOF */
@@ -221,31 +221,39 @@ static unsigned long ramfs_nommu_get_unmapped_area(struct file *file,
 		goto out;
 
 	/* gang-find the pages */
-	pages = kcalloc(lpages, sizeof(struct page *), GFP_KERNEL);
-	if (!pages)
-		goto out_free;
-
-	nr = find_get_pages_contig(inode->i_mapping, pgoff, lpages, pages);
-	if (nr != lpages)
-		goto out_free_pages; /* leave if some pages were missing */
+	folio_batch_init(&fbatch);
+	nr_pages = 0;
+repeat:
+	nr = filemap_get_folios_contig(inode->i_mapping, &pgoff,
+			ULONG_MAX, &fbatch);
+	if (!nr) {
+		ret = -ENOSYS;
+		return ret;
+	}
 
+	if (ret == -ENOSYS) {
+		ret = (unsigned long) folio_address(fbatch.folios[0]);
+		pfn = folio_pfn(fbatch.folios[0]);
+	}
 	/* check the pages for physical adjacency */
-	ptr = pages;
-	page = *ptr++;
-	page++;
-	for (loop = lpages; loop > 1; loop--)
-		if (*ptr++ != page++)
-			goto out_free_pages;
+	for (loop = 0; loop < nr; loop++) {
+		if (pfn + nr_pages != folio_pfn(fbatch.folios[loop])) {
+			ret = -ENOSYS;
+			goto out_free; /* leave if not physical adjacent */
+		}
+		nr_pages += folio_nr_pages(fbatch.folios[loop]);
+		if (nr_pages >= lpages)
+			goto out_free; /* successfully found desired pages*/
+	}
 
+	if (nr_pages < lpages) {
+		folio_batch_release(&fbatch);
+		goto repeat; /* loop if pages are missing */
+	}
 	/* okay - all conditions fulfilled */
-	ret = (unsigned long) page_address(pages[0]);
 
-out_free_pages:
-	ptr = pages;
-	for (loop = nr; loop > 0; loop--)
-		put_page(*ptr++);
 out_free:
-	kfree(pages);
+	folio_batch_release(&fbatch);
 out:
 	return ret;
 }
Signature · 1 line
2.36.1
#9 lore raw

PATCH 7/7 filemap: Remove find_get_pages_contig()

In reply to Vishal Moola (Oracle)

All callers of find_get_pages_contig() have been removed, so it is no longer needed.

---
 include/linux/pagemap.h |  2 --
 mm/filemap.c            | 60 -----------------------------------------
 2 files changed, 62 deletions(-)
include/linux/pagemap.h +0 -2
index 8689c32d628b..09de43e36a64 100644
@@ -720,8 +720,6 @@ unsigned filemap_get_folios(struct address_space *mapping, pgoff_t *start,
 		pgoff_t end, struct folio_batch *fbatch);
 unsigned filemap_get_folios_contig(struct address_space *mapping,
 		pgoff_t *start, pgoff_t end, struct folio_batch *fbatch);
-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,
 			pgoff_t end, xa_mark_t tag, unsigned int nr_pages,
 			struct page **pages);
mm/filemap.c +0 -60

66 lines not on this page · raw message

Signature · 1 line
2.36.1
maintainer
#10 lore raw
In reply to Vishal Moola (Oracle)
Quoted 4 lines · Vishal Moola (Oracle)

This patch series replaces find_get_pages_contig() with filemap_get_folios_contig(). I've run xfstests on btrfs. I've also tested the ramfs changes. I ran some xfstests on nilfs2, and its seemingly fine although more testing may be beneficial.

These all look good to me. I'd like to see R-b tags from the various fs maintainers, but I intend to add this series to the folio tree for merging in 6.1.