* Buffer allocation question
@ 2010-09-13 15:51 Ian Molton
2010-09-14 6:52 ` Clemens Ladisch
0 siblings, 1 reply; 3+ messages in thread
From: Ian Molton @ 2010-09-13 15:51 UTC (permalink / raw)
To: linux-kernel@vger.kernel.org
Hi,
I need to allocate some fairly large buffers which will be transferred
via virtio to a hypervisor.
the pages dont have to be contiguous physically and aside from the first
page int he transfer, the kernel wont really care about the contents of
the buffer.
the pages do need to be mapped into userspace contiguously, however.
They are also often dynamically resized.
the buffers can be quite large, and there can be several in flight at a
given time. They must always be present in physical space (or virtio
gets upset)
Obviously kmalloc() is out of the question, and given the size /
quantity of the buffers, vmalloc() space is getting tight.
I'm struggling to find a good example of how this should be done.
the buffers will usually be filled all in one go, so it seems silly to
fault them in a page at a time.
my first thought (before realising how limited vmalloc space is) was to
vmalloc() them in my mmap() function, but this approach ran into trouble
when I discovered that the mmap() call does not get called if the vma
grows, so I cant then hook in and allocate more vmalloc() space.
It seems like it would be sensible to let userspace allocate the memory
and then mmap() that range, but I've been told this is a bad idea.
Whats the best approach here? With the buffers being large I dont really
want to transmit them in tiny bits either.
-Ian
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Buffer allocation question
2010-09-13 15:51 Buffer allocation question Ian Molton
@ 2010-09-14 6:52 ` Clemens Ladisch
2010-09-14 17:43 ` Ian Molton
0 siblings, 1 reply; 3+ messages in thread
From: Clemens Ladisch @ 2010-09-14 6:52 UTC (permalink / raw)
To: Ian Molton; +Cc: linux-kernel@vger.kernel.org
Ian Molton wrote:
> I need to allocate some fairly large buffers which will be transferred
> via virtio to a hypervisor.
>
> the pages dont have to be contiguous physically and aside from the first
> page int he transfer, the kernel wont really care about the contents of
> the buffer.
>
> the pages do need to be mapped into userspace contiguously, however.
See drivers/firewire/core-iso.c, which uses fixed-size buffers.
> They are also often dynamically resized.
> ...
> my first thought (before realising how limited vmalloc space is) was to
> vmalloc() them in my mmap() function, but this approach ran into trouble
> when I discovered that the mmap() call does not get called if the vma
> grows, so I cant then hook in and allocate more vmalloc() space.
You can set vma->vm_ops.
> the buffers will usually be filled all in one go, so it seems silly to
> fault them in a page at a time.
AFAICS you don't have a choice when resizing.
Regards,
Clemens
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Buffer allocation question
2010-09-14 6:52 ` Clemens Ladisch
@ 2010-09-14 17:43 ` Ian Molton
0 siblings, 0 replies; 3+ messages in thread
From: Ian Molton @ 2010-09-14 17:43 UTC (permalink / raw)
To: Clemens Ladisch; +Cc: linux-kernel@vger.kernel.org
On 14/09/10 07:52, Clemens Ladisch wrote:
<>
Thanks!
I've decided to go for a fixed-buffer scheme in the end.
-Ian
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-09-14 17:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-13 15:51 Buffer allocation question Ian Molton
2010-09-14 6:52 ` Clemens Ladisch
2010-09-14 17:43 ` Ian Molton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox