slab_def.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #ifndef _LINUX_SLAB_DEF_H
  2. #define _LINUX_SLAB_DEF_H
  3. #include <linux/reciprocal_div.h>
  4. /*
  5. * Definitions unique to the original Linux SLAB allocator.
  6. */
  7. struct kmem_cache {
  8. struct array_cache __percpu *cpu_cache;
  9. /* 1) Cache tunables. Protected by slab_mutex */
  10. unsigned int batchcount;
  11. unsigned int limit;
  12. unsigned int shared;
  13. unsigned int size;
  14. struct reciprocal_value reciprocal_buffer_size;
  15. /* 2) touched by every alloc & free from the backend */
  16. unsigned int flags; /* constant flags */
  17. unsigned int num; /* # of objs per slab */
  18. /* 3) cache_grow/shrink */
  19. /* order of pgs per slab (2^n) */
  20. unsigned int gfporder;
  21. /* force GFP flags, e.g. GFP_DMA */
  22. gfp_t allocflags;
  23. size_t colour; /* cache colouring range */
  24. unsigned int colour_off; /* colour offset */
  25. struct kmem_cache *freelist_cache;
  26. unsigned int freelist_size;
  27. /* constructor func */
  28. void (*ctor)(void *obj);
  29. /* 4) cache creation/removal */
  30. const char *name;
  31. struct list_head list;
  32. int refcount;
  33. int object_size;
  34. int align;
  35. /* 5) statistics */
  36. #ifdef CONFIG_DEBUG_SLAB
  37. unsigned long num_active;
  38. unsigned long num_allocations;
  39. unsigned long high_mark;
  40. unsigned long grown;
  41. unsigned long reaped;
  42. unsigned long errors;
  43. unsigned long max_freeable;
  44. unsigned long node_allocs;
  45. unsigned long node_frees;
  46. unsigned long node_overflow;
  47. atomic_t allochit;
  48. atomic_t allocmiss;
  49. atomic_t freehit;
  50. atomic_t freemiss;
  51. #ifdef CONFIG_DEBUG_SLAB_LEAK
  52. atomic_t store_user_clean;
  53. #endif
  54. /*
  55. * If debugging is enabled, then the allocator can add additional
  56. * fields and/or padding to every object. size contains the total
  57. * object size including these internal fields, the following two
  58. * variables contain the offset to the user object and its size.
  59. */
  60. int obj_offset;
  61. #endif /* CONFIG_DEBUG_SLAB */
  62. #ifdef CONFIG_MEMCG
  63. struct memcg_cache_params memcg_params;
  64. #endif
  65. #ifdef CONFIG_KASAN
  66. struct kasan_cache kasan_info;
  67. #endif
  68. #ifdef CONFIG_SLAB_FREELIST_RANDOM
  69. unsigned int *random_seq;
  70. #endif
  71. struct kmem_cache_node *node[MAX_NUMNODES];
  72. };
  73. static inline void *nearest_obj(struct kmem_cache *cache, struct page *page,
  74. void *x)
  75. {
  76. void *object = x - (x - page->s_mem) % cache->size;
  77. void *last_object = page->s_mem + (cache->num - 1) * cache->size;
  78. if (unlikely(object > last_object))
  79. return last_object;
  80. else
  81. return object;
  82. }
  83. #endif /* _LINUX_SLAB_DEF_H */