* Doing a zero-copy move of data from a kernel buffer to hard disk
@ 2010-09-20 20:12 Neeraj Kumar
2010-09-22 1:02 ` Robert Hancock
2010-09-22 8:54 ` Miklos Szeredi
0 siblings, 2 replies; 5+ messages in thread
From: Neeraj Kumar @ 2010-09-20 20:12 UTC (permalink / raw)
To: linux-kernel
I am trying to move data from a buffer in kernel space into the hard
disk without having to incur any additional copies from kernel buffer to
user buffers or any other kernel buffers. Any ideas/suggestions would be
most helpful.
The use case is basically a demux driver which collects data into a
demux buffer in kernel space and this buffer has to be emptied
periodically by copying the contents into a FUSE-based partition on the
disk. As the buffer gets full, a user process is signalled which then
determines the sector numbers on the disk the contents need to be copied
to.
I was hoping to mmap the above demux kernel buffer into user address
space and issue a write system call to the raw partition device. But
from what I can see, the this data is being cached by the kernel on its
way to the Hard Disk driver. And so I am assuming that involves
additional copies by the linux kernel.
At this point I am wondering if there is any other mechansim to do this
without involving additional copies by the kernel. I realize this is an
unsual usage scenario for non-embedded environments, but I would
appreciate any feedback on possible options.
BTW - I have tried using O_DIRECT when opening the raw partition, but
the subsequent write call fails if the buffer being passed is the
mmapped buffer.
Thanx!
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Doing a zero-copy move of data from a kernel buffer to hard disk
2010-09-20 20:12 Doing a zero-copy move of data from a kernel buffer to hard disk Neeraj Kumar
@ 2010-09-22 1:02 ` Robert Hancock
2010-10-12 1:10 ` Neeraj Kumar
2010-09-22 8:54 ` Miklos Szeredi
1 sibling, 1 reply; 5+ messages in thread
From: Robert Hancock @ 2010-09-22 1:02 UTC (permalink / raw)
To: Neeraj Kumar; +Cc: linux-kernel
On 09/20/2010 02:12 PM, Neeraj Kumar wrote:
> I am trying to move data from a buffer in kernel space into the hard
> disk without having to incur any additional copies from kernel buffer to
> user buffers or any other kernel buffers. Any ideas/suggestions would be
> most helpful.
>
> The use case is basically a demux driver which collects data into a
> demux buffer in kernel space and this buffer has to be emptied
> periodically by copying the contents into a FUSE-based partition on the
> disk. As the buffer gets full, a user process is signalled which then
> determines the sector numbers on the disk the contents need to be copied
> to.
>
> I was hoping to mmap the above demux kernel buffer into user address
> space and issue a write system call to the raw partition device. But
> from what I can see, the this data is being cached by the kernel on its
> way to the Hard Disk driver. And so I am assuming that involves
> additional copies by the linux kernel.
>
> At this point I am wondering if there is any other mechansim to do this
> without involving additional copies by the kernel. I realize this is an
> unsual usage scenario for non-embedded environments, but I would
> appreciate any feedback on possible options.
>
> BTW - I have tried using O_DIRECT when opening the raw partition, but
> the subsequent write call fails if the buffer being passed is the
> mmapped buffer.
O_DIRECT would be the right way to do it - I think you'd need to figure
out why that write is failing. Keep in mind you need to observe the
alignment restrictions of O_DIRECT (man 2 open).
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Doing a zero-copy move of data from a kernel buffer to hard disk
2010-09-20 20:12 Doing a zero-copy move of data from a kernel buffer to hard disk Neeraj Kumar
2010-09-22 1:02 ` Robert Hancock
@ 2010-09-22 8:54 ` Miklos Szeredi
2010-10-12 0:58 ` Neeraj Kumar
1 sibling, 1 reply; 5+ messages in thread
From: Miklos Szeredi @ 2010-09-22 8:54 UTC (permalink / raw)
To: Neeraj Kumar; +Cc: linux-kernel
On Mon, 20 Sep 2010, Neeraj Kumar wrote:
> I am trying to move data from a buffer in kernel space into the hard
> disk without having to incur any additional copies from kernel buffer to
> user buffers or any other kernel buffers. Any ideas/suggestions would be
> most helpful.
>
> The use case is basically a demux driver which collects data into a
> demux buffer in kernel space and this buffer has to be emptied
> periodically by copying the contents into a FUSE-based partition on the
> disk. As the buffer gets full, a user process is signalled which then
> determines the sector numbers on the disk the contents need to be copied
> to.
>
> I was hoping to mmap the above demux kernel buffer into user address
> space and issue a write system call to the raw partition device. But
> from what I can see, the this data is being cached by the kernel on its
> way to the Hard Disk driver. And so I am assuming that involves
> additional copies by the linux kernel.
Isn't this functionality already served by relayfs?
> At this point I am wondering if there is any other mechansim to do this
> without involving additional copies by the kernel. I realize this is an
> unsual usage scenario for non-embedded environments, but I would
> appreciate any feedback on possible options.
>
> BTW - I have tried using O_DIRECT when opening the raw partition, but
> the subsequent write call fails if the buffer being passed is the
> mmapped buffer.
The other zero-copy mechanism is splice(2).
Thanks,
Miklos
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Doing a zero-copy move of data from a kernel buffer to hard disk
2010-09-22 8:54 ` Miklos Szeredi
@ 2010-10-12 0:58 ` Neeraj Kumar
0 siblings, 0 replies; 5+ messages in thread
From: Neeraj Kumar @ 2010-10-12 0:58 UTC (permalink / raw)
To: Miklos Szeredi; +Cc: linux-kernel
On Mon, 20 Sep 2010, Neeraj Kumar wrote:
>> I am trying to move data from a buffer in kernel space into the hard
>> disk without having to incur any additional copies from kernel buffer to
>> user buffers or any other kernel buffers. Any ideas/suggestions would be
>> most helpful.
>>
>> The use case is basically a demux driver which collects data into a
>> demux buffer in kernel space and this buffer has to be emptied
>> periodically by copying the contents into a FUSE-based partition on the
>> disk. As the buffer gets full, a user process is signalled which then
>> determines the sector numbers on the disk the contents need to be copied
>> to.
>>
>> I was hoping to mmap the above demux kernel buffer into user address
>> space and issue a write system call to the raw partition device. But
>> from what I can see, the this data is being cached by the kernel on its
>> way to the Hard Disk driver. And so I am assuming that involves
>> additional copies by the linux kernel.
>Isn't this functionality already served by relayfs?
I could not figure out how relayfs could help me.
>> At this point I am wondering if there is any other mechansim to do this
>> without involving additional copies by the kernel. I realize this is an
>> unsual usage scenario for non-embedded environments, but I would
>> appreciate any feedback on possible options.
>>
>> BTW - I have tried using O_DIRECT when opening the raw partition, but
>> the subsequent write call fails if the buffer being passed is the
>> mmapped buffer.
>The other zero-copy mechanism is splice(2).
I looked at the implementation of splice(). It looks promising. I have 2 more
questions related to it:
1. SPLICE_F_MOVE which is needed for zero copy movement of pages is defined as
no op in the kernel code.
Does splice still tries for zero copy movement?
2. I may need to implement splice_read() and splice_write() for the demux
driver. I did not find any other
driver making use of these interfaces in the kernel except file system. Is
there any sample code available
which could help me to understand/implement splice() interfaces in a better way?
Thanks,
Miklos
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Doing a zero-copy move of data from a kernel buffer to hard disk
2010-09-22 1:02 ` Robert Hancock
@ 2010-10-12 1:10 ` Neeraj Kumar
0 siblings, 0 replies; 5+ messages in thread
From: Neeraj Kumar @ 2010-10-12 1:10 UTC (permalink / raw)
To: Robert Hancock; +Cc: linux-kernel
>On 09/20/2010 02:12 PM, Neeraj Kumar wrote:
>> I am trying to move data from a buffer in kernel space into the hard
>> disk without having to incur any additional copies from kernel buffer to
> >user buffers or any other kernel buffers. Any ideas/suggestions would be
> >most helpful.
>>
>>The use case is basically a demux driver which collects data into a
>> demux buffer in kernel space and this buffer has to be emptied
>>periodically by copying the contents into a FUSE-based partition on the
> disk. As the buffer gets full, a user process is signalled which then
>> determines the sector numbers on the disk the contents need to be copied
>> to.
>>
>> I was hoping to mmap the above demux kernel buffer into user address
>> space and issue a write system call to the raw partition device. But
>> from what I can see, the this data is being cached by the kernel on its
>> way to the Hard Disk driver. And so I am assuming that involves
>> additional copies by the linux kernel.
>>
>> At this point I am wondering if there is any other mechansim to do this
>> without involving additional copies by the kernel. I realize this is an
>> unsual usage scenario for non-embedded environments, but I would
>> appreciate any feedback on possible options.
>>
>> BTW - I have tried using O_DIRECT when opening the raw partition, but
>> the subsequent write call fails if the buffer being passed is the
>> mmapped buffer.
>O_DIRECT would be the right way to do it - I think you'd need to figure
>out why that write is failing. Keep in mind you need to observe the
>alignment restrictions of O_DIRECT (man 2 open).
I was able to figure out that O_DIRECT can not work with memory mapped
pages. In the kernel, get_user_pages() returns error if user provided pages are
mapped kernel pages.
Thanks
Neeraj
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-10-12 1:16 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-20 20:12 Doing a zero-copy move of data from a kernel buffer to hard disk Neeraj Kumar
2010-09-22 1:02 ` Robert Hancock
2010-10-12 1:10 ` Neeraj Kumar
2010-09-22 8:54 ` Miklos Szeredi
2010-10-12 0:58 ` Neeraj Kumar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox