include/linux/list_lru.h
Source file repositories/reference/linux-study-clean/include/linux/list_lru.h
File Facts
- System
- Linux kernel
- Corpus path
include/linux/list_lru.h- Extension
.h- Size
- 12509 bytes
- Lines
- 360
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/list.hlinux/nodemask.hlinux/shrinker.hlinux/xarray.h
Detected Declarations
struct mem_cgroupstruct list_lru_onestruct list_lru_memcgstruct list_lru_nodestruct list_lruenum lru_statusfunction list_lru_init_memcg_keyfunction folio_memcg_list_lru_allocfunction list_lru_shrink_countfunction list_lru_countfunction list_lru_shrink_walkfunction list_lru_shrink_walk_irqfunction list_lru_walkfunction for_each_node_state
Annotated Snippet
struct list_lru_one {
struct list_head list;
/* may become negative during memcg reparenting */
long nr_items;
/* protects all fields above */
spinlock_t lock;
};
struct list_lru_memcg {
struct rcu_head rcu;
/* array of per cgroup per node lists, indexed by node id */
struct list_lru_one node[];
};
struct list_lru_node {
/* global list, used for the root cgroup in cgroup aware lrus */
struct list_lru_one lru;
atomic_long_t nr_items;
} ____cacheline_aligned_in_smp;
struct list_lru {
struct list_lru_node *node;
#ifdef CONFIG_MEMCG
struct list_head list;
int shrinker_id;
bool memcg_aware;
struct xarray xa;
#endif
#ifdef CONFIG_LOCKDEP
struct lock_class_key *key;
#endif
};
void list_lru_destroy(struct list_lru *lru);
int __list_lru_init(struct list_lru *lru, bool memcg_aware,
struct shrinker *shrinker);
#define list_lru_init(lru) \
__list_lru_init((lru), false, NULL)
#define list_lru_init_memcg(lru, shrinker) \
__list_lru_init((lru), true, shrinker)
static inline int list_lru_init_memcg_key(struct list_lru *lru, struct shrinker *shrinker,
struct lock_class_key *key)
{
#ifdef CONFIG_LOCKDEP
lru->key = key;
#endif
return list_lru_init_memcg(lru, shrinker);
}
int memcg_list_lru_alloc(struct mem_cgroup *memcg, struct list_lru *lru,
gfp_t gfp);
#ifdef CONFIG_MEMCG
/**
* folio_memcg_list_lru_alloc - allocate list_lru heads for shrinkable folio
* @folio: the newly allocated & charged folio
* @lru: the list_lru this might be queued on
* @gfp: gfp mask
*
* Allocate list_lru heads (per-memcg, per-node) needed to queue this
* particular folio down the line.
*
* This does memcg_list_lru_alloc(), but on the memcg that @folio is
* associated with. Handles folio_memcg() access rules in the fast
* path (list_lru heads allocated) and the allocation slowpath.
*
* Returns 0 on success, a negative error value otherwise.
*/
int folio_memcg_list_lru_alloc(struct folio *folio, struct list_lru *lru,
gfp_t gfp);
#else
static inline int folio_memcg_list_lru_alloc(struct folio *folio,
struct list_lru *lru, gfp_t gfp)
{
return 0;
}
#endif
void memcg_reparent_list_lrus(struct mem_cgroup *memcg, struct mem_cgroup *parent);
/**
* list_lru_lock: lock the sublist for the given node and memcg
* @lru: the lru pointer
* @nid: the node id of the sublist to lock.
* @memcg: pointer to the cgroup of the sublist to lock. On return,
* updated to the cgroup whose sublist was actually locked,
* which may be an ancestor if the original memcg was dying.
*
Annotation
- Immediate include surface: `linux/list.h`, `linux/nodemask.h`, `linux/shrinker.h`, `linux/xarray.h`.
- Detected declarations: `struct mem_cgroup`, `struct list_lru_one`, `struct list_lru_memcg`, `struct list_lru_node`, `struct list_lru`, `enum lru_status`, `function list_lru_init_memcg_key`, `function folio_memcg_list_lru_alloc`, `function list_lru_shrink_count`, `function list_lru_count`.
- 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.