From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 71821C7EE2A for ; Mon, 30 Jun 2025 04:52:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D5D8310E382; Mon, 30 Jun 2025 04:52:05 +0000 (UTC) Received: from us-smtp-delivery-44.mimecast.com (us-smtp-delivery-44.mimecast.com [205.139.111.44]) by gabe.freedesktop.org (Postfix) with ESMTPS id C34B710E382 for ; Mon, 30 Jun 2025 04:52:04 +0000 (UTC) Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-512-2-xU7Sf7PEObPb9a9K-3-A-1; Mon, 30 Jun 2025 00:51:58 -0400 X-MC-Unique: 2-xU7Sf7PEObPb9a9K-3-A-1 X-Mimecast-MFC-AGG-ID: 2-xU7Sf7PEObPb9a9K-3-A_1751259116 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C1DEF1956077; Mon, 30 Jun 2025 04:51:56 +0000 (UTC) Received: from dreadlord.redhat.com (unknown [10.67.24.96]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 936571956095; Mon, 30 Jun 2025 04:51:51 +0000 (UTC) From: Dave Airlie To: dri-devel@lists.freedesktop.org, linux-mm@kvack.org, Johannes Weiner , Christian Koenig Cc: Dave Chinner , Kairui Song , Dave Airlie Subject: [PATCH 14/17] ttm: hook up memcg placement flags. Date: Mon, 30 Jun 2025 14:49:33 +1000 Message-ID: <20250630045005.1337339-15-airlied@gmail.com> In-Reply-To: <20250630045005.1337339-1-airlied@gmail.com> References: <20250630045005.1337339-1-airlied@gmail.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: DnKcUSKfkG8GJACXF6995xVWQpTJB7PjmMU6bcGOh0c_1751259116 X-Mimecast-Originator: gmail.com Content-Transfer-Encoding: quoted-printable content-type: text/plain; charset=WINDOWS-1252; x-default=true X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Dave Airlie This adds a placement flag that requests that any bo with this placement flag set gets accounted for memcg if it's a system memory allocation. Signed-off-by: Dave Airlie --- drivers/gpu/drm/ttm/ttm_bo.c | 2 +- drivers/gpu/drm/ttm/ttm_bo_util.c | 6 +++--- drivers/gpu/drm/ttm/ttm_bo_vm.c | 2 +- include/drm/ttm/ttm_placement.h | 3 +++ 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index af04bb8e2c2a..273757974b9f 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -142,7 +142,7 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_obj= ect *bo, =09=09=09goto out_err; =20 =09=09if (mem->mem_type !=3D TTM_PL_SYSTEM) { -=09=09=09ret =3D ttm_bo_populate(bo, false, ctx); +=09=09=09ret =3D ttm_bo_populate(bo, mem->placement & TTM_PL_FLAG_MEMCG, c= tx); =09=09=09if (ret) =09=09=09=09goto out_err; =09=09} diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo= _util.c index 764d1cf1ecbe..b5521d1bd517 100644 --- a/drivers/gpu/drm/ttm/ttm_bo_util.c +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c @@ -167,7 +167,7 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo, =09src_man =3D ttm_manager_type(bdev, src_mem->mem_type); =09if (ttm && ((ttm->page_flags & TTM_TT_FLAG_SWAPPED) || =09=09 dst_man->use_tt)) { -=09=09ret =3D ttm_bo_populate(bo, false, ctx); +=09=09ret =3D ttm_bo_populate(bo, dst_mem->placement & TTM_PL_FLAG_MEMCG, = ctx); =09=09if (ret) =09=09=09return ret; =09} @@ -354,7 +354,7 @@ static int ttm_bo_kmap_ttm(struct ttm_buffer_object *bo= , =20 =09BUG_ON(!ttm); =20 -=09ret =3D ttm_bo_populate(bo, false, &ctx); +=09ret =3D ttm_bo_populate(bo, mem->placement & TTM_PL_FLAG_MEMCG, &ctx); =09if (ret) =09=09return ret; =20 @@ -511,7 +511,7 @@ int ttm_bo_vmap(struct ttm_buffer_object *bo, struct io= sys_map *map) =09=09pgprot_t prot; =09=09void *vaddr; =20 -=09=09ret =3D ttm_bo_populate(bo, false, &ctx); +=09=09ret =3D ttm_bo_populate(bo, mem->placement & TTM_PL_FLAG_MEMCG, &ctx= ); =09=09if (ret) =09=09=09return ret; =20 diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_v= m.c index c5ad447debe3..dddc904f8727 100644 --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c @@ -226,7 +226,7 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vm= f, =20 =09=09ttm =3D bo->ttm; =09=09err =3D ttm_bo_populate(bo, -=09=09=09=09 false, +=09=09=09=09 bo->resource->placement & TTM_PL_FLAG_MEMCG, =09=09=09=09 &ctx); =09=09if (err) { =09=09=09if (err =3D=3D -EINTR || err =3D=3D -ERESTARTSYS || diff --git a/include/drm/ttm/ttm_placement.h b/include/drm/ttm/ttm_placemen= t.h index b510a4812609..4e9f07d70483 100644 --- a/include/drm/ttm/ttm_placement.h +++ b/include/drm/ttm/ttm_placement.h @@ -70,6 +70,9 @@ /* Placement is only used during eviction */ #define TTM_PL_FLAG_FALLBACK=09(1 << 4) =20 +/* Placement should account mem cgroup */ +#define TTM_PL_FLAG_MEMCG=09(1 << 5) + /** * struct ttm_place * --=20 2.49.0