From: "Vishal Moola (Oracle)" <vishal.moola@gmail.com>
To: linux-fsdevel@vger.kernel.org
Cc: linux-btrfs@vger.kernel.org, linux-nilfs@vger.kernel.org,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
"Vishal Moola (Oracle)" <vishal.moola@gmail.com>
Subject: [PATCH v2 6/7] ramfs: Convert ramfs_nommu_get_unmapped_area() to use filemap_get_folios_contig()
Date: Tue, 16 Aug 2022 10:52:45 -0700 [thread overview]
Message-ID: <20220816175246.42401-7-vishal.moola@gmail.com> (raw)
In-Reply-To: <20220816175246.42401-1-vishal.moola@gmail.com>
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.
Signed-off-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
---
fs/ramfs/file-nommu.c | 50 +++++++++++++++++++++++++------------------
1 file changed, 29 insertions(+), 21 deletions(-)
diff --git a/fs/ramfs/file-nommu.c b/fs/ramfs/file-nommu.c
index ba3525ccc27e..81817f301e17 100644
--- a/fs/ramfs/file-nommu.c
+++ b/fs/ramfs/file-nommu.c
@@ -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;
}
--
2.36.1
next prev parent reply other threads:[~2022-08-16 17:54 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-16 17:52 [PATCH v2 0/7] Convert to filemap_get_folios_contig() Vishal Moola (Oracle)
2022-08-16 17:52 ` [PATCH v2 1/7] filemap: Add filemap_get_folios_contig() Vishal Moola (Oracle)
2022-08-16 17:52 ` [PATCH v2 2/7] btrfs: Convert __process_pages_contig() to use filemap_get_folios_contig() Vishal Moola (Oracle)
2022-08-22 18:32 ` Vishal Moola
2022-08-23 20:35 ` David Sterba
2022-08-16 17:52 ` [PATCH v2 3/7] btrfs: Convert end_compressed_writeback() to use filemap_get_folios() Vishal Moola (Oracle)
2022-08-23 20:36 ` David Sterba
2022-08-16 17:52 ` [PATCH v2 4/7] btrfs: Convert process_page_range() to use filemap_get_folios_contig() Vishal Moola (Oracle)
2022-08-23 20:38 ` David Sterba
2022-08-16 17:52 ` [PATCH v2 5/7] nilfs2: Convert nilfs_find_uncommited_extent() " Vishal Moola (Oracle)
2022-08-17 4:33 ` Ryusuke Konishi
2022-08-17 20:35 ` Vishal Moola
2022-08-16 17:52 ` Vishal Moola (Oracle) [this message]
2022-08-16 17:52 ` [PATCH v2 7/7] filemap: Remove find_get_pages_contig() Vishal Moola (Oracle)
2022-08-23 17:26 ` [PATCH v2 0/7] Convert to filemap_get_folios_contig() David Sterba
2022-08-23 18:02 ` Matthew Wilcox
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220816175246.42401-7-vishal.moola@gmail.com \
--to=vishal.moola@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-nilfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).