From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.remote-ip=192.198.163.8 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=fail; t=1796355580; b=xbgJuBjPZQ5zPZZ/Q7daAsaFLtVRqp0tLKorCiG1spfTnbuaE6QB8m58NXb8FY0/DvVc aIEqFc8mN80bAPMIQYAU4kIxAYS/aOae2i/DpOUnHkw3NgLGOLdpIS60lredfRk6jtNxS PTej0fC7sWlo8qtwaEGeCXSB4OGpEtoS5qrkooy765v77QQp90opIxxoLw1Vaqyx6D0Oo rcRLwrncCnC+VxyJ6qv3zkqu2Ng1ijSsals2HRW2fQN/M8jkzIP6FcIf0AXJFVI0uF0w+ RL7f5lhebdx07w5zdyE4CnVO5rwk1oCS8S0OwroE13p46yI4EY1GBbsLeXv+mCzIs2A== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796355580; 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=pqtuM7IrQvb+uO4t8Ts0gAoUDhRcjKpv74xSoV6uan0=; b=mgLbNzqSo+c2UJkg22cQGcCDkyvE6SiBl4sPO6TYt+NwarRdz67ZNv35mJpXPaOisJxS 3h4PjVGvc7CSDaKQhnIsWBR1lnPVCoR6JpNdT6lxu6qtxZGaO5tq1ncV2xOzJ31s3vFlM UCw8QdDdpeqwmPA0e+gqOVN+KEmKoTmg6EL4K99G04ot4UswFeFj+v57qax5LQok+Mdbu 70BwymEa4SNy4VnmTHyiRqK80ruZMXps1W/uvGrpRrkTEeZwjCmC5ZhevPGNvuc+AKrAC P0YMX0mnc2VUxT8fPCR3SG6eZRFTSSilmgoprhXwv6hLzkAoEIIA28X6uK7KMp7Ccpg== 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=HVp7+JIQ; arc=fail smtp.remote-ip=192.198.163.8 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (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 31F06606A33A for ; Fri, 4 Dec 2026 03:39:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 31F06606A33A 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=HVp7+JIQ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796355579; x=1827891579; h=date:from:to:cc:subject:message-id:references: content-transfer-encoding:in-reply-to:mime-version; bh=pqtuM7IrQvb+uO4t8Ts0gAoUDhRcjKpv74xSoV6uan0=; b=HVp7+JIQDpFv8+wDeuq134kU/1nsdLCnv6aM7wyPAD96c3f3VoApSCLD mLNCb88ghUSTTB91GY41bdAFANAPdm60QuEb/6oRQdoD4DG8S8Sl48EP0 wg/ybyyEY5WgP0gSXIVLT/XJflHN0A9yUhrOZPf0EhSllvyKq8HegRETw xFt0MuwrlKrIWO0K2RBKuOks+i0xb2rdR+3SDDypo2QZJTEXGfOVya8j3 NwzXk1g3qm+YZg0ExgoP+Q8/7ZLSooh9e/8MIHyYkzFoo4vLe1PO7AJXh 3nmRY/fc0VfygjGyb2iKG8DzoafzAejygNT4XIIKpukwRTbdPAAL4gMcc g==; X-CSE-ConnectionGUID: XGkbnoQvQnWyN8eUWUkgQw== X-CSE-MsgGUID: eWMoMijtR/C0ls5r+E8u1A== X-IronPort-AV: E=McAfee;i="6800,10657,11985"; a="5213803" X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="5213803" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 19:39:38 -0800 X-CSE-ConnectionGUID: d80gqh0mTBicXuhhd7MEOQ== X-CSE-MsgGUID: jGyrtIkNQ32L+RL+OdQnyg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.29,77,1794902400"; d="scan'208";a="14346469" Received: from orsmsx902.amr.corp.intel.com ([10.22.229.24]) by orviesa009.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 19:39:38 -0800 Received: from ORSMSX902.amr.corp.intel.com (10.22.229.24) by ORSMSX902.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Thu, 3 Dec 2026 19:39:37 -0800 Received: from ORSEDG902.ED.cps.intel.com (10.7.248.12) by ORSMSX902.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57 via Frontend Transport; Thu, 3 Dec 2026 19:39:37 -0800 Received: from SN4PR2101CU001.outbound.protection.outlook.com (40.93.195.30) by edgegateway.intel.com (134.134.137.112) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Thu, 3 Dec 2026 19:39:36 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TXzSKlnt7/9uPRGqMFKzZ1H1uq7d4xYMHIS83vQo6uaF/vthwMOLu3rXtAqqUzKx5FV3p2pZQ/Fs96LPalYI7UFNYRJGDrvPW/OU/zoTVtoFxBTLsWT/4RJWy9QZAe/mleS9Wp17pjl0bP6A6071oDhbS+JEJSc8NDPRz6P3j0rOI/qOxTslryBnuBK8ofEG5Sr8GNHdJCcNvU8eor1+YylqmvjQgr9BJCYBxQYB4rebqNStGzByeHz2wUo1myyB9TBN+9ZFwZ9dn3UJj6l1MYa7yQXLBDLH2H16lfgdi4lpI4IOGrM3ZiElKYIEX7h0Mco8g9FzgvBy4iMIFB+AGw== 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=XZhLwKZ8Zvl95hJAT4Qd6jpdO0nQizWoHlXRlZynNps=; b=W7ESKMyNQ5euosVncRmQomH9vxUMGrVdArgEVtL5eQxU52G2F5zcvf6qwh6Eg4DdUVRNBCSwytKF6cJA4vSuzPNFNE/7C7yNYT6dFJig+euqQ+drsSRTh/xjOHQR2C7E2CyMfHDjPZvAvD3yR4J0kCAjZl/0iYhGcmHAmFHvGtOIYIZNGK9CVNwlIQsMOM+K7m1/XyLE4oNLWXx1RNhy/5z8Kh4y7PHsr9N2ESnrJgES4knyMrnSlwUcsz0UBXNGtboCbSmJWtwV7HRCevtmRtwjMtmE+MNOb+6ui4RW5F0N8tiHa/69TjLzg69C4EZd2oAAK+fnTX0lz6sveW0zEQ== 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 MW3PR11MB4684.namprd11.prod.outlook.com (2603:10b6:303:5d::14) by MN2PR11MB4535.namprd11.prod.outlook.com (2603:10b6:208:24e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.13; Fri, 4 Dec 2026 03:39:29 +0000 Received: from MW3PR11MB4684.namprd11.prod.outlook.com ([fe80::2f5a:96ce:f7e4:c315]) by MW3PR11MB4684.namprd11.prod.outlook.com ([fe80::2f5a:96ce:f7e4:c315%7]) with mapi id 15.21.0688.011; Fri, 4 Dec 2026 03:39:28 +0000 Date: Thu, 3 Dec 2026 19:39: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 v6 11/35] drm/ttm: Add full out-of-lock preallocation for ttm_pool_alloc() Message-ID: References: <20261203202352.4153159-1-matthew.brost@intel.com> <20261203202352.4153159-12-matthew.brost@intel.com> Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20261203202352.4153159-12-matthew.brost@intel.com> X-ClientProxiedBy: PH5P220CA0009.NAMP220.PROD.OUTLOOK.COM (2603:10b6:510:34a::14) To MW3PR11MB4684.namprd11.prod.outlook.com (2603:10b6:303:5d::14) 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: MW3PR11MB4684:EE_|MN2PR11MB4535:EE_ X-MS-Office365-Filtering-Correlation-Id: 9f71b8be-c998-4083-86e4-08df51b8330c 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|23010399003|1800799024|376014|7416014|10067099003|56012099006|261022105027099003|261022075727099003|261021121427099003|261021123027099003|261026121527099003|261026140227099003|261028144727099003|261102130727099003|261102123227099003|261009221727099003|261009221227099003|261009220027099003|261009223027099003|261009223327099003|18002099003|22082099003|4143699003|5023799004|11063799006|6133799003; X-Microsoft-Antispam-Message-Info: XWPyYed4PmbLx4JVZ55Ns64rhE0yAZl8AZWdB73ZYagNfbdSMDO2VEVsUkzPyGK1bygEMnai4H4D/Usb8y5qOw6lymx2T4/CHk7FBCeW0fqUNRnxb+53qUDSXHM1PFYU9AacOK0e18H2tHPx8yZKYt7NpKcMxvBCxjBxnH/y9rrn4PYUTOLGDRWe/yY5bI5ULlJYpzdM7WBPuy15D2SKgKvAIjC9YpU2qtSDDh4s4C+LXaqsfnZz0z7dLt2zW9wtAMlq5H+Ckn4FblyL7kQFG4iTmWmcU/3+TbBx2+mtzOVKxJUds179WwufyXr7lvoyGB52c2a+q0xKZ2u7L4JddeNYMaMOB+IDT9OMuynAuYZX5wafCFcDKZEKg9qBbTpupm0KvHywIul39TPj0L0TwV4UOngNhUdynUIwWrTgP68VAEzUPgHoUZE2S2ixgcAdSamlTIYjix12QjNzjP1swbdGDUwtw/0ACnKz/DDLMLh1+bYECerYZ74le7e2jYuMH3j7WsQUP4gnzUDTWJyEql2bgpG0CkcAyNGSE3Q+YEF1N8Kb3TtRJXp2Qhq+//aQIN7o26rkfp+DCbnvTH5mlOjJvzs0dpdqv/mBfDT6QWnKjcEZCH+EF3GBKD+Nll7l8ESQI3b4pYfbZZIT1BE3wvi8ZNX0zCX7Skn76z8uq0w= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MW3PR11MB4684.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(23010399003)(1800799024)(376014)(7416014)(10067099003)(56012099006)(261022105027099003)(261022075727099003)(261021121427099003)(261021123027099003)(261026121527099003)(261026140227099003)(261028144727099003)(261102130727099003)(261102123227099003)(261009221727099003)(261009221227099003)(261009220027099003)(261009223027099003)(261009223327099003)(18002099003)(22082099003)(4143699003)(5023799004)(11063799006)(6133799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?iso-8859-1?Q?eZ8Y77HhTi7aoRudfRcfPgpY+w20xAPtNMvOEtxqCMJBGWBQdiLpYOntIf?= =?iso-8859-1?Q?aUYwsp5COjRjjSbWvAtzaC1V6TzkDNqe9473CiOXOlm3ssqffB02jFj9x/?= =?iso-8859-1?Q?66wz/XRSIhrFbrsA7LzM7pon5w9elragJ++ZMgbzm4RVUKfSZt3AXkw5dD?= =?iso-8859-1?Q?xyK99MDH79valpe6WNM2Kf9IChFiGuV0QVd6EaI9PCsMTnBnnGP3wv0iuj?= =?iso-8859-1?Q?NR8XFpYVONlsw0p008ciP2z0f89qQhluAlv3LBctye+dqaooW0rQzSQ7XK?= =?iso-8859-1?Q?FpvQY94ho0cm0JwGxpj+IeonLnB45V9SGeicr1gcpB55cODzZEqJgNSEqS?= =?iso-8859-1?Q?JrLi9qvd5ePYonlREBNMRincC9dJqgzCazubwye09+yvzyL2Y9A+ToqZwS?= =?iso-8859-1?Q?trhxoZk+5mG4YgIRZZcZdjunkUrDCquiOkXMeEDvMvIoiUn7iI0d0+WeUN?= =?iso-8859-1?Q?Nmst00GArNGU0yCn6LHm4eoQWRU+8md3r9wB5NCsZEzZWh7oLO8RBaeOwk?= =?iso-8859-1?Q?UsOwT0De17Kw62lfFgFadsOrMXgpyQtm+577O6iAY9YMtW4QGEJHP/7jyx?= =?iso-8859-1?Q?0879EI06jc5dij38bbTdPxpGqOtkfvP64wsDFpyT/94TicjHZcEeKnZDxo?= =?iso-8859-1?Q?ASQxfFCM+EW0C6/Vj+7gXccaGr2foxVXNbDp3+wscoCmazLXb/10ZoaZo/?= =?iso-8859-1?Q?sEtT5ghKq1VmkyJmmCGYGzPjn44fj3FcHiju/XfhJ3hB/UIiJ/BRTRoDrz?= =?iso-8859-1?Q?MP4pMbKi4hH8DR64J0OgOOZTnqnt9eNtIUULuH6lmG8Tr/bPdoujrJn1yx?= =?iso-8859-1?Q?vo8IFGRXk8P5szyEhRYVaaHR5WRq6HhFXTofEt/NAgBZVqeWB11D+dgzpz?= =?iso-8859-1?Q?adv8VoO66Gm1g8K7H5fW2KnEuSL0uizeutFdhP354f3T8Q9B2x2feHtSrA?= =?iso-8859-1?Q?EW1kjoL19CgRDJRD3LfwpkWoTMnnS3neHmvOBUEinK8pfpVZ9LhXUVlVHK?= =?iso-8859-1?Q?QQxiWLfZrCA7ug0WVGxSax3ctL/81JFFIf9dNvj6oktsNuDURKxOOXP1so?= =?iso-8859-1?Q?8lP7015h6u22pxK2JkDvx+uH92yeXUp7lK6b5/i85IQ/LjyI+5M8Bg3xzf?= =?iso-8859-1?Q?dqMWPpmJ5a8Unpt4Zyo9Wwrgw5/bM4Ozxd1/OFgSVWG6zEitVVPu57/P8q?= =?iso-8859-1?Q?GudI+dUTq5sP8giA/vyAkFidnJPAEo3QichzG/LOJAOz6GjH6uA9i8TuUf?= =?iso-8859-1?Q?9p7vf/umjwo9o7BsBfdFuf/+6pq2IyiSfBYRmLN1ciE5v0HdPdPRQHfp9W?= =?iso-8859-1?Q?cRrFTJTybMcR7pZU8vwKMwriAWWHm+AbrU16jXuTeP9uid/AQBEfQsJz6H?= =?iso-8859-1?Q?18wCQtvk0iC3aQq4gyRXbncJYCjg7wKjcOU74OG2l928bVf9GZ2agMn0xw?= =?iso-8859-1?Q?VuEYJRQ38kvzFeieWi2ldE6tPAHpfDqHd0YfGMPa3RptwtSdmXr4L9lhII?= =?iso-8859-1?Q?FfpY2tSd22mxOWZrlnfKRfgn211VkUP7CZgWX/hPLysXNcrzHPOcLqCoWu?= =?iso-8859-1?Q?IM1DN6zHdU/wALEATX8adJLayRsSkUjrfjXgyIeH8iAOq6su+FZRAvA0yr?= =?iso-8859-1?Q?vrsvA0sCutRwbxsIKq2Z7p3rFYF9aDj2I7sh3/q3dNb4/4heA1RAv5i2fo?= =?iso-8859-1?Q?y7uVYfUm2I/EG/eLpcxSBs3/EiEuWp7Uz3JFaUSLGkiYpgJhgcUj6mgSFF?= =?iso-8859-1?Q?vq4UF/HW9U9lvC4adBvhRN4KOXe6BWqDJZvnktvOW0VfxfjCp1dNNXKcog?= =?iso-8859-1?Q?Rw3WfOd5xMYs+dd4YiDNHwzcTjQmOTgxQALxPVTccmgSGF1s0/im?= X-Exchange-RoutingPolicyChecked: OqgsgAPnk6vPf6DfKUNvsjZRAw6XUzQWuCYeNRH5EURbH4yKE8meM7Ists0l6nPbx4yKBcBMT3uodsQqhiS/UyfWxsTt6cwpmZLKerHxtWvgmTCfhUM4lFwvV3ngphBAduVYNrZ2KhyM0PYbxGs0j0pZMl6xQev1WZlBddG0n1BfWfhOewG0noSwIYIvczYtITOm+Cjrf06OVRBnGPzpHiPESjGs0fdRASxoQ3O/kzWzsB8qFyrLdz64KmXZzd/H7NE3h9vRlTbgSRLejpvnT7v9xkjuh/lTE3Shb3YeXF5jkOn2JVv5kztx5nF1efh0Tv/Htnn9Qu/XrAx/O24uSQ== X-MS-Exchange-CrossTenant-Network-Message-Id: 9f71b8be-c998-4083-86e4-08df51b8330c X-MS-Exchange-CrossTenant-AuthSource: MW3PR11MB4684.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2026 03:39:28.5035 (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: ke6l4rzVnRNo5ysf+JOGXSRbvemOytj4mmRn1JeLABE1kqMsV9GydMXJTIjWgFW0mbeWKXurfgaXprFodseojrEoUEVRJ/HBx+OOAAEi/Wg2iCD52y6NdRTLIDAFfcc+ X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB4535 X-OriginatorOrg: intel.com On Thu, Dec 03, 2026 at 12:23:28PM -0800, Matthew Brost wrote: >ttm_pool_prealloc_fill() lets a driver preallocate beneficial-order pages >outside the dma-resv lock for a defragmentation move, so the high-order >allocations that may stall in reclaim/compaction happen off the critical >section. That bag is deliberately partial: it holds only interchangeable >beneficial-order chunks and the allocator consumes it opportunistically, >falling back to in-line allocation for everything else. > >An ordinary populate of a system-memory buffer object has the same >problem - the whole backing is allocated under the dma-resv lock - but no >way to move it out of the critical section, because the existing bag does >not cover sub-beneficial orders and does not describe a full tt. > >Add a "full" flavour of the same preallocation mechanism: > > - struct ttm_pool_prealloc gains a @full flag. In full mode the bag is > an ordered tiling of an entire tt at mixed orders (pool pages > included), rather than a set of interchangeable beneficial-order > chunks. The per-chunk order is recorded on the page itself and read > back at consume time, so no parallel order array is needed. > > - ttm_pool_prealloc_fill_full() allocates the whole backing for a tt of > @num_pages pages up front, mirroring the in-line allocator's order > walk (highest order first, capped by the remaining page count). It > reuses the existing unlocked helpers (ttm_pool_prealloc_gfp(), > ttm_pool_set_caching()) via a new ttm_pool_take_page() helper that > tries a same-order pool page before a fresh system allocation. > > - ttm_pool_prealloc_fini() frees any unconsumed tail at each chunk's own > order when @full. > > - ttm_pool_prealloc_fill_full() takes a @beneficial_reclaim_backoff > argument, plumbed to ttm_pool_alloc_page(), that lets the caller > allocate higher-order chunks without aggressive reclaim/compaction. > This suits a driver that upgrades suboptimal pages to beneficial order > in place later (e.g. via a background defragmenter) and so has no need > to stall the user context reclaiming for contiguity up front. > > - __ttm_pool_alloc() consumes a full bag with a single early branch in > ttm_pool_iter_acquire_page(): install the next chunk as-is (order > taken from the page) and return; once the best-effort bag is drained > the loop falls through to normal in-line allocation. The defrag > harvest and reuse-old phases are inert here as there is no > defrag_old_tt. > >Like the defrag bag, this is best-effort: a short fill is fine (the pool >allocates the shortfall in-line) and DMA-alloc pools are unsupported >(caching is applied on the kernel mapping). No functional change for >existing users; the new fill routine has no in-tree caller yet. > >v4: > - Reject prealloc / TT caching mismatches (Niranjana) >v5: > - Fix kernel doc (Sashiko) >v6: > - Skip pool probes at orders already found empty during fill (Sashiko) > >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 >Signed-off-by: Matthew Brost >--- > drivers/gpu/drm/ttm/ttm_pool.c | 247 ++++++++++++++++++++++++++++++++- > include/drm/ttm/ttm_bo.h | 23 +-- > include/drm/ttm/ttm_pool.h | 27 +++- > 3 files changed, 274 insertions(+), 23 deletions(-) > >diff --git a/drivers/gpu/drm/ttm/ttm_pool.c b/drivers/gpu/drm/ttm/ttm_pool.c >index bac4d45cc330..3600c2ea56af 100644 >--- a/drivers/gpu/drm/ttm/ttm_pool.c >+++ b/drivers/gpu/drm/ttm/ttm_pool.c >@@ -1107,6 +1107,7 @@ int ttm_pool_prealloc_fill(struct ttm_pool *pool, enum ttm_caching tt_caching, > pp->caching = tt_caching; > pp->count = 0; > pp->used = 0; >+ pp->full = false; > > /* Nothing to gain without a beneficial order or for DMA-alloc pools. */ > if (!order || !count || ttm_pool_uses_dma_alloc(pool)) >@@ -1163,6 +1164,199 @@ int ttm_pool_prealloc_fill(struct ttm_pool *pool, enum ttm_caching tt_caching, > } > EXPORT_SYMBOL(ttm_pool_prealloc_fill); > >+/* >+ * Acquire a single *@order chunk, trying a same-order pool page first (already >+ * carries @caching) then a fresh system allocation (write-back). Runs unlocked. >+ * When @beneficial_reclaim_backoff is set, higher-order system allocations skip >+ * aggressive reclaim/compaction (see ttm_pool_alloc_page()). >+ * >+ * A fresh system page is write-back and needs the tt's caching applied later in >+ * bulk; *@need_caching is set true for it and false for a (pre-cached) pool >+ * page. >+ * >+ * On a genuine failure *@order is left untouched (the caller lowers it by one >+ * and retries). Fault injection instead pretends allocation at (or above) the >+ * beneficial order failed and lowers *@order to the beneficial order, so the >+ * caller's next attempt lands below it - mirroring the in-line acquire path's >+ * fail_beneficial jump and exercising the beneficial_order_failed tracking >+ * without driving the system into real fragmentation. >+ * >+ * @pool_miss is a bitmask of orders whose pool type was found empty earlier in >+ * this fill; those orders skip the pool probe, as ttm_pool_type_take() takes >+ * the list_lru lock even on an empty list (mirrors the in-line acquire path's >+ * allow_pools). A miss here sets the order's bit. >+ * >+ * Returns NULL if no page of *@order could be obtained. >+ */ >+static struct page *ttm_pool_take_page(struct ttm_pool *pool, >+ enum ttm_caching caching, >+ unsigned int *order, gfp_t gfp, >+ bool *need_caching, >+ unsigned long *pool_miss, >+ bool beneficial_reclaim_backoff) >+{ >+ unsigned int beneficial = ttm_pool_beneficial_order(pool); >+ struct ttm_pool_type *pt; >+ struct page *p; >+ >+ *need_caching = false; >+ >+ if (IS_ENABLED(CONFIG_FAULT_INJECTION) && beneficial && >+ *order >= beneficial && >+ should_fail(&beneficial_order_fault_inject, 1)) { >+ *order = beneficial; >+ return NULL; >+ } >+ >+ pt = ttm_pool_select_type(pool, caching, *order); >+ if (pt && !(*pool_miss & BIT(*order))) { >+ p = ttm_pool_type_take(pt, ttm_pool_nid(pool)); >+ if (p) >+ return p; /* pool page already carries @caching */ >+ *pool_miss |= BIT(*order); >+ } >+ >+ p = ttm_pool_alloc_page(pool, gfp, *order, beneficial_reclaim_backoff); >+ if (!p) >+ return NULL; >+ >+ /* Fresh system page is write-back; caller applies @caching in bulk. */ >+ *need_caching = true; >+ return p; >+} >+ >+/** >+ * ttm_pool_prealloc_fill_full() - Preallocate a whole tt's backing outside any >+ * lock >+ * @pool: The pool to allocate from. >+ * @tt_caching: The requested cpu-caching for the pages allocated. >+ * @pp: Prealloc bag to fill; marked @full and tiled with mixed-order chunks. >+ * @num_pages: Number of 4K pages the tt needs backed. >+ * @beneficial_reclaim_backoff: Do not perform aggressive reclaim at the >+ * beneficial order. >+ * >+ * Unlike ttm_pool_prealloc_fill() (which parks a bag of interchangeable >+ * beneficial-order defrag chunks), this allocates the ENTIRE backing for a tt >+ * of @num_pages pages up front, at whatever mix of orders is available (pool >+ * pages included), so that the subsequent __ttm_pool_alloc() under the dma-resv >+ * lock merely installs the pages without stalling in reclaim/compaction. The >+ * chunk orders mirror the in-line allocator's order walk; each chunk's order is >+ * recorded on the page itself and read back at consume time. >+ * >+ * May sleep/reclaim freely as it runs unlocked. When >+ * @beneficial_reclaim_backoff is set, higher-order chunks are taken without >+ * aggressive reclaim/compaction: the caller relies on a background >+ * defragmenter to upgrade to beneficial-order pages in place later, so there >+ * is no need to stall the user context reclaiming for contiguity here. A short >+ * fill is fine: the pool falls back to in-line allocation for the shortfall. >+ * DMA-alloc pools are not supported (the bag stays empty). Returns 0 (release >+ * with ttm_pool_prealloc_fini()). >+ */ >+int ttm_pool_prealloc_fill_full(struct ttm_pool *pool, >+ enum ttm_caching tt_caching, >+ struct ttm_pool_prealloc *pp, >+ unsigned int num_pages, >+ bool beneficial_reclaim_backoff) >+{ >+ gfp_t gfp = ttm_pool_prealloc_gfp(pool) | __GFP_ZERO | >+ __GFP_RETRY_MAYFAIL | __GFP_NOWARN; >+ unsigned int highest = MAX_PAGE_ORDER; >+ unsigned int remaining = num_pages; >+ struct page **cpages = NULL; >+ unsigned int ncpages = 0; >+ unsigned long pool_miss = 0; >+ int r; >+ >+ BUILD_BUG_ON(MAX_PAGE_ORDER >= BITS_PER_LONG); >+ >+ pp->pages = NULL; >+ pp->order = 0; >+ pp->caching = tt_caching; >+ pp->count = 0; >+ pp->used = 0; >+ pp->full = true; >+ >+ /* Caching is applied on the kernel mapping, so DMA-alloc is unsupported. */ >+ if (!num_pages || ttm_pool_uses_dma_alloc(pool)) >+ return 0; >+ >+ /* Worst case is one order-0 chunk per page. */ >+ pp->pages = kvzalloc_objs(*pp->pages, num_pages); >+ if (!pp->pages) >+ return 0; >+ >+ /* >+ * Fresh write-back chunks get their caching changed in a single >+ * set_pages_array_*() after the fill; collect their constituent pages >+ * into an unpacked scratch array (one entry per 4K page) since the >+ * packed bag holds mixed-order chunks. Cached tts and pool pages need >+ * no change (and non-x86 handles caching at map time). >+ */ >+ if (IS_ENABLED(CONFIG_X86) && tt_caching != ttm_cached) { >+ cpages = kvzalloc_objs(*cpages, num_pages); >+ if (!cpages) { >+ kvfree(pp->pages); >+ pp->pages = NULL; >+ return 0; >+ } >+ } >+ >+ while (remaining) { >+ unsigned int order = min_t(unsigned int, highest, >+ __fls(remaining)); >+ bool need_caching; >+ struct page *p; >+ >+ for (;;) { >+ p = ttm_pool_take_page(pool, tt_caching, &order, gfp, >+ &need_caching, &pool_miss, >+ beneficial_reclaim_backoff); >+ if (p) >+ break; >+ if (!order) >+ goto apply_caching; /* short fill */ >+ /* >+ * Genuine failure: retry one order down. A fault >+ * injection lowered @order to the beneficial order >+ * above, so this drops it below - landing on a >+ * sub-optimal (defrag-worthy) chunk. >+ */ >+ order--; >+ } >+ >+ pp->pages[pp->count++] = p; >+ if (cpages && need_caching) >+ ttm_pool_prealloc_stage_caching(cpages, &ncpages, p, >+ order); >+ remaining -= 1u << order; >+ highest = order; >+ } >+ >+apply_caching: >+ /* >+ * Apply the requested caching to every collected page in one shot. On >+ * failure the pages' caching is indeterminate, so drop the whole bag >+ * (freeing restores write-back) and let the consumer allocate in-line. >+ */ >+ r = ttm_pool_prealloc_apply_caching(tt_caching, cpages, ncpages); >+ kvfree(cpages); >+ if (r) { >+ unsigned int i; >+ >+ for (i = 0; i < pp->count; i++) { >+ struct page *p = pp->pages[i]; >+ >+ ttm_pool_free_page(pool, tt_caching, >+ ttm_pool_page_order_nodma(p), p, >+ false); >+ } >+ pp->count = 0; >+ } >+ >+ return 0; >+} >+EXPORT_SYMBOL(ttm_pool_prealloc_fill_full); >+ > /** > * ttm_pool_prealloc_fini() - Release unconsumed preallocated pages > * @pool: The pool the pages came from. >@@ -1172,9 +1366,13 @@ void ttm_pool_prealloc_fini(struct ttm_pool *pool, struct ttm_pool_prealloc *pp) > { > unsigned int i; > >- for (i = pp->used; i < pp->count; ++i) >- ttm_pool_free_page(pool, pp->caching, pp->order, pp->pages[i], >- false); >+ for (i = pp->used; i < pp->count; ++i) { >+ struct page *p = pp->pages[i]; >+ unsigned int order = pp->full ? >+ ttm_pool_page_order_nodma(p) : pp->order; >+ >+ ttm_pool_free_page(pool, pp->caching, order, p, false); >+ } NIT..I totally agree that fixing the shashiko issue reported here about returning unconsumed WC/UC chunks to the TTM pool is not critical as that should rarely happen, it is not on critical path and it is just a minor perf win. But the fix seems simple (as per LLM)... struct ttm_pool_type *pt = ttm_pool_select_type(pool, pp->caching, order); if (pt) ttm_pool_type_give(pt, p); else ttm_pool_free_page(pool, pp->caching, order, p, false); Not sure if it is worth addressing it while we are here. But in anycase, the patch LGTM. Reviewed-by: Niranjana Vishwanathapura > kvfree(pp->pages); > pp->pages = NULL; > pp->count = 0; >@@ -1313,9 +1511,10 @@ static int ttm_pool_iter_reuse_old(struct ttm_pool_alloc_iter *it) > > /* > * Acquire a single page for the current order, leaving it in @it->p (NULL on >- * failure). Tries, in order: a beneficial-order page preallocated outside the >- * dma-resv lock (defrag), a same-order pool page, then a fresh system >- * allocation. Fault injection can force the beneficial-order paths to "fail". >+ * failure). Tries, in order: a chunk from a full out-of-lock prealloc (populate >+ * of the whole tt), a beneficial-order page preallocated outside the dma-resv >+ * lock (defrag), a same-order pool page, then a fresh system allocation. Fault >+ * injection can force the beneficial-order paths to "fail". > */ > static void ttm_pool_iter_acquire_page(struct ttm_pool_alloc_iter *it) > { >@@ -1324,6 +1523,39 @@ static void ttm_pool_iter_acquire_page(struct ttm_pool_alloc_iter *it) > > it->p = NULL; > >+ /* >+ * Full prealloc: the entire backing was allocated (pool + system, at >+ * mixed orders) outside the dma-resv lock. Install the next chunk as-is, >+ * taking its order from the page. Allocates in-line once the >+ * best-effort bag is drained. >+ */ >+ if (pp && pp->full && pp->used < pp->count) { >+ it->fail_beneficial = false; >+ it->p = pp->pages[pp->used++]; >+ it->order = ttm_pool_page_order_nodma(it->p); >+ it->page_caching = it->tt->caching; >+ >+ /* >+ * The full prealloc tiles at whatever orders were available >+ * without stalling in reclaim. A sub-beneficial chunk only >+ * means a sub-optimal backing (defrag-worthy) when it sits in a >+ * beneficial-order aligned region that fully fits in the tt - >+ * that region could have been a beneficial-order page. A low >+ * order in the unaligned trailing tail is expected and must not >+ * flag the tt (mirrors ttm_pool_harvest_remaining()). >+ */ >+ if (it->beneficial_order && it->order < it->beneficial_order) { >+ pgoff_t bnr = 1UL << it->beneficial_order; >+ pgoff_t off = it->tt->num_pages - >+ it->alloc->remaining_pages; >+ >+ if (round_down(off, bnr) + bnr <= it->tt->num_pages) >+ it->tt->page_flags |= >+ TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED; >+ } >+ return; >+ } >+ > /* > * Fault injection: pretend allocation at (or above) the device's > * beneficial order failed, forcing a sub-optimal backing. Exercises the >@@ -1582,7 +1814,8 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt, > int ret; > > if (WARN_ON(ttm_tt_is_backed_up(tt)) || >- WARN_ON(ctx->defrag_bytes_remaining < 0)) >+ WARN_ON(ctx->defrag_bytes_remaining < 0) || >+ WARN_ON(ctx->prealloc && ctx->prealloc->caching != tt->caching)) > return -EINVAL; > > tt->page_flags &= ~TTM_TT_FLAG_BENEFICIAL_ORDER_FAILED; >diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h >index 3055cc411d73..51c4ebd477b3 100644 >--- a/include/drm/ttm/ttm_bo.h >+++ b/include/drm/ttm/ttm_bo.h >@@ -238,16 +238,19 @@ struct ttm_operation_ctx { > */ > s64 defrag_bytes_remaining; > /** >- * @prealloc: Pages preallocated outside the dma-resv lock for a defrag >- * move. The pool allocator consumes these instead of allocating fresh >- * beneficial-order pages under the lock, moving the (potentially >- * reclaim/compaction stalling) high-order allocations out of the >- * critical section. NULL means allocate in-line as usual. The pool >- * never allocates in-line once the bag is drained: the remainder is >- * harvested from the old tt as-is, and a defrag move that allocates no >- * chunk fails with -ENOMEM. The allocator consumes it for >- * beneficial-order chunks of any populate; drivers only set it for a >- * defrag move. >+ * @prealloc: Pages preallocated outside the dma-resv lock. The pool >+ * allocator consumes these instead of allocating under the lock, moving >+ * the (potentially reclaim/compaction stalling) allocations out of the >+ * critical section. NULL means allocate in-line as usual. Two flavours, >+ * distinguished by ttm_pool_prealloc::full: >+ * - defrag bag (full=false): a bag of interchangeable beneficial-order >+ * chunks consumed only for beneficial-order chunks of a defrag move. >+ * - full tiling (full=true): the entire backing of the tt, at mixed >+ * orders, consumed for every chunk of an ordinary populate. >+ * For a full tiling the allocator falls back to in-line allocation >+ * for any shortfall. For a defrag bag it never allocates in-line: >+ * once the bag is drained the remainder is harvested from the old tt >+ * as-is, and a defrag move that allocates no chunk fails with -ENOMEM. > */ > struct ttm_pool_prealloc *prealloc; > /** >diff --git a/include/drm/ttm/ttm_pool.h b/include/drm/ttm/ttm_pool.h >index 3f2e51151af9..dc2fc4e855b2 100644 >--- a/include/drm/ttm/ttm_pool.h >+++ b/include/drm/ttm/ttm_pool.h >@@ -83,18 +83,27 @@ void ttm_pool_free(struct ttm_pool *pool, struct ttm_tt *tt); > > /** > * struct ttm_pool_prealloc - Pages preallocated outside the dma-resv lock >- * @pages: Array of @count beneficial-order pages (or fewer if a fill fell >- * short); each entry is the head page of a 1 << @order chunk. >- * @order: Page order of every preallocated chunk. >+ * @pages: Array of @count preallocated chunks; each entry is the head page of a >+ * chunk. In defrag mode every chunk is @order pages; in @full mode the >+ * chunks tile a whole tt at mixed orders and the per-chunk order is read >+ * back from the page itself. >+ * @order: Page order of every preallocated chunk (defrag mode only; 0 in @full >+ * mode where each chunk carries its own order). > * @caching: CPU caching applied to the pages, so leftovers can be restored > * to write-back before being freed. > * @count: Number of valid entries in @pages. > * @used: Number of entries already consumed by the pool allocator. >+ * @full: When set the bag holds a full, mixed-order tiling of an entire tt >+ * (produced by ttm_pool_prealloc_fill_full()) rather than a bag of >+ * interchangeable beneficial-order defrag chunks. The pool allocator >+ * then drains the bag in order for every populate, taking each chunk's >+ * order from the page, and falls back to in-line allocation only for any >+ * shortfall. > * > * Defrag pages are interchangeable, so only a count of beneficial-order chunks >- * is needed. ttm_pool_prealloc_fill() populates this outside the lock and >- * __ttm_pool_alloc() drains it; any unused tail is released by >- * ttm_pool_prealloc_fini(). >+ * is needed. ttm_pool_prealloc_fill() / ttm_pool_prealloc_fill_full() populate >+ * this outside the lock and __ttm_pool_alloc() drains it; any unused tail is >+ * released by ttm_pool_prealloc_fini(). > */ > struct ttm_pool_prealloc { > struct page **pages; >@@ -102,10 +111,16 @@ struct ttm_pool_prealloc { > enum ttm_caching caching; > unsigned int count; > unsigned int used; >+ bool full; > }; > > int ttm_pool_prealloc_fill(struct ttm_pool *pool, enum ttm_caching tt_caching, > struct ttm_pool_prealloc *pp, unsigned int count); >+int ttm_pool_prealloc_fill_full(struct ttm_pool *pool, >+ enum ttm_caching tt_caching, >+ struct ttm_pool_prealloc *pp, >+ unsigned int num_pages, >+ bool beneficial_reclaim_backoff); > void ttm_pool_prealloc_fini(struct ttm_pool *pool, > struct ttm_pool_prealloc *pp); > unsigned int ttm_pool_prealloc_order(struct ttm_pool *pool); >-- >2.34.1 >