From: Dave Airlie <[email protected]> This just adds the obj cgroup pointer to the bo and tt structs, and sets it between them.
Signed-off-by: Dave Airlie <[email protected]> v2: add the put and a setter helper --- drivers/gpu/drm/ttm/ttm_bo.c | 2 ++ drivers/gpu/drm/ttm/ttm_tt.c | 1 + include/drm/ttm/ttm_bo.h | 20 ++++++++++++++++++++ include/drm/ttm/ttm_tt.h | 2 ++ 4 files changed, 25 insertions(+) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index 5d84af5e0d74..073a1840ed9d 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -45,6 +45,7 @@ #include <linux/atomic.h> #include <linux/cgroup_dmem.h> #include <linux/dma-resv.h> +#include <linux/memcontrol.h> #include "ttm_module.h" #include "ttm_bo_internal.h" @@ -314,6 +315,7 @@ static void ttm_bo_release(struct kref *kref) dma_resv_unlock(bo->base.resv); } + obj_cgroup_put(bo->objcg); atomic_dec(&ttm_glob.bo_count); bo->destroy(bo); } diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c index 8f38de3b2f1c..0c54d5e2bfdd 100644 --- a/drivers/gpu/drm/ttm/ttm_tt.c +++ b/drivers/gpu/drm/ttm/ttm_tt.c @@ -162,6 +162,7 @@ static void ttm_tt_init_fields(struct ttm_tt *ttm, ttm->caching = caching; ttm->restore = NULL; ttm->backup = NULL; + ttm->objcg = bo->objcg; } int ttm_tt_init(struct ttm_tt *ttm, struct ttm_buffer_object *bo, diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h index 60676f2c1077..154805627065 100644 --- a/include/drm/ttm/ttm_bo.h +++ b/include/drm/ttm/ttm_bo.h @@ -135,6 +135,12 @@ struct ttm_buffer_object { * reservation lock. */ struct sg_table *sg; + + /** + * @objcg: object cgroup to charge this to if it ends up using system memory. + * NULL means don't charge. + */ + struct obj_cgroup *objcg; }; #define TTM_BO_MAP_IOMEM_MASK 0x80 @@ -334,6 +340,20 @@ ttm_bo_move_to_lru_tail_unlocked(struct ttm_buffer_object *bo) spin_unlock(&bo->bdev->lru_lock); } +/** + * ttm_bo_set_cgroup - assign a cgroup to a buffer object. + * @bo: The bo to set the cgroup for + * @objcg: the cgroup to set. + * + * This transfers the cgroup reference to the bo. From this + * point on the cgroup reference is owned by the ttm bo. + */ +static inline void ttm_bo_set_cgroup(struct ttm_buffer_object *bo, + struct obj_cgroup *objcg) +{ + bo->objcg = objcg; +} + static inline void ttm_bo_assign_mem(struct ttm_buffer_object *bo, struct ttm_resource *new_mem) { diff --git a/include/drm/ttm/ttm_tt.h b/include/drm/ttm/ttm_tt.h index 15d4019685f6..c13fea4c2915 100644 --- a/include/drm/ttm/ttm_tt.h +++ b/include/drm/ttm/ttm_tt.h @@ -126,6 +126,8 @@ struct ttm_tt { enum ttm_caching caching; /** @restore: Partial restoration from backup state. TTM private */ struct ttm_pool_tt_restore *restore; + /** @objcg: Object cgroup for this TT allocation */ + struct obj_cgroup *objcg; }; /** -- 2.51.0
