Can not find header files to use kmalloc()
Hi,
I want to use kmalloc() to allocate contiguous memory on ram. But I can not seem to find the required header file(s) like linux/slab.h. I suppose I do not have the required library and I certainly do not know what and where to look. I would really appreciate some help. Thanks |
Quote:
I suspect you're not doing that - you just want to use the ordinary malloc() from the C standard library. |
malloc does not serve the purpose of allocating contiguous memory on ram which is why i need to kmalloc. I would really appreciate if you can elaborate what do i need to do use kmalloc.
|
Quote:
But maybe, you could share with us why you definitely need the contiguous are in physical ram? Quote:
|
I am working on a utility library which would serve as an interface to many drivers and other low level operations like SMI operations which require having physically contiguous memory. Allocating virtually contiguous memory does not serve that purpose, I have already tried that.
A picture of the whole idea is to allocate physically contiguous memory, write to it, convert the virtual address to physical address and read the content using memory mapped I/O |
Quote:
There's no standard way to do it from user-space, because there's no point. If you ever need access to a specific area of physical memory, the kernel/a device driver will map it into your virtual address space for you. |
Quote:
There's no easy road to this though. Look up "linux device drivers, 3rd edition", which is a good book. |
Quote:
Quote:
|
Thanks John. I really appreciate it.
|
Quote:
Anyway, learning to write a device driver is the first hurdle, by then you should have a much better idea of what to do. |
Quote:
|
I have found something that might help me but I need your opinion on it ..
"mlock() locks pages in the address range starting at addr and continuing for len bytes. All pages that contain a part of the specified address range are guaranteed to be resident in RAM when the call returns successfully; the pages are guaranteed to stay in RAM until later unlocked" (http://linux.die.net/man/2/mlockall) So this would pretty much do what I need but I am not sure how to get the starting address of that physical memory |
Quote:
I think this is NOT what you're searching for. The mlock(2) guarantees that your virtual address space range starting from the addr argument is resident in physical memory, but the physical pages belonging to this virtual address might not be contiguous. Andi |
Quote:
|
In fact, mlock() can be useful only in case you want to have 4K of contiguous ram space. On a 32-bit system this is the page size you get ...
anyhow just for argument sake .. how can i know the physical address after doing mlock() .. ?? |
All times are GMT -5. The time now is 11:12 AM. |