Hello Eric.

On Tue, May 19, 2026 at 11:59:02AM -0400, Eric Chanudet <[email protected]> 
wrote:
> Add a root-only cgroupfs file "dmem.memcg" that lets an administrator
> configure whether allocations in a dmem region should also be charged to
> the memory controller.

This kinda makes sense as it is not unlike io.cost.* device
configurators.

Just for my better understanding -- will there be a space for userspace
to switch this? (No charged dmem allocations happen before responsible
userspace runs, so that the attribute remains unlocked.)

(I'm rather indifferent about the actual double charging/non-charging
matter.)


> 
> To handle inheritance, dmem adds a depends_on the memory controller,
> unless MEMCG isn't configured in.
> 
> Double-charging is disabled by default. Once a charge is attempted, the
> setting is locked to prevent inconsistent accounting by a small 4-state
> machine (off, on, locked off, locked on).
> 
> The memcg to charge is derived from the pool's cgroup, since the pool
> holds a reference to the dmem cgroup state that keeps the cgroup alive
> until it gets uncharged.
> 
> Signed-off-by: Eric Chanudet <[email protected]>
> ---
>  Documentation/admin-guide/cgroup-v2.rst |  23 +++++
>  kernel/cgroup/dmem.c                    | 158 
> +++++++++++++++++++++++++++++++-
>  2 files changed, 178 insertions(+), 3 deletions(-)
> 
> diff --git a/Documentation/admin-guide/cgroup-v2.rst 
> b/Documentation/admin-guide/cgroup-v2.rst
> index 
> 6efd0095ed995b1550317662bc1b56c7a7f3db23..1d2fa55ddf0faa17baa916a8914d3033e8e42359
>  100644
> --- a/Documentation/admin-guide/cgroup-v2.rst
> +++ b/Documentation/admin-guide/cgroup-v2.rst
> @@ -2828,6 +2828,29 @@ DMEM Interface Files
>         drm/0000:03:00.0/vram0 12550144
>         drm/0000:03:00.0/stolen 8650752
>  
> +  dmem.memcg
> +     A readwrite nested-keyed file that exists only on the root
> +     cgroup.

Strictly speaking this is not nested-keyed but flat keyed [1],
which leads me to realization that this is the first instance of a boolean.
All in call, such a composition comes to my mind (latter is RO):

        drm/0000:03:00.0/vram0 enable=0|1 locked=0|1




> +static ssize_t dmem_cgroup_memcg_write(struct kernfs_open_file *of, char 
> *buf,
> +                                    size_t nbytes, loff_t off)
> +{
> +     while (buf) {
> +             struct dmem_cgroup_region *region;
> +             char *options, *name;
> +             bool flag;
> +
> +             options = buf;
> +             buf = strchr(buf, '\n');
> +             if (buf)
> +                     *buf++ = '\0';

I recall there was a discussion about accepting only a single device per
write(2) (at the same time I see this idiom is still present in other
dmem.* files, so this is nothing to change in _this_ patch).

Thanks,
Michal

[1] https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html#format

Attachment: signature.asc
Description: PGP signature

Reply via email to