Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the semantics of vmsplice(2), with and without gifting?

I'm trying to understand the functionality of the vmsplice(2) syscall (man page here). I have two questions about the effect of the SPLICE_F_GIFT flag:

  1. The man page says that once you gift pages to the kernel, you must never modify the memory again. Does that mean the memory is pinned forever, or does it perhaps refer to virtual memory that can be unmapped by the gifting process, rather than physical memory? In other words, what does a typical use of this look like?

  2. If I don't set SPLICE_F_GIFT, is vmsplice(2) any different than a vectorized write syscall like writev(2)?

like image 809
jacobsa Avatar asked Aug 14 '15 01:08

jacobsa


1 Answers

1 - Yes, its different.
If you write 1GB to a pipe with write, it will loop until those 1GB are delivered to the pipe, unless a signal interrupts the work.
If you vmsplice 1GB to a pipe, it will only block if the pipe buffer is full, and then only write what's available in the pipe's buffer.
Very frustrating that it doesn't loop over and keep writing as a regular write. You trade not copying with having to do a whole bunch of vmsplice calls and having to implement a loop for partial vmsplice writes.

2 - I was vmsplicing from mmaped areas and was able to munmap instantly after vmsplicing, without crashes or data corruption.

like image 71
Marcelo Pacheco Avatar answered Oct 12 '22 13:10

Marcelo Pacheco