[PATCH v5 1/8] memcg: Add MEMCG_DMABUF accounting infrastructure

sashiko-bot at kernel.org sashiko-bot at kernel.org
Wed Nov 18 08:40:58 UTC 2026


> From: "T.J. Mercier" <tjmercier at google.com>
> 
> Introduce a MEMCG_DMABUF stat counter and helpers for charging,
> cancelling, and uncharging dma-buf memory against a memory cgroup.
> 
> The charge is tracked on struct dma_buf via a new objcg pointer.
> The object cgroup reference is stored into (or cleared from)
> dmabuf->objcg by the helpers, removing the need for callers to manage
> those details. The release path in dma_buf_release() is reduced to a
> single mem_cgroup_uncharge_dmabuf() call.
> 
> obj_cgroup_reserve_dmabuf() takes nr_pages as unsigned long and
> rejects values above INT_MAX. This differs from the rest of memcg
> API. Specifically, dma-buf sizes can be userspace-controlled
> and long-sized (size_t), while memcg charge and stat updates are
> int-sized. Charges that pass the reservation are therefore safe
> to handle as unsigned int in the export, transfer, and uncharge
> paths.
> 
> Rather than charging at the page level via __GFP_ACCOUNT, which
> would require exporters to expose their backing pages for
> cross-cgroup transfer via new dma_buf_ops, charges are tracked
> externally on struct dma_buf through a single accounting path.
> 
> The next patch wires up the charging policy in the dma-heap ioctl.
> 
> Signed-off-by: T.J. Mercier <tjmercier at google.com>
> Signed-off-by: Albert Esteve <aesteve at redhat.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117-v2_20230123_tjmercier_google_com-v5-0-1ce975f2a9ad@redhat.com?part=1




More information about the Linux-security-module-archive mailing list