2011-04-05 09:46:44     Blackfin memory allocation

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

2011-04-05 09:46:44     Blackfin memory allocation

Fabian M (GERMANY)

Message: 99600   

 

 

Hello,

 

I'm new to systems without MMU and I'm not sure how to deal with files and memory allocation. I'm using a bf537 with 32mb ram and a nightly snapshot of uClinux (because I'm using make 3.82 on my workstation...). I'v written an character device driver, which bit bangs some gpios to program a fpga, which is connected to the blackfin.

 

So there would be a user program which reads the configuration file, searches for the relevant parts and writes it as a dynamic allocated buffer to the device. Unfortunately this file is about 5 mb. On my system cat /proc/buddyinfo returns:

Node 0, zone DMA 16 6 3 1 2 2 1 2 3 2 2 0 0 0

 

and cat /proc/meminfo returns:

MemTotal: 29560 kB

MemFree: 17216 kB

Buffers: 0 kB

Cached: 6552 kB

SwapCached: 0 kB

Active: 0 kB

Inactive: 0 kB

Active(anon): 0 kB

Inactive(anon): 0 kB

Active(file): 0 kB

Inactive(file): 0 kB

Unevictable: 6508 kB

Mlocked: 0 kB

MmapCopy: 3064 kB

SwapTotal: 0 kB

SwapFree: 0 kB

Dirty: 0 kB

Writeback: 0 kB

AnonPages: 0 kB

Mapped: 0 kB

Shmem: 0 kB

Slab: 2456 kB

SReclaimable: 892 kB

SUnreclaim: 1564 kB

KernelStack: 224 kB

PageTables: 0 kB

NFS_Unstable: 0 kB

Bounce: 0 kB

WritebackTmp: 0 kB

CommitLimit: 14780 kB

Committed_AS: 0 kB

VmallocTotal: 0 kB

VmallocUsed: 0 kB

VmallocChunk: 0 kB

 

 

So there is enough space but not in a single chunk. What is the common way to deal with this problem? If I extend my driver I could pass several smaller buffer to it, but this won't be very convenient. There must be a general way to hold bigger files in memory?!

 

I've just play around with malloc and recognized that I can allocate a chunk about 4 mb (which I expect if I look to the buddyinfo). But if I do this twice in my program the second allocation always fails, though there should be two free chunks. What could be the reason for this?

 

I would be thankful for any help and advice!

 

Fabian

TranslateQuoteReplyEditDelete

 

 

2011-04-05 10:49:42     Re: Blackfin memory allocation

Mike Frysinger (UNITED STATES)

Message: 99602   

 

the problem is that you need a power of 2 chunk, so 8 MiB.  you could pre-allocate the 5 MiB in your kernel driver at boot time and then never release it, and then your userspace code would mmap the device driver to get at the pointer.

 

honestly though, the safest bet would be to break up the reads/writes into smaller pieces.

Attachments

    Outcomes