Subject: Re: Memory Mapping Buffers smaller than page size?

From: Simon Richter <[email-masked]>
Date: Wed, 28 Jul 2010 16:21:40 +0200

Hi,

On Wed, Jul 28, 2010 at 06:44:10PM +0530, Ravi Gupta wrote:

> I am new to linux device drivers development. I have created 16 buffers of
> size 256 bytes each(using kmalloc()) in my device driver code. I want to
> memory map these buffers to user space. Now is it possible to memory map
> these buffer(16*256 = 4096 = 1 page on 32 bit linux) into a single page in
> user space OR i have to map them in individual pages in user space? Note,
> all the buffers may not be stored in continuous memory location.

Pages are the smallest unit for mappings, so each buffer would end up in
its own mapping. If you want the buffers to be accessible without an
offset, then you cannot have them in continuous locations, as you cannot
map memory from the middle of a page to the beginning either.

So your options are: one page per buffer (wasteful, but gives you
granular access control), or allocating all the buffers as a single
block.

   Simon