44 lines · 1.7 KB · Text
RawDownload
= xalloc, xspanalloc, xfree: basic memory management     void* xalloc(ulong size)     void* xspanalloc(ulong size, int align, ulong span)     void  xfree(void *p) Xalloc  and  xfree are primitives used by higher-level memoryallocators in the kernel, such as malloc(10.2).  They are notintended  for use directly by most kernel routines.  The mainexceptions  are  routines  that  permanently  allocate  largestructures,  or need the special alignment properties guaran‐teed by xspanalloc. Xalloc returns a pointer to a range of size bytes of  memory.The memory will be zero filled and aligned on a 8 byte (BY2V)address. If the memory is not  available,  xalloc  returns  anull pointer. Xspanalloc allocates memory given alignment and spanning con‐straints.   The  block  returned  will  contain  size  bytes,aligned on a boundary that is 0 mod align, in such a way thatthe memory in the block does not span an address  that  is  0mod span.  Xspanalloc is intended for use allocating hardwaredata structures (eg, page tables) or I/O  buffers  that  mustsatisfy  specific alignment restrictions.  If xspanalloc can‐not allocate memory to satisfy the given constraints, it willpanic(10.2).   The technique it uses can sometimes cause mem‐ory to be wasted.  Consequently, xspanalloc  should  be  usedsparingly. Xfree  frees  the  block  of  memory  at  p, which must be anaddress previously returned by xalloc (not xspanalloc).    Allocation statusSome memory allocation statistics are written to the  consolein response to the debugging sequence The output includes thetotal free space, the number of free holes, and a summary  ofactive holes.  Each line shows `address top size'. == see ALSOmalloc(10.2)