Files
@ d6b9b2ac5869
Branch filter:
Location: vmkdrivers/BLD/build/HEADERS/vmkapi-current-all-public-bincomp/vmkernel64/release/base/vmkapi_slab.h
d6b9b2ac5869
15.3 KiB
text/x-chdr
ESXi-5.5-U2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | /* **********************************************************
* Copyright 1998 - 2010 VMware, Inc. All rights reserved.
* **********************************************************/
/*
* @VMKAPIMOD_LICENSE@
*/
/*
***********************************************************************
* Slabs */ /**
* \defgroup Slab Slab Allocation
* @{
*
* ESX Server supports slab allocation for high performance driver/stack
* implementations:
* - Reduces memory fragmentation, especially for smaller data structures
* allocated in high volume.
* - Reduces CPU consumption for data structure initialization/teardown.
* - Improves CPU hardware cache performance.
* - Provides finer grained control of memory consumption.
*
***********************************************************************
*/
#ifndef _VMKAPI_SLAB_H_
#define _VMKAPI_SLAB_H_
/** \cond never */
#ifndef VMK_HEADER_INCLUDED_FROM_VMKAPI_H
#error This vmkapi file should never be included directly but only via vmkapi.h
#endif
/** \endcond never */
/**
* \brief Opaque handle for a slab cache.
*/
typedef struct vmk_SlabIDInt *vmk_SlabID;
#define VMK_INVALID_SLAB_ID ((vmk_SlabID)NULL)
/**
* \brief Constant for specifying an unlimited number of slab objects.
*/
#define VMK_SLAB_MAX_UNLIMITED ((vmk_ByteCountSmall) -1)
/*
***********************************************************************
* vmk_SlabItemConstructor -- */ /**
*
* \brief Item constructor - optional user defined function. Runs for
* each object when a cluster of memory is
* allocated from the heap.
*
* \note When the control structure is placed inside the free object,
* then the constructor must take care not to modify the control
* structure.
*
* \note A callback of this type must not block or call any API
* functions that may block.
*
* \param[in] object Object to be constructed.
* \param[in] size Size of buffer (possibly greater than objSize).
* \param[in] arg constructorArg (see vmk_SlabCreateProps).
* \param[in] flags Currently unused (reserved for future use).
*
* \retval VMK_OK to indicate object construction has succeded.
* \return Other To indicate failure.
*
***********************************************************************
*/
typedef VMK_ReturnStatus (*vmk_SlabItemConstructor)(void *object,
vmk_ByteCountSmall size,
vmk_AddrCookie arg,
int flags);
/*
***********************************************************************
* vmk_SlabItemDestructor -- */ /**
*
* \brief Item destructor - optional user defined function. Runs for
* each buffer just before a cluster of memory
* is returned to the heap.
*
* \note When the control structure is placed inside the free object,
* then the destructor must take care not to modify the control
* structure.
*
* \note A callback of this type must not block or call any API
* functions that may block.
*
* \param[in] object Object to be destroyed.
* \param[in] size Size of buffer (possibly greater than objSize).
* \param[in] arg constructorArg (see vmk_SlabCreateProps).
*
***********************************************************************
*/
typedef void (*vmk_SlabItemDestructor)(void *object, vmk_ByteCountSmall size,
vmk_AddrCookie arg);
/**
* \brief Memory requirements for slabs.
*/
typedef struct vmk_SlabMemSize {
/** \brief Minimum number of memory pages this slab will occupy. */
vmk_uint32 minPages;
/** \brief Maximum number of memory pages this slab will occupy. */
vmk_uint32 maxPages;
} vmk_SlabMemSize;
/**
* \brief Types of slab
*/
typedef enum vmk_SlabType {
/**
* \brief Slabs that get their own memory pool.
*
* Slabs of type VMK_SLAB_TYPE_SIMPLE get a contiguity of
* VMK_MEM_PHYS_ANY_CONTIGUITY and a physical address constraint
* of VMK_PHYS_ADDR_ANY. For slabs with different constraints,
* use type VMK_SLAB_TYPE_CUSTOM or VMK_SLAB_TYPE_MEMPOOL.
*/
VMK_SLAB_TYPE_SIMPLE = 0,
/** \brief Slabs with custom memory properties. */
VMK_SLAB_TYPE_CUSTOM = 1,
/** \brief Slabs whose memory comes from an existing memPool. */
VMK_SLAB_TYPE_MEMPOOL = 2,
} vmk_SlabType;
/**
* \brief Properties of a slab allocator
*/
typedef struct vmk_SlabCreateProps {
/** \brief Type of slab */
vmk_SlabType type;
/**
* \brief Name of the slab.
*/
vmk_Name name;
/** \brief Module ID of the module creating this slab. */
vmk_ModuleID module;
/**
* \brief Byte Size of each object
*
* objSize must be at least 1 byte and not more than 28608 bytes.
**/
vmk_ByteCountSmall objSize;
/**
* \brief Byte alignment for each object
*
* The alignment must be a power of 2, and it must be less than or
* equal to VMK_L1_CACHELINE_SIZE.
*/
vmk_ByteCountSmall alignment;
/** \brief Called after an object is allocated (or NULL for no action) */
vmk_SlabItemConstructor constructor;
/** \brief Called before an object is freed (or NULL for no action) */
vmk_SlabItemDestructor destructor;
/** \brief Argument for constructor/destructor calls */
vmk_AddrCookie constructorArg;
/**
* \brief Offset in allocation for slab control structure.
* \sa vmk_SlabControlSize
*/
vmk_ByteCountSmall ctrlOffset;
/** \brief Minimum number of objects allocatable from this slab. */
vmk_uint32 minObj;
/** \brief Maximum number of objects allocatable from this slab. */
vmk_uint32 maxObj;
/** \brief How long to wait for memory during slab creation. */
vmk_uint32 creationTimeoutMS;
/** \brief Type-specific slab properties */
union {
/** \brief Properties for VMK_SLAB_TYPE_CUSTOM. */
struct {
/** \brief Physical contiguity of objects allocated from this slab. */
vmk_MemPhysContiguity physContiguity;
/** \brief Physical address restrictions. */
vmk_MemPhysAddrConstraint physRange;
} custom;
/** \brief Properties for VMK_SLAB_TYPE_MEMPOOL. */
struct {
/** \brief Physical contiguity allocated from this slab. */
vmk_MemPhysContiguity physContiguity;
/** \brief Physical address restrictions. */
vmk_MemPhysAddrConstraint physRange;
/** \brief Memory pool. */
vmk_MemPool memPool;
} memPool;
} typeSpecific;
} vmk_SlabCreateProps;
/**
* \brief Properties structure for querying a slab allocator.
*/
typedef struct vmk_SlabGetProps {
/** \brief Name of the slab. */
vmk_Name name;
/** \brief Module ID of the module creating this slab. */
vmk_ModuleID module;
/** \brief Byte Size of each object. */
vmk_ByteCountSmall objSize;
/**
* \brief Byte alignment for each object
*/
vmk_ByteCountSmall alignment;
/** \brief Called after an object is allocated (or NULL for no action) */
vmk_SlabItemConstructor constructor;
/** \brief Called before an object is freed (or NULL for no action) */
vmk_SlabItemDestructor destructor;
/** \brief Argument for constructor/destructor calls */
vmk_AddrCookie constructorArg;
/** \brief Offset in allocation for slab control structure. */
vmk_ByteCountSmall ctrlOffset;
/** \brief Minimum number of objects allocatable from this slab. */
vmk_uint32 minObj;
/** \brief Maximum number of objects allocatable from this slab. */
vmk_uint32 maxObj;
/** \brief Physical contiguity allocated from this slab. */
vmk_MemPhysContiguity physContiguity;
/** \brief Physical address restrictions. */
vmk_MemPhysAddrConstraint physRange;
/** \brief Memory pool. */
vmk_MemPool memPool;
} vmk_SlabGetProps;
/*
***********************************************************************
* vmk_SlabCreate -- */ /**
*
* \brief Create a slab allocator cache.
*
* A slab is created with the specified creation properties. Enough
* memory is allocated for props->minObj to be created. Slab creation
* will fail if enough memory cannot be allocated.
*
* \note This function may block if creationTimeoutMS is not
* VMK_TIMEOUT_NONBLOCKING.
*
* \param [in] props Properties of the new cache.
* \param [out] cache For use with vmk_SlabAlloc, etc.
*
* \retval VMK_OK indicates that the slab was created.
* \retval VMK_BAD_PARAM indicates that some slab parameters were
* invalid.
* \retval VMK_NO_MEMORY indicates that insufficient memory was
* available.
* \retval VMK_TIMEOUT indicates that the timeout was reached before
* enough memory could be allocated.
*
***********************************************************************
*/
VMK_ReturnStatus vmk_SlabCreate(vmk_SlabCreateProps *props,
vmk_SlabID *cache);
/*
***********************************************************************
* vmk_SlabAlloc -- */ /**
*
* \brief Allocate an item from a slab.
*
* The vmk_SlabItemConstructor (if defined) was previously called,
* or the object was previously freed via vmk_SlabFree().
*
* If the slab is not yet at maximum size, this function may attempt to
* allocate additional physical memory to satisfy the allocation request.
* If physical memory is not currently available, this function will not
* block to wait for memory to become available.
*
* \note When the control structure is placed inside the free object,
* the caller of vmk_SlabAlloc() must assume this portion of
* the object is uninitialized.
*
* \note This function will not block.
*
* \param[in] cache Slab from which allocation will take place.
*
* \retval NULL Memory could not be allocated.
*
***********************************************************************
*/
void *vmk_SlabAlloc(vmk_SlabID cache);
/*
***********************************************************************
* vmk_SlabAllocWithTimeout -- */ /**
*
* \brief Allocate an item, possibly waiting for physical memory.
*
* The vmk_SlabItemConstructor (if defined) was previously called,
* or the object was previously freed via vmk_SlabFree().
*
* If the slab is not yet at maximum size, this function may attempt to
* allocate additional physical memory to satisfy the allocation request.
* If physical memory is not currently available, this function will use
* the value of timeout to determine if it may block until memory is
* available, and if so, for how long.
*
* \note When the control structure is placed inside the free object,
* the caller of vmk_SlabAlloc() must assume this portion of
* the object is uninitialized.
*
* \note This function may block.
*
* \param[in] cache Slab from which allocation will take place.
* \param[in] timeoutMS Timeout specifying how long the call may wait.
*
* \retval NULL Memory could not be allocated.
*
***********************************************************************
*/
void *vmk_SlabAllocWithTimeout(
vmk_SlabID cache,
vmk_uint32 timeoutMS);
/*
***********************************************************************
* vmk_SlabFree -- */ /**
*
* \brief Free memory allocated by vmk_SlabAlloc.
*
* The memory object will be retained by the slab. If at some point
* the slab chooses to give the memory back to the system, the
* vmk_SlabItemDestructor (if defined) will be called.
*
* \note This function will not block.
*
* \param[in] cache Slab from which the item was allocated.
* \param[in] object object to be freed.
*
***********************************************************************
*/
void vmk_SlabFree(
vmk_SlabID cache,
void *object);
/*
***********************************************************************
* vmk_SlabDestroy -- */ /**
*
* \brief Destroy a slab cache previously created by vmk_SlabCreate.
*
* \note This function will not block.
*
* \param[in] cache The cache to be destroyed.
*
***********************************************************************
*/
VMK_ReturnStatus vmk_SlabDestroy(vmk_SlabID cache);
/*
***********************************************************************
* vmk_SlabControlSize -- */ /**
*
* \brief Get the size of the per-object "control" structure.
*
* The slab maintains a control structure for each free object
* cached by the slab. When VMK_SLAB_TYPE_SIMPLE properties are
* used to create the slab, the control structure will be tacked
* past the end of the client's object. To save space, the control
* structure can be placed within the user's free object using the
* ctrlOffset paramter to VMK_SLAB_TYPE_NOMINAL properties.
*
* \note For best performance, it is recommended that the control structure
* offset is a multiple of sizeof (void *), but this is not a
* requirement.
*
* \note See vmk_SlabItemConstructor, vmk_SlabItemDestructor and
* and vmk_SlabAlloc for the constraints that must be obeyed
* when the control structure is placed inside the object.
*
* \note This function will not block.
*
* \return Size of the control structure in bytes.
*
***********************************************************************
*/
vmk_ByteCountSmall vmk_SlabControlSize(void);
/*
***********************************************************************
* vmk_SlabGetMemSize -- */ /**
*
* \brief Returns the memory requirements for a slab.
*
* This function computes the minimum and maximum required
* memory for a slab with the provided characteristics.
*
* For a slab of type VMK_SLAB_TYPE_MEMPOOL, the provided memPool
* may be VMK_MEMPOOL_LEGACY_INVALID, so this function can be used
* to compute needed sizes for constructing a memory pool.
*
* \note This function will not block.
*
* \return VMK_BAD_PARAM minObj and maxObj were inconsistent,
* or maxObj was VMK_SLAB_MAX_UNLIMITED
* for a slab of type VMK_SLAB_TYPE_SIMPLE or
* VMK_SLAB_TYPE_CUSTOM.
*
***********************************************************************
*/
VMK_ReturnStatus vmk_SlabGetMemSize(vmk_SlabCreateProps *props,
vmk_SlabMemSize *size);
/*
***********************************************************************
* vmk_SlabGetProperties -- */ /**
*
* \brief Returns the allocation properties for a slab.
*
* \note This function will not block.
*
* \return VMK_OK Properties is filled in.
* \return VMK_NOT_FOUND slab was not a valid slab handle.
*
***********************************************************************
*/
VMK_ReturnStatus
vmk_SlabGetProperties(vmk_SlabID slab, vmk_SlabGetProps *props);
#endif /* _VMKAPI_SLAB_H_ */
/** @} */
|