Print this page
5513 KM_NORMALPRI should be documented in kmem_alloc(9f) and kmem_cache_create(9f) man pages
14465 Present KM_NOSLEEP_LAZY as documented interface
Change-Id: I002ec28ddf390650f1fcba1ca94f6abfdb241439


  13 
  14        void *kmem_alloc(size_t size, int flag);
  15 
  16 
  17        void *kmem_zalloc(size_t size, int flag);
  18 
  19 
  20        void kmem_free(void *buf, size_t size);
  21 
  22 
  23 INTERFACE LEVEL
  24        Architecture independent level 1 (DDI/DKI).
  25 
  26 PARAMETERS
  27        size
  28                Number of bytes to allocate.
  29 
  30 
  31        flag
  32                Determines whether caller can sleep for memory. Possible flags
  33                are KM_SLEEP to allow sleeping until memory is available, or
  34                KM_NOSLEEP to return NULL immediately if memory is not
  35                available.






  36 
  37 
  38        buf
  39                Pointer to allocated memory.
  40 
  41 
  42 DESCRIPTION
  43        The kmem_alloc() function allocates size bytes of kernel memory and
  44        returns a pointer to the allocated memory. The allocated memory is at
  45        least double-word aligned, so it can hold any C data structure. No
  46        greater alignment can be assumed. flag determines whether the caller
  47        can sleep for memory.  KM_SLEEP allocations may sleep but are
  48        guaranteed to succeed.  KM_NOSLEEP allocations are guaranteed not to
  49        sleep but may fail (return NULL) if no memory is currently available.
  50        The initial contents of memory allocated using kmem_alloc() are random
  51        garbage.


  52 
  53 
  54        The kmem_zalloc() function is like kmem_alloc() but returns zero-filled
  55        memory.
  56 
  57 
  58        The kmem_free() function frees previously allocated kernel memory. The
  59        buffer address and size must exactly match the original allocation.
  60        Memory cannot be returned piecemeal.
  61 
  62 RETURN VALUES
  63        If successful, kmem_alloc() and kmem_zalloc() return a pointer to the
  64        allocated memory. If KM_NOSLEEP is set and memory cannot be allocated
  65        without sleeping, kmem_alloc() and kmem_zalloc() return NULL.
  66 
  67 CONTEXT
  68        The kmem_alloc() and kmem_zalloc() functions can be called from
  69        interrupt context only if the KM_NOSLEEP flag is set. They can be
  70        called from user context with any valid flag. The kmem_free() function
  71        can be called from from user, interrupt, or kernel context.




  13 
  14        void *kmem_alloc(size_t size, int flag);
  15 
  16 
  17        void *kmem_zalloc(size_t size, int flag);
  18 
  19 
  20        void kmem_free(void *buf, size_t size);
  21 
  22 
  23 INTERFACE LEVEL
  24        Architecture independent level 1 (DDI/DKI).
  25 
  26 PARAMETERS
  27        size
  28                Number of bytes to allocate.
  29 
  30 
  31        flag
  32                Determines whether caller can sleep for memory. Possible flags
  33                are KM_SLEEP to allow sleeping until memory is available,
  34                KM_NOSLEEP to return NULL if memory is not available even after
  35                some reclamation attempts, and KM_NOSLEEP_LAZY to return NULL
  36                without reclamation attempts.  KM_NOSLEEP_LAZY is actually two
  37                flags combined: (KM_NOSLEEP | KM_NORMALPRI), the latter flag
  38                indicating not to attempt reclamation before giving up and
  39                returning NULL.  If any mention of KM_NOSLEEP appears in this
  40                man page by itself, it applies equally to KM_NOSLEEP_LAZY as
  41                well.
  42 
  43 
  44        buf
  45                Pointer to allocated memory.
  46 
  47 
  48 DESCRIPTION
  49        The kmem_alloc() function allocates size bytes of kernel memory and
  50        returns a pointer to the allocated memory. The allocated memory is at
  51        least double-word aligned, so it can hold any C data structure. No
  52        greater alignment can be assumed. flag determines whether the caller
  53        can sleep for memory.  KM_SLEEP allocations may sleep but are
  54        guaranteed to succeed.  KM_NOSLEEP and KM_NOSLEEP_LAZY allocations are
  55        guaranteed not to sleep but may fail (return NULL) if no memory is
  56        currently available. KM_NOSLEEP will first attempt to aggressively
  57        reclaim memory from otherwise unused blocks, while KM_NOSLEEP_LAZY will
  58        not attempt any reclamation. The initial contents of memory allocated
  59        using kmem_alloc() are random garbage.
  60 
  61 
  62        The kmem_zalloc() function is like kmem_alloc() but returns zero-filled
  63        memory.
  64 
  65 
  66        The kmem_free() function frees previously allocated kernel memory. The
  67        buffer address and size must exactly match the original allocation.
  68        Memory cannot be returned piecemeal.
  69 
  70 RETURN VALUES
  71        If successful, kmem_alloc() and kmem_zalloc() return a pointer to the
  72        allocated memory. If KM_NOSLEEP is set and memory cannot be allocated
  73        without sleeping, kmem_alloc() and kmem_zalloc() return NULL.
  74 
  75 CONTEXT
  76        The kmem_alloc() and kmem_zalloc() functions can be called from
  77        interrupt context only if the KM_NOSLEEP flag is set. They can be
  78        called from user context with any valid flag. The kmem_free() function
  79        can be called from from user, interrupt, or kernel context.