LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices

Reply
 
Search this Thread
Old 09-29-2010, 11:06 AM   #1
timboar
LQ Newbie
 
Registered: Aug 2010
Posts: 11

Rep: Reputation: 0
kmalloc onto an aligned border


I have a way around this (see my previous thread), but I spent some time researching this to no avail, and I'm wondering if I missed something.

Is it possible to allocate memory in the kernel, such that it starts on a 2^n boundary (for some value of n)? I'm asking because I have a sub-processor which can do address translation using or/mask registers, so its internal memory has to start on a physical 2^n boundary (where 2^n > imagesize). Of course, the memory has to be physically contiguous as well. The allocation would happen near boot time so memory fragmentation would not be an issue. imagesize is large, so allocating 2^(n+1), and finding a boundary within isn't ideal.


Thanks
 
Old 10-05-2010, 03:36 PM   #2
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,047

Rep: Reputation: 87
The kmalloc function can't do memory align. You have to do it yourself after allocating.
kmem_cache_create function can allocate memory on cache line align.
 
Old 10-06-2010, 12:20 PM   #3
timboar
LQ Newbie
 
Registered: Aug 2010
Posts: 11

Original Poster
Rep: Reputation: 0
How would you 'do it yourself after allocating'? Is there a way to free part of a malloc'ed buffer?

also, can kmem_cache_create align to a size larger than a page size (say to a 32k boundary?)

Thanks
 
Old 10-06-2010, 03:47 PM   #4
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,047

Rep: Reputation: 87
Assume you want to allocate 32k buffer and boundary is 32k, you can allocate 64k buffer and start to use at 32k boundary address. So you have to keep two pointers, buffer starting address and starting using address. Use buffer starting address to free the buffer later.
 
Old 10-07-2010, 10:13 AM   #5
timboar
LQ Newbie
 
Registered: Aug 2010
Posts: 11

Original Poster
Rep: Reputation: 0
Yes, but then I've allocated 64K, 32K of which is being wasted. I would prefer to have that extra 32K available for other applications. If it was possible to allocate the 64K, and then free only the unused parts, that would be great...
 
Old 10-30-2010, 10:36 AM   #6
timboar
LQ Newbie
 
Registered: Aug 2010
Posts: 11

Original Poster
Rep: Reputation: 0
I thought I would post my solution in case anyone else runs into the same problem. I used the kmem_cache_create / kmem_cache_alloc, with an align field set to the correct value. I read through the SLAB code, and it appears as though this will yield the correct result. I can't guarantee that this works with non-SLAB memory types though. Also, this is on the 2.6.30 kernel. I'm assuming this will be forward compatible with other kernel versions.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can not find header files to use kmalloc() yousafsajjad Programming 23 06-30-2010 12:12 AM
Unable to find kernel headers such as kmalloc.h manish.ym Linux - Kernel 2 06-16-2010 12:00 PM
kmalloc is failing and kernel is hanging zahidul Linux - Embedded & Single-board computer 2 12-19-2008 12:04 AM
kmalloc returning overlapped address dipakn Linux - General 4 10-30-2003 12:29 AM
Kmalloc returns null iannou Linux - General 0 06-28-2003 11:36 AM


All times are GMT -5. The time now is 04:58 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration