Skip to contentSkip to conversation

zero-copy read() interface

DISCUSSION Folkert van Heusden 5 participants 8 messages Aug 18, 2005 – Aug 21, 2005

lore
Share & tools
lore
#0 lore raw

What about a zero-copy read-interface?
An ioctl (or something) which enables the kernel to do dma directly to the userspace. Of course this should be limited to the root-user or a user with special capabilities (rights) since if a drive screws up, data from a different sector (or so) might end up in the proces' memory. Of course copying a sector from kernel- to userspace can be done pretty fast but i.m.h.o. all possible speedimprovements should be made unless unclean.

Folkert van Heusden

Signature · 5 lines
Auto te koop, zie: http://www.vanheusden.com/daihatsu.php
----------------------------------------------------------------------
Get your PGP/GPG key signed at www.biglumber.com!
----------------------------------------------------------------------
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
#1 lore raw
Quoted 9 lines · Folkert van Heusden

What about a zero-copy read-interface?
An ioctl (or something) which enables the kernel to do dma directly to the userspace. Of course this should be limited to the root-user or a user with special capabilities (rights) since if a drive screws up, data from a different sector (or so) might end up in the proces' memory. Of course copying a sector from kernel- to userspace can be done pretty fast but i.m.h.o. all possible speedimprovements should be made unless unclean.

Just use mmap(). Unlike your proposal, it cooperates with the page cache.

Jörn

Signature · 4 lines
Don't worry about people stealing your ideas. If your ideas are any good,
you'll have to ram them down people's throats.
-- Howard Aiken quoted by Ken Iverson quoted by Jim Horning quoted by
   Raph Levien, 1979
#2 lore raw
Quoted 10 lines
Quoted 8 lines

What about a zero-copy read-interface?
An ioctl (or something) which enables the kernel to do dma directly to the userspace. Of course this should be limited to the root-user or a user with special capabilities (rights) since if a drive screws up, data from a different sector (or so) might end up in the proces' memory. Of course copying a sector from kernel- to userspace can be done pretty fast but i.m.h.o. all possible speedimprovements should be made unless unclean.

Just use mmap(). Unlike your proposal, it cooperates with the page cache.

Doesn't that one also use copying? I've also heard that using mmap is expensive due to pagefaulting. I've found, for example, that copying a 1.3GB file using read/write instead of mmap & memcpy is seconds faster.

Folkert van Heusden

Signature · 5 lines
Auto te koop, zie: http://www.vanheusden.com/daihatsu.php
----------------------------------------------------------------------
Get your PGP/GPG key signed at www.biglumber.com!
----------------------------------------------------------------------
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
#3 lore raw
Quoted 7 lines · Folkert van Heusden
Quoted 3 lines

Just use mmap(). Unlike your proposal, it cooperates with the page cache.

Doesn't that one also use copying? I've also heard that using mmap is expensive due to pagefaulting. I've found, for example, that copying a 1.3GB file using read/write instead of mmap & memcpy is seconds faster.

Since you don't consider device DMA to be a copy, no, it doesn't. The data is transferred into page cache, then the pages are mapped into your processes memory without an additional copy.

The pagefaulting isn't free either, I agree. And for streaming accesses like your copy of a large file, taking one fault per 4k copied is not an ideal case.

Most likely you'd want Linus' pipe stuff for copying a large file without ever looking at the data. That work is still unfinished, though, and I'm currently lacking time to work on it.

Jörn

Signature · 2 lines
He that composes himself is wiser than he that composes a book.
-- B. Franklin
#4 lore raw
In reply to Folkert van Heusden
Quoted 3 lines · Folkert van Heusden

Doesn't that one also use copying? I've also heard that using mmap is expensive due to pagefaulting. I've found, for example, that copying a 1.3GB file using read/write instead of mmap & memcpy is seconds faster.

why would you memcpy if you're using mmap()? just write() the mmap()d region.

-dean

#5 lore raw
Quoted 8 lines · dean gaudet
Quoted 3 lines · Folkert van Heusden

Doesn't that one also use copying? I've also heard that using mmap is expensive due to pagefaulting. I've found, for example, that copying a 1.3GB file using read/write instead of mmap & memcpy is seconds faster.

why would you memcpy if you're using mmap()? just write() the mmap()d region.

Still unnecessary. Userspace doesn't want to see the data at all, so it shouldn't. The solution should either be sendfile(2), which Linus doesn't like much, or the upcoming pipe stuff.

Jörn

Signature · 3 lines
Linux [...] existed just for discussion between people who wanted
to show off how geeky they were.
-- Rob Enderle
#6 lore raw
In reply to Folkert van Heusden
Quoted 9 lines · Folkert van Heusden
Quoted 9 lines
Quoted 9 lines

What about a zero-copy read-interface?
An ioctl (or something) which enables the kernel to do dma directly to the userspace. Of course this should be limited to the root-user or a user with special capabilities (rights) since if a drive screws up, data from a different sector (or so) might end up in the proces' memory. Of course copying a sector from kernel- to userspace can be done pretty fast but i.m.h.o. all possible speedimprovements should be made unless unclean.

Quoted 7 lines
Quoted 2 lines

Just use mmap(). Unlike your proposal, it cooperates with the page cache.

Doesn't that one also use copying? I've also heard that using mmap is expensive due to pagefaulting. I've found, for example, that copying a 1.3GB file using read/write instead of mmap & memcpy is seconds faster.

You can use remap_file_pages() to read all the pages into pagecache and then instantiate all their pte's in a single syscall.

#7 lore raw
In reply to Folkert van Heusden
Quoted 8 lines · Folkert van Heusden

What about a zero-copy read-interface?
An ioctl (or something) which enables the kernel to do dma directly to the userspace. Of course this should be limited to the root-user or a user with special capabilities (rights) since if a drive screws up, data from a different sector (or so) might end up in the proces' memory. Of course copying a sector from kernel- to userspace can be done pretty fast but i.m.h.o. all possible speedimprovements should be made unless unclean.

It's called O_DIRECT, and doesn't need root, just some alignment-constraints.