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 E99C7C48BF6 for ; Thu, 29 Feb 2024 15:08:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B65A310E39E; Thu, 29 Feb 2024 15:08:55 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=amd.com header.i=@amd.com header.b="tghmHuKD"; dkim-atps=neutral Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2077.outbound.protection.outlook.com [40.107.244.77]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3902B10E39E; Thu, 29 Feb 2024 15:08:54 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EckK06Tw6tmW1KDcZYu3j1TBVA1lAfgnguAGwqI1TqvA/SXQdVYuQEiWOxJBhgkaxP913hblYGHWoODYboBjpR/4fozM968ElbikgK2/eCUGuS1yRyvdCdgMrcdHBm6Uqa9hnK0j+fgjWar1kP5wN27mZuB0jaEl/lLcffYyBItqTGkMBejPA2hJGlLsk+wIV2wWrcIagMtxMRFRdwOF7J17DLFo4/9ZPiAQSvCYKNMMWg7Q5WeD0OY0KjVh7uoKuaCdZAuyy2tYxPKkryJlfsPaxHUbF3G0hpEDV87DoEGK356I6tZPKOxkpSK4HZhRBb0xhxhnrO/rAf5BlCuyAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=b+pI9yGibRVNMtgsTkOjnM60QobhnTu5WdP5HpkUZZc=; b=cyauHZbVUgBACg0jvWMwZKY9CfjpzUb3WW8fGXDuH5LdqrrMmjCd+hN1ciPLoAm6NVro194K5jsWHfdmgbl/n87ga1TXBmxdfEgxot28XxzH1YYveJZ1T1zoxxE5RdnEPUCnx+WocTHVNY4Kw6YwDirAIOOzQWqyFd5JkfItUG6Ybbftovn8O+5zP2QsXpLRKWCLQ0YKZ3LoWnLdcwlCrgo5euaHNt0aLlbA5RfzdIO+wXil58BOobpGvh8TTUNzhzv+H5kulz/dBCrucYMakEW8MSjuSgzEYFZlcEPQNHt+nm1f0dlGs4y3mU7JXmv8SKsyPSllN6uMRfiqprOvLw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=b+pI9yGibRVNMtgsTkOjnM60QobhnTu5WdP5HpkUZZc=; b=tghmHuKDxXQcVFMGN2RdkRcV+/unZWO/QDwBSKAf283PCraLY3BZqh/uD/fPDHpI2Nw20673lWbhJXWjBgRmYQiPQsjYQRVufyxAFCbzLCw7NBnUibNcCYxNtnwP3zsQeuwo/hhakN/OVFoJxDGuJY8NXVQV/ahleexBT2LXzOA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from PH7PR12MB5685.namprd12.prod.outlook.com (2603:10b6:510:13c::22) by CH3PR12MB7500.namprd12.prod.outlook.com (2603:10b6:610:148::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.41; Thu, 29 Feb 2024 15:08:50 +0000 Received: from PH7PR12MB5685.namprd12.prod.outlook.com ([fe80::f2b6:1034:76e8:f15a]) by PH7PR12MB5685.namprd12.prod.outlook.com ([fe80::f2b6:1034:76e8:f15a%6]) with mapi id 15.20.7316.031; Thu, 29 Feb 2024 15:08:50 +0000 Content-Type: multipart/alternative; boundary="------------3jjBzPfZ2sKtzPi1eA02MLjj" Message-ID: Date: Thu, 29 Feb 2024 16:08:45 +0100 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 0/4] TTM unlockable restartable LRU list iteration Content-Language: en-US To: =?UTF-8?Q?Thomas_Hellstr=C3=B6m?= , intel-xe@lists.freedesktop.org, intel-gfx@list.freedesktop.org Cc: dri-devel@lists.freedesktop.org References: <20240216131306.101932-1-thomas.hellstrom@linux.intel.com> <29000a0d-19ce-4727-945b-d5734313c7f1@amd.com> <47fc8e42dcfd868341ffc32754c302e58ac49484.camel@linux.intel.com> From: =?UTF-8?Q?Christian_K=C3=B6nig?= In-Reply-To: <47fc8e42dcfd868341ffc32754c302e58ac49484.camel@linux.intel.com> X-ClientProxiedBy: FR5P281CA0041.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:f3::19) To PH7PR12MB5685.namprd12.prod.outlook.com (2603:10b6:510:13c::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PH7PR12MB5685:EE_|CH3PR12MB7500:EE_ X-MS-Office365-Filtering-Correlation-Id: a3196a9e-19cf-4cea-1d9f-08dc393855b0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cwCsMVgK6B5G8EIxS00NDKESNLDzXAHPgII8/1h+8VmWJHpFDnd/rgbMHmzDvq0ItgpnSVwNe6F1Elp8TqMI6nT3IQ3aVWMHx1ZOiGWVAEUpI9lDsGTrfW53vjBCEG/zc1mfcM2DRZ56roEZ0YgAnLKjdejDRFslLqBl7Nu8v6Y4t8lVbQ9cnvtbcqRXvcYj5HmGJsyTWXr4eD1X8jBbvDAP9/VMRQAWSJcsPpCxxPcsGPV3GjykCi1U7/1zT4BoFQ9ucu2+A8yaTh40g98yTqyROXRBHW6A2t4by12J5pcSm0gPcRbeusUFut4GJB1VC5+F4y1gI01Qrr/Eg1xVT8QKiCxdduhNT9Tjj7cBvWEORx5u/bQEo4jH6yMwAGDYPmmmwwRpqBrxjiPabHXcLEYPKBgOQ4wHmev+vGbpe+jQ5zMmC06coJyIu3MRS7/NclBzHpisPi/tJkgd0oOtIIpVWQlKd0hxNAATbtGn2tjPrNmcknGRE+GwUdOPNNS5NcwIuUxF6e8VBJwRXfnhsHjsGeoMAZo7fWyYetjHdIAJtr9l79196hdphPTDKtovN12pgJHZGPGt5V4nt6kdVg7oQJjC+oUx7/Vpg01LQTU8JCD2tfbP6ziS/IelT9LZ+Y9L8DvqAy9UiucKTIQD1g== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PH7PR12MB5685.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?OVQzWTRmL2dRTXVabFVVKzllTUd0R1gwSlNGY0VVQUZhTXEreUFCaHhGODM4?= =?utf-8?B?elFuV1dhbG5NcTJENytJOGhUTGVGbCtpUDIrMTI3b3lyeXNUOER3RFRDaXdV?= =?utf-8?B?alphZHlFcktOSDc1aVV2MTNSU29rdDYveEFHZERXa2Zvc0kxL1o0ZEZoTjZ1?= =?utf-8?B?eERFbCtIcExSRVkyVTNRRDNBU2RzZDYwY1VhVk03NHcySm5EaDVtbWY4Mko1?= =?utf-8?B?YktLVFZRMU45UEhpbGc0YkkwcmRmbUZ3QnBGd1VGMnNqMGVUYTVUckVKYnBq?= =?utf-8?B?WjVkazY4VFN6ZlNUbkNESDJjbm03N2diKytke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CxxxoNCIDMbwlfi?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: a3196a9e-19cf-4cea-1d9f-08dc393855b0 X-MS-Exchange-CrossTenant-AuthSource: PH7PR12MB5685.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Feb 2024 15:08:50.1216 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: lTw9P0L8G1NiENS8FW9QIiXTzmQl5fWIEdlY6DdWQQfrZUVveaPz4PEgC9E2cvov X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB7500 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" --------------3jjBzPfZ2sKtzPi1eA02MLjj Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Am 16.02.24 um 15:20 schrieb Thomas Hellström: [SNIP] >> My approach was basically to not only lock the current BO, but also >> the >> next one. Since only a locked BO can move on the LRU we effectively >> created an anchor. >> >> Before I dig into the code a couple of questions: > These are described in the patches but brief comments inline. > >> 1. How do you distinct BOs and iteration anchors on the LRU? > Using a struct ttm_lru_item, containing a struct list_head and the > type. List nodes embeds this instead of a struct list_head. This is > larger than the list head but makes it explicit what we're doing. Need to look deeper into the code of this, but it would be nice if we could abstract that better somehow. >> 2. How do you detect that a bulk list moved on the LRU? > An age u64 counter on the bulk move that we're comparing against. It's > updated each time it moves. > > >> 3. How do you remove the iteration anchors from the bulk list? > A function call at the end of iteration, that the function iterating is > requried to call. Thinking quite a bit about that in the last week and I came to the conclusion that this might be overkill. All BOs in a bulk share the same reservation object. So when you acquired one you can just keep the dma-resv locked even after evicting the BO. Since moving BOs requires locking the dma-resv object the whole problem then just boils down to a list_for_each_element_safe(). That's probably a bit simpler than doing the add/remove dance. Regards, Christian. > > > /Thomas > >> Regards, >> Christian. >> >>> The restartable property is used in patch 4 to restart swapout if >>> needed, but the main purpose is this paves the way for >>> shrinker- and exhaustive eviction. >>> >>> Cc: Christian König >>> Cc: >>> >>> Thomas Hellström (4): >>>    drm/ttm: Allow TTM LRU list nodes of different types >>>    drm/ttm: Use LRU hitches >>>    drm/ttm: Consider hitch moves within bulk sublist moves >>>    drm/ttm: Allow continued swapout after -ENOSPC falure >>> >>>   drivers/gpu/drm/ttm/ttm_bo.c       |   1 + >>>   drivers/gpu/drm/ttm/ttm_device.c   |  33 +++-- >>>   drivers/gpu/drm/ttm/ttm_resource.c | 202 +++++++++++++++++++++++- >>> ----- >>>   include/drm/ttm/ttm_resource.h     |  91 +++++++++++-- >>>   4 files changed, 267 insertions(+), 60 deletions(-) >>> --------------3jjBzPfZ2sKtzPi1eA02MLjj Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit Am 16.02.24 um 15:20 schrieb Thomas Hellström:
[SNIP]
My approach was basically to not only lock the current BO, but also
the 
next one. Since only a locked BO can move on the LRU we effectively 
created an anchor.

Before I dig into the code a couple of questions:
These are described in the patches but brief comments inline.

1. How do you distinct BOs and iteration anchors on the LRU?
Using a struct ttm_lru_item, containing a struct list_head and the
type. List nodes embeds this instead of a struct list_head. This is
larger than the list head but makes it explicit what we're doing.

Need to look deeper into the code of this, but it would be nice if we could abstract that better somehow.

2. How do you detect that a bulk list moved on the LRU?
An age u64 counter on the bulk move that we're comparing against. It's
updated each time it moves.


3. How do you remove the iteration anchors from the bulk list?
A function call at the end of iteration, that the function iterating is
requried to call.

Thinking quite a bit about that in the last week and I came to the conclusion that this might be overkill.

All BOs in a bulk share the same reservation object. So when you acquired one you can just keep the dma-resv locked even after evicting the BO.

Since moving BOs requires locking the dma-resv object the whole problem then just boils down to a list_for_each_element_safe().

That's probably a bit simpler than doing the add/remove dance.

Regards,
Christian.



/Thomas

Regards,
Christian.

The restartable property is used in patch 4 to restart swapout if
needed, but the main purpose is this paves the way for
shrinker- and exhaustive eviction.

Cc: Christian König <christian.koenig@amd.com>
Cc: <dri-devel@lists.freedesktop.org>

Thomas Hellström (4):
   drm/ttm: Allow TTM LRU list nodes of different types
   drm/ttm: Use LRU hitches
   drm/ttm: Consider hitch moves within bulk sublist moves
   drm/ttm: Allow continued swapout after -ENOSPC falure

  drivers/gpu/drm/ttm/ttm_bo.c       |   1 +
  drivers/gpu/drm/ttm/ttm_device.c   |  33 +++--
  drivers/gpu/drm/ttm/ttm_resource.c | 202 +++++++++++++++++++++++-
-----
  include/drm/ttm/ttm_resource.h     |  91 +++++++++++--
  4 files changed, 267 insertions(+), 60 deletions(-)


      

    

--------------3jjBzPfZ2sKtzPi1eA02MLjj--