[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Which types of locking should I use?
Hello, Jan.
I see. I will try to use linked list.
The 'const char *' data is a filename with caninicalized pathname,
and I don't want the array not to appear the same filename in
multiple indexes. So I will try something like this.
int len = strlen(filename) + 1;
const char *cp = kmalloc(len, GFP_KERNEL);
if (!cp) return;
memmove(cp, filename, len);
spin_lock();
// Scan linked list.
// Add cp to linked list if not found, kfree(cp) if found.
spin_unlock();
> 2) Be sure to remember how kmalloc works. It can only alocate power-of-2
> sized buffers, 32 bytes minimum, PAGE_SIZE << 5 (or something like
I don't remember, but I thought kmalloc() with less than 32 bytes
doesn't return NULL. I called kmalloc() with 6 bytes
("const char *" + "unsigned short int") and (I thought) succeeded.
Max size I could allocate with kmalloc() is 128 * 1024 bytes,
which is equals to PAGE_SIZE << 5.
# I have no linux PC here to verify now.
Thank you.
--
Tetsuo (a5497108 _at_ anet.ne.jp)
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/