at v6.2 2.5 kB view raw
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 22struct memory_tier; 23struct memory_dev_type { 24 /* list of memory types that are part of same tier as this type */ 25 struct list_head tier_sibiling; 26 /* abstract distance for this specific memory type */ 27 int adistance; 28 /* Nodes of same abstract distance */ 29 nodemask_t nodes; 30 struct kref kref; 31}; 32 33#ifdef CONFIG_NUMA 34extern bool numa_demotion_enabled; 35struct memory_dev_type *alloc_memory_type(int adistance); 36void destroy_memory_type(struct memory_dev_type *memtype); 37void init_node_memory_type(int node, struct memory_dev_type *default_type); 38void clear_node_memory_type(int node, struct memory_dev_type *memtype); 39#ifdef CONFIG_MIGRATION 40int next_demotion_node(int node); 41void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets); 42bool node_is_toptier(int node); 43#else 44static inline int next_demotion_node(int node) 45{ 46 return NUMA_NO_NODE; 47} 48 49static inline void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets) 50{ 51 *targets = NODE_MASK_NONE; 52} 53 54static inline bool node_is_toptier(int node) 55{ 56 return true; 57} 58#endif 59 60#else 61 62#define numa_demotion_enabled false 63/* 64 * CONFIG_NUMA implementation returns non NULL error. 65 */ 66static inline struct memory_dev_type *alloc_memory_type(int adistance) 67{ 68 return NULL; 69} 70 71static inline void destroy_memory_type(struct memory_dev_type *memtype) 72{ 73 74} 75 76static inline void init_node_memory_type(int node, struct memory_dev_type *default_type) 77{ 78 79} 80 81static inline void clear_node_memory_type(int node, struct memory_dev_type *memtype) 82{ 83 84} 85 86static inline int next_demotion_node(int node) 87{ 88 return NUMA_NO_NODE; 89} 90 91static inline void node_get_allowed_targets(pg_data_t *pgdat, nodemask_t *targets) 92{ 93 *targets = NODE_MASK_NONE; 94} 95 96static inline bool node_is_toptier(int node) 97{ 98 return true; 99} 100#endif /* CONFIG_NUMA */ 101#endif /* _LINUX_MEMORY_TIERS_H */