kernel/cgroup/rdma.c

Source file repositories/reference/linux-study-clean/kernel/cgroup/rdma.c

File Facts

System
Linux kernel
Corpus path
kernel/cgroup/rdma.c
Extension
.c
Size
20760 bytes
Lines
790
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct rdmacg_resource {
	int max;
	int usage;
	int peak;
};

/*
 * resource pool object which represents per cgroup, per device
 * resources. There are multiple instances of this object per cgroup,
 * therefore it cannot be embedded within rdma_cgroup structure. It
 * is maintained as list.
 */
struct rdmacg_resource_pool {
	struct rdmacg_device	*device;
	struct rdmacg_resource	resources[RDMACG_RESOURCE_MAX];

	struct list_head	cg_node;
	struct list_head	dev_node;

	/* count active user tasks of this pool */
	u64			usage_sum;
	/* total number counts which are set to max */
	int			num_max_cnt;

	/* per-resource event counters */
	u64			events_max[RDMACG_RESOURCE_MAX];
	u64			events_alloc_fail[RDMACG_RESOURCE_MAX];
	u64			events_local_max[RDMACG_RESOURCE_MAX];
	u64			events_local_alloc_fail[RDMACG_RESOURCE_MAX];
};

static struct rdma_cgroup *css_rdmacg(struct cgroup_subsys_state *css)
{
	return container_of(css, struct rdma_cgroup, css);
}

static struct rdma_cgroup *parent_rdmacg(struct rdma_cgroup *cg)
{
	return css_rdmacg(cg->css.parent);
}

static inline struct rdma_cgroup *get_current_rdmacg(void)
{
	return css_rdmacg(task_get_css(current, rdma_cgrp_id));
}

static void set_resource_limit(struct rdmacg_resource_pool *rpool,
			       int index, int new_max)
{
	if (new_max == S32_MAX) {
		if (rpool->resources[index].max != S32_MAX)
			rpool->num_max_cnt++;
	} else {
		if (rpool->resources[index].max == S32_MAX)
			rpool->num_max_cnt--;
	}
	rpool->resources[index].max = new_max;
}

static void set_all_resource_max_limit(struct rdmacg_resource_pool *rpool)
{
	int i;

	for (i = 0; i < RDMACG_RESOURCE_MAX; i++)
		set_resource_limit(rpool, i, S32_MAX);
}

static void free_cg_rpool_locked(struct rdmacg_resource_pool *rpool)
{
	lockdep_assert_held(&rdmacg_mutex);

	list_del(&rpool->cg_node);
	list_del(&rpool->dev_node);
	kfree(rpool);
}

static bool rpool_has_persistent_state(struct rdmacg_resource_pool *rpool)
{
	int i;

	/*
	 * Keep the rpool alive if any peak value is non-zero,
	 * so that rdma.peak persists as a historical high-
	 * watermark even after all resources are freed.
	 */
	for (i = 0; i < RDMACG_RESOURCE_MAX; i++) {
		if (rpool->resources[i].peak ||
		    rpool->events_max[i] ||
		    rpool->events_local_max[i] ||
		    rpool->events_alloc_fail[i] ||

Annotation

Implementation Notes