kernel/cgroup/dmem.c
Source file repositories/reference/linux-study-clean/kernel/cgroup/dmem.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/cgroup/dmem.c- Extension
.c- Size
- 21650 bytes
- Lines
- 887
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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/cgroup.hlinux/cgroup_dmem.hlinux/list.hlinux/mutex.hlinux/page_counter.hlinux/parser.hlinux/refcount.hlinux/rculist.hlinux/slab.h
Detected Declarations
struct dmem_cgroup_regionstruct dmemcg_statestruct dmem_cgroup_pool_statefunction css_to_dmemcsfunction dmemcg_pool_getfunction dmemcg_pool_trygetfunction dmemcg_pool_putfunction dmemcg_pool_free_rcufunction free_cg_poolfunction set_resource_minfunction set_resource_lowfunction set_resource_maxfunction get_resource_lowfunction get_resource_minfunction get_resource_maxfunction get_resource_currentfunction reset_all_resource_limitsfunction dmemcs_offlinefunction dmemcs_freefunction dmemcs_allocfunction find_cg_pool_lockedfunction dmem_cgroup_calculate_protectionfunction css_for_each_descendant_prefunction list_for_each_entry_rcufunction dmem_cgroup_state_evict_valuablefunction alloc_pool_singlefunction get_cg_pool_lockedfunction dmemcg_free_rcufunction dmemcg_free_regionfunction dmem_cgroup_unregister_regionfunction list_for_each_entry_safefunction dmem_cgroup_register_regionfunction dmem_cgroup_pool_state_putfunction get_cg_pool_unlockedfunction dmem_cgroup_unchargefunction dmem_cgroup_try_chargefunction dmem_cgroup_region_capacity_showfunction dmemcg_parse_limitfunction dmemcg_limit_writefunction dmemcg_limit_showfunction dmem_cgroup_region_current_showfunction dmem_cgroup_region_min_showfunction dmem_cgroup_region_min_writefunction dmem_cgroup_region_low_showfunction dmem_cgroup_region_low_writefunction dmem_cgroup_region_max_showfunction dmem_cgroup_region_max_writeexport dmem_cgroup_state_evict_valuable
Annotated Snippet
struct dmem_cgroup_region {
/**
* @ref: References keeping the region alive.
* Keeps the region reference alive after a succesful RCU lookup.
*/
struct kref ref;
/** @rcu: RCU head for freeing */
struct rcu_head rcu;
/**
* @region_node: Linked into &dmem_cgroup_regions list.
* Protected by RCU and global spinlock.
*/
struct list_head region_node;
/**
* @pools: List of pools linked to this region.
* Protected by global spinlock only
*/
struct list_head pools;
/** @size: Size of region, in bytes */
u64 size;
/** @name: Name describing the node, set by dmem_cgroup_register_region */
char *name;
/**
* @unregistered: Whether the region is unregistered by its caller.
* No new pools should be added to the region afterwards.
*/
bool unregistered;
};
struct dmemcg_state {
struct cgroup_subsys_state css;
struct list_head pools;
};
struct dmem_cgroup_pool_state {
struct dmem_cgroup_region *region;
struct dmemcg_state *cs;
/* css node, RCU protected against region teardown */
struct list_head css_node;
/* dev node, no RCU protection required */
struct list_head region_node;
struct rcu_head rcu;
struct page_counter cnt;
struct dmem_cgroup_pool_state *parent;
refcount_t ref;
bool inited;
};
/*
* 3 operations require locking protection:
* - Registering and unregistering region to/from list, requires global lock.
* - Adding a dmem_cgroup_pool_state to a CSS, removing when CSS is freed.
* - Adding a dmem_cgroup_pool_state to a region list.
*
* Since for the most common operations RCU provides enough protection, I
* do not think more granular locking makes sense. Most protection is offered
* by RCU and the lockless operating page_counter.
*/
static DEFINE_SPINLOCK(dmemcg_lock);
static LIST_HEAD(dmem_cgroup_regions);
static void dmemcg_free_region(struct kref *ref);
static void dmemcg_pool_free_rcu(struct rcu_head *rcu);
static inline struct dmemcg_state *
css_to_dmemcs(struct cgroup_subsys_state *css)
{
return container_of(css, struct dmemcg_state, css);
}
static inline struct dmemcg_state *get_current_dmemcs(void)
{
return css_to_dmemcs(task_get_css(current, dmem_cgrp_id));
}
static struct dmemcg_state *parent_dmemcs(struct dmemcg_state *cg)
{
return cg->css.parent ? css_to_dmemcs(cg->css.parent) : NULL;
Annotation
- Immediate include surface: `linux/cgroup.h`, `linux/cgroup_dmem.h`, `linux/list.h`, `linux/mutex.h`, `linux/page_counter.h`, `linux/parser.h`, `linux/refcount.h`, `linux/rculist.h`.
- Detected declarations: `struct dmem_cgroup_region`, `struct dmemcg_state`, `struct dmem_cgroup_pool_state`, `function css_to_dmemcs`, `function dmemcg_pool_get`, `function dmemcg_pool_tryget`, `function dmemcg_pool_put`, `function dmemcg_pool_free_rcu`, `function free_cg_pool`, `function set_resource_min`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration 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.