10

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)?

jacobsa
  • 5,719
  • 1
  • 28
  • 60

2 Answers2

1

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.

Marcelo Pacheco
  • 152
  • 1
  • 5
0

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?

You are promising not to modify the page. Not the page's virtual addressing. For most use cases the suggest operation is something like:

mmap
read
vmsplice
munmap

Generally you want to use mmap over malloc as you want to ensure you have a page, not just 4096bytes of RAM. Which could sit in the middle of a 2MB, or 1GB HUGE_PAGE if your allocator determines that is more efficient.

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

Yes

Most buffers in the kernels are pipes. Or really pipes are represented by the same data structure as buffers.

Valarauca
  • 1,041
  • 3
  • 10
  • 23