1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #include <linux/node.h> 3 #include <linux/mmzone.h> 4 #include <linux/compaction.h> 5 /* 6 * The order of these masks is important. Matching masks will be seen 7 * first and the left over flags will end up showing by themselves. 8 * 9 * For example, if we have GFP_KERNEL before GFP_USER we wil get: 10 * 11 * GFP_KERNEL|GFP_HARDWALL 12 * 13 * Thus most bits set go first. 14 */ 15 16 #define gfpflag_string(flag) {(__force unsigned long)flag, #flag} 17 18 #define __def_gfpflag_names \ 19 gfpflag_string(GFP_TRANSHUGE), \ 20 gfpflag_string(GFP_TRANSHUGE_LIGHT), \ 21 gfpflag_string(GFP_HIGHUSER_MOVABLE), \ 22 gfpflag_string(GFP_HIGHUSER), \ 23 gfpflag_string(GFP_USER), \ 24 gfpflag_string(GFP_KERNEL_ACCOUNT), \ 25 gfpflag_string(GFP_KERNEL), \ 26 gfpflag_string(GFP_NOFS), \ 27 gfpflag_string(GFP_ATOMIC), \ 28 gfpflag_string(GFP_NOIO), \ 29 gfpflag_string(GFP_NOWAIT), \ 30 gfpflag_string(GFP_DMA), \ 31 gfpflag_string(__GFP_HIGHMEM), \ 32 gfpflag_string(GFP_DMA32), \ 33 gfpflag_string(__GFP_HIGH), \ 34 gfpflag_string(__GFP_IO), \ 35 gfpflag_string(__GFP_FS), \ 36 gfpflag_string(__GFP_NOWARN), \ 37 gfpflag_string(__GFP_RETRY_MAYFAIL), \ 38 gfpflag_string(__GFP_NOFAIL), \ 39 gfpflag_string(__GFP_NORETRY), \ 40 gfpflag_string(__GFP_COMP), \ 41 gfpflag_string(__GFP_ZERO), \ 42 gfpflag_string(__GFP_NOMEMALLOC), \ 43 gfpflag_string(__GFP_MEMALLOC), \ 44 gfpflag_string(__GFP_HARDWALL), \ 45 gfpflag_string(__GFP_THISNODE), \ 46 gfpflag_string(__GFP_RECLAIMABLE), \ 47 gfpflag_string(__GFP_MOVABLE), \ 48 gfpflag_string(__GFP_ACCOUNT), \ 49 gfpflag_string(__GFP_WRITE), \ 50 gfpflag_string(__GFP_RECLAIM), \ 51 gfpflag_string(__GFP_DIRECT_RECLAIM), \ 52 gfpflag_string(__GFP_KSWAPD_RECLAIM), \ 53 gfpflag_string(__GFP_ZEROTAGS) 54 55 #ifdef CONFIG_KASAN_HW_TAGS 56 #define __def_gfpflag_names_kasan , \ 57 gfpflag_string(__GFP_SKIP_ZERO), \ 58 gfpflag_string(__GFP_SKIP_KASAN) 59 #else 60 #define __def_gfpflag_names_kasan 61 #endif 62 63 #define show_gfp_flags(flags) \ 64 (flags) ? __print_flags(flags, "|", \ 65 __def_gfpflag_names __def_gfpflag_names_kasan \ 66 ) : "none" 67 68 #ifdef CONFIG_MMU 69 #define IF_HAVE_PG_MLOCK(_name) ,{1UL << PG_##_name, __stringify(_name)} 70 #else 71 #define IF_HAVE_PG_MLOCK(_name) 72 #endif 73 74 #ifdef CONFIG_MEMORY_FAILURE 75 #define IF_HAVE_PG_HWPOISON(_name) ,{1UL << PG_##_name, __stringify(_name)} 76 #else 77 #define IF_HAVE_PG_HWPOISON(_name) 78 #endif 79 80 #if defined(CONFIG_PAGE_IDLE_FLAG) && defined(CONFIG_64BIT) 81 #define IF_HAVE_PG_IDLE(_name) ,{1UL << PG_##_name, __stringify(_name)} 82 #else 83 #define IF_HAVE_PG_IDLE(_name) 84 #endif 85 86 #ifdef CONFIG_ARCH_USES_PG_ARCH_2 87 #define IF_HAVE_PG_ARCH_2(_name) ,{1UL << PG_##_name, __stringify(_name)} 88 #else 89 #define IF_HAVE_PG_ARCH_2(_name) 90 #endif 91 92 #ifdef CONFIG_ARCH_USES_PG_ARCH_3 93 #define IF_HAVE_PG_ARCH_3(_name) ,{1UL << PG_##_name, __stringify(_name)} 94 #else 95 #define IF_HAVE_PG_ARCH_3(_name) 96 #endif 97 98 #define DEF_PAGEFLAG_NAME(_name) { 1UL << PG_##_name, __stringify(_name) } 99 100 #define __def_pageflag_names \ 101 DEF_PAGEFLAG_NAME(locked), \ 102 DEF_PAGEFLAG_NAME(waiters), \ 103 DEF_PAGEFLAG_NAME(referenced), \ 104 DEF_PAGEFLAG_NAME(uptodate), \ 105 DEF_PAGEFLAG_NAME(dirty), \ 106 DEF_PAGEFLAG_NAME(lru), \ 107 DEF_PAGEFLAG_NAME(active), \ 108 DEF_PAGEFLAG_NAME(workingset), \ 109 DEF_PAGEFLAG_NAME(owner_priv_1), \ 110 DEF_PAGEFLAG_NAME(owner_2), \ 111 DEF_PAGEFLAG_NAME(arch_1), \ 112 DEF_PAGEFLAG_NAME(reserved), \ 113 DEF_PAGEFLAG_NAME(private), \ 114 DEF_PAGEFLAG_NAME(private_2), \ 115 DEF_PAGEFLAG_NAME(writeback), \ 116 DEF_PAGEFLAG_NAME(head), \ 117 DEF_PAGEFLAG_NAME(reclaim), \ 118 DEF_PAGEFLAG_NAME(swapbacked), \ 119 DEF_PAGEFLAG_NAME(unevictable) \ 120 IF_HAVE_PG_MLOCK(mlocked) \ 121 IF_HAVE_PG_HWPOISON(hwpoison) \ 122 IF_HAVE_PG_IDLE(idle) \ 123 IF_HAVE_PG_IDLE(young) \ 124 IF_HAVE_PG_ARCH_2(arch_2) \ 125 IF_HAVE_PG_ARCH_3(arch_3) 126 127 #define show_page_flags(flags) \ 128 (flags) ? __print_flags(flags, "|", \ 129 __def_pageflag_names \ 130 ) : "none" 131 132 #if defined(CONFIG_X86) 133 #define __VM_ARCH_SPECIFIC_1 {VM_PAT, "pat" } 134 #elif defined(CONFIG_PPC64) 135 #define __VM_ARCH_SPECIFIC_1 {VM_SAO, "sao" } 136 #elif defined(CONFIG_PARISC) 137 #define __VM_ARCH_SPECIFIC_1 {VM_GROWSUP, "growsup" } 138 #elif !defined(CONFIG_MMU) 139 #define __VM_ARCH_SPECIFIC_1 {VM_MAPPED_COPY,"mappedcopy" } 140 #else 141 #define __VM_ARCH_SPECIFIC_1 {VM_ARCH_1, "arch_1" } 142 #endif 143 144 #ifdef CONFIG_MEM_SOFT_DIRTY 145 #define IF_HAVE_VM_SOFTDIRTY(flag,name) {flag, name }, 146 #else 147 #define IF_HAVE_VM_SOFTDIRTY(flag,name) 148 #endif 149 150 #ifdef CONFIG_HAVE_ARCH_USERFAULTFD_MINOR 151 # define IF_HAVE_UFFD_MINOR(flag, name) {flag, name}, 152 #else 153 # define IF_HAVE_UFFD_MINOR(flag, name) 154 #endif 155 156 #if defined(CONFIG_64BIT) || defined(CONFIG_PPC32) 157 # define IF_HAVE_VM_DROPPABLE(flag, name) {flag, name}, 158 #else 159 # define IF_HAVE_VM_DROPPABLE(flag, name) 160 #endif 161 162 #define __def_vmaflag_names \ 163 {VM_READ, "read" }, \ 164 {VM_WRITE, "write" }, \ 165 {VM_EXEC, "exec" }, \ 166 {VM_SHARED, "shared" }, \ 167 {VM_MAYREAD, "mayread" }, \ 168 {VM_MAYWRITE, "maywrite" }, \ 169 {VM_MAYEXEC, "mayexec" }, \ 170 {VM_MAYSHARE, "mayshare" }, \ 171 {VM_GROWSDOWN, "growsdown" }, \ 172 {VM_UFFD_MISSING, "uffd_missing" }, \ 173 IF_HAVE_UFFD_MINOR(VM_UFFD_MINOR, "uffd_minor" ) \ 174 {VM_PFNMAP, "pfnmap" }, \ 175 {VM_UFFD_WP, "uffd_wp" }, \ 176 {VM_LOCKED, "locked" }, \ 177 {VM_IO, "io" }, \ 178 {VM_SEQ_READ, "seqread" }, \ 179 {VM_RAND_READ, "randread" }, \ 180 {VM_DONTCOPY, "dontcopy" }, \ 181 {VM_DONTEXPAND, "dontexpand" }, \ 182 {VM_LOCKONFAULT, "lockonfault" }, \ 183 {VM_ACCOUNT, "account" }, \ 184 {VM_NORESERVE, "noreserve" }, \ 185 {VM_HUGETLB, "hugetlb" }, \ 186 {VM_SYNC, "sync" }, \ 187 __VM_ARCH_SPECIFIC_1 , \ 188 {VM_WIPEONFORK, "wipeonfork" }, \ 189 {VM_DONTDUMP, "dontdump" }, \ 190 IF_HAVE_VM_SOFTDIRTY(VM_SOFTDIRTY, "softdirty" ) \ 191 {VM_MIXEDMAP, "mixedmap" }, \ 192 {VM_HUGEPAGE, "hugepage" }, \ 193 {VM_NOHUGEPAGE, "nohugepage" }, \ 194 IF_HAVE_VM_DROPPABLE(VM_DROPPABLE, "droppable" ) \ 195 {VM_MERGEABLE, "mergeable" } \ 196 197 #define show_vma_flags(flags) \ 198 (flags) ? __print_flags(flags, "|", \ 199 __def_vmaflag_names \ 200 ) : "none" 201 202 #ifdef CONFIG_COMPACTION 203 #define COMPACTION_STATUS \ 204 EM( COMPACT_SKIPPED, "skipped") \ 205 EM( COMPACT_DEFERRED, "deferred") \ 206 EM( COMPACT_CONTINUE, "continue") \ 207 EM( COMPACT_SUCCESS, "success") \ 208 EM( COMPACT_PARTIAL_SKIPPED, "partial_skipped") \ 209 EM( COMPACT_COMPLETE, "complete") \ 210 EM( COMPACT_NO_SUITABLE_PAGE, "no_suitable_page") \ 211 EM( COMPACT_NOT_SUITABLE_ZONE, "not_suitable_zone") \ 212 EMe(COMPACT_CONTENDED, "contended") 213 214 /* High-level compaction status feedback */ 215 #define COMPACTION_FAILED 1 216 #define COMPACTION_WITHDRAWN 2 217 #define COMPACTION_PROGRESS 3 218 219 #define compact_result_to_feedback(result) \ 220 ({ \ 221 enum compact_result __result = result; \ 222 (__result == COMPACT_COMPLETE) ? COMPACTION_FAILED : \ 223 (__result == COMPACT_SUCCESS) ? COMPACTION_PROGRESS : COMPACTION_WITHDRAWN; \ 224 }) 225 226 #define COMPACTION_FEEDBACK \ 227 EM(COMPACTION_FAILED, "failed") \ 228 EM(COMPACTION_WITHDRAWN, "withdrawn") \ 229 EMe(COMPACTION_PROGRESS, "progress") 230 231 #define COMPACTION_PRIORITY \ 232 EM(COMPACT_PRIO_SYNC_FULL, "COMPACT_PRIO_SYNC_FULL") \ 233 EM(COMPACT_PRIO_SYNC_LIGHT, "COMPACT_PRIO_SYNC_LIGHT") \ 234 EMe(COMPACT_PRIO_ASYNC, "COMPACT_PRIO_ASYNC") 235 #else 236 #define COMPACTION_STATUS 237 #define COMPACTION_PRIORITY 238 #define COMPACTION_FEEDBACK 239 #endif 240 241 #ifdef CONFIG_ZONE_DMA 242 #define IFDEF_ZONE_DMA(X) X 243 #else 244 #define IFDEF_ZONE_DMA(X) 245 #endif 246 247 #ifdef CONFIG_ZONE_DMA32 248 #define IFDEF_ZONE_DMA32(X) X 249 #else 250 #define IFDEF_ZONE_DMA32(X) 251 #endif 252 253 #ifdef CONFIG_HIGHMEM 254 #define IFDEF_ZONE_HIGHMEM(X) X 255 #else 256 #define IFDEF_ZONE_HIGHMEM(X) 257 #endif 258 259 #define ZONE_TYPE \ 260 IFDEF_ZONE_DMA( EM (ZONE_DMA, "DMA")) \ 261 IFDEF_ZONE_DMA32( EM (ZONE_DMA32, "DMA32")) \ 262 EM (ZONE_NORMAL, "Normal") \ 263 IFDEF_ZONE_HIGHMEM( EM (ZONE_HIGHMEM,"HighMem")) \ 264 EMe(ZONE_MOVABLE,"Movable") 265 266 #define LRU_NAMES \ 267 EM (LRU_INACTIVE_ANON, "inactive_anon") \ 268 EM (LRU_ACTIVE_ANON, "active_anon") \ 269 EM (LRU_INACTIVE_FILE, "inactive_file") \ 270 EM (LRU_ACTIVE_FILE, "active_file") \ 271 EMe(LRU_UNEVICTABLE, "unevictable") 272 273 /* 274 * First define the enums in the above macros to be exported to userspace 275 * via TRACE_DEFINE_ENUM(). 276 */ 277 #undef EM 278 #undef EMe 279 #define EM(a, b) TRACE_DEFINE_ENUM(a); 280 #define EMe(a, b) TRACE_DEFINE_ENUM(a); 281 282 COMPACTION_STATUS 283 COMPACTION_PRIORITY 284 /* COMPACTION_FEEDBACK are defines not enums. Not needed here. */ 285 ZONE_TYPE 286 LRU_NAMES 287 288 /* 289 * Now redefine the EM() and EMe() macros to map the enums to the strings 290 * that will be printed in the output. 291 */ 292 #undef EM 293 #undef EMe 294 #define EM(a, b) {a, b}, 295 #define EMe(a, b) {a, b} 296