@@ -11,10 +11,11 @@
* refining of this idea.
*/
#include <linux/fs.h>
#include <linux/slab.h>
+#include <linux/cgroup_dmem.h>
#include <linux/dma-buf.h>
#include <linux/dma-fence.h>
#include <linux/dma-fence-unwrap.h>
#include <linux/anon_inodes.h>
#include <linux/export.h>
@@ -97,10 +98,16 @@ static void dma_buf_release(struct dentry *dentry)
* * dmabuf->cb_in/out.active are non-0 despite no pending fence callback
*/
BUG_ON(dmabuf->cb_in.active || dmabuf->cb_out.active);
dma_buf_stats_teardown(dmabuf);
+
+#ifdef CONFIG_CGROUP_DMEM
+ if (dmabuf->cgroup_pool)
+ dmem_cgroup_uncharge(dmabuf->cgroup_pool, dmabuf->size);
+#endif
+
dmabuf->ops->release(dmabuf);
if (dmabuf->resv == (struct dma_resv *)&dmabuf[1])
dma_resv_fini(dmabuf->resv);
@@ -437,10 +437,15 @@ struct dma_buf {
struct dma_fence_cb cb;
wait_queue_head_t *poll;
__poll_t active;
} cb_in, cb_out;
+
+#ifdef CONFIG_CGROUP_DMEM
+ struct dmem_cgroup_pool_state *cgroup_pool;
+#endif
+
#ifdef CONFIG_DMABUF_SYSFS_STATS
/**
* @sysfs_entry:
*
* For exposing information about this buffer in sysfs. See also
In order to clean thing up when dma-heaps will allocate and register buffers in the dev cgroup, let's uncharge a released buffer for any (optional) cgroup controller. Signed-off-by: Maxime Ripard <mripard@kernel.org> --- drivers/dma-buf/dma-buf.c | 7 +++++++ include/linux/dma-buf.h | 5 +++++ 2 files changed, 12 insertions(+)