2

I have been trying to allocate space using malloc in kernel space for a driver I am working on (using malloc is a constraint here; I am not allowed to allocate space in any other manner), but if I try to allocate "too many" elements (~500 times a very small struct), only a fraction of the space I required is actually allocated.

Reducing the number of allocated elements did work for me with no problems. Does dynamic allocation in kernel space have limits which might be causing the behavior I am seeing?

pap42
  • 1,236
  • 1
  • 17
  • 28

1 Answers1

4

malloc is a user space library function. You cannot use it in kernel space. There is a function called kmalloc() which is used to allocate memory in kernel space.

You can use vmalloc() also. I suggest you to read this thread What is the difference between vmalloc and kmalloc? for some clarification on vmalloc() and kmalloc().

And also I suggest you to search your queries in SO, then Ask Questions. Because, Already someone asked here

Community
  • 1
  • 1
Jeyaram
  • 9,158
  • 7
  • 41
  • 63