diff mbox series

[v2,09/13] fuse: convert retrieves to use folios

Message ID 20241022185443.1891563-10-joannelkoong@gmail.com (mailing list archive)
State New
Headers show
Series fuse: use folios instead of pages for requests | expand

Commit Message

Joanne Koong Oct. 22, 2024, 6:54 p.m. UTC
Convert retrieve requests to use folios instead of pages.

No functional changes.

Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
Reviewed-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/fuse/dev.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

Comments

Joanne Koong Oct. 23, 2024, 5:23 p.m. UTC | #1
On Tue, Oct 22, 2024 at 11:54 AM Joanne Koong <joannelkoong@gmail.com> wrote:
>
> Convert retrieve requests to use folios instead of pages.
>
> No functional changes.
>
> Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
> Reviewed-by: Josef Bacik <josef@toxicpanda.com>
> ---
>  fs/fuse/dev.c | 23 +++++++++++++----------
>  1 file changed, 13 insertions(+), 10 deletions(-)
>
> diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
> index 9f860bd655a4..220b1bddb74e 100644
> --- a/fs/fuse/dev.c
> +++ b/fs/fuse/dev.c
> @@ -1728,7 +1728,7 @@ static void fuse_retrieve_end(struct fuse_mount *fm, struct fuse_args *args,
>         struct fuse_retrieve_args *ra =
>                 container_of(args, typeof(*ra), ap.args);
>
> -       release_pages(ra->ap.pages, ra->ap.num_pages);
> +       release_pages(ra->ap.folios, ra->ap.num_folios);
>         kfree(ra);
>  }
>
> @@ -1742,7 +1742,8 @@ static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode,
>         unsigned int num;
>         unsigned int offset;
>         size_t total_len = 0;
> -       unsigned int num_pages;
> +       unsigned int num_folios;
> +       unsigned int num_pages, cur_pages = 0;
>         struct fuse_conn *fc = fm->fc;
>         struct fuse_retrieve_args *ra;
>         size_t args_size = sizeof(*ra);
> @@ -1761,15 +1762,16 @@ static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode,
>         num_pages = (num + offset + PAGE_SIZE - 1) >> PAGE_SHIFT;
>         num_pages = min(num_pages, fc->max_pages);
>
> -       args_size += num_pages * (sizeof(ap->pages[0]) + sizeof(ap->descs[0]));
> +       args_size += num_pages * (sizeof(ap->folios[0]) + sizeof(ap->folio_descs[0]));
>
>         ra = kzalloc(args_size, GFP_KERNEL);
>         if (!ra)
>                 return -ENOMEM;
>
>         ap = &ra->ap;
> -       ap->pages = (void *) (ra + 1);
> -       ap->descs = (void *) (ap->pages + num_pages);
> +       ap->folios = (void *) (ra + 1);
> +       ap->folio_descs = (void *) (ap->folios + num_folios);

Agh, I messed this up in the refactoring I did between v1 -> v2. This
should be ap->folios + num_pages. Will fix this in v3.

