include/linux/shrinker.h
Source file repositories/reference/linux-study-clean/include/linux/shrinker.h
File Facts
- System
- Linux kernel
- Corpus path
include/linux/shrinker.h- Extension
.h- Size
- 4987 bytes
- Lines
- 161
- Domain
- Core OS
- Bucket
- Core Kernel Interface
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/atomic.hlinux/types.hlinux/refcount.hlinux/completion.h
Detected Declarations
struct shrinker_info_unitstruct shrinker_infostruct shrink_controlstruct shrinkerfunction shrinker_try_getfunction shrinker_putfunction __printf
Annotated Snippet
struct shrinker_info_unit {
atomic_long_t nr_deferred[SHRINKER_UNIT_BITS];
DECLARE_BITMAP(map, SHRINKER_UNIT_BITS);
};
struct shrinker_info {
struct rcu_head rcu;
int map_nr_max;
struct shrinker_info_unit *unit[];
};
/*
* This struct is used to pass information from page reclaim to the shrinkers.
* We consolidate the values for easier extension later.
*
* The 'gfpmask' refers to the allocation we are currently trying to
* fulfil.
*/
struct shrink_control {
gfp_t gfp_mask;
/* current node being shrunk (for NUMA aware shrinkers) */
int nid;
/*
* How many objects scan_objects should scan and try to reclaim.
* This is reset before every call, so it is safe for callees
* to modify.
*/
unsigned long nr_to_scan;
/*
* How many objects did scan_objects process?
* This defaults to nr_to_scan before every call, but the callee
* should track its actual progress.
*/
unsigned long nr_scanned;
/* current memcg being shrunk (for memcg aware shrinkers) */
struct mem_cgroup *memcg;
};
#define SHRINK_STOP (~0UL)
#define SHRINK_EMPTY (~0UL - 1)
/*
* A callback you can register to apply pressure to ageable caches.
*
* @count_objects should return the number of freeable items in the cache. If
* there are no objects to free, it should return SHRINK_EMPTY, while 0 is
* returned in cases of the number of freeable items cannot be determined
* or shrinker should skip this cache for this time (e.g., their number
* is below shrinkable limit). No deadlock checks should be done during the
* count callback - the shrinker relies on aggregating scan counts that couldn't
* be executed due to potential deadlocks to be run at a later call when the
* deadlock condition is no longer pending.
*
* @scan_objects will only be called if @count_objects returned a non-zero
* value for the number of freeable objects. The callout should scan the cache
* and attempt to free items from the cache. It should then return the number
* of objects freed during the scan, or SHRINK_STOP if progress cannot be made
* due to potential deadlocks. If SHRINK_STOP is returned, then no further
* attempts to call the @scan_objects will be made from the current reclaim
* context.
*
* @flags determine the shrinker abilities, like numa awareness
*/
struct shrinker {
unsigned long (*count_objects)(struct shrinker *,
struct shrink_control *sc);
unsigned long (*scan_objects)(struct shrinker *,
struct shrink_control *sc);
long batch; /* reclaim batch size, 0 = default */
int seeks; /* seeks to recreate an obj */
unsigned flags;
/*
* The reference count of this shrinker. Registered shrinker have an
* initial refcount of 1, then the lookup operations are now allowed
* to use it via shrinker_try_get(). Later in the unregistration step,
* the initial refcount will be discarded, and will free the shrinker
* asynchronously via RCU after its refcount reaches 0.
*/
refcount_t refcount;
struct completion done; /* use to wait for refcount to reach 0 */
struct rcu_head rcu;
void *private_data;
/* These are for internal use */
Annotation
- Immediate include surface: `linux/atomic.h`, `linux/types.h`, `linux/refcount.h`, `linux/completion.h`.
- Detected declarations: `struct shrinker_info_unit`, `struct shrinker_info`, `struct shrink_control`, `struct shrinker`, `function shrinker_try_get`, `function shrinker_put`, `function __printf`.
- Atlas domain: Core OS / Core Kernel Interface.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.