Skip to contentSkip to conversation

fuse: drop unused fuse_mount arg in fuse_writepage_finish

PATCH Superseded Joanne Koong 4 participants 10 messages Aug 19, 2024 – Aug 22, 2024

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 fuse: drop unused fuse_mount arg in fuse_writepage_finish

---
 fs/fuse/file.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
fs/fuse/file.c +3 -4
index f39456c65ed7..63fd5fc6872e 100644
@@ -1769,8 +1769,7 @@ static void fuse_writepage_free(struct fuse_writepage_args *wpa)
 	kfree(wpa);
 }
 
-static void fuse_writepage_finish(struct fuse_mount *fm,
-				  struct fuse_writepage_args *wpa)
+static void fuse_writepage_finish(struct fuse_writepage_args *wpa)
 {
 	struct fuse_args_pages *ap = &wpa->ia.ap;
 	struct inode *inode = wpa->inode;
@@ -1829,7 +1828,7 @@ __acquires(fi->lock)
  out_free:
 	fi->writectr--;
 	rb_erase(&wpa->writepages_entry, &fi->writepages);
-	fuse_writepage_finish(fm, wpa);
+	fuse_writepage_finish(wpa);
 	spin_unlock(&fi->lock);
 
 	/* After fuse_writepage_finish() aux request list is private */
@@ -1959,7 +1958,7 @@ static void fuse_writepage_end(struct fuse_mount *fm, struct fuse_args *args,
 		fuse_send_writepage(fm, next, inarg->offset + inarg->size);
 	}
 	fi->writectr--;
-	fuse_writepage_finish(fm, wpa);
+	fuse_writepage_finish(wpa);
 	spin_unlock(&fi->lock);
 	fuse_writepage_free(wpa);
 }
Signature · 1 line
2.43.5
#1 lore raw

PATCH 2/2 fuse: update stats for pages in dropped aux writeback list

In the case where the aux writeback list is dropped (eg the pages have been truncated or the connection is broken), the stats for its pages and backing device info need to be updated as well.

Fixes e2653bd53a98 ("fuse: fix leaked aux requests")
---
 fs/fuse/file.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/fuse/file.c +2 -1
index 63fd5fc6872e..7ac56be5fee6 100644
@@ -1831,10 +1831,11 @@ __acquires(fi->lock)
 	fuse_writepage_finish(wpa);
 	spin_unlock(&fi->lock);
 
-	/* After fuse_writepage_finish() aux request list is private */
+	/* After rb_erase() aux request list is private */
 	for (aux = wpa->next; aux; aux = next) {
 		next = aux->next;
 		aux->next = NULL;
+		fuse_writepage_finish(aux);
 		fuse_writepage_free(aux);
 	}
 
Signature · 1 line
2.43.5
#2 lore raw

Re: [PATCH 2/2] fuse: update stats for pages in dropped aux writeback list

Quoted 17 lines · Joanne Koong

In the case where the aux writeback list is dropped (eg the pages have been truncated or the connection is broken), the stats for its pages and backing device info need to be updated as well.

Fixes e2653bd53a98 ("fuse: fix leaked aux requests")
---
 fs/fuse/file.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/fuse/file.c +0 -0
index 63fd5fc6872e..7ac56be5fee6 100644
@@ -1831,10 +1831,11 @@ __acquires(fi->lock)
 	fuse_writepage_finish(wpa);
 	spin_unlock(&fi->lock);

fs/fuse/file.c __acquires(fi->lock) · line 1841

Quoted 10 lines
fs/fuse/file.c +2 -1
 
-	/* After fuse_writepage_finish() aux request list is private */
+	/* After rb_erase() aux request list is private */
 	for (aux = wpa->next; aux; aux = next) {
 		next = aux->next;
 		aux->next = NULL;
+		fuse_writepage_finish(aux);
 		fuse_writepage_free(aux);
 	}
 

LGTM.

Besides, there is similar logic of decreasing stats info for replaced aux (temp) request inside fuse_writepage_add(), though without waking up fi->page_waitq.

I wonder if we could factor out a new helper function, saying fuse_writepage_dec_stat(), which could be called both from fuse_writepage_add() and fuse_send_writepage().

Signature · 2 lines
Thanks,
Jingbo
#3 lore raw

Re: [PATCH 2/2] fuse: update stats for pages in dropped aux writeback list

Quoted 34 lines · Jingbo Xu
Quoted 17 lines · Joanne Koong

In the case where the aux writeback list is dropped (eg the pages have been truncated or the connection is broken), the stats for its pages and backing device info need to be updated as well.

Fixes e2653bd53a98 ("fuse: fix leaked aux requests")
---
 fs/fuse/file.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/fuse/file.c +0 -0
index 63fd5fc6872e..7ac56be5fee6 100644
@@ -1831,10 +1831,11 @@ __acquires(fi->lock)
      fuse_writepage_finish(wpa);
      spin_unlock(&fi->lock);

fs/fuse/file.c __acquires(fi->lock) · line 1841

Quoted 10 lines
fs/fuse/file.c +2 -1
 
-     /* After fuse_writepage_finish() aux request list is private */
+     /* After rb_erase() aux request list is private */
      for (aux = wpa->next; aux; aux = next) {
              next = aux->next;
              aux->next = NULL;
+             fuse_writepage_finish(aux);
              fuse_writepage_free(aux);
      }
 

LGTM.

Quoted 7 lines

Besides, there is similar logic of decreasing stats info for replaced aux (temp) request inside fuse_writepage_add(), though without waking up fi->page_waitq.

I wonder if we could factor out a new helper function, saying fuse_writepage_dec_stat(), which could be called both from fuse_writepage_add() and fuse_send_writepage().

This sounds good to me. I'll add this refactoring when I resubmit this patch series.

Thanks,
Joanne

Quoted 5 lines

--
Thanks,
Jingbo

maintainer
#4 lore raw

Re: [PATCH 2/2] fuse: update stats for pages in dropped aux writeback list

In reply to Joanne Koong
Quoted 4 lines · Joanne Koong

In the case where the aux writeback list is dropped (eg the pages have been truncated or the connection is broken), the stats for its pages and backing device info need to be updated as well.

Patch looks good. Thanks.

Do you have a reproducer or was this found by code review only?

Thanks,
Miklos

#5 lore raw

Re: [PATCH 2/2] fuse: update stats for pages in dropped aux writeback list

Quoted 9 lines · Miklos Szeredi
Quoted 4 lines · Joanne Koong

In the case where the aux writeback list is dropped (eg the pages have been truncated or the connection is broken), the stats for its pages and backing device info need to be updated as well.

Patch looks good. Thanks.

Do you have a reproducer or was this found by code review only?

That's indeed a nice catch from Joanne!.

I would have expected that writing to a file and in parallel truncating it would leak WritebackTmp in /proc/meminfo. But I see it going up and always to 0 again.

Thanks,
Bernd

#6 lore raw

Re: [PATCH 2/2] fuse: update stats for pages in dropped aux writeback list

Quoted 6 lines · Bernd Schubert
Quoted 2 lines · Miklos Szeredi
Quoted 1 line · Joanne Koong
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines

In the case where the aux writeback list is dropped (eg the pages have been truncated or the connection is broken), the stats for its pages and backing device info need to be updated as well.

Patch looks good. Thanks.

Do you have a reproducer or was this found by code review only?

Hi Miklos!

I unfortunately don't have a repro, this was found by code review. I started looking at the writeback code after reading through this thread
https://lore.kernel.org/all/[email protected]/#t

For v2 of this patchset, I am planning to add a few more refactoring patches like abstracting out the shared logic between fuse_writepages_fill() and fuse_writepage_locked(). My plan is to submit v2 this week.

Quoted 6 lines

That's indeed a nice catch from Joanne!.

I would have expected that writing to a file and in parallel truncating it would leak WritebackTmp in /proc/meminfo. But I see it going up and always to 0 again.

I think we only hit this leaked case when we're writing back to a page that is already in writeback (which then leads it to being placed on the auxiliary list). I think in your example, the page isn't already in writeback?

Quoted 4 lines

Thanks,
Bernd

Thanks,
Joanne

maintainer
#7 lore raw

Re: [PATCH 2/2] fuse: update stats for pages in dropped aux writeback list

Quoted 4 lines · Joanne Koong

I unfortunately don't have a repro, this was found by code review. I started looking at the writeback code after reading through this thread
https://lore.kernel.org/all/[email protected]/#t

No problem, I was just curious.

Thanks,
Miklos

Reviewed-by on v1 1/2
#8 lore raw
In reply to Joanne Koong
Quoted 29 lines · Joanne Koong
---
 fs/fuse/file.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
fs/fuse/file.c +2 -3
index f39456c65ed7..63fd5fc6872e 100644
@@ -1769,8 +1769,7 @@ static void fuse_writepage_free(struct fuse_writepage_args *wpa)
 	kfree(wpa);
 }
 
-static void fuse_writepage_finish(struct fuse_mount *fm,
-				  struct fuse_writepage_args *wpa)
+static void fuse_writepage_finish(struct fuse_writepage_args *wpa)
 {
 	struct fuse_args_pages *ap = &wpa->ia.ap;
 	struct inode *inode = wpa->inode;
@@ -1829,7 +1828,7 @@ __acquires(fi->lock)
  out_free:
 	fi->writectr--;
 	rb_erase(&wpa->writepages_entry, &fi->writepages);
-	fuse_writepage_finish(fm, wpa);
+	fuse_writepage_finish(wpa);
 	spin_unlock(&fi->lock);
 
 	/* After fuse_writepage_finish() aux request list is private */

fs/fuse/file.c static void fuse_writepage_end(struct fuse_mount *fm, struct fuse_args *args, · line 1964

Quoted 8 lines
fs/fuse/file.c +1 -1
@@ -1959,7 +1958,7 @@ static void fuse_writepage_end(struct fuse_mount *fm, struct fuse_args *args,
 		fuse_send_writepage(fm, next, inarg->offset + inarg->size);
 	}
 	fi->writectr--;
-	fuse_writepage_finish(fm, wpa);
+	fuse_writepage_finish(wpa);
 	spin_unlock(&fi->lock);
 	fuse_writepage_free(wpa);
 }

I'm afraid an empty commit message will trigger a warning when running checkpatch. Otherwise LGTM.

Signature · 2 lines
Thanks,
Jingbo
#9 lore raw
Quoted 30 lines · Jingbo Xu
Quoted 27 lines · Joanne Koong
---
 fs/fuse/file.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
fs/fuse/file.c +2 -3
index f39456c65ed7..63fd5fc6872e 100644
@@ -1769,8 +1769,7 @@ static void fuse_writepage_free(struct fuse_writepage_args *wpa)
      kfree(wpa);
 }
 
-static void fuse_writepage_finish(struct fuse_mount *fm,
-                               struct fuse_writepage_args *wpa)
+static void fuse_writepage_finish(struct fuse_writepage_args *wpa)
 {
      struct fuse_args_pages *ap = &wpa->ia.ap;
      struct inode *inode = wpa->inode;
@@ -1829,7 +1828,7 @@ __acquires(fi->lock)
  out_free:
      fi->writectr--;
      rb_erase(&wpa->writepages_entry, &fi->writepages);
-     fuse_writepage_finish(fm, wpa);
+     fuse_writepage_finish(wpa);
      spin_unlock(&fi->lock);
 
Quoted 13 lines

fs/fuse/file.c static void fuse_writepage_end(struct fuse_mount *fm, struct fuse_args *args, · line 1964

Quoted 10 lines
fs/fuse/file.c +1 -1
      /* After fuse_writepage_finish() aux request list is private */
@@ -1959,7 +1958,7 @@ static void fuse_writepage_end(struct fuse_mount *fm, struct fuse_args *args,
              fuse_send_writepage(fm, next, inarg->offset + inarg->size);
      }
      fi->writectr--;
-     fuse_writepage_finish(fm, wpa);
+     fuse_writepage_finish(wpa);
      spin_unlock(&fi->lock);
      fuse_writepage_free(wpa);
 }

I'm afraid an empty commit message will trigger a warning when running checkpatch. Otherwise LGTM.

Gotcha, I'll resubmit this with a commit message. Thanks for taking a look.

Quoted 6 lines

--
Thanks,
Jingbo