Cgroup Kernel APIs

Device Memory Cgroup API (dmemcg)

booldmem_cgroup_state_evict_valuable(structdmem_cgroup_pool_state*limit_pool,structdmem_cgroup_pool_state*test_pool,boolignore_low,bool*ret_hit_low)

Check if we should evict from test_pool

Parameters

structdmem_cgroup_pool_state*limit_pool

The pool for which we hit limits

structdmem_cgroup_pool_state*test_pool

The pool for which to test

boolignore_low

Whether we have to respect low watermarks.

bool*ret_hit_low

Pointer to whether it makes sense to consider low watermark.

Description

This function returns true if we can evict fromtest_pool, false if not.When returning false andignore_low is false,ret_hit_low maybe set to true to indicate this function can be retried withignore_lowset to true.

Return

bool

voiddmem_cgroup_unregister_region(structdmem_cgroup_region*region)

Unregister a previously registered region.

Parameters

structdmem_cgroup_region*region

The region to unregister.

Description

This function undoes dmem_cgroup_register_region.

structdmem_cgroup_region*dmem_cgroup_register_region(u64size,constchar*fmt,...)

Register a regions for dev cgroup.

Parameters

u64size

Size of region to register, in bytes.

constchar*fmt

Region parameters to register

...

variable arguments

Description

This function registers a node in the dmem cgroup with thename given. After calling this function, the region can beused for allocations.

Return

NULL or astructon success, PTR_ERR on failure.

voiddmem_cgroup_pool_state_put(structdmem_cgroup_pool_state*pool)

Drop a reference to a dmem_cgroup_pool_state

Parameters

structdmem_cgroup_pool_state*pool

dmem_cgroup_pool_state

Description

Called to drop a reference to the limiting pool returned bydmem_cgroup_try_charge().

voiddmem_cgroup_uncharge(structdmem_cgroup_pool_state*pool,u64size)

Uncharge a pool.

Parameters

structdmem_cgroup_pool_state*pool

Pool to uncharge.

u64size

Size to uncharge.

Description

Undoes the effects of dmem_cgroup_try_charge.Must be called with the returned pool as argument,and sameindex andsize.

intdmem_cgroup_try_charge(structdmem_cgroup_region*region,u64size,structdmem_cgroup_pool_state**ret_pool,structdmem_cgroup_pool_state**ret_limit_pool)

Try charging a new allocation to a region.

Parameters

structdmem_cgroup_region*region

dmem region to charge

u64size

Size (in bytes) to charge.

structdmem_cgroup_pool_state**ret_pool

On succesfull allocation, the pool that is charged.

structdmem_cgroup_pool_state**ret_limit_pool

On a failed allocation, the limiting pool.

Description

This function charges theregion region for a size ofsize bytes.

If the function succeeds,ret_pool is set, which must be passed todmem_cgroup_uncharge() when undoing the allocation.

When this function fails with -EAGAIN andret_limit_pool is non-null, itwill be set to the pool for which the limit is hit. This can be used foreviction as argument todmem_cgroup_evict_valuable(). This reference must be freedwithdmem_cgroup_pool_state_put().

Return

0 on success, -EAGAIN on hitting a limit, or a negative errno on failure.