v2 2026-10-22

dma-buf 的 memcg 记账与转移 · v2

dma-buf 增加 memcg 计费,通过 dma_buf 上 MEMCG_DMABUF 计数并支持按 pidfd 或 cgroupfd 选择目标 cgroup。

原始补丁链接

子 Patch(8)

1/8
memcg: Add MEMCG_DMABUF accounting infrastructure
From: “T.J. Mercier” tjmercier@google.com Introduce a MEMCG_DMABUF stat counter and helpers for charging, and uncharging dma-buf memory against a memory cgroup: The charge is tracked on struct dma
2/8
dma-heap: charge dma-buf memory via explicit memcg
On embedded platforms a central process often allocates dma-buf memory on behalf of client applications. Without a way to attribute the charge to the requesting client’s cgroup, the cost lands on the
3/8
security: dma-buf: Add dma_buf_charge_task LSM hook
DMA_HEAP_IOCTL_ALLOC accepts a charge_fd field that, when set, causes the allocation to be charged to an arbitrary process’s cgroup rather than the caller’s. Without an access-control point, any proc
4/8
security: dma-buf: Add dma_buf_charge_cgroup LSM hook
Similar to how security_dma_buf_charge_task adds an access-control point for pidfd for the charge_fd of a DMA_HEAP_IOCTL_ALLOC ioctl, we need a new access-control point for the case where charge_fd re
5/8
selinux: Restrict cross-cgroup dma-buf charging
The security_dma_buf_charge_task() hook allows security modules to control which processes may charge dma-buf allocations to another process’s cgroup via the charge_fd field of DMA_HEAP_IOCTL_ALLOC. W
6/8
selinux: Restrict dma-buf direct cgroup charging
The security_dma_buf_charge_cgroup() hook allows security modules to control which processes may charge dma-buf to an arbitrary cgroup via cgroupfd passed in charge_fd. Without a policy implementation
7/8
dma-buf: transfer memcg charges via DMA_BUF_IOCTL_XFER_CHARGE
dma-heap already supports charging a specific cgroup at allocation time via charge_fd in DMA_HEAP_IOCTL_ALLOC. However, dma-bufs can originate from any exporter (DRM, V4L2, etc.), and the allocator ma
8/8
selftests/dmabuf-heaps: Add dma-buf memcg accounting tests
[selftests/dmabuf-heaps: Add dma-buf memcg accounting tests] Add tests for the new charge_fd field in struct dma_heap_allocation_data. When the charge_fd feature is absent (unpatched kernel), the pro