![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0 */ 0002 #ifndef __LINUX_GFP_TYPES_H 0003 #define __LINUX_GFP_TYPES_H 0004 0005 /* The typedef is in types.h but we want the documentation here */ 0006 #if 0 0007 /** 0008 * typedef gfp_t - Memory allocation flags. 0009 * 0010 * GFP flags are commonly used throughout Linux to indicate how memory 0011 * should be allocated. The GFP acronym stands for get_free_pages(), 0012 * the underlying memory allocation function. Not every GFP flag is 0013 * supported by every function which may allocate memory. Most users 0014 * will want to use a plain ``GFP_KERNEL``. 0015 */ 0016 typedef unsigned int __bitwise gfp_t; 0017 #endif 0018 0019 /* 0020 * In case of changes, please don't forget to update 0021 * include/trace/events/mmflags.h and tools/perf/builtin-kmem.c 0022 */ 0023 0024 /* Plain integer GFP bitmasks. Do not use this directly. */ 0025 #define ___GFP_DMA 0x01u 0026 #define ___GFP_HIGHMEM 0x02u 0027 #define ___GFP_DMA32 0x04u 0028 #define ___GFP_MOVABLE 0x08u 0029 #define ___GFP_RECLAIMABLE 0x10u 0030 #define ___GFP_HIGH 0x20u 0031 #define ___GFP_IO 0x40u 0032 #define ___GFP_FS 0x80u 0033 #define ___GFP_ZERO 0x100u 0034 #define ___GFP_ATOMIC 0x200u 0035 #define ___GFP_DIRECT_RECLAIM 0x400u 0036 #define ___GFP_KSWAPD_RECLAIM 0x800u 0037 #define ___GFP_WRITE 0x1000u 0038 #define ___GFP_NOWARN 0x2000u 0039 #define ___GFP_RETRY_MAYFAIL 0x4000u 0040 #define ___GFP_NOFAIL 0x8000u 0041 #define ___GFP_NORETRY 0x10000u 0042 #define ___GFP_MEMALLOC 0x20000u 0043 #define ___GFP_COMP 0x40000u 0044 #define ___GFP_NOMEMALLOC 0x80000u 0045 #define ___GFP_HARDWALL 0x100000u 0046 #define ___GFP_THISNODE 0x200000u 0047 #define ___GFP_ACCOUNT 0x400000u 0048 #define ___GFP_ZEROTAGS 0x800000u 0049 #ifdef CONFIG_KASAN_HW_TAGS 0050 #define ___GFP_SKIP_ZERO 0x1000000u 0051 #define ___GFP_SKIP_KASAN_UNPOISON 0x2000000u 0052 #define ___GFP_SKIP_KASAN_POISON 0x4000000u 0053 #else 0054 #define ___GFP_SKIP_ZERO 0 0055 #define ___GFP_SKIP_KASAN_UNPOISON 0 0056 #define ___GFP_SKIP_KASAN_POISON 0 0057 #endif 0058 #ifdef CONFIG_LOCKDEP 0059 #define ___GFP_NOLOCKDEP 0x8000000u 0060 #else 0061 #define ___GFP_NOLOCKDEP 0 0062 #endif 0063 /* If the above are modified, __GFP_BITS_SHIFT may need updating */ 0064 0065 /* 0066 * Physical address zone modifiers (see linux/mmzone.h - low four bits) 0067 * 0068 * Do not put any conditional on these. If necessary modify the definitions 0069 * without the underscores and use them consistently. The definitions here may 0070 * be used in bit comparisons. 0071 */ 0072 #define __GFP_DMA ((__force gfp_t)___GFP_DMA) 0073 #define __GFP_HIGHMEM ((__force gfp_t)___GFP_HIGHMEM) 0074 #define __GFP_DMA32 ((__force gfp_t)___GFP_DMA32) 0075 #define __GFP_MOVABLE ((__force gfp_t)___GFP_MOVABLE) /* ZONE_MOVABLE allowed */ 0076 #define GFP_ZONEMASK (__GFP_DMA|__GFP_HIGHMEM|__GFP_DMA32|__GFP_MOVABLE) 0077 0078 /** 0079 * DOC: Page mobility and placement hints 0080 * 0081 * Page mobility and placement hints 0082 * --------------------------------- 0083 * 0084 * These flags provide hints about how mobile the page is. Pages with similar 0085 * mobility are placed within the same pageblocks to minimise problems due 0086 * to external fragmentation. 0087 * 0088 * %__GFP_MOVABLE (also a zone modifier) indicates that the page can be 0089 * moved by page migration during memory compaction or can be reclaimed. 0090 * 0091 * %__GFP_RECLAIMABLE is used for slab allocations that specify 0092 * SLAB_RECLAIM_ACCOUNT and whose pages can be freed via shrinkers. 0093 * 0094 * %__GFP_WRITE indicates the caller intends to dirty the page. Where possible, 0095 * these pages will be spread between local zones to avoid all the dirty 0096 * pages being in one zone (fair zone allocation policy). 0097 * 0098 * %__GFP_HARDWALL enforces the cpuset memory allocation policy. 0099 * 0100 * %__GFP_THISNODE forces the allocation to be satisfied from the requested 0101 * node with no fallbacks or placement policy enforcements. 0102 * 0103 * %__GFP_ACCOUNT causes the allocation to be accounted to kmemcg. 0104 */ 0105 #define __GFP_RECLAIMABLE ((__force gfp_t)___GFP_RECLAIMABLE) 0106 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) 0107 #define __GFP_HARDWALL ((__force gfp_t)___GFP_HARDWALL) 0108 #define __GFP_THISNODE ((__force gfp_t)___GFP_THISNODE) 0109 #define __GFP_ACCOUNT ((__force gfp_t)___GFP_ACCOUNT) 0110 0111 /** 0112 * DOC: Watermark modifiers 0113 * 0114 * Watermark modifiers -- controls access to emergency reserves 0115 * ------------------------------------------------------------ 0116 * 0117 * %__GFP_HIGH indicates that the caller is high-priority and that granting 0118 * the request is necessary before the system can make forward progress. 0119 * For example, creating an IO context to clean pages. 0120 * 0121 * %__GFP_ATOMIC indicates that the caller cannot reclaim or sleep and is 0122 * high priority. Users are typically interrupt handlers. This may be 0123 * used in conjunction with %__GFP_HIGH 0124 * 0125 * %__GFP_MEMALLOC allows access to all memory. This should only be used when 0126 * the caller guarantees the allocation will allow more memory to be freed 0127 * very shortly e.g. process exiting or swapping. Users either should 0128 * be the MM or co-ordinating closely with the VM (e.g. swap over NFS). 0129 * Users of this flag have to be extremely careful to not deplete the reserve 0130 * completely and implement a throttling mechanism which controls the 0131 * consumption of the reserve based on the amount of freed memory. 0132 * Usage of a pre-allocated pool (e.g. mempool) should be always considered 0133 * before using this flag. 0134 * 0135 * %__GFP_NOMEMALLOC is used to explicitly forbid access to emergency reserves. 0136 * This takes precedence over the %__GFP_MEMALLOC flag if both are set. 0137 */ 0138 #define __GFP_ATOMIC ((__force gfp_t)___GFP_ATOMIC) 0139 #define __GFP_HIGH ((__force gfp_t)___GFP_HIGH) 0140 #define __GFP_MEMALLOC ((__force gfp_t)___GFP_MEMALLOC) 0141 #define __GFP_NOMEMALLOC ((__force gfp_t)___GFP_NOMEMALLOC) 0142 0143 /** 0144 * DOC: Reclaim modifiers 0145 * 0146 * Reclaim modifiers 0147 * ----------------- 0148 * Please note that all the following flags are only applicable to sleepable 0149 * allocations (e.g. %GFP_NOWAIT and %GFP_ATOMIC will ignore them). 0150 * 0151 * %__GFP_IO can start physical IO. 0152 * 0153 * %__GFP_FS can call down to the low-level FS. Clearing the flag avoids the 0154 * allocator recursing into the filesystem which might already be holding 0155 * locks. 0156 * 0157 * %__GFP_DIRECT_RECLAIM indicates that the caller may enter direct reclaim. 0158 * This flag can be cleared to avoid unnecessary delays when a fallback 0159 * option is available. 0160 * 0161 * %__GFP_KSWAPD_RECLAIM indicates that the caller wants to wake kswapd when 0162 * the low watermark is reached and have it reclaim pages until the high 0163 * watermark is reached. A caller may wish to clear this flag when fallback 0164 * options are available and the reclaim is likely to disrupt the system. The 0165 * canonical example is THP allocation where a fallback is cheap but 0166 * reclaim/compaction may cause indirect stalls. 0167 * 0168 * %__GFP_RECLAIM is shorthand to allow/forbid both direct and kswapd reclaim. 0169 * 0170 * The default allocator behavior depends on the request size. We have a concept 0171 * of so called costly allocations (with order > %PAGE_ALLOC_COSTLY_ORDER). 0172 * !costly allocations are too essential to fail so they are implicitly 0173 * non-failing by default (with some exceptions like OOM victims might fail so 0174 * the caller still has to check for failures) while costly requests try to be 0175 * not disruptive and back off even without invoking the OOM killer. 0176 * The following three modifiers might be used to override some of these 0177 * implicit rules 0178 * 0179 * %__GFP_NORETRY: The VM implementation will try only very lightweight 0180 * memory direct reclaim to get some memory under memory pressure (thus 0181 * it can sleep). It will avoid disruptive actions like OOM killer. The 0182 * caller must handle the failure which is quite likely to happen under 0183 * heavy memory pressure. The flag is suitable when failure can easily be 0184 * handled at small cost, such as reduced throughput 0185 * 0186 * %__GFP_RETRY_MAYFAIL: The VM implementation will retry memory reclaim 0187 * procedures that have previously failed if there is some indication 0188 * that progress has been made else where. It can wait for other 0189 * tasks to attempt high level approaches to freeing memory such as 0190 * compaction (which removes fragmentation) and page-out. 0191 * There is still a definite limit to the number of retries, but it is 0192 * a larger limit than with %__GFP_NORETRY. 0193 * Allocations with this flag may fail, but only when there is 0194 * genuinely little unused memory. While these allocations do not 0195 * directly trigger the OOM killer, their failure indicates that 0196 * the system is likely to need to use the OOM killer soon. The 0197 * caller must handle failure, but can reasonably do so by failing 0198 * a higher-level request, or completing it only in a much less 0199 * efficient manner. 0200 * If the allocation does fail, and the caller is in a position to 0201 * free some non-essential memory, doing so could benefit the system 0202 * as a whole. 0203 * 0204 * %__GFP_NOFAIL: The VM implementation _must_ retry infinitely: the caller 0205 * cannot handle allocation failures. The allocation could block 0206 * indefinitely but will never return with failure. Testing for 0207 * failure is pointless. 0208 * New users should be evaluated carefully (and the flag should be 0209 * used only when there is no reasonable failure policy) but it is 0210 * definitely preferable to use the flag rather than opencode endless 0211 * loop around allocator. 0212 * Using this flag for costly allocations is _highly_ discouraged. 0213 */ 0214 #define __GFP_IO ((__force gfp_t)___GFP_IO) 0215 #define __GFP_FS ((__force gfp_t)___GFP_FS) 0216 #define __GFP_DIRECT_RECLAIM ((__force gfp_t)___GFP_DIRECT_RECLAIM) /* Caller can reclaim */ 0217 #define __GFP_KSWAPD_RECLAIM ((__force gfp_t)___GFP_KSWAPD_RECLAIM) /* kswapd can wake */ 0218 #define __GFP_RECLAIM ((__force gfp_t)(___GFP_DIRECT_RECLAIM|___GFP_KSWAPD_RECLAIM)) 0219 #define __GFP_RETRY_MAYFAIL ((__force gfp_t)___GFP_RETRY_MAYFAIL) 0220 #define __GFP_NOFAIL ((__force gfp_t)___GFP_NOFAIL) 0221 #define __GFP_NORETRY ((__force gfp_t)___GFP_NORETRY) 0222 0223 /** 0224 * DOC: Action modifiers 0225 * 0226 * Action modifiers 0227 * ---------------- 0228 * 0229 * %__GFP_NOWARN suppresses allocation failure reports. 0230 * 0231 * %__GFP_COMP address compound page metadata. 0232 * 0233 * %__GFP_ZERO returns a zeroed page on success. 0234 * 0235 * %__GFP_ZEROTAGS zeroes memory tags at allocation time if the memory itself 0236 * is being zeroed (either via __GFP_ZERO or via init_on_alloc, provided that 0237 * __GFP_SKIP_ZERO is not set). This flag is intended for optimization: setting 0238 * memory tags at the same time as zeroing memory has minimal additional 0239 * performace impact. 0240 * 0241 * %__GFP_SKIP_KASAN_UNPOISON makes KASAN skip unpoisoning on page allocation. 0242 * Only effective in HW_TAGS mode. 0243 * 0244 * %__GFP_SKIP_KASAN_POISON makes KASAN skip poisoning on page deallocation. 0245 * Typically, used for userspace pages. Only effective in HW_TAGS mode. 0246 */ 0247 #define __GFP_NOWARN ((__force gfp_t)___GFP_NOWARN) 0248 #define __GFP_COMP ((__force gfp_t)___GFP_COMP) 0249 #define __GFP_ZERO ((__force gfp_t)___GFP_ZERO) 0250 #define __GFP_ZEROTAGS ((__force gfp_t)___GFP_ZEROTAGS) 0251 #define __GFP_SKIP_ZERO ((__force gfp_t)___GFP_SKIP_ZERO) 0252 #define __GFP_SKIP_KASAN_UNPOISON ((__force gfp_t)___GFP_SKIP_KASAN_UNPOISON) 0253 #define __GFP_SKIP_KASAN_POISON ((__force gfp_t)___GFP_SKIP_KASAN_POISON) 0254 0255 /* Disable lockdep for GFP context tracking */ 0256 #define __GFP_NOLOCKDEP ((__force gfp_t)___GFP_NOLOCKDEP) 0257 0258 /* Room for N __GFP_FOO bits */ 0259 #define __GFP_BITS_SHIFT (27 + IS_ENABLED(CONFIG_LOCKDEP)) 0260 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1)) 0261 0262 /** 0263 * DOC: Useful GFP flag combinations 0264 * 0265 * Useful GFP flag combinations 0266 * ---------------------------- 0267 * 0268 * Useful GFP flag combinations that are commonly used. It is recommended 0269 * that subsystems start with one of these combinations and then set/clear 0270 * %__GFP_FOO flags as necessary. 0271 * 0272 * %GFP_ATOMIC users can not sleep and need the allocation to succeed. A lower 0273 * watermark is applied to allow access to "atomic reserves". 0274 * The current implementation doesn't support NMI and few other strict 0275 * non-preemptive contexts (e.g. raw_spin_lock). The same applies to %GFP_NOWAIT. 0276 * 0277 * %GFP_KERNEL is typical for kernel-internal allocations. The caller requires 0278 * %ZONE_NORMAL or a lower zone for direct access but can direct reclaim. 0279 * 0280 * %GFP_KERNEL_ACCOUNT is the same as GFP_KERNEL, except the allocation is 0281 * accounted to kmemcg. 0282 * 0283 * %GFP_NOWAIT is for kernel allocations that should not stall for direct 0284 * reclaim, start physical IO or use any filesystem callback. 0285 * 0286 * %GFP_NOIO will use direct reclaim to discard clean pages or slab pages 0287 * that do not require the starting of any physical IO. 0288 * Please try to avoid using this flag directly and instead use 0289 * memalloc_noio_{save,restore} to mark the whole scope which cannot 0290 * perform any IO with a short explanation why. All allocation requests 0291 * will inherit GFP_NOIO implicitly. 0292 * 0293 * %GFP_NOFS will use direct reclaim but will not use any filesystem interfaces. 0294 * Please try to avoid using this flag directly and instead use 0295 * memalloc_nofs_{save,restore} to mark the whole scope which cannot/shouldn't 0296 * recurse into the FS layer with a short explanation why. All allocation 0297 * requests will inherit GFP_NOFS implicitly. 0298 * 0299 * %GFP_USER is for userspace allocations that also need to be directly 0300 * accessibly by the kernel or hardware. It is typically used by hardware 0301 * for buffers that are mapped to userspace (e.g. graphics) that hardware 0302 * still must DMA to. cpuset limits are enforced for these allocations. 0303 * 0304 * %GFP_DMA exists for historical reasons and should be avoided where possible. 0305 * The flags indicates that the caller requires that the lowest zone be 0306 * used (%ZONE_DMA or 16M on x86-64). Ideally, this would be removed but 0307 * it would require careful auditing as some users really require it and 0308 * others use the flag to avoid lowmem reserves in %ZONE_DMA and treat the 0309 * lowest zone as a type of emergency reserve. 0310 * 0311 * %GFP_DMA32 is similar to %GFP_DMA except that the caller requires a 32-bit 0312 * address. Note that kmalloc(..., GFP_DMA32) does not return DMA32 memory 0313 * because the DMA32 kmalloc cache array is not implemented. 0314 * (Reason: there is no such user in kernel). 0315 * 0316 * %GFP_HIGHUSER is for userspace allocations that may be mapped to userspace, 0317 * do not need to be directly accessible by the kernel but that cannot 0318 * move once in use. An example may be a hardware allocation that maps 0319 * data directly into userspace but has no addressing limitations. 0320 * 0321 * %GFP_HIGHUSER_MOVABLE is for userspace allocations that the kernel does not 0322 * need direct access to but can use kmap() when access is required. They 0323 * are expected to be movable via page reclaim or page migration. Typically, 0324 * pages on the LRU would also be allocated with %GFP_HIGHUSER_MOVABLE. 0325 * 0326 * %GFP_TRANSHUGE and %GFP_TRANSHUGE_LIGHT are used for THP allocations. They 0327 * are compound allocations that will generally fail quickly if memory is not 0328 * available and will not wake kswapd/kcompactd on failure. The _LIGHT 0329 * version does not attempt reclaim/compaction at all and is by default used 0330 * in page fault path, while the non-light is used by khugepaged. 0331 */ 0332 #define GFP_ATOMIC (__GFP_HIGH|__GFP_ATOMIC|__GFP_KSWAPD_RECLAIM) 0333 #define GFP_KERNEL (__GFP_RECLAIM | __GFP_IO | __GFP_FS) 0334 #define GFP_KERNEL_ACCOUNT (GFP_KERNEL | __GFP_ACCOUNT) 0335 #define GFP_NOWAIT (__GFP_KSWAPD_RECLAIM) 0336 #define GFP_NOIO (__GFP_RECLAIM) 0337 #define GFP_NOFS (__GFP_RECLAIM | __GFP_IO) 0338 #define GFP_USER (__GFP_RECLAIM | __GFP_IO | __GFP_FS | __GFP_HARDWALL) 0339 #define GFP_DMA __GFP_DMA 0340 #define GFP_DMA32 __GFP_DMA32 0341 #define GFP_HIGHUSER (GFP_USER | __GFP_HIGHMEM) 0342 #define GFP_HIGHUSER_MOVABLE (GFP_HIGHUSER | __GFP_MOVABLE | \ 0343 __GFP_SKIP_KASAN_POISON | __GFP_SKIP_KASAN_UNPOISON) 0344 #define GFP_TRANSHUGE_LIGHT ((GFP_HIGHUSER_MOVABLE | __GFP_COMP | \ 0345 __GFP_NOMEMALLOC | __GFP_NOWARN) & ~__GFP_RECLAIM) 0346 #define GFP_TRANSHUGE (GFP_TRANSHUGE_LIGHT | __GFP_DIRECT_RECLAIM) 0347 0348 #endif /* __LINUX_GFP_TYPES_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |