Skip to contentSkip to conversation

use fuse_buf_writev to replace fuse_buf_write for better performance

RFC PATCH Superseded piaojun 3 participants 6 messages Aug 7, 2019 – Aug 8, 2019

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

piaojun

author
#0 lore raw

RFC PATCH v2 2/2 use fuse_buf_writev to replace fuse_buf_write for better performance

fuse_buf_writev() only handles the normal write in which src is buffer and dest is fd. Specially if src buffer represents guest physical address that can't be mapped by the daemon process, IO must be bounced back to the VMM to do it by fuse_buf_copy().

---
 contrib/virtiofsd/passthrough_ll.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
contrib/virtiofsd/passthrough_ll.c +4 -1
index cc9c175..c1bbc53 100644
@@ -2023,7 +2023,10 @@ static void lo_write_buf(fuse_req_t req, fuse_ino_t ino,
 		fuse_debug("lo_write_buf(ino=%" PRIu64 ", size=%zd, off=%lu)\n",
 			   ino, out_buf.buf[0].size, (unsigned long) off);
 
-	res = fuse_buf_copy(req, &out_buf, in_buf, 0);
+	if (!(in_buf->buf[0].flags & FUSE_BUF_PHYS_ADDR))
+		res = fuse_buf_writev(req, &out_buf, in_buf, out_buf.buf[0].flags);
+	else
+		res = fuse_buf_copy(req, &out_buf, in_buf, 0);
 	if(res < 0) {
 		fuse_reply_err(req, -res);
 	} else {
#1 lore raw
Quoted 16 lines · piaojun

fuse_buf_writev() only handles the normal write in which src is buffer and dest is fd. Specially if src buffer represents guest physical address that can't be mapped by the daemon process, IO must be bounced back to the VMM to do it by fuse_buf_copy().

---
 contrib/virtiofsd/passthrough_ll.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
contrib/virtiofsd/passthrough_ll.c +0 -0
index cc9c175..c1bbc53 100644

contrib/virtiofsd/passthrough_ll.c static void lo_write_buf(fuse_req_t req, fuse_ino_t ino, · line 2029

Quoted 8 lines
contrib/virtiofsd/passthrough_ll.c +4 -1
@@ -2023,7 +2023,10 @@ static void lo_write_buf(fuse_req_t req, fuse_ino_t ino,
 		fuse_debug("lo_write_buf(ino=%" PRIu64 ", size=%zd, off=%lu)\n",
 			   ino, out_buf.buf[0].size, (unsigned long) off);
 
-	res = fuse_buf_copy(req, &out_buf, in_buf, 0);
+	if (!(in_buf->buf[0].flags & FUSE_BUF_PHYS_ADDR))
+		res = fuse_buf_writev(req, &out_buf, in_buf, out_buf.buf[0].flags);
+	else
+		res = fuse_buf_copy(req, &out_buf, in_buf, 0);

Can you move the check inside fuse_buf_copy() and make fuse_buf_writev() a static function? This way all fuse_buf_copy() callers automatically benefit from the improvement (when possible).

By the way, this improvement can be sent upstream to libfuse so that other FUSE file systems also get improved performance.

Stefan

author
#2 lore raw

Hi Stefan,

Quoted 20 lines · Stefan Hajnoczi
Quoted 19 lines · piaojun

fuse_buf_writev() only handles the normal write in which src is buffer and dest is fd. Specially if src buffer represents guest physical address that can't be mapped by the daemon process, IO must be bounced back to the VMM to do it by fuse_buf_copy().

---
 contrib/virtiofsd/passthrough_ll.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
contrib/virtiofsd/passthrough_ll.c +0 -0
index cc9c175..c1bbc53 100644
@@ -2023,7 +2023,10 @@ static void lo_write_buf(fuse_req_t req, fuse_ino_t ino,
 		fuse_debug("lo_write_buf(ino=%" PRIu64 ", size=%zd, off=%lu)\n",
 			   ino, out_buf.buf[0].size, (unsigned long) off);
 
Quoted 9 lines

contrib/virtiofsd/passthrough_ll.c static void lo_write_buf(fuse_req_t req, fuse_ino_t ino, · line 2029

Quoted 5 lines
contrib/virtiofsd/passthrough_ll.c +4 -1
-	res = fuse_buf_copy(req, &out_buf, in_buf, 0);
+	if (!(in_buf->buf[0].flags & FUSE_BUF_PHYS_ADDR))
+		res = fuse_buf_writev(req, &out_buf, in_buf, out_buf.buf[0].flags);
+	else
+		res = fuse_buf_copy(req, &out_buf, in_buf, 0);

Can you move the check inside fuse_buf_copy() and make fuse_buf_writev() a static function? This way all fuse_buf_copy() callers automatically benefit from the improvement (when possible).

Good suggestion. I will try it in patch v3, and I'm also waiting other developers's comments.

Quoted 3 lines

By the way, this improvement can be sent upstream to libfuse so that other FUSE file systems also get improved performance.

Yes, I need some time looking into libfuse code and sync the fix.

Thanks,
Jun

Quoted 4 lines

Stefan
.

#3 lore raw
In reply to piaojun
Quoted 16 lines · * piaojun ([email protected]) wrote:

fuse_buf_writev() only handles the normal write in which src is buffer and dest is fd. Specially if src buffer represents guest physical address that can't be mapped by the daemon process, IO must be bounced back to the VMM to do it by fuse_buf_copy().

---
 contrib/virtiofsd/passthrough_ll.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
contrib/virtiofsd/passthrough_ll.c +0 -0
index cc9c175..c1bbc53 100644

contrib/virtiofsd/passthrough_ll.c static void lo_write_buf(fuse_req_t req, fuse_ino_t ino, · line 2026

Quoted 5 lines
contrib/virtiofsd/passthrough_ll.c +1 -1
@@ -2023,7 +2023,10 @@ static void lo_write_buf(fuse_req_t req, fuse_ino_t ino,
 		fuse_debug("lo_write_buf(ino=%" PRIu64 ", size=%zd, off=%lu)\n",
 			   ino, out_buf.buf[0].size, (unsigned long) off);
 
-	res = fuse_buf_copy(req, &out_buf, in_buf, 0);
+	if (!(in_buf->buf[0].flags & FUSE_BUF_PHYS_ADDR))

I don't think you can assume that the flags in in_buf[0] represent the state of the entire vector; I'm pretty sure we had a case of an application that did a writev() in the guest where the first element was on the stack and the other was in an mmap, and it was only the 2nd one that had the flag.

But also you're not checking any of the other flags either.

Dave

contrib/virtiofsd/passthrough_ll.c static void lo_write_buf(fuse_req_t req, fuse_ino_t ino, · line 2032

Quoted 7 lines
contrib/virtiofsd/passthrough_ll.c +3 -0
+		res = fuse_buf_writev(req, &out_buf, in_buf, out_buf.buf[0].flags);
+	else
+		res = fuse_buf_copy(req, &out_buf, in_buf, 0);
 	if(res < 0) {
 		fuse_reply_err(req, -res);
 	} else {

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

author
#4 lore raw

Hi Dave,

Quoted 20 lines · Dr. David Alan Gilbert
Quoted 19 lines · * piaojun ([email protected]) wrote:

fuse_buf_writev() only handles the normal write in which src is buffer and dest is fd. Specially if src buffer represents guest physical address that can't be mapped by the daemon process, IO must be bounced back to the VMM to do it by fuse_buf_copy().

---
 contrib/virtiofsd/passthrough_ll.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
contrib/virtiofsd/passthrough_ll.c +0 -0
index cc9c175..c1bbc53 100644
@@ -2023,7 +2023,10 @@ static void lo_write_buf(fuse_req_t req, fuse_ino_t ino,
 		fuse_debug("lo_write_buf(ino=%" PRIu64 ", size=%zd, off=%lu)\n",
 			   ino, out_buf.buf[0].size, (unsigned long) off);
 
Quoted 8 lines

contrib/virtiofsd/passthrough_ll.c static void lo_write_buf(fuse_req_t req, fuse_ino_t ino, · line 2026

Quoted 2 lines
contrib/virtiofsd/passthrough_ll.c +1 -1
-	res = fuse_buf_copy(req, &out_buf, in_buf, 0);
+	if (!(in_buf->buf[0].flags & FUSE_BUF_PHYS_ADDR))

I don't think you can assume that the flags in in_buf[0] represent the state of the entire vector; I'm pretty sure we had a case of an application that did a writev() in the guest where the first element was on the stack and the other was in an mmap, and it was only the 2nd one that had the flag.

Yes, this assumption is idealized, and perhaps I need check all the flags of entire vector before doing writev, right?

Thanks,
Jun

Quoted 16 lines

But also you're not checking any of the other flags either.

Dave

contrib/virtiofsd/passthrough_ll.c static void lo_write_buf(fuse_req_t req, fuse_ino_t ino, · line 2032

Quoted 7 lines
contrib/virtiofsd/passthrough_ll.c +3 -0
+		res = fuse_buf_writev(req, &out_buf, in_buf, out_buf.buf[0].flags);
+	else
+		res = fuse_buf_copy(req, &out_buf, in_buf, 0);
 	if(res < 0) {
 		fuse_reply_err(req, -res);
 	} else {

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK .

#5 lore raw
Quoted 32 lines · * piaojun ([email protected]) wrote:

Hi Dave,

Quoted 20 lines · Dr. David Alan Gilbert
Quoted 19 lines · * piaojun ([email protected]) wrote:

fuse_buf_writev() only handles the normal write in which src is buffer and dest is fd. Specially if src buffer represents guest physical address that can't be mapped by the daemon process, IO must be bounced back to the VMM to do it by fuse_buf_copy().

---
 contrib/virtiofsd/passthrough_ll.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
contrib/virtiofsd/passthrough_ll.c +0 -0
index cc9c175..c1bbc53 100644
@@ -2023,7 +2023,10 @@ static void lo_write_buf(fuse_req_t req, fuse_ino_t ino,
 		fuse_debug("lo_write_buf(ino=%" PRIu64 ", size=%zd, off=%lu)\n",
 			   ino, out_buf.buf[0].size, (unsigned long) off);
 
Quoted 8 lines

contrib/virtiofsd/passthrough_ll.c static void lo_write_buf(fuse_req_t req, fuse_ino_t ino, · line 2026

Quoted 2 lines
contrib/virtiofsd/passthrough_ll.c +1 -1
-	res = fuse_buf_copy(req, &out_buf, in_buf, 0);
+	if (!(in_buf->buf[0].flags & FUSE_BUF_PHYS_ADDR))

I don't think you can assume that the flags in in_buf[0] represent the state of the entire vector; I'm pretty sure we had a case of an application that did a writev() in the guest where the first element was on the stack and the other was in an mmap, and it was only the 2nd one that had the flag.

Quoted 2 lines

Yes, this assumption is idealized, and perhaps I need check all the flags of entire vector before doing writev, right?

Yes, you need to make sure that the vector fits the nice easy sequential case for pwritev.

Dave

Quoted 19 lines

Thanks,
Jun

Quoted 16 lines

But also you're not checking any of the other flags either.

Dave

contrib/virtiofsd/passthrough_ll.c static void lo_write_buf(fuse_req_t req, fuse_ino_t ino, · line 2032

Quoted 7 lines
contrib/virtiofsd/passthrough_ll.c +3 -0
+		res = fuse_buf_writev(req, &out_buf, in_buf, out_buf.buf[0].flags);
+	else
+		res = fuse_buf_copy(req, &out_buf, in_buf, 0);
 	if(res < 0) {
 		fuse_reply_err(req, -res);
 	} else {

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK .

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK