Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp775586rdb; Fri, 26 Jan 2024 10:12:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IGePuA27ffICwKVKSfhTm5YqJqVawLGDDb9AHcguPY2XTBdRlGJVdSSr4ckXRzhKUaRiOJy X-Received: by 2002:a17:902:6b89:b0:1d7:6f4f:c61a with SMTP id p9-20020a1709026b8900b001d76f4fc61amr124614plk.36.1706292767600; Fri, 26 Jan 2024 10:12:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706292767; cv=pass; d=google.com; s=arc-20160816; b=q6kUupJSwE+9JqsKz71UmizPHCGbRVG1dZW3xNa6QdNHoYapgnknHvOOuMs923m4Y0 NxOyIir+I6LBCXKDc+wDnRzjyb4Sch24cyslhSJMOQbEgr3T4BMteyH5p5S2f6jP1p6g XRxSFN4BFLfvxGkVLDXn9JZzP+dU3sJG0RdXrn7rOh8nN3S6+EDuy2j1PsFdXkOPBfOo QF+H6kodAgjbHawXAt8DE1l3JCsH1lLW+6Gss8eyoSqPYbnAieRGg2lp9bzwpxIujOqv nzu3z1iIww+J+sbsa2KngH8x1LdxjVYpS5m2g2uhYi3qYwhsqm0V1xCm+AygYHhx8h04 4QCw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:organization:references :in-reply-to:message-id:subject:cc:to:from:date:dkim-signature; bh=nwRrviKgEmi/ZpcvHeLFBXtnC9zu190FnwdmXbbXeyw=; fh=uxLNaPoPRUzmkUc1KOgGwCEU/bTSjK8Yed2Up6ovXLY=; b=mtMHcTWUbgllIWkjSxaotvp6aXJiRT+UAvRJ3AIkBcYwsZD/5OZ5KSVQCYiSqJGd5Y 2tsEjMWlvNVk+exejkSeGSyF4UIldooChz3JXVGvL1vH2XcVF7Usp56K/myF+SR+5HYC VzW2LS8XjjU8l6o+/hM/6c7ghSeMiI3naHxMmNjfkJtEAE4BsDFChOcum2PDs7aMBiWw ByVQxNtbSuQ/6BwnL2crRdh4Y2Ya8S/euoZZxI0yWL5flXABH2eKvOpTHZc7h1Qq53GE c8raNq05BVfHlTktRQiZJ/tcH7geEA8WcvBmM60jFXsfEQCPXyuMlkpbnooU26RwFYO7 BUsg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=z2Mcdipo; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-40474-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40474-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id k12-20020a170902f28c00b001d7584cd1dcsi1440044plc.369.2024.01.26.10.12.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 10:12:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-40474-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=z2Mcdipo; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-40474-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40474-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id F1BB8B21C2C for ; Fri, 26 Jan 2024 18:12:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B741F208CA; Fri, 26 Jan 2024 18:12:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="z2Mcdipo" Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1C63D20326 for ; Fri, 26 Jan 2024 18:12:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706292756; cv=none; b=X7wZUtQX1GtMFeiCKjs58zmnzKkMEPfa9y66kzpvibxg8ZK1VrpjegEorEwHRX49wXuqLnbjCVdRruY+SkJMUyBuX1TH+whGWU6xHkX/rS7jlpvoCZBXR3Yg80mkLoanMjdydJM3noz9Ke7Fw/Oomo6nVeIOlXsbW2pfs038Y6k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706292756; c=relaxed/simple; bh=JDNIvZuMGsH6s984qiL/y1FXodR70awLtoCBhq6levQ=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LnSaUg41iWsz9xsDU1Z6RwIdRrE7Cjwx0o4xZgQH58Q0dHLAsrL8z0UpwdQerZ2iTZ5xcHyUAOiGPmJIrk8bn3A5of5/9+azWajIbw4hPV8DJe/FdUBjxblbcAb+7Sj/cF1h/Yggn+lqJZQU9X5i6lm2TAZBD58uSAKkA8eWHLE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=z2Mcdipo; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706292752; bh=JDNIvZuMGsH6s984qiL/y1FXodR70awLtoCBhq6levQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=z2Mcdipo1S1x+3LnuallCP+ps+hfIolUneIOMhEuL0j5VKCpnQeAAe8SHcmwZQIqC TIbPXqcZorydPCbzKAdc62baRjreH8vAXWA+6K4nZw132svW/vsZWqOxBj6+dJ4lsP /VNcDqhT8EDuYSEW6LcrYPH6yh3fNXzpvS8oNeOiU+MhdyNGRu+9AY51izH5Z0Zekc BqmHfGEpSP7iWDlhbA636AVY3RKpsCeuTZ4hQdUFhbenRh+sLaQ0xNv5/o6IwotJIk LO5JiC6EQZ49jFoY87NDuVKVoCMjnMmTJlnpfzmhJXKV/TNuWx5nCIWV315YbXTAoo 86XAstgCeIBXQ== Received: from localhost (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bbrezillon) by madrid.collaboradmins.com (Postfix) with ESMTPSA id E055237813DA; Fri, 26 Jan 2024 18:12:31 +0000 (UTC) Date: Fri, 26 Jan 2024 19:12:30 +0100 From: Boris Brezillon To: Dmitry Osipenko Cc: David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Christian =?UTF-8?B?S8O2bmln?= , Qiang Yu , Steven Price , Emma Anholt , Melissa Wen , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel@collabora.com, virtualization@lists.linux-foundation.org Subject: Re: [PATCH v19 22/30] drm/shmem-helper: Add common memory shrinker Message-ID: <20240126191230.0ee6f99f@collabora.com> In-Reply-To: References: <20240105184624.508603-1-dmitry.osipenko@collabora.com> <20240105184624.508603-23-dmitry.osipenko@collabora.com> <20240125111946.797a1e1e@collabora.com> <20240126105537.67b1613e@collabora.com> Organization: Collabora X-Mailer: Claws Mail 4.2.0 (GTK 3.24.38; x86_64-redhat-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 26 Jan 2024 19:27:49 +0300 Dmitry Osipenko wrote: > On 1/26/24 12:55, Boris Brezillon wrote: > > On Fri, 26 Jan 2024 00:56:47 +0300 > > Dmitry Osipenko wrote: > > > >> On 1/25/24 13:19, Boris Brezillon wrote: > >>> On Fri, 5 Jan 2024 21:46:16 +0300 > >>> Dmitry Osipenko wrote: > >>> > >>>> +static bool drm_gem_shmem_is_evictable(struct drm_gem_shmem_object *shmem) > >>>> +{ > >>>> + return (shmem->madv >= 0) && shmem->base.funcs->evict && > >>>> + refcount_read(&shmem->pages_use_count) && > >>>> + !refcount_read(&shmem->pages_pin_count) && > >>>> + !shmem->base.dma_buf && !shmem->base.import_attach && > >>>> + !shmem->evicted; > >>> > >>> Are we missing > >>> > >>> && dma_resv_test_signaled(shmem->base.resv, > >>> DMA_RESV_USAGE_BOOKKEEP) > >>> > >>> to make sure the GPU is done using the BO? > >>> The same applies to drm_gem_shmem_is_purgeable() BTW. > >>> > >>> If you don't want to do this test here, we need a way to let drivers > >>> provide a custom is_{evictable,purgeable}() test. > >>> > >>> I guess we should also expose drm_gem_shmem_shrinker_update_lru_locked() > >>> to let drivers move the GEMs that were used most recently (those > >>> referenced by a GPU job) at the end of the evictable LRU. > >> > >> We have the signaled-check in the common drm_gem_evict() helper: > >> > >> https://elixir.bootlin.com/linux/v6.8-rc1/source/drivers/gpu/drm/drm_gem.c#L1496 > > > > Ah, indeed. I'll need DMA_RESV_USAGE_BOOKKEEP instead of > > DMA_RESV_USAGE_READ in panthor, but I can add it in the driver specific > > ->evict() hook (though that means calling dma_resv_test_signaled() > > twice, which is not great, oh well). > > Maybe we should change drm_gem_evict() to use BOOKKEEP. The > test_signaled(BOOKKEEP) should be a "stronger" check than > test_signaled(READ)? It is, just wondering if some users have a good reason to want READ here. > > > The problem about the evictable LRU remains though: we need a way to let > > drivers put their BOs at the end of the list when the BO has been used > > by the GPU, don't we? > > If BO is use, then it won't be evicted, while idling BOs will be > evicted. Hence, the used BOs will be naturally moved down the LRU list > each time shrinker is invoked. > That only do the trick if the BOs being used most often are busy when the shrinker kicks in though. Let's take this scenario: BO 1 BO 2 shinker busy idle (first-pos-in-evictable-LRU) busy idle (second-pos-in-evictable-LRU) busy idle busy idle busy idle find a BO to evict pick BO 2 busy (swapin) idle If the LRU had been updated at each busy event, BO 1 should have been picked for eviction. But we evicted the BO that was first recorded idle instead of the one that was least recently recorded busy.