Skip to contentSkip to conversation

Zero-copy block driver?

DISCUSSION Darko Petrović 2 participants 4 messages Jan 29, 2011 KVM

lore
Share & tools
lore
#0 lore raw

Hi everyone,

Could you please tell me if it is possible to use a block driver that completely avoids the guest kernel and copies block data directly to/from the given buffer in the guest userspace? If yes, how to activate it? If not... why not? :)

Thanks!
Darko

#1 lore raw

2011/1/29 Darko Petrović <[email protected]>:

Quoted 4 lines

Could you please tell me if it is possible to use a block driver that completely avoids the guest kernel and copies block data directly to/from the given buffer in the guest userspace?
If yes, how to activate it? If not... why not? :)

Inside the guest, open files using the O_DIRECT flag. This tells the guest kernel to avoid the page cache when possible, enabling zero-copy. You need to use aligned memory buffers and perform I/O in multiples of the block size.

See the open(2) man page for details. Make sure you really want to do this, most applications don't.

Stefan

#2 lore raw

Thanks for your help. Actually, I am more interested in doing it from the outside, if possible (I am not allowed to change the application code). Can the guest be tricked by KVM somehow, using the appropriate drivers? Just to clear it out, copying to/from a host buffer is fine, I just want to avoid having guest buffers.

Cheers!
Darko

Quoted 9 lines · Stefan Hajnoczi

Inside the guest, open files using the O_DIRECT flag. This tells the guest kernel to avoid the page cache when possible, enabling zero-copy. You need to use aligned memory buffers and perform I/O in multiples of the block size.

See the open(2) man page for details. Make sure you really want to do this, most applications don't.

Stefan

#3 lore raw

2011/1/29 Darko Petrović <[email protected]>:

Quoted 5 lines

Thanks for your help. Actually, I am more interested in doing it from the outside, if possible (I am not allowed to change the application code). Can the guest be tricked by KVM somehow, using the appropriate drivers? Just to clear it out, copying to/from a host buffer is fine, I just want to avoid having guest buffers.

Not really. If the application is designed to use the page cache then it will use it.

You might want to look at unmapped page cache control which is not in mainline Linux yet:
http://lwn.net/Articles/419713/

Stefan