Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1635523rdb; Thu, 25 Jan 2024 01:19:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IEzWBv/vxhDQngWMhwb+RKZtEOhu0krsaxSH6KISf94MsHDGg6cj4k2dMtrKBuYXsqGNZOs X-Received: by 2002:ac2:4c02:0:b0:50e:6168:c99d with SMTP id t2-20020ac24c02000000b0050e6168c99dmr297792lfq.27.1706174370669; Thu, 25 Jan 2024 01:19:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706174370; cv=pass; d=google.com; s=arc-20160816; b=vgIibl+8ceQF1qsM2eLhZgVg82uLjw4MCmpa89+tqp4+3ROdaxjMYqKCei6YF6Gvnd K7pnyXkRmgroJgbpyY91FdpBmI7uT76C3Q/O+FBOi7PyWp0Xk6CvFe7C9B3AQ48hHQHc 4ZXy1NBLXquvTVOK4ILYQXQOYdDVDAUxmSY1dW5kA+2R3opUqAPNKk5+eNKsqNEW89b/ zs23lpx3Go0RVgiRg+UhZ9JiPG93ZE0aWVHMN1p5OsSMLnWRz9e3NxKSp41O/XXfXHh8 7sMVLTN7KEnKVrw5B1ML/tl1jmssdsEMF8XiYOdVW/ZtTxY7wh9mxazMsntR+Nsu3hk1 dfCg== 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=fRL6ulzzls0xoqOC+vO/WCpyJwNj+K+Ysd83fa70aiw=; fh=uxLNaPoPRUzmkUc1KOgGwCEU/bTSjK8Yed2Up6ovXLY=; b=Sio0uAUGZvjDMzeMkcCwEo5yu9OcImDRAfVgKE9Jq8pGtEJvYdhE/YfcXudgWjMTml KbZhQpOunWkXdaUnjX57blu51uKtX93EFRmee32Ekho/bSy40Z68xN4ea49Km7wwsIxo 3698Lh8ceafY4BCLAzP4xvl7qCMTaUSe8wih3ZOz3eGCGOY4qHiCEP6jn8fiJQsn8Q5A GyoyBOylV65UWLjxqGYE4l/rYbFsV8RdFF5wW4ivAI3sJ3jtU/CT5d4AyQ7X1KQYB0Nw afPkw/JznCxvqiPfxDqmkB3oUC6aw5xgD/QWn2CY31fXtwQOy3ddqz+QmHJ2T2NPraUl PoQA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=XJdgAyCR; 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-38235-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38235-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id t35-20020a056402242300b0055536f0db2esi14917064eda.155.2024.01.25.01.19.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 01:19:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38235-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=XJdgAyCR; 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-38235-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38235-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 03C221F2FA8E for ; Thu, 25 Jan 2024 09:10:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BA2DF1BDE2; Thu, 25 Jan 2024 09:07:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="XJdgAyCR" 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 677A91BDDA for ; Thu, 25 Jan 2024 09:07:07 +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=1706173628; cv=none; b=WS3GAL5pwYN7Usv/LfZT63wfRqzqZsaYZtt7bIbRBLELrCYGaDQJ02tmIrQUWXybM8pKJhI9Oef7p/C9hMpjQS32xaQWUZ1JDIpfEJtpNbWcfDfz/kCN3M1ZRjetlRK27gwkjAZgo2ntGZB47WkVF/T69plWsyMhInXsADf+aUQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706173628; c=relaxed/simple; bh=jmxwkZEbRI0XAx+cYJ9cpE0ROLMlbdLaVvy/jQgXN+k=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=n+7ujEPbfriM5jd+TGY4eGn69hUafy33ZUphYmW8EyQ9lC2gzwJdJkemcqFbWD6DTjMr1991EHGTZpuTwFJwy7Em0+imz/11D/xGcshpfnCHlzmToHzdCEQvgeQtXYL5CFzGsCGjOoAzvj5V0r0+g8Ovysjru0wvsL7d1pKZki4= 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=XJdgAyCR; 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=1706173625; bh=jmxwkZEbRI0XAx+cYJ9cpE0ROLMlbdLaVvy/jQgXN+k=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=XJdgAyCRCGRT5DZYiJj70aIqs9zLKE3ws7azgqOUKukhW8MrG7e30kyqaQrg6pZ/J SjlBmKORjFGH0UJk9kC//JPytCbBFzL4bp9od75RK2NDfH+7O005+UUqwet/hfBx+S GsL/eKTgsKTtZOC/DDaCxr6OnY+lPxCWn6lkP0SzeJgFCbFlREWsJPN51u25R61ZCy nRFY5YLfNHLWDu8KndWfMdqEiOdwYwFLMJsgtv9LHCknZt9ob0UrjHmMoLVdNaDYnP wJ9b9gjuSaklo5rFWUUS8ZD1E4NFN8CCMD7EeZp5hR7adRcqPzlduZ7g57t0v4r9Dp rKhAqRsiXmH2g== 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 44F1437813C4; Thu, 25 Jan 2024 09:07:04 +0000 (UTC) Date: Thu, 25 Jan 2024 10:07:03 +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: <20240125100703.76d802ad@collabora.com> In-Reply-To: <20240105184624.508603-23-dmitry.osipenko@collabora.com> References: <20240105184624.508603-1-dmitry.osipenko@collabora.com> <20240105184624.508603-23-dmitry.osipenko@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, 5 Jan 2024 21:46:16 +0300 Dmitry Osipenko wrote: > * > * This function Increases the use count and allocates the backing pages if > * use-count equals to zero. > + * > + * Note that this function doesn't pin pages in memory. If your driver > + * uses drm-shmem shrinker, then it's free to relocate pages to swap. > + * Getting pages only guarantees that pages are allocated, and not that > + * pages reside in memory. In order to pin pages use drm_gem_shmem_pin(). I still find this explanation confusing, if pages are allocated, they reside in memory. The only difference between drm_gem_shmem_get_pages() and drm_gem_shmem_pin_pages() is that the former lets the system reclaim the memory if the buffer is idle (no unsignalled fence attached to the dma_resv). We also need to describe the workflow for GEM validation (that's the TTM term for the swapin process happening when a GPU job is submitted). 1. Prepare the GPU job and initialize its fence 2. Lock the GEM resv 3. Add the GPU job fence to the resv object 4. If the GEM is evicted a. call drm_gem_shmem_swapin_locked() b. get the new sgt with drm_gem_shmem_get_pages_sgt_locked() c. repopulate the MMU table (driver internals) 5. Unlock the GEM dma_resv 6. Submit the GPU job With this sequence, the GEM pages are guaranteed to stay around until the GPU job is finished. > */ > int drm_gem_shmem_get_pages(struct drm_gem_shmem_object *shmem)