![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0 */ 0002 #ifndef _LINUX_SHRINKER_H 0003 #define _LINUX_SHRINKER_H 0004 0005 /* 0006 * This struct is used to pass information from page reclaim to the shrinkers. 0007 * We consolidate the values for easier extension later. 0008 * 0009 * The 'gfpmask' refers to the allocation we are currently trying to 0010 * fulfil. 0011 */ 0012 struct shrink_control { 0013 gfp_t gfp_mask; 0014 0015 /* current node being shrunk (for NUMA aware shrinkers) */ 0016 int nid; 0017 0018 /* 0019 * How many objects scan_objects should scan and try to reclaim. 0020 * This is reset before every call, so it is safe for callees 0021 * to modify. 0022 */ 0023 unsigned long nr_to_scan; 0024 0025 /* 0026 * How many objects did scan_objects process? 0027 * This defaults to nr_to_scan before every call, but the callee 0028 * should track its actual progress. 0029 */ 0030 unsigned long nr_scanned; 0031 0032 /* current memcg being shrunk (for memcg aware shrinkers) */ 0033 struct mem_cgroup *memcg; 0034 }; 0035 0036 #define SHRINK_STOP (~0UL) 0037 #define SHRINK_EMPTY (~0UL - 1) 0038 /* 0039 * A callback you can register to apply pressure to ageable caches. 0040 * 0041 * @count_objects should return the number of freeable items in the cache. If 0042 * there are no objects to free, it should return SHRINK_EMPTY, while 0 is 0043 * returned in cases of the number of freeable items cannot be determined 0044 * or shrinker should skip this cache for this time (e.g., their number 0045 * is below shrinkable limit). No deadlock checks should be done during the 0046 * count callback - the shrinker relies on aggregating scan counts that couldn't 0047 * be executed due to potential deadlocks to be run at a later call when the 0048 * deadlock condition is no longer pending. 0049 * 0050 * @scan_objects will only be called if @count_objects returned a non-zero 0051 * value for the number of freeable objects. The callout should scan the cache 0052 * and attempt to free items from the cache. It should then return the number 0053 * of objects freed during the scan, or SHRINK_STOP if progress cannot be made 0054 * due to potential deadlocks. If SHRINK_STOP is returned, then no further 0055 * attempts to call the @scan_objects will be made from the current reclaim 0056 * context. 0057 * 0058 * @flags determine the shrinker abilities, like numa awareness 0059 */ 0060 struct shrinker { 0061 unsigned long (*count_objects)(struct shrinker *, 0062 struct shrink_control *sc); 0063 unsigned long (*scan_objects)(struct shrinker *, 0064 struct shrink_control *sc); 0065 0066 long batch; /* reclaim batch size, 0 = default */ 0067 int seeks; /* seeks to recreate an obj */ 0068 unsigned flags; 0069 0070 /* These are for internal use */ 0071 struct list_head list; 0072 #ifdef CONFIG_MEMCG 0073 /* ID in shrinker_idr */ 0074 int id; 0075 #endif 0076 #ifdef CONFIG_SHRINKER_DEBUG 0077 int debugfs_id; 0078 const char *name; 0079 struct dentry *debugfs_entry; 0080 #endif 0081 /* objs pending delete, per node */ 0082 atomic_long_t *nr_deferred; 0083 }; 0084 #define DEFAULT_SEEKS 2 /* A good number if you don't know better. */ 0085 0086 /* Flags */ 0087 #define SHRINKER_REGISTERED (1 << 0) 0088 #define SHRINKER_NUMA_AWARE (1 << 1) 0089 #define SHRINKER_MEMCG_AWARE (1 << 2) 0090 /* 0091 * It just makes sense when the shrinker is also MEMCG_AWARE for now, 0092 * non-MEMCG_AWARE shrinker should not have this flag set. 0093 */ 0094 #define SHRINKER_NONSLAB (1 << 3) 0095 0096 extern int __printf(2, 3) prealloc_shrinker(struct shrinker *shrinker, 0097 const char *fmt, ...); 0098 extern void register_shrinker_prepared(struct shrinker *shrinker); 0099 extern int __printf(2, 3) register_shrinker(struct shrinker *shrinker, 0100 const char *fmt, ...); 0101 extern void unregister_shrinker(struct shrinker *shrinker); 0102 extern void free_prealloced_shrinker(struct shrinker *shrinker); 0103 extern void synchronize_shrinkers(void); 0104 0105 #ifdef CONFIG_SHRINKER_DEBUG 0106 extern int shrinker_debugfs_add(struct shrinker *shrinker); 0107 extern void shrinker_debugfs_remove(struct shrinker *shrinker); 0108 extern int __printf(2, 3) shrinker_debugfs_rename(struct shrinker *shrinker, 0109 const char *fmt, ...); 0110 #else /* CONFIG_SHRINKER_DEBUG */ 0111 static inline int shrinker_debugfs_add(struct shrinker *shrinker) 0112 { 0113 return 0; 0114 } 0115 static inline void shrinker_debugfs_remove(struct shrinker *shrinker) 0116 { 0117 } 0118 static inline __printf(2, 3) 0119 int shrinker_debugfs_rename(struct shrinker *shrinker, const char *fmt, ...) 0120 { 0121 return 0; 0122 } 0123 #endif /* CONFIG_SHRINKER_DEBUG */ 0124 #endif /* _LINUX_SHRINKER_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |