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.

Dependency Surface

Detected Declarations

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

Implementation Notes