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