From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=198.175.65.12 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail; t=1796191838; b=ECsSwKkFZSkx9uWi4bQxaBkS3IV5RtIlp8siWIvRFgz5nJ93r2npGVbljU0bI4B/0Rlg R++FyVNwUagako7+hdJRZLz22W0KGmSjhdrLv+/VvH3XuEr5kfnr+f5UkJN6KaR9hckEd npBzlgqZ0dVGs3Wgz1pokUKXvDEqhdRCuhuX6T/PO+uF12RSgZZRaax4pYkH2G3bUczXk KNl7p+vgKd+AaQxzZ8OHvJCA9ggtVotWiHUnYDeNfIUqPPtIKmB2o/Bsju0MMZ1VE9ot+ jp/ClCG3DnMONXnQFApZcO/Wp5chfbddC91igB4m0/92FMrfV+Mc5QDW698AJOFKRdg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796191838; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:Received:Received: Received:Received:Received:Date:From:To:CC:Subject:Message-ID: References:Content-Type:Content-Disposition:Content-Transfer-Encoding: In-Reply-To:X-ClientProxiedBy:MIME-Version:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-LD-Processed:X-MS-Exchange-SenderADCheck: X-MS-Exchange-AntiSpam-Relay:X-Microsoft-Antispam: X-Microsoft-Antispam-Message-Info:X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-Exchange-RoutingPolicyChecked: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped:X-OriginatorOrg; bh=e8OlwkrSjvPhxwQz2MKr0FriEPh1JmkV/6rKjaK/wNM=; b=Uwvco+8sxOTI5PSlGEYGx9QSQwini/MypmyVZTprninw9h5CwWYAx0jvaFBJJ9sM/fyJ /jDNVo69NBX4UT2ObGrRFDBZjhptCHaYuOvj30bN2Hwkf2lcUKQACNMsnZPKEGIYKyMhX KPo46RznhP51SkqPN3TJxEKb2XgC2PoE0CbkpeRNlMw5RJ6Tt7Wcsw42tw8xdV7uicm6S w1U5eIQklUHxf3m+JATIX0wDNXmqK/OmlkrV8zO9SggHZfV325Y0/3n02UbvUi3AJ4Ur+ hGyur8pcVTMDb45K78EFZlFm3Y5CkbqedSxXqTEuG0r6kb1pN5ctGbUgWBK6z2fUYeg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=hWR3CVTI; arc=fail smtp.remote-ip=198.175.65.12 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BF19606A323 for ; Wed, 2 Dec 2026 06:10:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5BF19606A323 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=hWR3CVTI DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796191838; x=1827727838; h=date:from:to:cc:subject:message-id:references: content-transfer-encoding:in-reply-to:mime-version; bh=e8OlwkrSjvPhxwQz2MKr0FriEPh1JmkV/6rKjaK/wNM=; b=hWR3CVTIqnA99lrwuAWaVm1dAvxU9qcdAn3xjg4Emd9OoRr/3KIFRbWq OpuyrNbB2qHu01r6qTwc1YBhHdBKIRZqAm5wfKK8ANKuSrEmBLPn6CFP+ JQRDe+KI7CoOeWcUqiCgSLHBWQB+F22rNLUqfk9qpizrjhnr2306FDDwG trSTQbe6Nn0RZ9CJZB0bdTDh0R2GWeeqZRbZ0AoryemAASfHQrUrLpmhG jxLOqjTRi4Ax+ocdYMmF3WFbkzM31FOVHF9Y/IOnewFJDiT1tk+YQcSsT eof8SA/EPss/l59+CJSNduEywYTZdPfTlj7W0L5nZK0o8Vw0Qjzwo8oLR Q==; X-CSE-ConnectionGUID: eCUKetfGTumCcGtEYFaKZQ== X-CSE-MsgGUID: eEh5mgRbRVq0BBwQXqfvIA== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="5010452" X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="5010452" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 22:10:37 -0800 X-CSE-ConnectionGUID: 4bcU2Q0kRv228tIq/NOi+Q== X-CSE-MsgGUID: hqE5W5OwSHig/uM07IPBRg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,246,1787036400"; d="scan'208";a="13723125" Received: from fmsmsx901.amr.corp.intel.com ([10.18.126.90]) by fmviesa007.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 22:10:38 -0800 Received: from FMSMSX901.amr.corp.intel.com (10.18.126.90) by fmsmsx901.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Tue, 1 Dec 2026 22:10:36 -0800 Received: from fmsedg901.ED.cps.intel.com (10.1.192.143) by FMSMSX901.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57 via Frontend Transport; Tue, 1 Dec 2026 22:10:36 -0800 Received: from CO1PR03CU002.outbound.protection.outlook.com (52.101.46.27) by edgegateway.intel.com (192.55.55.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Tue, 1 Dec 2026 22:10:36 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MlzucOG/+KmwgZoFhTYc945gQT6316CIya39jfdBHjzRTctrR8RP9we9Eb81rCKATNt5hibVZ2PYtTKJIpF3WGpuNuvUuFRTnJyCoKSvpw1inf4ePpPsgAJasWVZ9X8XdHklYtH/sGCrvdTYCnJoZbhXX1dYHA0d7wPB4MDN8Br1WQKYPt4IpVHs6TA5Up+LTQaPk9R+bmP5DpmgpIiA5SHJEMNE3b1wOb7udVGn7NAMIMEAzUzk6OnCwmCSEJEvzTz24ILx+BOC0qQD4OO2Bc1hMvVfJWGrzrLFrmz7rlLg0ZWyJBUC/CyNNrWXDRXeD6h7+ZjuSkqQ982OWAWceQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=drjYdufqxS/A3zueF6fZuvzjj4kccRBBkPFFSGkcGU0=; b=sWk3pmFtX2rfze6VON3FUd0oCTjDuuVafMQCmIMUF+7RcJ5kOWRdbQfCfUs36qxgKcnyRInftQxRosbSnhtA4YhLM5Y9nyOMCOOTtgVI6YTiCljpAhFUtPNqut1JyvG1wFid0zkOhgxplw2Nzhc3sFWPotxXzZxNQh9yY+CqlBT6QpRB07r+PDcmnN0jeNHcWbF52rSJXYtRfUW4tSlZnILGHeSLJsn0RrQJxpAdEs/EhPHF9njGNCw0+oKBhYAP48YDI9FnCR/lzzyqoX3Ov9KvnAH80v6S+z/+AgyhmHlY6cG0CIz82S01u6EHRyqW6UOHXbiibkK7B0MllbKlFQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from MN2PR11MB4677.namprd11.prod.outlook.com (2603:10b6:208:24e::23) by CH0PR11MB5236.namprd11.prod.outlook.com (2603:10b6:610:e3::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Wed, 2 Dec 2026 06:10:29 +0000 Received: from MN2PR11MB4677.namprd11.prod.outlook.com ([fe80::5b69:f9a9:3a17:ceb9]) by MN2PR11MB4677.namprd11.prod.outlook.com ([fe80::5b69:f9a9:3a17:ceb9%4]) with mapi id 15.21.0688.009; Wed, 2 Dec 2026 06:10:29 +0000 Date: Tue, 1 Dec 2026 22:10:25 -0800 From: Niranjana Vishwanathapura To: Matthew Brost CC: , , Carlos Santa , Ryan Neph , Natalie Vock , Arun Pravin , Matthew Auld , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , , Thomas =?iso-8859-1?Q?Hellstr=F6m?= Subject: Re: [PATCH v4 08/33] drm/ttm: Bound page (re)allocation per defragmentation move Message-ID: References: <20261201234915.3305331-1-matthew.brost@intel.com> <20261201234915.3305331-9-matthew.brost@intel.com> Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20261201234915.3305331-9-matthew.brost@intel.com> X-ClientProxiedBy: SJ0PR13CA0188.namprd13.prod.outlook.com (2603:10b6:a03:2c3::13) To MN2PR11MB4677.namprd11.prod.outlook.com (2603:10b6:208:24e::23) 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 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR11MB4677:EE_|CH0PR11MB5236:EE_ X-MS-Office365-Filtering-Correlation-Id: f7bedff6-e4fc-4990-3c12-08df503af6dd X-LD-Processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014|7416014|23010399003|22082099003|10067099003|56012099006|261022075727099003|261026140227099003|261026121527099003|261022105027099003|261022113327099003|261021121427099003|261021123027099003|261102123227099003|261102130727099003|261028144727099003|261009223327099003|261009221227099003|261009220027099003|261009223027099003|261009221727099003|11063799006|4143699003|18002099003; X-Microsoft-Antispam-Message-Info: NISBPTR0mV52ifHxKuPlMEtj0KGXUE6enwbLeMpjdbL+7mU32NaIVN1PLTy+cVSMf/DlcTHQft6nBDePkoFyw/bl51+laZVKhojIBN72IPMam6tZTSCGuyH0QU7+BQiedoApJNj+FOUJJjqAg2ZYV3Y4T8dC1U5b7HEBFPjS7X840+bqBvq1mKWZcEICzsAbQ4p6zOGjbhDTImYvn3tUMJ8Mix1JWI8tVr1x5NA5FVnScA5khE71bm/2Fp7rYmd7mlh219i7kBY0a/xxHYY7y6UmTxWcuw6gbIY+cVYUEihP5rR1/IKPh6dOmOXsrhrXNqoqWtsF0NQMm9JXd4X8Tuf5uxdR/MtcdKn6F/yQ+Ppk5V7jsN9it3UoSwZs3ohtJSdNj3YhAlyf/jNWbrVWNq3t3p5k2rsPGvx+uetzHLoTnkZ4pw9ubsNVvZy0ZgD2Y4iJNGmFVWH5hAJw9Y0mXF5MxbS+JEb/j33hm3X/yNKBJQpF490OziYIs2OUP2iV5J12ITGpBfHPql5+YG6mqUXXPvu16LihSip77XoP3o8KkK+/x39r67NkQaUyVYEGNwhNYtQTRlg/8Kev2d62lshW+Ni2b2nY14imvIWsJw6ho4gg16TAQ+sNxwHRgGjOopBCU68Mf4X68JNNgFVxGkeIZVFEDDOG7gjpS5WNiS8= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR11MB4677.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(376014)(7416014)(23010399003)(22082099003)(10067099003)(56012099006)(261022075727099003)(261026140227099003)(261026121527099003)(261022105027099003)(261022113327099003)(261021121427099003)(261021123027099003)(261102123227099003)(261102130727099003)(261028144727099003)(261009223327099003)(261009221227099003)(261009220027099003)(261009223027099003)(261009221727099003)(11063799006)(4143699003)(18002099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?iso-8859-1?Q?a4uMKkZxAtc0QFrhOVD5W/5xs+9GlkS96hhQueYtnywDMqcgxevOARIgm8?= =?iso-8859-1?Q?W+iocGSU4K8WUNkgGP3Es5XpkGIqtc5XCP5kPD9H09uDdVjWNnqbIPL9C8?= =?iso-8859-1?Q?pa41itiqcEQ8LkLClOjQc/KIaRHz5nB6oyqg3h4QJ6VCDi/++XH3i/giZ+?= =?iso-8859-1?Q?YXFg9t+rcsJZQc7jdzk7eerVeAqlNOLMouE4BMhZEaEtrEGpljCVNerkDG?= =?iso-8859-1?Q?EdytjJ/gSgiq/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YgtM/QoxYcKe6/wx5MbTSH3uBSvJzyCSBdWoSxoi9jud0NZR1zF6h614KZdd9IRJrvLN1qQ7kw5Ifb0duhGfD4Q7YJN0RnT3WIedgvKDQMw3sDq14JQMNFx8d+VVVKxzR6jJRWnBOgRtc552fZ04nKabwyxR1IA6mDjUgl5NC63F81vjZ8jb1AAZg== X-MS-Exchange-CrossTenant-Network-Message-Id: f7bedff6-e4fc-4990-3c12-08df503af6dd X-MS-Exchange-CrossTenant-AuthSource: MN2PR11MB4677.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2026 06:10:29.0829 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 38SiD82QQNP1p8XRgNW04mWUA/YQOmCoH4n7lRFUv+tPHF6qTO73eB58XQOyn3y6VJ51jAuYwBAznxTD9HExDuLu45xRqLXtIdUAOc0r2eSvcj7ZAWxGnfw64AYM8NZl X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH0PR11MB5236 X-OriginatorOrg: intel.com On Tue, Dec 01, 2026 at 03:48:50PM -0800, Matthew Brost wrote: >A defragmentation move reallocates an object's backing at the device's >beneficial order and harvests whatever the allocator cannot upgrade from >the old tt. For a very large object this can reallocate (and have the >driver re-copy) the entire backing in one move, which is expensive and >can stall concurrent work for an unbounded stretch. > >Add an optional per-move byte budget so a large object can be upgraded in >slices across successive moves. Plumb a new >ttm_operation_ctx::defrag_bytes_remaining through to the pool allocator: >only pages actually (re)allocated at the beneficial order are charged >against it; pages harvested (borrowed) from defrag_old_tt are free and do >not count. Once the budget is exhausted the allocator stops upgrading and >completes the new tt by harvesting the remainder of the old tt as-is, >marking the tt sub-optimal (TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED) so the >driver re-queues it and a later move resumes the upgrade. The slices >already upgraded come back as free already-beneficial harvests on the >next pass, so each move spends budget only on new forward progress. > >The allocator decrements the budget as it allocates and writes the unused >remainder back on success, letting the caller compute how many bytes were >actually spent. A value of 0 means unlimited (upgrade the whole object in >one move), preserving the previous behaviour. This is only consulted on a >defragmentation move, i.e. when defrag_old_tt is set. > >v4: > - Allow suboptimal to be NULL (Niranjana) > - Reject defrag_bytes_remaining less than zero (Niranjana) > - Move num_pages outside of loop (Niranjana) > >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öm >Assisted-by: LLM >Signed-off-by: Matthew Brost >--- > drivers/gpu/drm/ttm/ttm_pool.c | 103 +++++++++++++++++++++++++++++++-- > include/drm/ttm/ttm_bo.h | 14 +++++ > 2 files changed, 113 insertions(+), 4 deletions(-) > >diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c >index 111d83da5971..9e95e368ff82 100644 >--- a/drivers/gpu/drm/ttm/ttm_pool.c >+++ b/drivers/gpu/drm/ttm/ttm_pool.c >@@ -92,6 +92,11 @@ struct ttm_pool_dma { > * @dma_addr: Pointer to the next tt dma_address entry to populate if any. > * @remaining_pages: Remaining pages to populate. > * @tt_caching: The requested cpu-caching for the pages allocated. >+ * @defrag_bytes_remaining: Byte budget for newly (re)allocated pages on a >+ * defragmentation move, seeded from ttm_operation_ctx::defrag_bytes_remaining. >+ * Pages harvested (borrowed) from the old tt are free and do not count; once >+ * this drops to zero the allocator stops upgrading and harvests the remainder. >+ * On completion it holds the unused budget. 0 means unlimited (no defrag cap). > */ > struct ttm_pool_alloc_state { > struct page **pages; >@@ -99,6 +104,7 @@ struct ttm_pool_alloc_state { > dma_addr_t *dma_addr; > pgoff_t remaining_pages; > enum ttm_caching tt_caching; >+ s64 defrag_bytes_remaining; > }; > > /** >@@ -796,6 +802,7 @@ static void ttm_pool_alloc_state_init(const struct ttm_tt *tt, > alloc->dma_addr = tt->dma_address; > alloc->remaining_pages = tt->num_pages; > alloc->tt_caching = tt->caching; >+ alloc->defrag_bytes_remaining = 0; > } > > /* >@@ -901,8 +908,13 @@ static int ttm_pool_harvest_page(struct ttm_tt *old_tt, unsigned int order, > > static int ttm_pool_harvest_remaining(struct ttm_pool *pool, > struct ttm_tt *old_tt, pgoff_t off, >- struct ttm_pool_alloc_state *alloc) >+ struct ttm_pool_alloc_state *alloc, >+ bool *suboptimal) > { >+ unsigned int beneficial = ttm_pool_beneficial_order(pool); >+ pgoff_t bnr = 1UL << beneficial; >+ pgoff_t num_pages = off + alloc->remaining_pages; >+ > /* > * @off is always an old-tt chunk head here, never a tail page, so > * reading the per-chunk order below is safe. This holds because: >@@ -925,6 +937,20 @@ static int ttm_pool_harvest_remaining(struct ttm_pool *pool, > pgoff_t nr = 1UL << order; > int r; > >+ /* >+ * Only report a sub-optimal backing when a chunk we cannot >+ * upgrade (out of budget/prealloc) sits in a beneficial-order >+ * aligned region that fully fits in the tt: that region could >+ * have been upgraded with more budget. A chunk below the >+ * beneficial order is expected for the unaligned tail (the last >+ * partial beneficial-order region) and for already beneficial- >+ * order harvests - neither leaves real defrag work, so they must >+ * not flag the tt for re-queue. >+ */ >+ if (suboptimal && beneficial && order < beneficial && >+ round_down(off, bnr) + bnr <= num_pages) >+ *suboptimal = true; >+ > r = ttm_pool_harvest_page(old_tt, order, off, alloc); > if (r) > return r; >@@ -967,6 +993,7 @@ struct ttm_pool_alloc_iter { > struct ttm_tt *defrag_old_tt; > unsigned int beneficial_order; > gfp_t gfp_flags; >+ bool defrag_capped; If using kernel-doc for the structure, the fields need documentation. With that taken care of, Reviewed-by: Niranjana Vishwanathapura > > /* Mutated as the loop walks the orders. */ > unsigned int order; >@@ -978,6 +1005,44 @@ struct ttm_pool_alloc_iter { > struct page *p; > }; > >+/* >+ * Defrag move budget exhausted: the upgrade can make no further progress this >+ * pass. Snapshot @defrag_capped is set only when a byte budget was in force at >+ * entry. >+ */ >+static bool ttm_pool_iter_defrag_exhausted(const struct ttm_pool_alloc_iter *it) >+{ >+ if (!it->defrag_old_tt) >+ return false; >+ >+ return it->defrag_capped && it->alloc->defrag_bytes_remaining <= 0; >+} >+ >+/* >+ * Complete the new tt by harvesting the rest of the old tt as-is (borrowing its >+ * pages, including any still below beneficial order). Never fall back to in-lock >+ * reclaim for the shortfall - that would reintroduce the stall we preallocated >+ * to avoid. Only re-queue (flag) the tt when the harvested remainder is >+ * genuinely sub-optimal; if every remaining old chunk was already at beneficial >+ * order the move fully upgraded the object. >+ */ >+static int ttm_pool_iter_harvest_rest(struct ttm_pool_alloc_iter *it) >+{ >+ pgoff_t off = it->tt->num_pages - it->alloc->remaining_pages; >+ bool suboptimal = false; >+ int r; >+ >+ r = ttm_pool_harvest_remaining(it->pool, it->defrag_old_tt, off, >+ it->alloc, &suboptimal); >+ if (r) >+ return r; >+ >+ if (suboptimal) >+ it->tt->page_flags |= TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED; >+ >+ return 0; >+} >+ > /* > * Defrag move: reuse an already beneficial-order chunk from the old tt at this > * offset rather than reallocating it. Harvest whatever order the old chunk has >@@ -1082,7 +1147,7 @@ static int ttm_pool_iter_lower_order(struct ttm_pool_alloc_iter *it) > > r = ttm_pool_harvest_remaining(it->pool, > it->defrag_old_tt, off, >- it->alloc); >+ it->alloc, NULL); > if (r) > return r; > >@@ -1141,10 +1206,23 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt, > gfp_flags |= GFP_HIGHUSER; > > it.gfp_flags = gfp_flags; >+ it.defrag_capped = it.defrag_old_tt && alloc->defrag_bytes_remaining > 0; > > for (it.order = ttm_pool_alloc_find_order(MAX_PAGE_ORDER, alloc); > alloc->remaining_pages; > it.order = ttm_pool_alloc_find_order(it.order, alloc)) { >+ /* >+ * Out of defrag budget: harvest the rest of the old tt as-is and >+ * stop (the tt is re-queued if the remainder is still >+ * sub-optimal). >+ */ >+ if (ttm_pool_iter_defrag_exhausted(&it)) { >+ r = ttm_pool_iter_harvest_rest(&it); >+ if (r) >+ goto error_free_all; >+ break; >+ } >+ > /* Reuse an already beneficial-order chunk from the old tt. */ > r = ttm_pool_iter_reuse_old(&it); > if (r < 0) >@@ -1175,6 +1253,15 @@ static int __ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt, > goto error_free_all; > } > >+ /* >+ * Charge a newly (re)allocated chunk against the defrag move >+ * budget. Harvested chunks borrow the old tt's pages for free >+ * and never reach here. >+ */ >+ if (it.defrag_capped) >+ alloc->defrag_bytes_remaining -= >+ (s64)(1UL << it.order) << PAGE_SHIFT; >+ > it.alloc_count++; > } > >@@ -1224,14 +1311,22 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt, > struct ttm_operation_ctx *ctx) > { > struct ttm_pool_alloc_state alloc; >+ int ret; > >- if (WARN_ON(ttm_tt_is_backed_up(tt))) >+ if (WARN_ON(ttm_tt_is_backed_up(tt)) || >+ WARN_ON(ctx->defrag_bytes_remaining < 0)) > return -EINVAL; > > tt->page_flags &= ~TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED; > ttm_pool_alloc_state_init(tt, &alloc); >+ alloc.defrag_bytes_remaining = ctx->defrag_bytes_remaining; >+ >+ ret = __ttm_pool_alloc(pool, tt, ctx, &alloc, NULL); >+ >+ /* Report the unused defrag budget back to the caller. */ >+ ctx->defrag_bytes_remaining = alloc.defrag_bytes_remaining; > >- return __ttm_pool_alloc(pool, tt, ctx, &alloc, NULL); >+ return ret; > } > EXPORT_SYMBOL(ttm_pool_alloc); > >diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h >index 22d12fea6f3c..4ab67d6a926e 100644 >--- a/include/drm/ttm/ttm_bo.h >+++ b/include/drm/ttm/ttm_bo.h >@@ -223,6 +223,20 @@ struct ttm_operation_ctx { > * NULL for non-defrag operations. > */ > struct ttm_tt *defrag_old_tt; >+ /** >+ * @defrag_bytes_remaining: Byte budget for newly allocated pages during >+ * a defragmentation move. Only pages that are actually (re)allocated at >+ * the beneficial order count against it; pages harvested (borrowed) from >+ * @defrag_old_tt are free and do not. When the budget is exhausted the >+ * pool allocator stops upgrading and completes the new tt by harvesting >+ * the remainder of @defrag_old_tt, marking the tt sub-optimal so the >+ * driver can resume on a later pass. The allocator decrements this as it >+ * allocates, so on return it holds the unused budget (which the caller >+ * can use to compute how many bytes were spent). A value of 0 means >+ * unlimited (upgrade the whole object). Only consulted when >+ * @defrag_old_tt is set. >+ */ >+ s64 defrag_bytes_remaining; > /** > * @resv: Reservation object to be used together with > * @allow_res_evict. >-- >2.34.1 >