public inbox for linux-fsdevel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/3] fuse: clean up offset and page count calculations
@ 2026-01-16 23:56 Joanne Koong
  2026-01-16 23:56 ` [PATCH v1 1/3] fuse: use DIV_ROUND_UP() for " Joanne Koong
                   ` (4 more replies)
  0 siblings, 5 replies; 17+ messages in thread
From: Joanne Koong @ 2026-01-16 23:56 UTC (permalink / raw)
  To: miklos; +Cc: linux-fsdevel, jefflexu

This patchset aims to improve code clarity by using standard kernel helper
macros for common calculations:
 * DIV_ROUND_UP() for page count calculations
 * offset_in_folio() for large folio offset calculations
 * offset_in_page() for page offset calculations

These helpers improve readability and consistency with patterns used
elsewhere in the kernel. No functional changes intended.

This patchset is on top of Jingbo's patch in [1].

Thanks,
Joanne

[1] https://lore.kernel.org/linux-fsdevel/20260115023607.77349-1-jefflexu@linux.alibaba.com/

Joanne Koong (3):
  fuse: use DIV_ROUND_UP() for page count calculations
  fuse: use offset_in_folio() for large folio offset calculations
  fuse: use offset_in_page() for page offset calculations

 fs/fuse/dev.c     | 14 +++++++-------
 fs/fuse/file.c    |  2 +-
 fs/fuse/readdir.c |  8 ++++----
 3 files changed, 12 insertions(+), 12 deletions(-)

-- 
2.47.3


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH v1 1/3] fuse: use DIV_ROUND_UP() for page count calculations
  2026-01-16 23:56 [PATCH v1 0/3] fuse: clean up offset and page count calculations Joanne Koong
@ 2026-01-16 23:56 ` Joanne Koong
  2026-01-19  2:12   ` Jingbo Xu
  2026-01-16 23:56 ` [PATCH v1 2/3] fuse: use offset_in_folio() for large folio offset calculations Joanne Koong
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 17+ messages in thread
From: Joanne Koong @ 2026-01-16 23:56 UTC (permalink / raw)
  To: miklos; +Cc: linux-fsdevel, jefflexu

Use DIV_ROUND_UP() instead of manually computing round-up division
calculations.

Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
---
 fs/fuse/dev.c  | 6 +++---
 fs/fuse/file.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 6d59cbc877c6..698289b5539e 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1814,7 +1814,7 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size,
 
 		folio_offset = ((index - folio->index) << PAGE_SHIFT) + offset;
 		nr_bytes = min_t(unsigned, num, folio_size(folio) - folio_offset);
-		nr_pages = (offset + nr_bytes + PAGE_SIZE - 1) >> PAGE_SHIFT;
+		nr_pages = DIV_ROUND_UP(offset + nr_bytes, PAGE_SIZE);
 
 		err = fuse_copy_folio(cs, &folio, folio_offset, nr_bytes, 0);
 		if (!folio_test_uptodate(folio) && !err && offset == 0 &&
@@ -1883,7 +1883,7 @@ static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode,
 	else if (outarg->offset + num > file_size)
 		num = file_size - outarg->offset;
 
-	num_pages = (num + offset + PAGE_SIZE - 1) >> PAGE_SHIFT;
+	num_pages = DIV_ROUND_UP(num + offset, PAGE_SIZE);
 	num_pages = min(num_pages, fc->max_pages);
 	num = min(num, num_pages << PAGE_SHIFT);
 
@@ -1918,7 +1918,7 @@ static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode,
 
 		folio_offset = ((index - folio->index) << PAGE_SHIFT) + offset;
 		nr_bytes = min(folio_size(folio) - folio_offset, num);
-		nr_pages = (offset + nr_bytes + PAGE_SIZE - 1) >> PAGE_SHIFT;
+		nr_pages = DIV_ROUND_UP(offset + nr_bytes, PAGE_SIZE);
 
 		ap->folios[ap->num_folios] = folio;
 		ap->descs[ap->num_folios].offset = folio_offset;
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index eba70ebf6e77..a4342b269cb9 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -2170,7 +2170,7 @@ static bool fuse_folios_need_send(struct fuse_conn *fc, loff_t pos,
 	WARN_ON(!ap->num_folios);
 
 	/* Reached max pages */
-	if ((bytes + PAGE_SIZE - 1) >> PAGE_SHIFT > fc->max_pages)
+	if (DIV_ROUND_UP(bytes, PAGE_SIZE) > fc->max_pages)
 		return true;
 
 	if (bytes > max_bytes)
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v1 2/3] fuse: use offset_in_folio() for large folio offset calculations
  2026-01-16 23:56 [PATCH v1 0/3] fuse: clean up offset and page count calculations Joanne Koong
  2026-01-16 23:56 ` [PATCH v1 1/3] fuse: use DIV_ROUND_UP() for " Joanne Koong
@ 2026-01-16 23:56 ` Joanne Koong
  2026-01-19  4:41   ` Chunsheng Luo
  2026-01-19  6:24   ` Chunsheng Luo
  2026-01-16 23:56 ` [PATCH v1 3/3] fuse: use offset_in_page() for page " Joanne Koong
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 17+ messages in thread
From: Joanne Koong @ 2026-01-16 23:56 UTC (permalink / raw)
  To: miklos; +Cc: linux-fsdevel, jefflexu

Use offset_in_folio() instead of manually calculating the folio offset.

Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
---
 fs/fuse/dev.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 698289b5539e..4dda4e24cc90 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1812,7 +1812,7 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size,
 		if (IS_ERR(folio))
 			goto out_iput;
 
-		folio_offset = ((index - folio->index) << PAGE_SHIFT) + offset;
+		folio_offset = offset_in_folio(folio, outarg.offset);
 		nr_bytes = min_t(unsigned, num, folio_size(folio) - folio_offset);
 		nr_pages = DIV_ROUND_UP(offset + nr_bytes, PAGE_SIZE);
 
@@ -1916,7 +1916,7 @@ static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode,
 		if (IS_ERR(folio))
 			break;
 
-		folio_offset = ((index - folio->index) << PAGE_SHIFT) + offset;
+		folio_offset = offset_in_folio(folio, outarg->offset);
 		nr_bytes = min(folio_size(folio) - folio_offset, num);
 		nr_pages = DIV_ROUND_UP(offset + nr_bytes, PAGE_SIZE);
 
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH v1 3/3] fuse: use offset_in_page() for page offset calculations
  2026-01-16 23:56 [PATCH v1 0/3] fuse: clean up offset and page count calculations Joanne Koong
  2026-01-16 23:56 ` [PATCH v1 1/3] fuse: use DIV_ROUND_UP() for " Joanne Koong
  2026-01-16 23:56 ` [PATCH v1 2/3] fuse: use offset_in_folio() for large folio offset calculations Joanne Koong
@ 2026-01-16 23:56 ` Joanne Koong
  2026-01-17  5:03 ` [PATCH v1 0/3] fuse: clean up offset and page count calculations Darrick J. Wong
  2026-01-17  7:51 ` Horst Birthelmer
  4 siblings, 0 replies; 17+ messages in thread
From: Joanne Koong @ 2026-01-16 23:56 UTC (permalink / raw)
  To: miklos; +Cc: linux-fsdevel, jefflexu

Replace open-coded (x & ~PAGE_MASK) with offset_in_page().

Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
---
 fs/fuse/dev.c     | 4 ++--
 fs/fuse/readdir.c | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 4dda4e24cc90..9ba8ca796ff3 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -1792,7 +1792,7 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size,
 
 	mapping = inode->i_mapping;
 	index = outarg.offset >> PAGE_SHIFT;
-	offset = outarg.offset & ~PAGE_MASK;
+	offset = offset_in_page(outarg.offset);
 	file_size = i_size_read(inode);
 	end = outarg.offset + outarg.size;
 	if (end > file_size) {
@@ -1874,7 +1874,7 @@ static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode,
 	struct fuse_args_pages *ap;
 	struct fuse_args *args;
 
-	offset = outarg->offset & ~PAGE_MASK;
+	offset = offset_in_page(outarg->offset);
 	file_size = i_size_read(inode);
 
 	num = min(outarg->size, fc->max_write);
diff --git a/fs/fuse/readdir.c b/fs/fuse/readdir.c
index c2aae2eef086..c88194e52d18 100644
--- a/fs/fuse/readdir.c
+++ b/fs/fuse/readdir.c
@@ -52,7 +52,7 @@ static void fuse_add_dirent_to_cache(struct file *file,
 	}
 	version = fi->rdc.version;
 	size = fi->rdc.size;
-	offset = size & ~PAGE_MASK;
+	offset = offset_in_page(size);
 	index = size >> PAGE_SHIFT;
 	/* Dirent doesn't fit in current page?  Jump to next page. */
 	if (offset + reclen > PAGE_SIZE) {
@@ -392,7 +392,7 @@ static enum fuse_parse_result fuse_parse_cache(struct fuse_file *ff,
 					       void *addr, unsigned int size,
 					       struct dir_context *ctx)
 {
-	unsigned int offset = ff->readdir.cache_off & ~PAGE_MASK;
+	unsigned int offset = offset_in_page(ff->readdir.cache_off);
 	enum fuse_parse_result res = FOUND_NONE;
 
 	WARN_ON(offset >= size);
@@ -518,13 +518,13 @@ static int fuse_readdir_cached(struct file *file, struct dir_context *ctx)
 	index = ff->readdir.cache_off >> PAGE_SHIFT;
 
 	if (index == (fi->rdc.size >> PAGE_SHIFT))
-		size = fi->rdc.size & ~PAGE_MASK;
+		size = offset_in_page(fi->rdc.size);
 	else
 		size = PAGE_SIZE;
 	spin_unlock(&fi->rdc.lock);
 
 	/* EOF? */
-	if ((ff->readdir.cache_off & ~PAGE_MASK) == size)
+	if (offset_in_page(ff->readdir.cache_off) == size)
 		return 0;
 
 	page = find_get_page_flags(file->f_mapping, index,
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH v1 0/3] fuse: clean up offset and page count calculations
  2026-01-16 23:56 [PATCH v1 0/3] fuse: clean up offset and page count calculations Joanne Koong
                   ` (2 preceding siblings ...)
  2026-01-16 23:56 ` [PATCH v1 3/3] fuse: use offset_in_page() for page " Joanne Koong
@ 2026-01-17  5:03 ` Darrick J. Wong
  2026-01-20 19:05   ` Joanne Koong
  2026-01-17  7:51 ` Horst Birthelmer
  4 siblings, 1 reply; 17+ messages in thread
From: Darrick J. Wong @ 2026-01-17  5:03 UTC (permalink / raw)
  To: Joanne Koong; +Cc: miklos, linux-fsdevel, jefflexu

On Fri, Jan 16, 2026 at 03:56:03PM -0800, Joanne Koong wrote:
> This patchset aims to improve code clarity by using standard kernel helper
> macros for common calculations:
>  * DIV_ROUND_UP() for page count calculations
>  * offset_in_folio() for large folio offset calculations
>  * offset_in_page() for page offset calculations
> 
> These helpers improve readability and consistency with patterns used
> elsewhere in the kernel. No functional changes intended.
> 
> This patchset is on top of Jingbo's patch in [1].

As a straight conversion this looks fine to me so
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>

OTOH I just learned that fuse has a backchannel for fuse servers to
inject pagecache data for a regular file.  That might be kinda nice for
an HSM or something?  Though that would be covered by FUSE_READ.

Hrmm, I wonder how well that interacts with iomap... we don't mark the
folios dirty or update timestamps, so I'm guessing the contents could
disappear at any time if the page cache gets reclaimed?

Weiiiird.....

--D


> Thanks,
> Joanne
> 
> [1] https://lore.kernel.org/linux-fsdevel/20260115023607.77349-1-jefflexu@linux.alibaba.com/
> 
> Joanne Koong (3):
>   fuse: use DIV_ROUND_UP() for page count calculations
>   fuse: use offset_in_folio() for large folio offset calculations
>   fuse: use offset_in_page() for page offset calculations
> 
>  fs/fuse/dev.c     | 14 +++++++-------
>  fs/fuse/file.c    |  2 +-
>  fs/fuse/readdir.c |  8 ++++----
>  3 files changed, 12 insertions(+), 12 deletions(-)
> 
> -- 
> 2.47.3
> 
> 

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v1 0/3] fuse: clean up offset and page count calculations
  2026-01-16 23:56 [PATCH v1 0/3] fuse: clean up offset and page count calculations Joanne Koong
                   ` (3 preceding siblings ...)
  2026-01-17  5:03 ` [PATCH v1 0/3] fuse: clean up offset and page count calculations Darrick J. Wong
@ 2026-01-17  7:51 ` Horst Birthelmer
  2026-01-20 20:06   ` Joanne Koong
  4 siblings, 1 reply; 17+ messages in thread
From: Horst Birthelmer @ 2026-01-17  7:51 UTC (permalink / raw)
  To: Joanne Koong; +Cc: miklos, linux-fsdevel, jefflexu

