1 VMEM_ALLOC(9F)           Kernel Functions for Drivers           VMEM_ALLOC(9F)
   2 
   3 NAME
   4      vmem_alloc, vmem_xalloc, vmem_free, vmem_xfree - allocate and free
   5      segments from a vmem arena
   6 
   7 SYNOPSIS
   8      #include <sys/vmem.h>
   9 
  10      void *
  11      vmem_alloc(vmem_t *vmp, size_t size, int vmflag);
  12 
  13      void *
  14      vmem_xalloc(vmem_t *vmp, size_t size, size_t align_arg, size_t phase,
  15          size_t nocross, void *minaddr, void *maxaddr, int vmflag);
  16 
  17      void
  18      vmem_free(vmem_t *vmp, void *vaddr, size_t size);
  19 
  20      void
  21      vmem_xfree(vmem_t *vmp, void *vaddr, size_t size);
  22 
  23 INTERFACE LEVEL
  24      illumos DDI specific
  25 
  26 PARAMETERS
  27      vmp     The vmem arena from which to allocate or free.
  28 
  29      size    The size of the segment to allocate or free.
  30 
  31      vmflag  A bitmask of flags controlling the behaviour of the allocation.
  32              There are two meaningful groups of flags.  VM_SLEEP or VM_NOSLEEP
  33              must be specified, and indicate whether the allocation may block.
  34              A VM_SLEEP allocation can never fail but may block indefinitely.
  35 
  36              The allocation policy may be specified by one of the following
  37              flags:
  38 
  39              VM_BESTFIT
  40                      Take the segment from the smallest free segment that
  41                      could satisfy this allocation.
  42 
  43              VM_FIRSTFIT
  44                      Take the segment from the first free segment found that
  45                      could satisfy this allocation.
  46 
  47              VM_NEXTFIT
  48                      Take the segment from the segment after the one
  49                      previously allocated.  This provides sequential behaviour
  50                      useful when allocating identifiers from a VMC_IDENTIFIER
  51                      arena.
  52 
  53              VM_ENDALLOC
  54                      May be specified in combination with VM_BESTFIT,
  55                      VM_FIRSTFIT or the default policy to indicate that the
  56                      higher addresses should be preferred.
  57 
  58              The default (unnamed) allocation policy is ``instant fit'', an
  59              approximation of VM_BESTFIT in guaranteed constant time.
  60 
  61      align_arg
  62              The minimum alignment of the allocation.  If 0, the allocated
  63              segment will be aligned as the arena's quantum.
  64 
  65      phase   The allocated segment must be phase bytes from the alignment
  66              boundary.
  67 
  68      nocross
  69              The allocated segment may not straddle a nocross alignment
  70              boundary.
  71 
  72      minaddr
  73              The minimum address at which the segment may be allocated.
  74 
  75      maxaddr
  76              The maximum address which may be included in the segment.
  77 
  78      vaddr   The address of the segment which vmem_free() or vmem_xfree()
  79              should free.
  80 
  81 DESCRIPTION
  82      The vmem_alloc() and vmem_xalloc() functions allocate a segment of size
  83      length from the vmem arena vmp.
  84 
  85      The vmflag argument controls the behaviour of the allocation, as
  86      described in PARAMETERS.
  87 
  88      For allocations with complex requirements, such as those used for DMA
  89      vmem_xalloc() takes additional arguments allowing those requirements to
  90      be expressed.
  91 
  92      Segments allocated with vmem_xalloc() must always be freed with
  93      vmem_xfree(), since these allocations are uncached.
  94 
  95 CONTEXT
  96      This function can be called from either user or kernel context.  If the
  97      VM_NOSLEEP flag is specified, it may also be called from interrupt
  98      context.
  99 
 100 RETURN VALUES
 101      Upon successful completion the vmem_alloc() and vmem_xalloc() functions
 102      return a pointer to the beginning of the allocated segment.  In the case
 103      of a VMC_IDENTIFIER arena, the address of this pointer is the meaningful
 104      component, not the value to which it points.
 105 
 106      On failure, NULL is returned.  When the VM_SLEEP flag is specified, these
 107      functions can never fail (but may block forever).
 108 
 109 SEE ALSO
 110      vmem(9), vmem_contains(9F), vmem_create(9F)
 111 
 112 illumos                        January 18, 2017                        illumos