From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (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 A8EA51D6BD for ; Fri, 26 Jan 2024 16:27:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=140.211.166.136 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706286480; cv=none; b=FPXa27xVH8BjgRSaZw2aa/W4Toez4003HH6FjF3pDxEqAA/cLbLXluZLIUJNszpAy4PStBUgN6gLzEKenlvXVqeu7OUnGCKzaBkrZZl/YbuqaUIV4E2QWjzXTOrHBbaoVubfFwYO2inezbenDiZAV91uwWtBiNsgOgfs/nadn4g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706286480; c=relaxed/simple; bh=bfATvgFGy1C+UULaXubImPOXGtd8BvEu9bs2VEk+/Dw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=mr36+zqYDpBdt5CHHrIvhu6rxvk1mQGlYi+hYSC8AGrKdwgJ4U9sEB5YULLu4CL/SWhVPLzNYys2eWvkWkw+3c77B+jLBocx7hfCbcUQAK80xI7B237CX3wR1+ZXpwfyRwbxTvJcxjZyAERADr7q6ZexzBhcoR87Ab6LMOwRPXQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=sCBvO4UI; arc=none smtp.client-ip=140.211.166.136 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="sCBvO4UI" Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 3EF5D614E1 for ; Fri, 26 Jan 2024 16:27:57 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 3EF5D614E1 Authentication-Results: smtp3.osuosl.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=sCBvO4UI X-Virus-Scanned: amavisd-new at osuosl.org X-Spam-Flag: NO X-Spam-Score: -2.1 X-Spam-Level: Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8pxSkSPbNUOY for ; Fri, 26 Jan 2024 16:27:56 +0000 (UTC) Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [IPv6:2a00:1098:ed:100::25]) by smtp3.osuosl.org (Postfix) with ESMTPS id 29F4660BAC for ; Fri, 26 Jan 2024 16:27:56 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 29F4660BAC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706286473; bh=bfATvgFGy1C+UULaXubImPOXGtd8BvEu9bs2VEk+/Dw=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=sCBvO4UIouCEmJXzxqhm0SshcENzhxQdzX0Ocvo34m24MIWT1NPDpdD8VvY6p0fy0 hX9gcK9H2vZArf3s2YTSQDD35NhF3W+dJJX66Jr4xNCsb2yyHujIzRw+8u1iMqHydj MYXEo3txYBnr2zSxMgLextGneTBTMta24DazKJLef/lU05FoJ3FGXEsU1K9I9kRwrb UE7DOoB/eP3bW6+HrZgT6rVfw9Uj/sMVVhXIMemG7R2sKwrg+G4RC9bpoLOOzkUjc8 r/eppjQtRE0/C3od/3tcmkeiNkjDwNLut4TejaqdnPhosvebrZH50F69DQA+EVnGMa vQzB+px0U5RVA== Received: from [100.109.49.129] (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dmitry.osipenko) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 2322A378107C; Fri, 26 Jan 2024 16:27:52 +0000 (UTC) Message-ID: Date: Fri, 26 Jan 2024 19:27:49 +0300 Precedence: bulk X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v19 22/30] drm/shmem-helper: Add common memory shrinker Content-Language: en-US To: Boris Brezillon Cc: David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , =?UTF-8?Q?Christian_K=C3=B6nig?= , 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 References: <20240105184624.508603-1-dmitry.osipenko@collabora.com> <20240105184624.508603-23-dmitry.osipenko@collabora.com> <20240125111946.797a1e1e@collabora.com> <20240126105537.67b1613e@collabora.com> From: Dmitry Osipenko In-Reply-To: <20240126105537.67b1613e@collabora.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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)? > 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. -- Best regards, Dmitry