Linux Media Controller development
 help / color / mirror / Atom feed
* [PATCH] dma-buf: system_heap: account for system heap allocation in memcg
@ 2025-12-11 19:31 Eric Chanudet
  2025-12-11 23:25 ` T.J. Mercier
  0 siblings, 1 reply; 14+ messages in thread
From: Eric Chanudet @ 2025-12-11 19:31 UTC (permalink / raw)
  To: Sumit Semwal, Benjamin Gaignard, Brian Starkey, John Stultz,
	T.J. Mercier, Christian Koenig, Maxime Ripard
  Cc: linux-media, dri-devel, linaro-mm-sig, linux-kernel,
	Eric Chanudet

The system dma-buf heap lets userspace allocate buffers from the page
allocator. However, these allocations are not accounted for in memcg,
allowing processes to escape limits that may be configured.

Pass the __GFP_ACCOUNT for our allocations to account them into memcg.

Userspace components using the system heap can be constrained with, e.g:
  systemd-run --user --scope -p MemoryMax=10M ...

Signed-off-by: Eric Chanudet <echanude@redhat.com>
---
 drivers/dma-buf/heaps/system_heap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c
index 4c782fe33fd4..c91fcdff4b77 100644
--- a/drivers/dma-buf/heaps/system_heap.c
+++ b/drivers/dma-buf/heaps/system_heap.c
@@ -38,10 +38,10 @@ struct dma_heap_attachment {
 	bool mapped;
 };
 
-#define LOW_ORDER_GFP (GFP_HIGHUSER | __GFP_ZERO)
+#define LOW_ORDER_GFP (GFP_HIGHUSER | __GFP_ZERO | __GFP_ACCOUNT)
 #define HIGH_ORDER_GFP  (((GFP_HIGHUSER | __GFP_ZERO | __GFP_NOWARN \
 				| __GFP_NORETRY) & ~__GFP_RECLAIM) \
-				| __GFP_COMP)
+				| __GFP_COMP | __GFP_ACCOUNT)
 static gfp_t order_flags[] = {HIGH_ORDER_GFP, HIGH_ORDER_GFP, LOW_ORDER_GFP};
 /*
  * The selection of the orders used for allocation (1MB, 64K, 4K) is designed
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2026-01-07 12:20 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-11 19:31 [PATCH] dma-buf: system_heap: account for system heap allocation in memcg Eric Chanudet
2025-12-11 23:25 ` T.J. Mercier
2025-12-15 10:51   ` Maxime Ripard
2025-12-15 13:30     ` Christian König
2025-12-15 13:59       ` Maxime Ripard
2025-12-15 14:53         ` Christian König
2025-12-16  2:08           ` T.J. Mercier
2025-12-19 10:25           ` Maxime Ripard
2025-12-19 13:50             ` Christian König
2025-12-19 15:58               ` Maxime Ripard
2026-01-07 12:19                 ` Christian König
2025-12-16  2:06     ` T.J. Mercier
2025-12-19 10:19       ` Maxime Ripard
2025-12-23 19:20         ` T.J. Mercier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox