~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/shrinker.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /include/linux/shrinker.h (Architecture alpha) and /include/linux/shrinker.h (Architecture ppc)


  1 /* SPDX-License-Identifier: GPL-2.0 */              1 /* SPDX-License-Identifier: GPL-2.0 */
  2 #ifndef _LINUX_SHRINKER_H                           2 #ifndef _LINUX_SHRINKER_H
  3 #define _LINUX_SHRINKER_H                           3 #define _LINUX_SHRINKER_H
  4                                                     4 
  5 #include <linux/atomic.h>                           5 #include <linux/atomic.h>
  6 #include <linux/types.h>                            6 #include <linux/types.h>
  7 #include <linux/refcount.h>                         7 #include <linux/refcount.h>
  8 #include <linux/completion.h>                       8 #include <linux/completion.h>
  9                                                     9 
 10 #define SHRINKER_UNIT_BITS      BITS_PER_LONG      10 #define SHRINKER_UNIT_BITS      BITS_PER_LONG
 11                                                    11 
 12 /*                                                 12 /*
 13  * Bitmap and deferred work of shrinker::id co     13  * Bitmap and deferred work of shrinker::id corresponding to memcg-aware
 14  * shrinkers, which have elements charged to t     14  * shrinkers, which have elements charged to the memcg.
 15  */                                                15  */
 16 struct shrinker_info_unit {                        16 struct shrinker_info_unit {
 17         atomic_long_t nr_deferred[SHRINKER_UNI     17         atomic_long_t nr_deferred[SHRINKER_UNIT_BITS];
 18         DECLARE_BITMAP(map, SHRINKER_UNIT_BITS     18         DECLARE_BITMAP(map, SHRINKER_UNIT_BITS);
 19 };                                                 19 };
 20                                                    20 
 21 struct shrinker_info {                             21 struct shrinker_info {
 22         struct rcu_head rcu;                       22         struct rcu_head rcu;
 23         int map_nr_max;                            23         int map_nr_max;
 24         struct shrinker_info_unit *unit[];         24         struct shrinker_info_unit *unit[];
 25 };                                                 25 };
 26                                                    26 
 27 /*                                                 27 /*
 28  * This struct is used to pass information fro     28  * This struct is used to pass information from page reclaim to the shrinkers.
 29  * We consolidate the values for easier extens     29  * We consolidate the values for easier extension later.
 30  *                                                 30  *
 31  * The 'gfpmask' refers to the allocation we a     31  * The 'gfpmask' refers to the allocation we are currently trying to
 32  * fulfil.                                         32  * fulfil.
 33  */                                                33  */
 34 struct shrink_control {                            34 struct shrink_control {
 35         gfp_t gfp_mask;                            35         gfp_t gfp_mask;
 36                                                    36 
 37         /* current node being shrunk (for NUMA     37         /* current node being shrunk (for NUMA aware shrinkers) */
 38         int nid;                                   38         int nid;
 39                                                    39 
 40         /*                                         40         /*
 41          * How many objects scan_objects shoul     41          * How many objects scan_objects should scan and try to reclaim.
 42          * This is reset before every call, so     42          * This is reset before every call, so it is safe for callees
 43          * to modify.                              43          * to modify.
 44          */                                        44          */
 45         unsigned long nr_to_scan;                  45         unsigned long nr_to_scan;
 46                                                    46 
 47         /*                                         47         /*
 48          * How many objects did scan_objects p     48          * How many objects did scan_objects process?
 49          * This defaults to nr_to_scan before      49          * This defaults to nr_to_scan before every call, but the callee
 50          * should track its actual progress.       50          * should track its actual progress.
 51          */                                        51          */
 52         unsigned long nr_scanned;                  52         unsigned long nr_scanned;
 53                                                    53 
 54         /* current memcg being shrunk (for mem     54         /* current memcg being shrunk (for memcg aware shrinkers) */
 55         struct mem_cgroup *memcg;                  55         struct mem_cgroup *memcg;
 56 };                                                 56 };
 57                                                    57 
 58 #define SHRINK_STOP (~0UL)                         58 #define SHRINK_STOP (~0UL)
 59 #define SHRINK_EMPTY (~0UL - 1)                    59 #define SHRINK_EMPTY (~0UL - 1)
 60 /*                                                 60 /*
 61  * A callback you can register to apply pressu     61  * A callback you can register to apply pressure to ageable caches.
 62  *                                                 62  *
 63  * @count_objects should return the number of      63  * @count_objects should return the number of freeable items in the cache. If
 64  * there are no objects to free, it should ret     64  * there are no objects to free, it should return SHRINK_EMPTY, while 0 is
 65  * returned in cases of the number of freeable     65  * returned in cases of the number of freeable items cannot be determined
 66  * or shrinker should skip this cache for this     66  * or shrinker should skip this cache for this time (e.g., their number
 67  * is below shrinkable limit). No deadlock che     67  * is below shrinkable limit). No deadlock checks should be done during the
 68  * count callback - the shrinker relies on agg     68  * count callback - the shrinker relies on aggregating scan counts that couldn't
 69  * be executed due to potential deadlocks to b     69  * be executed due to potential deadlocks to be run at a later call when the
 70  * deadlock condition is no longer pending.        70  * deadlock condition is no longer pending.
 71  *                                                 71  *
 72  * @scan_objects will only be called if @count     72  * @scan_objects will only be called if @count_objects returned a non-zero
 73  * value for the number of freeable objects. T     73  * value for the number of freeable objects. The callout should scan the cache
 74  * and attempt to free items from the cache. I     74  * and attempt to free items from the cache. It should then return the number
 75  * of objects freed during the scan, or SHRINK     75  * of objects freed during the scan, or SHRINK_STOP if progress cannot be made
 76  * due to potential deadlocks. If SHRINK_STOP      76  * due to potential deadlocks. If SHRINK_STOP is returned, then no further
 77  * attempts to call the @scan_objects will be      77  * attempts to call the @scan_objects will be made from the current reclaim
 78  * context.                                        78  * context.
 79  *                                                 79  *
 80  * @flags determine the shrinker abilities, li     80  * @flags determine the shrinker abilities, like numa awareness
 81  */                                                81  */
 82 struct shrinker {                                  82 struct shrinker {
 83         unsigned long (*count_objects)(struct      83         unsigned long (*count_objects)(struct shrinker *,
 84                                        struct      84                                        struct shrink_control *sc);
 85         unsigned long (*scan_objects)(struct s     85         unsigned long (*scan_objects)(struct shrinker *,
 86                                       struct s     86                                       struct shrink_control *sc);
 87                                                    87 
 88         long batch;     /* reclaim batch size,     88         long batch;     /* reclaim batch size, 0 = default */
 89         int seeks;      /* seeks to recreate a     89         int seeks;      /* seeks to recreate an obj */
 90         unsigned flags;                            90         unsigned flags;
 91                                                    91 
 92         /*                                         92         /*
 93          * The reference count of this shrinke     93          * The reference count of this shrinker. Registered shrinker have an
 94          * initial refcount of 1, then the loo     94          * initial refcount of 1, then the lookup operations are now allowed
 95          * to use it via shrinker_try_get(). L     95          * to use it via shrinker_try_get(). Later in the unregistration step,
 96          * the initial refcount will be discar     96          * the initial refcount will be discarded, and will free the shrinker
 97          * asynchronously via RCU after its re     97          * asynchronously via RCU after its refcount reaches 0.
 98          */                                        98          */
 99         refcount_t refcount;                       99         refcount_t refcount;
100         struct completion done; /* use to wait    100         struct completion done; /* use to wait for refcount to reach 0 */
101         struct rcu_head rcu;                      101         struct rcu_head rcu;
102                                                   102 
103         void *private_data;                       103         void *private_data;
104                                                   104 
105         /* These are for internal use */          105         /* These are for internal use */
106         struct list_head list;                    106         struct list_head list;
107 #ifdef CONFIG_MEMCG                               107 #ifdef CONFIG_MEMCG
108         /* ID in shrinker_idr */                  108         /* ID in shrinker_idr */
109         int id;                                   109         int id;
110 #endif                                            110 #endif
111 #ifdef CONFIG_SHRINKER_DEBUG                      111 #ifdef CONFIG_SHRINKER_DEBUG
112         int debugfs_id;                           112         int debugfs_id;
113         const char *name;                         113         const char *name;
114         struct dentry *debugfs_entry;             114         struct dentry *debugfs_entry;
115 #endif                                            115 #endif
116         /* objs pending delete, per node */       116         /* objs pending delete, per node */
117         atomic_long_t *nr_deferred;               117         atomic_long_t *nr_deferred;
118 };                                                118 };
119 #define DEFAULT_SEEKS 2 /* A good number if yo    119 #define DEFAULT_SEEKS 2 /* A good number if you don't know better. */
120                                                   120 
121 /* Internal flags */                              121 /* Internal flags */
122 #define SHRINKER_REGISTERED     BIT(0)            122 #define SHRINKER_REGISTERED     BIT(0)
123 #define SHRINKER_ALLOCATED      BIT(1)            123 #define SHRINKER_ALLOCATED      BIT(1)
124                                                   124 
125 /* Flags for users to use */                      125 /* Flags for users to use */
126 #define SHRINKER_NUMA_AWARE     BIT(2)            126 #define SHRINKER_NUMA_AWARE     BIT(2)
127 #define SHRINKER_MEMCG_AWARE    BIT(3)            127 #define SHRINKER_MEMCG_AWARE    BIT(3)
128 /*                                                128 /*
129  * It just makes sense when the shrinker is al    129  * It just makes sense when the shrinker is also MEMCG_AWARE for now,
130  * non-MEMCG_AWARE shrinker should not have th    130  * non-MEMCG_AWARE shrinker should not have this flag set.
131  */                                               131  */
132 #define SHRINKER_NONSLAB        BIT(4)            132 #define SHRINKER_NONSLAB        BIT(4)
133                                                   133 
134 __printf(2, 3)                                    134 __printf(2, 3)
135 struct shrinker *shrinker_alloc(unsigned int f    135 struct shrinker *shrinker_alloc(unsigned int flags, const char *fmt, ...);
136 void shrinker_register(struct shrinker *shrink    136 void shrinker_register(struct shrinker *shrinker);
137 void shrinker_free(struct shrinker *shrinker);    137 void shrinker_free(struct shrinker *shrinker);
138                                                   138 
139 static inline bool shrinker_try_get(struct shr    139 static inline bool shrinker_try_get(struct shrinker *shrinker)
140 {                                                 140 {
141         return refcount_inc_not_zero(&shrinker    141         return refcount_inc_not_zero(&shrinker->refcount);
142 }                                                 142 }
143                                                   143 
144 static inline void shrinker_put(struct shrinke    144 static inline void shrinker_put(struct shrinker *shrinker)
145 {                                                 145 {
146         if (refcount_dec_and_test(&shrinker->r    146         if (refcount_dec_and_test(&shrinker->refcount))
147                 complete(&shrinker->done);        147                 complete(&shrinker->done);
148 }                                                 148 }
149                                                   149 
150 #ifdef CONFIG_SHRINKER_DEBUG                      150 #ifdef CONFIG_SHRINKER_DEBUG
151 extern int __printf(2, 3) shrinker_debugfs_ren    151 extern int __printf(2, 3) shrinker_debugfs_rename(struct shrinker *shrinker,
152                                                   152                                                   const char *fmt, ...);
153 #else /* CONFIG_SHRINKER_DEBUG */                 153 #else /* CONFIG_SHRINKER_DEBUG */
154 static inline __printf(2, 3)                      154 static inline __printf(2, 3)
155 int shrinker_debugfs_rename(struct shrinker *s    155 int shrinker_debugfs_rename(struct shrinker *shrinker, const char *fmt, ...)
156 {                                                 156 {
157         return 0;                                 157         return 0;
158 }                                                 158 }
159 #endif /* CONFIG_SHRINKER_DEBUG */                159 #endif /* CONFIG_SHRINKER_DEBUG */
160 #endif /* _LINUX_SHRINKER_H */                    160 #endif /* _LINUX_SHRINKER_H */
161                                                   161 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php