On Fri, Jan 16, 2026 at 03:56:03PM -0800, Joanne Koong wrote:
> This patchset aims to improve code clarity by using standard kernel helper
> macros for common calculations:
>  * DIV_ROUND_UP() for page count calculations
>  * offset_in_folio() for large folio offset calculations
>  * offset_in_page() for page offset calculations
> 
> These helpers improve readability and consistency with patterns used
> elsewhere in the kernel. No functional changes intended.
> 
> This patchset is on top of Jingbo's patch in [1].
> 
> Thanks,
> Joanne
> 
> [1] https://lore.kernel.org/linux-fsdevel/20260115023607.77349-1-jefflexu@linux.alibaba.com/
> 
> Joanne Koong (3):
>   fuse: use DIV_ROUND_UP() for page count calculations
>   fuse: use offset_in_folio() for large folio offset calculations
>   fuse: use offset_in_page() for page offset calculations
> 
>  fs/fuse/dev.c     | 14 +++++++-------
>  fs/fuse/file.c    |  2 +-
>  fs/fuse/readdir.c |  8 ++++----
>  3 files changed, 12 insertions(+), 12 deletions(-)
> 
> -- 
> 2.47.3
>

Looks good to me.

Reviewed-by: Horst Birthelmer <hbirthelmer@ddn.com>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v1 1/3] fuse: use DIV_ROUND_UP() for page count calculations
  2026-01-16 23:56 ` [PATCH v1 1/3] fuse: use DIV_ROUND_UP() for " Joanne Koong
@ 2026-01-19  2:12   ` Jingbo Xu
  2026-01-20 19:10     ` Joanne Koong
  0 siblings, 1 reply; 17+ messages in thread
From: Jingbo Xu @ 2026-01-19  2:12 UTC (permalink / raw)
  To: Joanne Koong, miklos; +Cc: linux-fsdevel



On 1/17/26 7:56 AM, Joanne Koong wrote:
> Use DIV_ROUND_UP() instead of manually computing round-up division
> calculations.
> 
> Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
> ---
>  fs/fuse/dev.c  | 6 +++---
>  fs/fuse/file.c | 2 +-
>  2 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
> index 6d59cbc877c6..698289b5539e 100644
> --- a/fs/fuse/dev.c
> +++ b/fs/fuse/dev.c
> @@ -1814,7 +1814,7 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size,
>  
>  		folio_offset = ((index - folio->index) << PAGE_SHIFT) + offset;
>  		nr_bytes = min_t(unsigned, num, folio_size(folio) - folio_offset);
> -		nr_pages = (offset + nr_bytes + PAGE_SIZE - 1) >> PAGE_SHIFT;
> +		nr_pages = DIV_ROUND_UP(offset + nr_bytes, PAGE_SIZE);
>  
>  		err = fuse_copy_folio(cs, &folio, folio_offset, nr_bytes, 0);
>  		if (!folio_test_uptodate(folio) && !err && offset == 0 &&

IMHO, could we drop page offset, instead just update the file offset and
re-calculate folio index and folio offset for each loop, i.e. something
like what [1] did?

This could make the code simpler and cleaner.

BTW, it seems that if the grabbed folio is newly created on hand and the
range described by the store notify doesn't cover the folio completely,
the folio won't be set as Uptodate and thus the written data may be
missed?  I'm not sure if this is in design.

[1]
https://lore.kernel.org/linux-fsdevel/20260115023607.77349-1-jefflexu@linux.alibaba.com/


> @@ -1883,7 +1883,7 @@ static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode,
>  	else if (outarg->offset + num > file_size)
>  		num = file_size - outarg->offset;
>  
> -	num_pages = (num + offset + PAGE_SIZE - 1) >> PAGE_SHIFT;
> +	num_pages = DIV_ROUND_UP(num + offset, PAGE_SIZE);
>  	num_pages = min(num_pages, fc->max_pages);
>  	num = min(num, num_pages << PAGE_SHIFT);
>  
> @@ -1918,7 +1918,7 @@ static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode,
>  
>  		folio_offset = ((index - folio->index) << PAGE_SHIFT) + offset;
>  		nr_bytes = min(folio_size(folio) - folio_offset, num);
> -		nr_pages = (offset + nr_bytes + PAGE_SIZE - 1) >> PAGE_SHIFT;
> +		nr_pages = DIV_ROUND_UP(offset + nr_bytes, PAGE_SIZE);
>  
>  		ap->folios[ap->num_folios] = folio;
>  		ap->descs[ap->num_folios].offset = folio_offset;

Ditto.

> diff --git a/fs/fuse/file.c b/fs/fuse/file.c
> index eba70ebf6e77..a4342b269cb9 100644
> --- a/fs/fuse/file.c
> +++ b/fs/fuse/file.c
> @@ -2170,7 +2170,7 @@ static bool fuse_folios_need_send(struct fuse_conn *fc, loff_t pos,
>  	WARN_ON(!ap->num_folios);
>  
>  	/* Reached max pages */
> -	if ((bytes + PAGE_SIZE - 1) >> PAGE_SHIFT > fc->max_pages)
> +	if (DIV_ROUND_UP(bytes, PAGE_SIZE) > fc->max_pages)
>  		return true;
>  
>  	if (bytes > max_bytes)

-- 
Thanks,
Jingbo


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v1 2/3] fuse: use offset_in_folio() for large folio offset calculations
  2026-01-16 23:56 ` [PATCH v1 2/3] fuse: use offset_in_folio() for large folio offset calculations Joanne Koong
