Suppose we want to maintain a pool of memory in a device driver or module. How can that pool be created and be available to multiple processes lets say 4 processes, accessing this driver/module.
Assume 1 MB of memory in the pool.
When I was reading LDD I came across api's mempool_create() but then there's also kmalloc.
If someone has done such a thing kindly share the knowledge.
My initial approach is to allocate using kmalloc() and then maintain start and end pointers in the private object for each process that opens the module.
EDIT: Thanks @kikigood for spending some time on this. So based on your comments, I do something like this.
Lets say I allocated 1MB of mempool during init. And I want to restrict the count of processes to 4, so I keep a count. Increment this count at every
atomic_t count =0;
open()
{
if(count >4)
return -ENOMEM;
count++;
}
Also I maintain a buffer within my private device structure per process.
How to assign some memory from pool to this buffer.