From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18EFC606A32D for ; Fri, 4 Dec 2026 13:23:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=pixelcluster.dev header.i=@pixelcluster.dev header.a=rsa-sha256 header.s=ovhmo-selector-1 header.b=uLLUjATd Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D350C10E34A; Fri, 4 Dec 2026 13:23:44 +0000 (UTC) Received: from smtpout9.mo538.mail-out.ovh.net (smtpout9.mo538.mail-out.ovh.net [51.210.91.38]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6B8AF10EA96 for ; Fri, 4 Dec 2026 13:23:38 +0000 (UTC) Received: from director1.derp.mail-out.ovh.net (director1.derp.mail-out.ovh.net [79.137.60.221]) by mo538.mail-out.ovh.net (Postfix) with ESMTPS id 4jgsTm4y0Pz61p7; Fri, 4 Dec 2026 13:17:00 +0000 (UTC) Received: from director1.derp.mail-out.ovh.net (director1.derp.mail-out.ovh.net. [127.0.0.1]) by director1.derp.mail-out.ovh.net (inspect_sender_mail_agent) with SMTP for ; Fri, 4 Dec 2026 13:17:00 +0000 (UTC) Received: from mta6.priv.ovhmail-u1.ea.mail.ovh.net (unknown [10.110.164.72]) by director1.derp.mail-out.ovh.net (Postfix) with ESMTPS id 4jgsTm3bqRz6Ly1; Fri, 4 Dec 2026 13:17:00 +0000 (UTC) Received: from pixelcluster.dev (unknown [10.1.6.0]) (Authenticated sender: nat@pixelcluster.dev) by mta6.priv.ovhmail-u1.ea.mail.ovh.net (Postfix) with ESMTPSA id 625678E177E; Fri, 4 Dec 2026 13:16:59 +0000 (UTC) Authentication-Results: garm.ovh; auth=pass (GARM-112S006a8e6f40e-8d03-422b-b86a-44da128dbd7b, C72A8C269379148255D259EF506AD3C5C1B61040) smtp.auth=nat@pixelcluster.dev X-OVh-ClientIp: 141.95.41.139 From: Natalie Vock To: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Matthew Brost Cc: Carlos Santa , Ryan Neph , Arun Pravin , Matthew Auld , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , linux-kernel@vger.kernel.org, Thomas =?UTF-8?B?SGVsbHN0csO2bQ==?= , Niranjana Vishwanathapura Subject: Re: [PATCH v6 03/35] drm/ttm: Record sub-optimal page order allocations in ttm_tt Date: Fri, 04 Dec 2026 14:16:58 +0100 Message-ID: In-Reply-To: <20261203202352.4153159-4-matthew.brost@intel.com> References: <20261203202352.4153159-1-matthew.brost@intel.com> <20261203202352.4153159-4-matthew.brost@intel.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" x-ovh-tracer-id: 13640277372568953148 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: dmFkZTETSJhkvPh3bnEfCmYQnBVDpdqHuLuYhNvn4Or+h/E1kg8Cw7JbmS+2s7CFogAWAIPqKFx+qQAsxKO4sOXz/zbbGPp59DVCKHPKJWh56UzEkErRA2eaiQycZ5R4wV577IVvkh9vj+zifTALsfWSWLiyUkDph1z6+hdVqHyyTGxwrChXMTn4at2QI7pk2rIWm7RTYkE26ujGVX/47H/tPIxAHHuvGJ0g16BzBfnS5TCCAGZVxb78cF9dAPl06dajRlLMZ+6useSck5CgrGtFqoNQrRq4GLOqe+VWifnO7jUzMPtnKxEiQ7/khkJh3Kv424rGJGZxFbeFbi4K5fKA5peTUUE5+ME8KfBU/9wh4L9tMrJGKxPexmmUEV66nT1yuihSU7M6n8NC22894oIui29wkCDZklwuL5AY4dtOYXeWwLbQKXJYGZ6MJeMQIHsQgpiDE4OIoE578BVBJWV9qWaHCCgguD0o9KfLpYf/vsu3N7XgAM+wZwxgIepq8BKE9QkjRm5ufPZf7vuZu6mcMp88MSDTItp3P8w1ntlr0eVmcVmnQZku1wTK3RetPfEw58H70J7krFFrgMwczL7Yk2EWWoKYVEEUnurQte0PUqIMnbX7r6oXKH3xB/T+birsKZPLLJtESJtaay7tLNgnGqRdhP+iTDERn3pEth9kbU1iqQ DKIM-Signature: a=rsa-sha256; bh=tzbtQHWdSgp8LA3U6zFxnEn0TpQ7QUGuSvjIEaW+5X8=; c=relaxed/relaxed; d=pixelcluster.dev; h=From; s=ovhmo-selector-1; t=1796390220; v=1; b=uLLUjATdmE2EYolqlXN8BzUKzX3CdDNFHop02uVJHdtbnACvlOpZ9zi1gcP8r8YYX9nH/Tw3 d4TBnYA2o9eGQ/Z6iCxuU3WM6B42jdnUTU0DU8DVRZfcAx3vCDhOXX5qEXqiGO6h8SrDJrIkSzt 5WRPkGXjVOtX3OA5rtEL1ZW+9V3wqbzyc3otwvU8Z2degwtPl2e79fLPVJZ/h/jQgyd25O0EAAj jNdyyWmPpt3yXZjfWgDARn0iSrvb5jsAR2+4ayguz0fdaBKJUBPPwlTV2Pviwv1BP/WpwneIfI3 fwFQtGDFbAdvllnOyjBOHviowQABAO0EvJqblRTlOtrMw== X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Intel-xe" X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Thursday, 3 December 2026 21:23 Matthew Brost wrote: > When __ttm_pool_alloc() fails to allocate a chunk at the device's > beneficial order and falls back to a smaller order, the object ends up > backed by a sub-optimal set of pages. Nothing currently records this, so > a driver has no way to know an object would benefit from being re-backed > with beneficial-order pages later. >=20 > Add TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED to struct ttm_tt page_flags, > cleared at the start of every fresh allocation (in both ttm_pool_alloc() > and ttm_pool_restore_and_alloc()). Set it in __ttm_pool_alloc() when an > allocation at exactly the beneficial order fails before dropping to a > lower order. >=20 > Drivers can use this hint to queue the buffer object for later > defragmentation. >=20 > Cc: Carlos Santa > Cc: Ryan Neph > Cc: Natalie Vock > Cc: Arun Pravin > Cc: Matthew Auld > Cc: Maarten Lankhorst > Cc: Maxime Ripard > Cc: Thomas Zimmermann > Cc: David Airlie > Cc: Simona Vetter > Cc: dri-devel@lists.freedesktop.org > Cc: linux-kernel@vger.kernel.org > Cc: Thomas Hellstr=C3=B6m > Signed-off-by: Matthew Brost > Reviewed-by: Niranjana Vishwanathapura Reviewed-by: Natalie Vock > --- > drivers/gpu/drm/ttm/ttm_pool.c | 13 +++++++++++++ > include/drm/ttm/ttm_tt.h | 24 +++++++++++++++++++++++- > 2 files changed, 36 insertions(+), 1 deletion(-) >=20 > diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_poo= l.c > index c6fbcdba9bdb..e06bd3cf6855 100644 > --- a/drivers/gpu/drm/ttm/ttm_pool.c > +++ b/drivers/gpu/drm/ttm/ttm_pool.c > @@ -812,6 +812,7 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, st= ruct ttm_tt *tt, > struct ttm_pool_alloc_state *alloc, > struct ttm_pool_tt_restore *restore) > { > + const unsigned int beneficial_order =3D ttm_pool_beneficial_order(pool); > enum ttm_caching page_caching; > gfp_t gfp_flags =3D GFP_USER; > pgoff_t caching_divide; > @@ -862,6 +863,16 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, s= truct ttm_tt *tt, > /* If that fails, lower the order if possible and retry. */ > if (!p) { > if (order) { > + /* > + * Failing to allocate at the device's beneficial > + * order means we are about to back this object > + * with a sub-optimal (smaller order) set of > + * pages. Record it so the driver can later try to > + * defragment the object back to beneficial order. > + */ > + if (beneficial_order && order =3D=3D beneficial_order) > + tt->page_flags |=3D > + TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED; > --order; > page_caching =3D tt->caching; > allow_pools =3D true; > @@ -926,6 +937,7 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_= tt *tt, > if (WARN_ON(ttm_tt_is_backed_up(tt))) > return -EINVAL; > =20 > + tt->page_flags &=3D ~TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED; > ttm_pool_alloc_state_init(tt, &alloc); > =20 > return __ttm_pool_alloc(pool, tt, ctx, &alloc, NULL); > @@ -958,6 +970,7 @@ int ttm_pool_restore_and_alloc(struct ttm_pool *pool,= struct ttm_tt *tt, > if (!restore) { > gfp_t gfp =3D GFP_KERNEL | __GFP_NOWARN; > =20 > + tt->page_flags &=3D ~TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED; > ttm_pool_alloc_state_init(tt, &alloc); > if (ctx->gfp_retry_mayfail) > gfp |=3D __GFP_RETRY_MAYFAIL; > diff --git a/include/drm/ttm/ttm_tt.h b/include/drm/ttm/ttm_tt.h > index 406437ad674b..ce7533677d77 100644 > --- a/include/drm/ttm/ttm_tt.h > +++ b/include/drm/ttm/ttm_tt.h > @@ -90,6 +90,14 @@ struct ttm_tt { > * TTM_TT_FLAG_BACKED_UP: TTM internal only. This is set if the > * struct ttm_tt has been (possibly partially) backed up. > * > + * TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED: Set by the TTM pool allocator > + * when at least one chunk that could have been allocated at the pool's > + * beneficial order had to fall back to a smaller order. This indicates > + * that a sub-optimal set of pages was chosen for this object, and can > + * be used by drivers to queue the buffer object for later > + * defragmentation. Drivers should access this via the > + * ttm_tt_is_beneficial_order_failed() helper. > + * > * TTM_TT_FLAG_PRIV_POPULATED: TTM internal only. DO NOT USE. This is > * set by TTM after ttm_tt_populate() has successfully returned, and is > * then unset when TTM calls ttm_tt_unpopulate(). > @@ -101,8 +109,9 @@ struct ttm_tt { > #define TTM_TT_FLAG_EXTERNAL_MAPPABLE BIT(3) > #define TTM_TT_FLAG_DECRYPTED BIT(4) > #define TTM_TT_FLAG_BACKED_UP BIT(5) > +#define TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED BIT(6) > =20 > -#define TTM_TT_FLAG_PRIV_POPULATED BIT(6) > +#define TTM_TT_FLAG_PRIV_POPULATED BIT(7) > uint32_t page_flags; > /** @num_pages: Number of pages in the page array. */ > uint32_t num_pages; > @@ -179,6 +188,19 @@ static inline void ttm_tt_clear_backed_up(struct ttm= _tt *tt) > tt->page_flags &=3D ~TTM_TT_FLAG_BACKED_UP; > } > =20 > +/** > + * ttm_tt_is_beneficial_order_failed() - Whether the tt is backed at a > + * sub-optimal page order > + * @tt: The struct ttm_tt. > + * > + * Return: true if the pool allocator had to fall back below the pool's > + * beneficial order when backing this tt, false otherwise. > + */ > +static inline bool ttm_tt_is_beneficial_order_failed(const struct ttm_tt= *tt) > +{ > + return tt->page_flags & TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED; > +} > + > /** > * ttm_tt_create > * >=20