@ 2026-01-19  4:41   ` Chunsheng Luo
  2026-01-20 18:59     ` Joanne Koong
  2026-01-19  6:24   ` Chunsheng Luo
  1 sibling, 1 reply; 17+ messages in thread
From: Chunsheng Luo @ 2026-01-19  4:41 UTC (permalink / raw)
  To: Joanne Koong, miklos; +Cc: linux-fsdevel, jefflexu



On 1/17/26 7:56 AM, Joanne Koong wrote:
> Use offset_in_folio() instead of manually calculating the folio offset.
> 
> Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
> ---
>   fs/fuse/dev.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
> index 698289b5539e..4dda4e24cc90 100644
> --- a/fs/fuse/dev.c
> +++ b/fs/fuse/dev.c
> @@ -1812,7 +1812,7 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size,
>   		if (IS_ERR(folio))
>   			goto out_iput;
>   
> -		folio_offset = ((index - folio->index) << PAGE_SHIFT) + offset;
> +		folio_offset = offset_in_folio(folio, outarg.offset);

offset is a loop variable, and later offset will be set to 0. Replacing 
it with outarg.offset here would change the behavior. The same applies 
to the cases below. Will there be any problem here?

Thanks,
Chunsheng Luo

>   		nr_bytes = min_t(unsigned, num, folio_size(folio) - folio_offset);
>   		nr_pages = DIV_ROUND_UP(offset + nr_bytes, PAGE_SIZE);
>   
> @@ -1916,7 +1916,7 @@ static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode,
>   		if (IS_ERR(folio))
>   			break;
>   
> -		folio_offset = ((index - folio->index) << PAGE_SHIFT) + offset;
> +		folio_offset = offset_in_folio(folio, outarg->offset);
>   		nr_bytes = min(folio_size(folio) - folio_offset, num);
>   		nr_pages = DIV_ROUND_UP(offset + nr_bytes, PAGE_SIZE);
>   


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v1 2/3] fuse: use offset_in_folio() for large folio offset calculations
  2026-01-16 23:56 ` [PATCH v1 2/3] fuse: use offset_in_folio() for large folio offset calculations Joanne Koong
  2026-01-19  4:41   ` Chunsheng Luo
@ 2026-01-19  6:24   ` Chunsheng Luo
  1 sibling, 0 replies; 17+ messages in thread
From: Chunsheng Luo @ 2026-01-19  6:24 UTC (permalink / raw)
  To: joannelkoong; +Cc: jefflexu, linux-fsdevel, miklos

On 1/17/26 7:56 AM, Joanne Koong wrote:
> Use offset_in_folio() instead of manually calculating the folio offset.
>
> Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
> ---
>   fs/fuse/dev.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
> index 698289b5539e..4dda4e24cc90 100644
> --- a/fs/fuse/dev.c
> +++ b/fs/fuse/dev.c
> @@ -1812,7 +1812,7 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size,
>           if (IS_ERR(folio))
>               goto out_iput;
>   -        folio_offset = ((index - folio->index) << PAGE_SHIFT) + offset;
> +        folio_offset = offset_in_folio(folio, outarg.offset);

offset is a loop variable, and later offset maybe set to 0. Replacing it
with outarg.offset here would change the behavior. The same below.
Will this cause any problems?

Thanks,
Chunsheng Luo

>           nr_bytes = min_t(unsigned, num, folio_size(folio) - folio_offset);
>           nr_pages = DIV_ROUND_UP(offset + nr_bytes, PAGE_SIZE);
>   @@ -1916,7 +1916,7 @@ static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode,
>           if (IS_ERR(folio))
>               break;
>   -        folio_offset = ((index - folio->index) << PAGE_SHIFT) + offset;
> +        folio_offset = offset_in_folio(folio, outarg->offset);
>           nr_bytes = min(folio_size(folio) - folio_offset, num);
>           nr_pages = DIV_ROUND_UP(offset + nr_bytes, PAGE_SIZE);
>   


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v1 2/3] fuse: use offset_in_folio() for large folio offset calculations
  2026-01-19  4:41   ` Chunsheng Luo
@ 2026-01-20 18:59     ` Joanne Koong
  0 siblings, 0 replies; 17+ messages in thread
From: Joanne Koong @ 2026-01-20 18:59 UTC (permalink / raw)
  To: Chunsheng Luo; +Cc: miklos, linux-fsdevel, jefflexu

On Sun, Jan 18, 2026 at 8:41 PM Chunsheng Luo <luochunsheng@ustc.edu> wrote:
>
> On 1/17/26 7:56 AM, Joanne Koong wrote:
> > Use offset_in_folio() instead of manually calculating the folio offset.
> >
> > Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
> > ---
> >   fs/fuse/dev.c | 4 ++--
> >   1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
> > index 698289b5539e..4dda4e24cc90 100644
> > --- a/fs/fuse/dev.c
> > +++ b/fs/fuse/dev.c
> > @@ -1812,7 +1812,7 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size,
> >               if (IS_ERR(folio))
> >                       goto out_iput;
> >
> > -             folio_offset = ((index - folio->index) << PAGE_SHIFT) + offset;
> > +             folio_offset = offset_in_folio(folio, outarg.offset);
>
> offset is a loop variable, and later offset will be set to 0. Replacing
> it with outarg.offset here would change the behavior. The same applies
> to the cases below. Will there be any problem here?

Hi Chunsheng,

Good catch, the offset variable should get replaced entirely by
outarg.offset. I'll make this change in v2.

Thanks,
Joanne

>
> Thanks,
> Chunsheng Luo
>
> >               nr_bytes = min_t(unsigned, num, folio_size(folio) - folio_offset);
> >               nr_pages = DIV_ROUND_UP(offset + nr_bytes, PAGE_SIZE);
> >
> > @@ -1916,7 +1916,7 @@ static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode,
> >               if (IS_ERR(folio))
> >                       break;
> >
> > -             folio_offset = ((index - folio->index) << PAGE_SHIFT) + offset;
> > +             folio_offset = offset_in_folio(folio, outarg->offset);
> >               nr_bytes = min(folio_size(folio) - folio_offset, num);
> >               nr_pages = DIV_ROUND_UP(offset + nr_bytes, PAGE_SIZE);
> >
>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v1 0/3] fuse: clean up offset and page count calculations
  2026-01-17  5:03 ` [PATCH v1 0/3] fuse: clean up offset and page count calculations Darrick J. Wong
@ 2026-01-20 19:05   ` Joanne Koong
  0 siblings, 0 replies; 17+ messages in thread
From: Joanne Koong @ 2026-01-20 19:05 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: miklos, linux-fsdevel, jefflexu

On Fri, Jan 16, 2026 at 9:03 PM Darrick J. Wong <djwong@kernel.org> wrote:
>
> On Fri, Jan 16, 2026 at 03:56:03PM -0800, Joanne Koong wrote:
> > This patchset aims to improve code clarity by using standard kernel helper
> > macros for common calculations:
> >  * DIV_ROUND_UP() for page count calculations
> >  * offset_in_folio() for large folio offset calculations
> >  * offset_in_page() for page offset calculations
> >
> > These helpers improve readability and consistency with patterns used
> > elsewhere in the kernel. No functional changes intended.
> >
> > This patchset is on top of Jingbo's patch in [1].
>
> As a straight conversion this looks fine to me so
> Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
>
> OTOH I just learned that fuse has a backchannel for fuse servers to
> inject pagecache data for a regular file.  That might be kinda nice for
> an HSM or something?  Though that would be covered by FUSE_READ.
>
> Hrmm, I wonder how well that interacts with iomap... we don't mark the
> folios dirty or update timestamps, so I'm guessing the contents could
> disappear at any time if the page cache gets reclaimed?

My interpretation of it is that it doesn't need to be marked dirty
because the server is the one injecting this data into the folio so
theoretically it should already have all of this data already
committed on its backend.

Thanks,
Joanne

>
> Weiiiird.....
>
> --D
>
>
> > Thanks,
> > Joanne
> >
> > [1] https://lore.kernel.org/linux-fsdevel/20260115023607.77349-1-jefflexu@linux.alibaba.com/
> >
> > Joanne Koong (3):
> >   fuse: use DIV_ROUND_UP() for page count calculations
> >   fuse: use offset_in_folio() for large folio offset calculations
> >   fuse: use offset_in_page() for page offset calculations
> >
> >  fs/fuse/dev.c     | 14 +++++++-------
> >  fs/fuse/file.c    |  2 +-
> >  fs/fuse/readdir.c |  8 ++++----
> >  3 files changed, 12 insertions(+), 12 deletions(-)
> >
> > --
> > 2.47.3
> >
> >

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v1 1/3] fuse: use DIV_ROUND_UP() for page count calculations
  2026-01-19  2:12   ` Jingbo Xu
@ 2026-01-20 19:10     ` Joanne Koong
  2026-01-20 20:06       ` Joanne Koong
  0 siblings, 1 reply; 17+ messages in thread
From: Joanne Koong @ 2026-01-20 19:10 UTC (permalink / raw)
  To: Jingbo Xu; +Cc: miklos, linux-fsdevel

On Sun, Jan 18, 2026 at 6:12 PM Jingbo Xu <jefflexu@linux.alibaba.com> wrote:
>
> On 1/17/26 7:56 AM, Joanne Koong wrote:
> > Use DIV_ROUND_UP() instead of manually computing round-up division
> > calculations.
> >
> > Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
> > ---
> >  fs/fuse/dev.c  | 6 +++---
> >  fs/fuse/file.c | 2 +-
> >  2 files changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
> > index 6d59cbc877c6..698289b5539e 100644
> > --- a/fs/fuse/dev.c
> > +++ b/fs/fuse/dev.c
> > @@ -1814,7 +1814,7 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size,
> >
> >               folio_offset = ((index - folio->index) << PAGE_SHIFT) + offset;
> >               nr_bytes = min_t(unsigned, num, folio_size(folio) - folio_offset);
> > -             nr_pages = (offset + nr_bytes + PAGE_SIZE - 1) >> PAGE_SHIFT;
> > +             nr_pages = DIV_ROUND_UP(offset + nr_bytes, PAGE_SIZE);
> >
> >               err = fuse_copy_folio(cs, &folio, folio_offset, nr_bytes, 0);
> >               if (!folio_test_uptodate(folio) && !err && offset == 0 &&
>
> IMHO, could we drop page offset, instead just update the file offset and
> re-calculate folio index and folio offset for each loop, i.e. something
> like what [1] did?
>
> This could make the code simpler and cleaner.

Hi Jingbo,

I'll break this change out into a separate patch. I agree your
proposed restructuring of the logic makes it simpler to parse.

Thanks,
Joanne

>
> BTW, it seems that if the grabbed folio is newly created on hand and the
> range described by the store notify doesn't cover the folio completely,
> the folio won't be set as Uptodate and thus the written data may be
> missed?  I'm not sure if this is in design.
>
> [1]
> https://lore.kernel.org/linux-fsdevel/20260115023607.77349-1-jefflexu@linux.alibaba.com/
>
>
> > @@ -1883,7 +1883,7 @@ static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode,
> >       else if (outarg->offset + num > file_size)
> >               num = file_size - outarg->offset;
> >
> > -     num_pages = (num + offset + PAGE_SIZE - 1) >> PAGE_SHIFT;
> > +     num_pages = DIV_ROUND_UP(num + offset, PAGE_SIZE);
> >       num_pages = min(num_pages, fc->max_pages);
> >       num = min(num, num_pages << PAGE_SHIFT);
> >
> > @@ -1918,7 +1918,7 @@ static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode,
> >
> >               folio_offset = ((index - folio->index) << PAGE_SHIFT) + offset;
> >               nr_bytes = min(folio_size(folio) - folio_offset, num);
> > -             nr_pages = (offset + nr_bytes + PAGE_SIZE - 1) >> PAGE_SHIFT;
> > +             nr_pages = DIV_ROUND_UP(offset + nr_bytes, PAGE_SIZE);
> >
> >               ap->folios[ap->num_folios] = folio;
> >               ap->descs[ap->num_folios].offset = folio_offset;
>
> Ditto.
>
> > diff --git a/fs/fuse/file.c b/fs/fuse/file.c
> > index eba70ebf6e77..a4342b269cb9 100644
> > --- a/fs/fuse/file.c
> > +++ b/fs/fuse/file.c
> > @@ -2170,7 +2170,7 @@ static bool fuse_folios_need_send(struct fuse_conn *fc, loff_t pos,
> >       WARN_ON(!ap->num_folios);
> >
> >       /* Reached max pages */
> > -     if ((bytes + PAGE_SIZE - 1) >> PAGE_SHIFT > fc->max_pages)
> > +     if (DIV_ROUND_UP(bytes, PAGE_SIZE) > fc->max_pages)
> >               return true;
> >
> >       if (bytes > max_bytes)
>
> --
> Thanks,
> Jingbo
>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v1 1/3] fuse: use DIV_ROUND_UP() for page count calculations
  2026-01-20 19:10     ` Joanne Koong
@ 2026-01-20 20:06       ` Joanne Koong
  2026-01-21  3:21         ` Jingbo Xu
  0 siblings, 1 reply; 17+ messages in thread
From: Joanne Koong @ 2026-01-20 20:06 UTC (permalink / raw)
  To: Jingbo Xu; +Cc: miklos, linux-fsdevel

