From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=51.210.91.30 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796390230; b=GBqndzFJJINSUGN/diHp0XrXB8njsfGjGUZfw1pR6Z0m6BvnuThyyLPq8gJLX0iT4Vnx pIodH5xtuSj0pwat/tov1LvWaGBdZ9xwzT2ROUdw7Vviy4HXrP4M9IL3Pa2hLH80Eg+xW V/xBfOhwivnxd/75SA4ZViwG6AVw0IkCQHRnoEVhyr5kMua+m4HlEhuF2IxcXHu8Z2A2L 9IR/F+BVLcbiFxpiiOShDEZQaQ7oXoZqwh9yph9M2B3MxjpZg2vH0s0o+A2XKNDdTbBWY dQTVRTwvyx5KiZU8g0yYPMHH/hVqXlRCjaaa1o93o+d+5IlWh2gh2queeloORi6VCUA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796390230; h=DMARC-Filter:Received:Received:Received:Received:X-OVh-ClientIp:From: To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:Content-Type:x-ovh-tracer-id:X-VR-SPAMSTATE: X-VR-SPAMSCORE:X-VR-SPAMCAUSE:DKIM-Signature; bh=tzbtQHWdSgp8LA3U6zFxnEn0TpQ7QUGuSvjIEaW+5X8=; b=BPnhmI7FOTvrz6v9hMJvb3prTCcZ+ROo8g9enoef6tLtJemex0ZOMh1b5209dRjCIDgU cQ9WPBgQUr4/laHnkpsfHIB2GMyBHWhL2P8Xum1Vlv5ei4oVE3W+DPL8CruwA39+tBAdH xzTqwNyIuO/3/9A/Z5gj6SxpeMT7R9DyBz/lFDd2M+ouSURTSDZdX9PsGL6ZMeOQoioSJ a70ZWfzOaB1hRYqkUCc4poorchBnuvEQY/tFoimrVv863zCFHxpSFD0gkD4nkgT5hqW06 jvGO9tktAFQZw84FVU9SBuRB3R7CDMhXwGoxA2nSsCCds9jDS6gaMzvx16kVet/TyGQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=pixelcluster.dev; spf=pass smtp.mailfrom=pixelcluster.dev; dkim=pass header.d=pixelcluster.dev header.i=@pixelcluster.dev header.a=rsa-sha256 header.s=ovhmo-selector-1 header.b=uLLUjATd; arc=none smtp.remote-ip=51.210.91.30 Received: from smtpout1.mo538.mail-out.ovh.net (smtpout1.mo538.mail-out.ovh.net [51.210.91.30]) (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 0FD48606A322 for ; Fri, 4 Dec 2026 13:17:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0FD48606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pixelcluster.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pixelcluster.dev 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 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-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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== 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