> +       ap->uses_folios = true;
>
>         args = &ap->args;
>         args->nodeid = outarg->nodeid;
> @@ -1780,7 +1782,7 @@ static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode,
>
>         index = outarg->offset >> PAGE_SHIFT;
>
> -       while (num && ap->num_pages < num_pages) {
> +       while (num && cur_pages < num_pages) {
>                 struct folio *folio;
>                 unsigned int this_num;
>
> @@ -1789,10 +1791,11 @@ static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode,
>                         break;
>
>                 this_num = min_t(unsigned, num, PAGE_SIZE - offset);
> -               ap->pages[ap->num_pages] = &folio->page;
> -               ap->descs[ap->num_pages].offset = offset;
> -               ap->descs[ap->num_pages].length = this_num;
> -               ap->num_pages++;
> +               ap->folios[ap->num_folios] = folio;
> +               ap->folio_descs[ap->num_folios].offset = offset;
> +               ap->folio_descs[ap->num_folios].length = this_num;
> +               ap->num_folios++;
> +               cur_pages++;
>
>                 offset = 0;
>                 num -= this_num;
> --
> 2.43.5
>
kernel test robot Oct. 23, 2024, 8:53 p.m. UTC | #2
Hi Joanne,

kernel test robot noticed the following build warnings:

[auto build test WARNING on mszeredi-fuse/for-next]
[also build test WARNING on next-20241023]
[cannot apply to akpm-mm/mm-everything linus/master v6.12-rc4]
[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/Joanne-Koong/fuse-support-folios-in-struct-fuse_args_pages-and-fuse_copy_pages/20241023-025923
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse.git for-next
patch link:    https://lore.kernel.org/r/20241022185443.1891563-10-joannelkoong%40gmail.com
patch subject: [PATCH v2 09/13] fuse: convert retrieves to use folios
config: x86_64-kexec (https://download.01.org/0day-ci/archive/20241024/202410240414.YVec3s6S-lkp@intel.com/config)
compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241024/202410240414.YVec3s6S-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202410240414.YVec3s6S-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> fs/fuse/dev.c:1773:43: warning: variable 'num_folios' is uninitialized when used here [-Wuninitialized]
    1773 |         ap->folio_descs = (void *) (ap->folios + num_folios);
         |                                                  ^~~~~~~~~~
   fs/fuse/dev.c:1745:25: note: initialize the variable 'num_folios' to silence this warning
    1745 |         unsigned int num_folios;
         |                                ^
         |                                 = 0
   1 warning generated.


vim +/num_folios +1773 fs/fuse/dev.c

  1734	
  1735	static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode,
  1736				 struct fuse_notify_retrieve_out *outarg)
  1737	{
  1738		int err;
  1739		struct address_space *mapping = inode->i_mapping;
  1740		pgoff_t index;
  1741		loff_t file_size;
  1742		unsigned int num;
  1743		unsigned int offset;
  1744		size_t total_len = 0;
  1745		unsigned int num_folios;
  1746		unsigned int num_pages, cur_pages = 0;
  1747		struct fuse_conn *fc = fm->fc;
  1748		struct fuse_retrieve_args *ra;
  1749		size_t args_size = sizeof(*ra);
  1750		struct fuse_args_pages *ap;
  1751		struct fuse_args *args;
  1752	
  1753		offset = outarg->offset & ~PAGE_MASK;
  1754		file_size = i_size_read(inode);
  1755	
  1756		num = min(outarg->size, fc->max_write);
  1757		if (outarg->offset > file_size)
  1758			num = 0;
  1759		else if (outarg->offset + num > file_size)
  1760			num = file_size - outarg->offset;
  1761	
  1762		num_pages = (num + offset + PAGE_SIZE - 1) >> PAGE_SHIFT;
  1763		num_pages = min(num_pages, fc->max_pages);
  1764	
  1765		args_size += num_pages * (sizeof(ap->folios[0]) + sizeof(ap->folio_descs[0]));
  1766	
  1767		ra = kzalloc(args_size, GFP_KERNEL);
  1768		if (!ra)
  1769			return -ENOMEM;
  1770	
  1771		ap = &ra->ap;
  1772		ap->folios = (void *) (ra + 1);
> 1773		ap->folio_descs = (void *) (ap->folios + num_folios);
  1774		ap->uses_folios = true;
  1775	
  1776		args = &ap->args;
  1777		args->nodeid = outarg->nodeid;
  1778		args->opcode = FUSE_NOTIFY_REPLY;
  1779		args->in_numargs = 2;
  1780		args->in_pages = true;
  1781		args->end = fuse_retrieve_end;
  1782	
  1783		index = outarg->offset >> PAGE_SHIFT;
  1784	
  1785		while (num && cur_pages < num_pages) {
  1786			struct folio *folio;
  1787			unsigned int this_num;
  1788	
  1789			folio = filemap_get_folio(mapping, index);
  1790			if (IS_ERR(folio))
  1791				break;
  1792	
  1793			this_num = min_t(unsigned, num, PAGE_SIZE - offset);
  1794			ap->folios[ap->num_folios] = folio;
  1795			ap->folio_descs[ap->num_folios].offset = offset;
  1796			ap->folio_descs[ap->num_folios].length = this_num;
  1797			ap->num_folios++;
  1798			cur_pages++;
  1799	
  1800			offset = 0;
  1801			num -= this_num;
  1802			total_len += this_num;
  1803			index++;
  1804		}
  1805		ra->inarg.offset = outarg->offset;
  1806		ra->inarg.size = total_len;
  1807		args->in_args[0].size = sizeof(ra->inarg);
  1808		args->in_args[0].value = &ra->inarg;
  1809		args->in_args[1].size = total_len;
  1810	
  1811		err = fuse_simple_notify_reply(fm, args, outarg->notify_unique);
  1812		if (err)
  1813			fuse_retrieve_end(fm, args, err);
  1814	
  1815		return err;
  1816	}
  1817
diff mbox series

Patch

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 9f860bd655a4..220b1bddb74e 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1728,7 +1728,7 @@  static void fuse_retrieve_end(struct fuse_mount *fm, struct fuse_args *args,
 	struct fuse_retrieve_args *ra =
 		container_of(args, typeof(*ra), ap.args);
 
-	release_pages(ra->ap.pages, ra->ap.num_pages);
+	release_pages(ra->ap.folios, ra->ap.num_folios);
 	kfree(ra);
 }
 
@@ -1742,7 +1742,8 @@  static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode,
 	unsigned int num;
 	unsigned int offset;
 	size_t total_len = 0;
-	unsigned int num_pages;
+	unsigned int num_folios;
+	unsigned int num_pages, cur_pages = 0;
 	struct fuse_conn *fc = fm->fc;
 	struct fuse_retrieve_args *ra;
 	size_t args_size = sizeof(*ra);
@@ -1761,15 +1762,16 @@  static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode,
 	num_pages = (num + offset + PAGE_SIZE - 1) >> PAGE_SHIFT;
 	num_pages = min(num_pages, fc->max_pages);
 
-	args_size += num_pages * (sizeof(ap->pages[0]) + sizeof(ap->descs[0]));
+	args_size += num_pages * (sizeof(ap->folios[0]) + sizeof(ap->folio_descs[0]));
 
 	ra = kzalloc(args_size, GFP_KERNEL);
 	if (!ra)
 		return -ENOMEM;
 
 	ap = &ra->ap;
-	ap->pages = (void *) (ra + 1);
-	ap->descs = (void *) (ap->pages + num_pages);
+	ap->folios = (void *) (ra + 1);
+	ap->folio_descs = (void *) (ap->folios + num_folios);
+	ap->uses_folios = true;
 
 	args = &ap->args;
 	args->nodeid = outarg->nodeid;
@@ -1780,7 +1782,7 @@  static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode,
 
 	index = outarg->offset >> PAGE_SHIFT;
 
-	while (num && ap->num_pages < num_pages) {
+	while (num && cur_pages < num_pages) {
 		struct folio *folio;
 		unsigned int this_num;
 
@@ -1789,10 +1791,11 @@  static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode,
 			break;
 
 		this_num = min_t(unsigned, num, PAGE_SIZE - offset);
-		ap->pages[ap->num_pages] = &folio->page;
-		ap->descs[ap->num_pages].offset = offset;
-		ap->descs[ap->num_pages].length = this_num;
-		ap->num_pages++;
+		ap->folios[ap->num_folios] = folio;
+		ap->folio_descs[ap->num_folios].offset = offset;
+		ap->folio_descs[ap->num_folios].length = this_num;
+		ap->num_folios++;
+		cur_pages++;
 
 		offset = 0;
 		num -= this_num;