On Tue, Jan 20, 2026 at 11:10 AM Joanne Koong <joannelkoong@gmail.com> wrote:
>
> On Sun, Jan 18, 2026 at 6:12 PM Jingbo Xu <jefflexu@linux.alibaba.com> wrote:
> >
> > On 1/17/26 7:56 AM, Joanne Koong wrote:
> > > Use DIV_ROUND_UP() instead of manually computing round-up division
> > > calculations.
> > >
> > > Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
> > > ---
> > >  fs/fuse/dev.c  | 6 +++---
> > >  fs/fuse/file.c | 2 +-
> > >  2 files changed, 4 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
> > > index 6d59cbc877c6..698289b5539e 100644
> > > --- a/fs/fuse/dev.c
> > > +++ b/fs/fuse/dev.c
> > > @@ -1814,7 +1814,7 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size,
> > >
> > >               folio_offset = ((index - folio->index) << PAGE_SHIFT) + offset;
> > >               nr_bytes = min_t(unsigned, num, folio_size(folio) - folio_offset);
> > > -             nr_pages = (offset + nr_bytes + PAGE_SIZE - 1) >> PAGE_SHIFT;
> > > +             nr_pages = DIV_ROUND_UP(offset + nr_bytes, PAGE_SIZE);
> > >
> > >               err = fuse_copy_folio(cs, &folio, folio_offset, nr_bytes, 0);
> > >               if (!folio_test_uptodate(folio) && !err && offset == 0 &&
> >
> > IMHO, could we drop page offset, instead just update the file offset and
> > re-calculate folio index and folio offset for each loop, i.e. something
> > like what [1] did?
> >
> > This could make the code simpler and cleaner.
>
> Hi Jingbo,
>
> I'll break this change out into a separate patch. I agree your
> proposed restructuring of the logic makes it simpler to parse.
>
> Thanks,
> Joanne
>
> >
> > BTW, it seems that if the grabbed folio is newly created on hand and the
> > range described by the store notify doesn't cover the folio completely,
> > the folio won't be set as Uptodate and thus the written data may be
> > missed?  I'm not sure if this is in design.

(sorry, forgot to respond to this part of your email)

I think this is intentional. By "thus the written data may be missed",
I think you're talking about the writeback path? My understanding is
it's the dirty bit, not uptodate, that determines whether the written
data gets written back. I think Darrick had the same question about
this. AFAICT, it's by design to not have writeback triggered for this
path since the server is the one providing the data so they already
know the state-of-truth for the folio contents and that should already
be reflected on their backend.


Thanks,
Joanne

> >
> > [1]
> > https://lore.kernel.org/linux-fsdevel/20260115023607.77349-1-jefflexu@linux.alibaba.com/
> >
> >
> > > @@ -1883,7 +1883,7 @@ static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode,
> > >       else if (outarg->offset + num > file_size)
> > >               num = file_size - outarg->offset;
> > >
> > > -     num_pages = (num + offset + PAGE_SIZE - 1) >> PAGE_SHIFT;
> > > +     num_pages = DIV_ROUND_UP(num + offset, PAGE_SIZE);
> > >       num_pages = min(num_pages, fc->max_pages);
> > >       num = min(num, num_pages << PAGE_SHIFT);
> > >
> > > @@ -1918,7 +1918,7 @@ static int fuse_retrieve(struct fuse_mount *fm, struct inode *inode,
> > >
> > >               folio_offset = ((index - folio->index) << PAGE_SHIFT) + offset;
> > >               nr_bytes = min(folio_size(folio) - folio_offset, num);
> > > -             nr_pages = (offset + nr_bytes + PAGE_SIZE - 1) >> PAGE_SHIFT;
> > > +             nr_pages = DIV_ROUND_UP(offset + nr_bytes, PAGE_SIZE);
> > >
> > >               ap->folios[ap->num_folios] = folio;
> > >               ap->descs[ap->num_folios].offset = folio_offset;
> >
> > Ditto.
> >
> > > diff --git a/fs/fuse/file.c b/fs/fuse/file.c
> > > index eba70ebf6e77..a4342b269cb9 100644
> > > --- a/fs/fuse/file.c
> > > +++ b/fs/fuse/file.c
> > > @@ -2170,7 +2170,7 @@ static bool fuse_folios_need_send(struct fuse_conn *fc, loff_t pos,
> > >       WARN_ON(!ap->num_folios);
> > >
> > >       /* Reached max pages */
> > > -     if ((bytes + PAGE_SIZE - 1) >> PAGE_SHIFT > fc->max_pages)
> > > +     if (DIV_ROUND_UP(bytes, PAGE_SIZE) > fc->max_pages)
> > >               return true;
> > >
> > >       if (bytes > max_bytes)
> >
> > --
> > Thanks,
> > Jingbo
> >

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v1 0/3] fuse: clean up offset and page count calculations
  2026-01-17  7:51 ` Horst Birthelmer
@ 2026-01-20 20:06   ` Joanne Koong
  0 siblings, 0 replies; 17+ messages in thread
From: Joanne Koong @ 2026-01-20 20:06 UTC (permalink / raw)
  To: Horst Birthelmer; +Cc: miklos, linux-fsdevel, jefflexu

On Fri, Jan 16, 2026 at 11:51 PM Horst Birthelmer <horst@birthelmer.de> wrote:
>
> On Fri, Jan 16, 2026 at 03:56:03PM -0800, Joanne Koong wrote:
> > This patchset aims to improve code clarity by using standard kernel helper
> > macros for common calculations:
> >  * DIV_ROUND_UP() for page count calculations
> >  * offset_in_folio() for large folio offset calculations
> >  * offset_in_page() for page offset calculations
> >
> > These helpers improve readability and consistency with patterns used
> > elsewhere in the kernel. No functional changes intended.
> >
> > This patchset is on top of Jingbo's patch in [1].
> >
> > Thanks,
> > Joanne
> >
> > [1] https://lore.kernel.org/linux-fsdevel/20260115023607.77349-1-jefflexu@linux.alibaba.com/
> >
> > Joanne Koong (3):
> >   fuse: use DIV_ROUND_UP() for page count calculations
> >   fuse: use offset_in_folio() for large folio offset calculations
> >   fuse: use offset_in_page() for page offset calculations
> >
> >  fs/fuse/dev.c     | 14 +++++++-------
> >  fs/fuse/file.c    |  2 +-
> >  fs/fuse/readdir.c |  8 ++++----
> >  3 files changed, 12 insertions(+), 12 deletions(-)
> >
> > --
> > 2.47.3
> >
>
> Looks good to me.
>
> Reviewed-by: Horst Birthelmer <hbirthelmer@ddn.com>

Thanks for taking the time to look at this, Horst!

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v1 1/3] fuse: use DIV_ROUND_UP() for page count calculations
  2026-01-20 20:06       ` Joanne Koong
@ 2026-01-21  3:21         ` Jingbo Xu
  2026-01-21 21:59           ` Joanne Koong
  0 siblings, 1 reply; 17+ messages in thread
From: Jingbo Xu @ 2026-01-21  3:21 UTC (permalink / raw)
  To: Joanne Koong; +Cc: miklos, linux-fsdevel

Hi Joanne,

Thanks for the replying ;)

On 1/21/26 4:06 AM, Joanne Koong wrote:
> On Tue, Jan 20, 2026 at 11:10 AM Joanne Koong <joannelkoong@gmail.com> wrote:
>>
>> On Sun, Jan 18, 2026 at 6:12 PM Jingbo Xu <jefflexu@linux.alibaba.com> wrote:
>>>
>>> On 1/17/26 7:56 AM, Joanne Koong wrote:
>>>> Use DIV_ROUND_UP() instead of manually computing round-up division
>>>> calculations.
>>>>
>>>> Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
>>>> ---
>>>>  fs/fuse/dev.c  | 6 +++---
>>>>  fs/fuse/file.c | 2 +-
>>>>  2 files changed, 4 insertions(+), 4 deletions(-)
>>>>
>>>> diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
>>>> index 6d59cbc877c6..698289b5539e 100644
>>>> --- a/fs/fuse/dev.c
>>>> +++ b/fs/fuse/dev.c
>>>> @@ -1814,7 +1814,7 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size,
>>>>
>>>>               folio_offset = ((index - folio->index) << PAGE_SHIFT) + offset;
>>>>               nr_bytes = min_t(unsigned, num, folio_size(folio) - folio_offset);
>>>> -             nr_pages = (offset + nr_bytes + PAGE_SIZE - 1) >> PAGE_SHIFT;
>>>> +             nr_pages = DIV_ROUND_UP(offset + nr_bytes, PAGE_SIZE);
>>>>
>>>>               err = fuse_copy_folio(cs, &folio, folio_offset, nr_bytes, 0);
>>>>               if (!folio_test_uptodate(folio) && !err && offset == 0 &&
>>>
>>> IMHO, could we drop page offset, instead just update the file offset and
>>> re-calculate folio index and folio offset for each loop, i.e. something
>>> like what [1] did?
>>>
>>> This could make the code simpler and cleaner.
>>
>> Hi Jingbo,
>>
>> I'll break this change out into a separate patch. I agree your
>> proposed restructuring of the logic makes it simpler to parse.
>>
>> Thanks,
>> Joanne
>>
>>>
>>> BTW, it seems that if the grabbed folio is newly created on hand and the
>>> range described by the store notify doesn't cover the folio completely,
>>> the folio won't be set as Uptodate and thus the written data may be
>>> missed?  I'm not sure if this is in design.
> 
> (sorry, forgot to respond to this part of your email)
> 
> I think this is intentional. By "thus the written data may be missed",
> I think you're talking about the writeback path? My understanding is
> it's the dirty bit, not uptodate,

Not exactly. What I'm concerned is the uptodate bit.

In the case where "the grabbed folio is newly created on hand and the
range described by the store notify doesn't cover the folio completely,
the folio won't be set as Uptodate", the following read(2) or write(2)
on the folio will discard the content already in the folio, instead it
triggers .readpage() to fetch data from FUSE server again.

It seems that it is a deliberate constraint for FUSE_NOTIFY_STORE.

 that determines whether the written
> data gets written back. I think Darrick had the same question about
> this. AFAICT, it's by design to not have writeback triggered for this
> path since the server is the one providing the data so they already
> know the state-of-truth for the folio contents and that should already
> be reflected on their backend.
> 
-- 
Thanks,
Jingbo


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v1 1/3] fuse: use DIV_ROUND_UP() for page count calculations
  2026-01-21  3:21         ` Jingbo Xu
@ 2026-01-21 21:59           ` Joanne Koong
  2026-01-22  1:49             ` Jingbo Xu
  0 siblings, 1 reply; 17+ messages in thread
From: Joanne Koong @ 2026-01-21 21:59 UTC (permalink / raw)
  To: Jingbo Xu; +Cc: miklos, linux-fsdevel

On Tue, Jan 20, 2026 at 7:21 PM Jingbo Xu <jefflexu@linux.alibaba.com> wrote:
>
> Hi Joanne,
>
> Thanks for the replying ;)
>
> On 1/21/26 4:06 AM, Joanne Koong wrote:
> > On Tue, Jan 20, 2026 at 11:10 AM Joanne Koong <joannelkoong@gmail.com> wrote:
> >>
> >> On Sun, Jan 18, 2026 at 6:12 PM Jingbo Xu <jefflexu@linux.alibaba.com> wrote:
> >>>
> >>> On 1/17/26 7:56 AM, Joanne Koong wrote:
> >>>> Use DIV_ROUND_UP() instead of manually computing round-up division
> >>>> calculations.
> >>>>
> >>>> Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
> >>>> ---
> >>>>  fs/fuse/dev.c  | 6 +++---
> >>>>  fs/fuse/file.c | 2 +-
> >>>>  2 files changed, 4 insertions(+), 4 deletions(-)
> >>>>
> >>>> diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
> >>>> index 6d59cbc877c6..698289b5539e 100644
> >>>> --- a/fs/fuse/dev.c
> >>>> +++ b/fs/fuse/dev.c
> >>>> @@ -1814,7 +1814,7 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size,
> >>>>
> >>>>               folio_offset = ((index - folio->index) << PAGE_SHIFT) + offset;
> >>>>               nr_bytes = min_t(unsigned, num, folio_size(folio) - folio_offset);
> >>>> -             nr_pages = (offset + nr_bytes + PAGE_SIZE - 1) >> PAGE_SHIFT;
> >>>> +             nr_pages = DIV_ROUND_UP(offset + nr_bytes, PAGE_SIZE);
> >>>>
> >>>>               err = fuse_copy_folio(cs, &folio, folio_offset, nr_bytes, 0);
> >>>>               if (!folio_test_uptodate(folio) && !err && offset == 0 &&
> >>>
> >>> IMHO, could we drop page offset, instead just update the file offset and
> >>> re-calculate folio index and folio offset for each loop, i.e. something
> >>> like what [1] did?
> >>>
> >>> This could make the code simpler and cleaner.
> >>
> >> Hi Jingbo,
> >>
> >> I'll break this change out into a separate patch. I agree your
> >> proposed restructuring of the logic makes it simpler to parse.
> >>
> >> Thanks,
> >> Joanne
> >>
> >>>
> >>> BTW, it seems that if the grabbed folio is newly created on hand and the
> >>> range described by the store notify doesn't cover the folio completely,
> >>> the folio won't be set as Uptodate and thus the written data may be
> >>> missed?  I'm not sure if this is in design.
> >
> > (sorry, forgot to respond to this part of your email)
> >
> > I think this is intentional. By "thus the written data may be missed",
> > I think you're talking about the writeback path? My understanding is
> > it's the dirty bit, not uptodate,
>
> Not exactly. What I'm concerned is the uptodate bit.
>
> In the case where "the grabbed folio is newly created on hand and the
> range described by the store notify doesn't cover the folio completely,
> the folio won't be set as Uptodate", the following read(2) or write(2)
> on the folio will discard the content already in the folio, instead it
> triggers .readpage() to fetch data from FUSE server again.

Could you elaborate on why this concerns you? Isn't this necessary
behavior given that it needs to fetch the parts that the store notify
didn't cover? Or is your concern that the contents are discarded? But
the server already has that information stored on their side, so I'm
not seeing why that's a problem.

Thanks,
Joanne

>
> It seems that it is a deliberate constraint for FUSE_NOTIFY_STORE.
>
>  that determines whether the written
> > data gets written back. I think Darrick had the same question about
> > this. AFAICT, it's by design to not have writeback triggered for this
> > path since the server is the one providing the data so they already
> > know the state-of-truth for the folio contents and that should already
> > be reflected on their backend.
> >
> --
> Thanks,
> Jingbo
>

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH v1 1/3] fuse: use DIV_ROUND_UP() for page count calculations
  2026-01-21 21:59           ` Joanne Koong
@ 2026-01-22  1:49             ` Jingbo Xu
  0 siblings, 0 replies; 17+ messages in thread
