Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _LINUX_MEMORY_TIERS_H
3#define _LINUX_MEMORY_TIERS_H
4
5#include <linux/types.h>
6#include <linux/nodemask.h>
7#include <linux/kref.h>
8#include <linux/mmzone.h>
9/*
10 * Each tier cover a abstrace distance chunk size of 128
11 */
12#define MEMTIER_CHUNK_BITS 7
13#define MEMTIER_CHUNK_SIZE (1 << MEMTIER_CHUNK_BITS)
14/*
15 * Smaller abstract distance values imply faster (higher) memory tiers. Offset
16 * the DRAM adistance so that we can accommodate devices with a slightly lower
17 * adistance value (slightly faster) than default DRAM adistance to be part of
18 * the same memory tier.
19 */
20#define MEMTIER_ADISTANCE_DRAM ((4 * MEMTIER_CHUNK_SIZE) + (MEMTIER_CHUNK_SIZE >> 1))
21#define MEMTIER_HOTPLUG_PRIO 100
22
23struct memory_tier;
24struct memory_dev_type {
25 /* list of memory types that are part of same tier as this type */
26 struct list_head tier_sibiling;
27 /* abstract distance for this specific memory type */
28 int adistance;
29 /* Nodes of same abstract distance */
30 nodemask_t nodes;
31 struct kref kref;
32};
33
34#ifdef CONFIG_NUMA
35extern bool numa_demotion_enabled;
36struct memory_dev_type *alloc_memory_type(int adistance);
37void destroy_memory_type(struct memory_dev_type *memtype);
38void init_node_memory_type(int node, struct memory_dev_type *default_type);
39void clear_node_memory_type(int node, struct memory_dev_type *memtype);
40#ifdef CONFIG_MIGRATION
41int next_demotion_node(int node);
42void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets);
43bool node_is_toptier(int node);
44#else
45static inline int next_demotion_node(int node)
46{
47 return NUMA_NO_NODE;
48}
49
50static inline void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets)
51{
52 *targets = NODE_MASK_NONE;
53}
54
55static inline bool node_is_toptier(int node)
56{
57 return true;
58}
59#endif
60
61#else
62
63#define numa_demotion_enabled false
64/*
65 * CONFIG_NUMA implementation returns non NULL error.
66 */
67static inline struct memory_dev_type *alloc_memory_type(int adistance)
68{
69 return NULL;
70}
71
72static inline void destroy_memory_type(struct memory_dev_type *memtype)
73{
74
75}
76
77static inline void init_node_memory_type(int node, struct memory_dev_type *default_type)
78{
79
80}
81
82static inline void clear_node_memory_type(int node, struct memory_dev_type *memtype)
83{
84
85}
86
87static inline int next_demotion_node(int node)
88{
89 return NUMA_NO_NODE;
90}
91
92static inline void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets)
93{
94 *targets = NODE_MASK_NONE;
95}
96
97static inline bool node_is_toptier(int node)
98{
99 return true;
100}
101#endif /* CONFIG_NUMA */
102#endif /* _LINUX_MEMORY_TIERS_H */