Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
torvalds
GitHub Repository: torvalds/linux
Path: blob/master/mm/cma.h
26131 views
1
/* SPDX-License-Identifier: GPL-2.0 */
2
#ifndef __MM_CMA_H__
3
#define __MM_CMA_H__
4
5
#include <linux/debugfs.h>
6
#include <linux/kobject.h>
7
8
struct cma_kobject {
9
struct kobject kobj;
10
struct cma *cma;
11
};
12
13
/*
14
* Multi-range support. This can be useful if the size of the allocation
15
* is not expected to be larger than the alignment (like with hugetlb_cma),
16
* and the total amount of memory requested, while smaller than the total
17
* amount of memory available, is large enough that it doesn't fit in a
18
* single physical memory range because of memory holes.
19
*
20
* Fields:
21
* @base_pfn: physical address of range
22
* @early_pfn: first PFN not reserved through cma_reserve_early
23
* @count: size of range
24
* @bitmap: bitmap of allocated (1 << order_per_bit)-sized chunks.
25
*/
26
struct cma_memrange {
27
unsigned long base_pfn;
28
unsigned long count;
29
union {
30
unsigned long early_pfn;
31
unsigned long *bitmap;
32
};
33
#ifdef CONFIG_CMA_DEBUGFS
34
struct debugfs_u32_array dfs_bitmap;
35
#endif
36
};
37
#define CMA_MAX_RANGES 8
38
39
struct cma {
40
unsigned long count;
41
unsigned long available_count;
42
unsigned int order_per_bit; /* Order of pages represented by one bit */
43
spinlock_t lock;
44
struct mutex alloc_mutex;
45
#ifdef CONFIG_CMA_DEBUGFS
46
struct hlist_head mem_head;
47
spinlock_t mem_head_lock;
48
#endif
49
char name[CMA_MAX_NAME];
50
int nranges;
51
struct cma_memrange ranges[CMA_MAX_RANGES];
52
#ifdef CONFIG_CMA_SYSFS
53
/* the number of CMA page successful allocations */
54
atomic64_t nr_pages_succeeded;
55
/* the number of CMA page allocation failures */
56
atomic64_t nr_pages_failed;
57
/* the number of CMA page released */
58
atomic64_t nr_pages_released;
59
/* kobject requires dynamic object */
60
struct cma_kobject *cma_kobj;
61
#endif
62
unsigned long flags;
63
/* NUMA node (NUMA_NO_NODE if unspecified) */
64
int nid;
65
};
66
67
enum cma_flags {
68
CMA_RESERVE_PAGES_ON_ERROR,
69
CMA_ZONES_VALID,
70
CMA_ZONES_INVALID,
71
CMA_ACTIVATED,
72
};
73
74
extern struct cma cma_areas[MAX_CMA_AREAS];
75
extern unsigned int cma_area_count;
76
77
static inline unsigned long cma_bitmap_maxno(struct cma *cma,
78
struct cma_memrange *cmr)
79
{
80
return cmr->count >> cma->order_per_bit;
81
}
82
83
#ifdef CONFIG_CMA_SYSFS
84
void cma_sysfs_account_success_pages(struct cma *cma, unsigned long nr_pages);
85
void cma_sysfs_account_fail_pages(struct cma *cma, unsigned long nr_pages);
86
void cma_sysfs_account_release_pages(struct cma *cma, unsigned long nr_pages);
87
#else
88
static inline void cma_sysfs_account_success_pages(struct cma *cma,
89
unsigned long nr_pages) {};
90
static inline void cma_sysfs_account_fail_pages(struct cma *cma,
91
unsigned long nr_pages) {};
92
static inline void cma_sysfs_account_release_pages(struct cma *cma,
93
unsigned long nr_pages) {};
94
#endif
95
#endif
96
97