summaryrefslogtreecommitdiffstats
path: root/mm/mm_slot.h
blob: 83f18ed1c4bde71eaab92a67ae64db3e466d65f3 (plain)
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
// SPDX-License-Identifier: GPL-2.0

#ifndef _LINUX_MM_SLOT_H
#define _LINUX_MM_SLOT_H

#include <linux/hashtable.h>
#include <linux/slab.h>

/*
 * struct mm_slot - hash lookup from mm to mm_slot
 * @hash: link to the mm_slots hash list
 * @mm_node: link into the mm_slots list
 * @mm: the mm that this information is valid for
 */
struct mm_slot {
	struct hlist_node hash;
	struct list_head mm_node;
	struct mm_struct *mm;
};

#define mm_slot_entry(ptr, type, member) \
	container_of(ptr, type, member)

static inline void *mm_slot_alloc(struct kmem_cache *cache)
{
	if (!cache)	/* initialization failed */
		return NULL;
	return kmem_cache_zalloc(cache, GFP_KERNEL);
}

static inline void mm_slot_free(struct kmem_cache *cache, void *objp)
{
	kmem_cache_free(cache, objp);
}

#define mm_slot_lookup(_hashtable, _mm) 				       \
({									       \
	struct mm_slot *tmp_slot, *mm_slot = NULL;			       \
									       \
	hash_for_each_possible(_hashtable, tmp_slot, hash, (unsigned long)_mm) \
		if (_mm == tmp_slot->mm) {				       \
			mm_slot = tmp_slot;				       \
			break;						       \
		}							       \
									       \
	mm_slot;							       \
})

#define mm_slot_insert(_hashtable, _mm, _mm_slot)			       \
({									       \
	_mm_slot->mm = _mm;						       \
	hash_add(_hashtable, &_mm_slot->hash, (unsigned long)_mm);	       \
})

#endif /* _LINUX_MM_SLOT_H */