mm_slot.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // SPDX-License-Identifier: GPL-2.0
  2. #ifndef _LINUX_MM_SLOT_H
  3. #define _LINUX_MM_SLOT_H
  4. #include <linux/hashtable.h>
  5. #include <linux/slab.h>
  6. /*
  7. * struct mm_slot - hash lookup from mm to mm_slot
  8. * @hash: link to the mm_slots hash list
  9. * @mm_node: link into the mm_slots list
  10. * @mm: the mm that this information is valid for
  11. */
  12. struct mm_slot {
  13. struct hlist_node hash;
  14. struct list_head mm_node;
  15. struct mm_struct *mm;
  16. };
  17. #define mm_slot_entry(ptr, type, member) \
  18. container_of(ptr, type, member)
  19. static inline void *mm_slot_alloc(struct kmem_cache *cache)
  20. {
  21. if (!cache) /* initialization failed */
  22. return NULL;
  23. return kmem_cache_zalloc(cache, GFP_KERNEL);
  24. }
  25. static inline void mm_slot_free(struct kmem_cache *cache, void *objp)
  26. {
  27. kmem_cache_free(cache, objp);
  28. }
  29. #define mm_slot_lookup(_hashtable, _mm) \
  30. ({ \
  31. struct mm_slot *tmp_slot, *mm_slot = NULL; \
  32. \
  33. hash_for_each_possible(_hashtable, tmp_slot, hash, (unsigned long)_mm) \
  34. if (_mm == tmp_slot->mm) { \
  35. mm_slot = tmp_slot; \
  36. break; \
  37. } \
  38. \
  39. mm_slot; \
  40. })
  41. #define mm_slot_insert(_hashtable, _mm, _mm_slot) \
  42. ({ \
  43. _mm_slot->mm = _mm; \
  44. hash_add(_hashtable, &_mm_slot->hash, (unsigned long)_mm); \
  45. })
  46. #endif /* _LINUX_MM_SLOT_H */