2010-11-30 15:49:00     mmap unmanaged memory?

Document created by Aaronwu Employee on Aug 23, 2013
Version 1Show Document
  • View in full screen mode

2010-11-30 15:49:00     mmap unmanaged memory?

Andrew Kohlsmith (CANADA)

Message: 96341   

 

I am trying to use the "Silly noMMU Memory Tricks" found here along with mmap() to get a pointer to memory that the kernel is not managing. It appears, however, that the documentation is incorrect and that on nommu systems I do not require mmap at all.

 

With my bootargs set to include "mem=32M max_mem=64M" (I don't want to enable the cache on this region for my application) I correctly see that the kernel is leaving half the RAM alone. However, mmap() fails.

 

#define THIRTYTWOMEG (32 * 1048576)

dmadata = mmap((void *)THIRTYTWOMEG, THIRTYTWOMEG, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS | MAP_UNITIALIZE, 0, 0);

 

This line will always fail with errno = EINVAL and I receive "Can't do fixed-address/overlay mmap of RAM" in dmesg.

 

Now looking at linux-2.6.x/mm/nommu.c line 704 I see that I cannot specify an address nor can I use the MAP_FIXED flag or mmap will fail after printing that message to dmesg.

 

This seems to go against the text in the link which suggests using mmap to obtain a pointer to this unmanaged memory. If I do not specify an address mmap() fails because it obviously cannot allocate that much memory. If I stop trying to use mmap() and simply declare my pointer address to the 32nd megabyte I can use the memory without issue.

 

Am I missing anything? Should I be using mmap (and if so, how?) or is there another way that I should be attempting to use a large block of memory for a DMA buffer?

QuoteReplyEditDelete

 

 

2010-11-30 16:02:32     Re: mmap unmanaged memory?

Mike Frysinger (UNITED STATES)

Message: 96343   

 

mmap is not for generically unmanaged memory.  the docs were referring to a driver itself taking care of the mmap call.

 

just do what the docs say in the frst place --use direct pointers.

Attachments

    Outcomes