user_uma.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*-
  2. * Copyright (c) 2009-2010 Brad Penoff
  3. * Copyright (c) 2009-2010 Humaira Kamal
  4. * Copyright (c) 2011-2012 Irene Ruengeler
  5. * Copyright (c) 2011-2012 Michael Tuexen
  6. *
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  22. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  24. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. */
  30. #ifndef _USER_UMA_H_
  31. #define _USER_UMA_H_
  32. #define UMA_ZFLAG_FULL 0x40000000 /* Reached uz_maxpages */
  33. #define UMA_ALIGN_PTR (sizeof(void *) - 1) /* Alignment fit for ptr */
  34. /* __Userspace__ All these definitions will change for
  35. userspace Universal Memory Allocator (UMA). These are included
  36. for reference purposes and to avoid compile errors for the time being.
  37. */
  38. typedef int (*uma_ctor)(void *mem, int size, void *arg, int flags);
  39. typedef void (*uma_dtor)(void *mem, int size, void *arg);
  40. typedef int (*uma_init)(void *mem, int size, int flags);
  41. typedef void (*uma_fini)(void *mem, int size);
  42. typedef struct uma_zone * uma_zone_t;
  43. typedef struct uma_keg * uma_keg_t;
  44. struct uma_cache {
  45. int stub; /* TODO __Userspace__ */
  46. };
  47. struct uma_keg {
  48. int stub; /* TODO __Userspace__ */
  49. };
  50. struct uma_zone {
  51. char *uz_name; /* Text name of the zone */
  52. struct mtx *uz_lock; /* Lock for the zone (keg's lock) */
  53. uma_keg_t uz_keg; /* Our underlying Keg */
  54. LIST_ENTRY(uma_zone) uz_link; /* List of all zones in keg */
  55. LIST_HEAD(,uma_bucket) uz_full_bucket; /* full buckets */
  56. LIST_HEAD(,uma_bucket) uz_free_bucket; /* Buckets for frees */
  57. uma_ctor uz_ctor; /* Constructor for each allocation */
  58. uma_dtor uz_dtor; /* Destructor */
  59. uma_init uz_init; /* Initializer for each item */
  60. uma_fini uz_fini; /* Discards memory */
  61. u_int64_t uz_allocs; /* Total number of allocations */
  62. u_int64_t uz_frees; /* Total number of frees */
  63. u_int64_t uz_fails; /* Total number of alloc failures */
  64. uint16_t uz_fills; /* Outstanding bucket fills */
  65. uint16_t uz_count; /* Highest value ub_ptr can have */
  66. /*
  67. * This HAS to be the last item because we adjust the zone size
  68. * based on NCPU and then allocate the space for the zones.
  69. */
  70. struct uma_cache uz_cpu[1]; /* Per cpu caches */
  71. };
  72. /* Prototype */
  73. uma_zone_t
  74. uma_zcreate(char *name, size_t size, uma_ctor ctor, uma_dtor dtor,
  75. uma_init uminit, uma_fini fini, int align, uint32_t flags);
  76. #define uma_zone_set_max(zone, number) /* stub TODO __Userspace__ */
  77. uma_zone_t
  78. uma_zcreate(char *name, size_t size, uma_ctor ctor, uma_dtor dtor,
  79. uma_init uminit, uma_fini fini, int align, uint32_t flags) {
  80. return NULL; /* stub TODO __Userspace__. Also place implementation in a separate .c file */
  81. }
  82. #endif