From: Jingbo Xu @ 2026-01-22  1:49 UTC (permalink / raw)
  To: Joanne Koong; +Cc: miklos, linux-fsdevel



On 1/22/26 5:59 AM, Joanne Koong wrote:
> On Tue, Jan 20, 2026 at 7:21 PM Jingbo Xu <jefflexu@linux.alibaba.com> wrote:
>>
>> Hi Joanne,
>>
>> Thanks for the replying ;)
>>
>> On 1/21/26 4:06 AM, Joanne Koong wrote:
>>> On Tue, Jan 20, 2026 at 11:10 AM Joanne Koong <joannelkoong@gmail.com> wrote:
>>>>
>>>> On Sun, Jan 18, 2026 at 6:12 PM Jingbo Xu <jefflexu@linux.alibaba.com> wrote:
>>>>>
>>>>> On 1/17/26 7:56 AM, Joanne Koong wrote:
>>>>>> Use DIV_ROUND_UP() instead of manually computing round-up division
>>>>>> calculations.
>>>>>>
>>>>>> Signed-off-by: Joanne Koong <joannelkoong@gmail.com>
>>>>>> ---
>>>>>>  fs/fuse/dev.c  | 6 +++---
>>>>>>  fs/fuse/file.c | 2 +-
>>>>>>  2 files changed, 4 insertions(+), 4 deletions(-)
>>>>>>
>>>>>> diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
>>>>>> index 6d59cbc877c6..698289b5539e 100644
>>>>>> --- a/fs/fuse/dev.c
>>>>>> +++ b/fs/fuse/dev.c
>>>>>> @@ -1814,7 +1814,7 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size,
>>>>>>
>>>>>>               folio_offset = ((index - folio->index) << PAGE_SHIFT) + offset;
>>>>>>               nr_bytes = min_t(unsigned, num, folio_size(folio) - folio_offset);
>>>>>> -             nr_pages = (offset + nr_bytes + PAGE_SIZE - 1) >> PAGE_SHIFT;
>>>>>> +             nr_pages = DIV_ROUND_UP(offset + nr_bytes, PAGE_SIZE);
>>>>>>
>>>>>>               err = fuse_copy_folio(cs, &folio, folio_offset, nr_bytes, 0);
>>>>>>               if (!folio_test_uptodate(folio) && !err && offset == 0 &&
>>>>>
>>>>> IMHO, could we drop page offset, instead just update the file offset and
>>>>> re-calculate folio index and folio offset for each loop, i.e. something
>>>>> like what [1] did?
>>>>>
>>>>> This could make the code simpler and cleaner.
>>>>
>>>> Hi Jingbo,
>>>>
>>>> I'll break this change out into a separate patch. I agree your
>>>> proposed restructuring of the logic makes it simpler to parse.
>>>>
>>>> Thanks,
>>>> Joanne
>>>>
>>>>>
>>>>> BTW, it seems that if the grabbed folio is newly created on hand and the
>>>>> range described by the store notify doesn't cover the folio completely,
>>>>> the folio won't be set as Uptodate and thus the written data may be
>>>>> missed?  I'm not sure if this is in design.
>>>
>>> (sorry, forgot to respond to this part of your email)
>>>
>>> I think this is intentional. By "thus the written data may be missed",
>>> I think you're talking about the writeback path? My understanding is
>>> it's the dirty bit, not uptodate,
>>
>> Not exactly. What I'm concerned is the uptodate bit.
>>
>> In the case where "the grabbed folio is newly created on hand and the
>> range described by the store notify doesn't cover the folio completely,
>> the folio won't be set as Uptodate", the following read(2) or write(2)
>> on the folio will discard the content already in the folio, instead it
>> triggers .readpage() to fetch data from FUSE server again.
> 
> Could you elaborate on why this concerns you? Isn't this necessary
> behavior given that it needs to fetch the parts that the store notify
> didn't cover? Or is your concern that the contents are discarded? But
> the server already has that information stored on their side, so I'm
> not seeing why that's a problem.
> 

I'm not thinking it as a problem.  As said, I guess it is just a design
constraint for FUSE_NOTIFY_STORE.

Thanks.


-- 
Thanks,
Jingbo


^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2026-01-22  1:49 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-16 23:56 [PATCH v1 0/3] fuse: clean up offset and page count calculations Joanne Koong
2026-01-16 23:56 ` [PATCH v1 1/3] fuse: use DIV_ROUND_UP() for " Joanne Koong
2026-01-19  2:12   ` Jingbo Xu
2026-01-20 19:10     ` Joanne Koong
2026-01-20 20:06       ` Joanne Koong
2026-01-21  3:21         ` Jingbo Xu
2026-01-21 21:59           ` Joanne Koong
2026-01-22  1:49             ` Jingbo Xu
2026-01-16 23:56 ` [PATCH v1 2/3] fuse: use offset_in_folio() for large folio offset calculations Joanne Koong
2026-01-19  4:41   ` Chunsheng Luo
2026-01-20 18:59     ` Joanne Koong
2026-01-19  6:24   ` Chunsheng Luo
2026-01-16 23:56 ` [PATCH v1 3/3] fuse: use offset_in_page() for page " Joanne Koong
2026-01-17  5:03 ` [PATCH v1 0/3] fuse: clean up offset and page count calculations Darrick J. Wong
2026-01-20 19:05   ` Joanne Koong
2026-01-17  7:51 ` Horst Birthelmer
2026-01-20 20:06   ` Joanne Koong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox