[PATCH v3 1/2] dma-buf: heaps: add parameter to account allocations using cgroup

Eric Chanudet posted 2 patches 3 weeks, 2 days ago
[PATCH v3 1/2] dma-buf: heaps: add parameter to account allocations using cgroup
Posted by Eric Chanudet 3 weeks, 2 days ago
Add a parameter to enable dma-buf heaps allocation accounting using
cgroup for heaps that implement it. It is disabled by default as doing
so incurs caveats based on how memcg currently accounts for shared
buffers.

Signed-off-by: Eric Chanudet <echanude@redhat.com>
---
 drivers/dma-buf/dma-heap.c | 5 +++++
 include/linux/dma-heap.h   | 2 ++
 2 files changed, 7 insertions(+)

diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c
index 8ab49924f8b71a0272dc89a609539a429feaf6c8..d230ddeb24e0fa1f2d51cb5d2868ec54fc8376a8 100644
--- a/drivers/dma-buf/dma-heap.c
+++ b/drivers/dma-buf/dma-heap.c
@@ -49,6 +49,11 @@ static dev_t dma_heap_devt;
 static struct class *dma_heap_class;
 static DEFINE_XARRAY_ALLOC(dma_heap_minors);
 
+bool __read_mostly mem_accounting;
+module_param(mem_accounting, bool, 0444);
+MODULE_PARM_DESC(mem_accounting,
+		 "Enable cgroup-based memory accounting for dma-buf heap allocations (default=false).");
+
 static int dma_heap_buffer_alloc(struct dma_heap *heap, size_t len,
 				 u32 fd_flags,
 				 u64 heap_flags)
diff --git a/include/linux/dma-heap.h b/include/linux/dma-heap.h
index 27d15f60950a2093e592be1b961c02e672826e58..648328a64b27eaf25c8b18809a02c6410cbbffde 100644
--- a/include/linux/dma-heap.h
+++ b/include/linux/dma-heap.h
@@ -46,4 +46,6 @@ const char *dma_heap_get_name(struct dma_heap *heap);
 
 struct dma_heap *dma_heap_add(const struct dma_heap_export_info *exp_info);
 
+extern bool mem_accounting;
+
 #endif /* _DMA_HEAPS_H */

-- 
2.52.0
Re: [PATCH v3 1/2] dma-buf: heaps: add parameter to account allocations using cgroup
Posted by T.J. Mercier 3 weeks, 2 days ago
On Fri, Jan 16, 2026 at 12:06 PM Eric Chanudet <echanude@redhat.com> wrote:
>
> Add a parameter to enable dma-buf heaps allocation accounting using
> cgroup for heaps that implement it. It is disabled by default as doing
> so incurs caveats based on how memcg currently accounts for shared
> buffers.
>
> Signed-off-by: Eric Chanudet <echanude@redhat.com>

Reviewed-by: T.J. Mercier <tjmercier@google.com>
Re: [PATCH v3 1/2] dma-buf: heaps: add parameter to account allocations using cgroup
Posted by Christian König 3 weeks ago
On 1/16/26 23:36, T.J. Mercier wrote:
> On Fri, Jan 16, 2026 at 12:06 PM Eric Chanudet <echanude@redhat.com> wrote:
>>
>> Add a parameter to enable dma-buf heaps allocation accounting using
>> cgroup for heaps that implement it. It is disabled by default as doing
>> so incurs caveats based on how memcg currently accounts for shared
>> buffers.
>>
>> Signed-off-by: Eric Chanudet <echanude@redhat.com>
> 
> Reviewed-by: T.J. Mercier <tjmercier@google.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

Should I push that into drm-misc-next or does anybody else has commit access?

Regards,
Christian.
Re: [PATCH v3 1/2] dma-buf: heaps: add parameter to account allocations using cgroup
Posted by Sumit Semwal 3 weeks ago
Hi Christian,

On Mon, 19 Jan 2026 at 15:19, Christian König <christian.koenig@amd.com> wrote:
>
> On 1/16/26 23:36, T.J. Mercier wrote:
> > On Fri, Jan 16, 2026 at 12:06 PM Eric Chanudet <echanude@redhat.com> wrote:
> >>
> >> Add a parameter to enable dma-buf heaps allocation accounting using
> >> cgroup for heaps that implement it. It is disabled by default as doing
> >> so incurs caveats based on how memcg currently accounts for shared
> >> buffers.
> >>
> >> Signed-off-by: Eric Chanudet <echanude@redhat.com>
> >
> > Reviewed-by: T.J. Mercier <tjmercier@google.com>
>
> Reviewed-by: Christian König <christian.koenig@amd.com>
LGTM as well.
>
> Should I push that into drm-misc-next or does anybody else has commit access?
>
I will push it to drm-misc-next tonight. Thanks for your review!
> Regards,
> Christian.

Best,
Sumit.