RE: kmalloc question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Dymanic memory allocation is not done or checked at compile time, its
done at run time, so when a kernel module or any code in kernel request
memory thru kmalloc(), kmalloc() first checks if it can find the memory
block somwhat greater than the requested memory size, if it is not able
to get any memory block of suffient size it returns an error.

Once again, I would like to say, all this is done at run time (execution
time). It has nothing to do with compilation.

Regards,
Gaurav.


-----Original Message-----
From: kernelnewbies-bounce@xxxxxxxxxxxx
[mailto:kernelnewbies-bounce@xxxxxxxxxxxx] On Behalf Of Borislav Petkov
Sent: Monday, August 02, 2004 2:14 PM
To: kernelnewbies@xxxxxxxxxxxx
Subject: kmalloc question

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi there people,
i only need a confirmation on some unclear issues concerning the
following 
function:

<include/linux/slab.h>
77 static inline void *kmalloc(size_t size, int flags)
 78 {
 79         if (__builtin_constant_p(size)) {
 80                 int i = 0;
 81 #define CACHE(x) \
 82                 if (size <= x) \
 83                         goto found; \
 84                 else \
 85                         i++;
 86 #include "kmalloc_sizes.h"
 87 #undef CACHE
 88                 {
 89                         extern void
__you_cannot_kmalloc_that_much(void);
 90                         __you_cannot_kmalloc_that_much();
 91                 }
 92 found:
 93                 return kmem_cache_alloc((flags & GFP_DMA) ?
 94                         malloc_sizes[i].cs_dmacachep :
 95                         malloc_sizes[i].cs_cachep, flags);
 96         }
 97         return __kmalloc(size, flags);
 98 }

I understand that the CACHE macro is used to search the malloc_sizes
array to 
find a slab object that is (size <= x) and if it is found, we jump to
the 
found label where we call kmem_cache_alloc(). After we #undef CACHE, we
have 
a block with that external function that is declared nowhere. After
googling 
a while, I think I know what this does but i'm not sure - when, at
compile 
time, something requests a slab object that is bigger than the alloc'd
ones, 
we break compilation and force the caller to change its call to kmalloc
in 
order to request a more suitable size object. I don't understand the
thoughts 
behind that, though, thus my question.

Thanks in advance for your help,
Boris.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)

iD8DBQFBDf64iBySr3Fn37QRAsreAJ4nAZof1ixOM3ZDo2ADIMjgXrYCzACfXBVc
VMqT17YfOFPlmPyEXOLjxic=
=i6PV
-----END PGP SIGNATURE-----

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux