Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp872696rdb; Tue, 30 Jan 2024 00:39:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IGXFav2jH4IsbZ7ky5ZSqInAuyeQwyDJTkkoBvO8v9Enz9pTohWdK60MbjIg2Z4DDF4acDO X-Received: by 2002:a05:622a:1792:b0:42a:5c13:824d with SMTP id s18-20020a05622a179200b0042a5c13824dmr7883534qtk.31.1706603957223; Tue, 30 Jan 2024 00:39:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706603957; cv=pass; d=google.com; s=arc-20160816; b=RCwiQOva+CPYNy11YhP0helT85y5PGQjb2QUReOeKLHgDSZiPtHC7547ynY2MeVHgz 5lg9sfpnnfGgIXtF1wkJfKtIotjko6/ezp2sSFgm1NiPsysVbgTa79JuMKUqAspwnaVT tDOSuMHsvfBIFh0HbdCGqHRW2nJWj9UmybwzYrr8NsXeFe0XshGhLyDaGDdUasePkSTE VT3c6tp5pcFbx5ojErhbnSCxsatCB4UN0YIpCkq0k2yOMl00c4KdqjvxoR1qh/dFt/zn u/nrxaCJIiwFtr2NvOJNA9Ldp0ed5jmWp+bVfQpBwELwUzQCPDKnZWHvQzKBpjtdG/+x Xtmw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:mail-followup-to :message-id:subject:cc:to:from:date:dkim-signature; bh=TE8g68bLoogToLshL4JAe9mPYk5p/5wsw2SHoYT3R4c=; fh=/3voy5nOUfuebLwJtTaRSN2b5yGsBB8CJEG7LtgSSJw=; b=yGKY9CyXUteYGpYBw9g8BjNePnRuzSmHIC+YV9qpyQIYoZzSEMCOJ1RZ/VB848CcR0 pR3iy+j3Y9FLuIHYcfcUYE4Qj2CVICWVctpdmQZq9MIxOquk1xe3IApumEdz4R0W/ySR 4BYYtL5hESEIUg5sDjyCD39uNq6+f4/B6PoN7vl1k6uGPEWatMVV1TR4kixZJ6CmWBRU LcTxxSKrR5ZSpb+mmj96Yt++fDh18y0RIBIetXmXntt12bqY0ShigjWU5orMkBCz66tf wIICY8XPyppz+KGmZfxeZk8zGtEcD/9akgUMZGEy5HD54oQ1CBTMFQsuGjSrZa0OgAI+ I38A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=VLFkN1Km; arc=pass (i=1 dkim=pass dkdomain=ffwll.ch); spf=pass (google.com: domain of linux-kernel+bounces-44151-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44151-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id g12-20020ac85d4c000000b0042ab0364ddbsi2167596qtx.774.2024.01.30.00.39.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 00:39:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-44151-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@ffwll.ch header.s=google header.b=VLFkN1Km; arc=pass (i=1 dkim=pass dkdomain=ffwll.ch); spf=pass (google.com: domain of linux-kernel+bounces-44151-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-44151-linux.lists.archive=gmail.com@vger.kernel.org" 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id E6A101C23952 for ; Tue, 30 Jan 2024 08:39:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4869438393; Tue, 30 Jan 2024 08:39:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="VLFkN1Km" Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF11D5647A for ; Tue, 30 Jan 2024 08:39:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706603949; cv=none; b=N5hTTxqiqnKYhX1ET1ceLJUQdxTla1FJk1aTH1YlbRRIg+BBAxjCUqDofwSCoXXvDrii1eniEjCWd2ledNkLnpPvf460PgKBEt6wUB0QP1TeVKtZsX0QGSXO10FRoprBhGkH1mlgXwL8VVbe3O9qFIbuFDgK9szFI9w6j+puRJE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706603949; c=relaxed/simple; bh=UKBvv/BFlyrDxBcZH/pwwW+bTFeY41MHyLdKXLHf118=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=RcWbZlQA2IBIJQrlVZ0KxIRvkcpcxXd3oO+HZpNt3KEdvrQMx6pJkmoFKkTb6uUPc55m4pwbp1JvlTyPVEGHzm33nJ+95GWF904pqFmGGZMxPdvUKl+tUVaOv5LYpRAiQa1lleSGPT+FODz3uOM558nbHxsyVBaJumslCqFiDRM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch; spf=none smtp.mailfrom=ffwll.ch; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b=VLFkN1Km; arc=none smtp.client-ip=209.85.218.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=ffwll.ch Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a352d9c0f9dso108323166b.0 for ; Tue, 30 Jan 2024 00:39:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; t=1706603946; x=1707208746; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date:from:to:cc :subject:date:message-id:reply-to; bh=TE8g68bLoogToLshL4JAe9mPYk5p/5wsw2SHoYT3R4c=; b=VLFkN1KmuWTsVitoLnBh79rcMLIg3LOLoqWwkQf+bPNukQbpPJTaYrMFXakN42Kcny G6ez3u1M278sO8iOxJ7xvldiPgnYcXcQ+1JLrCJM/R7kINbII56iwpolpooBZsaEDuPE aqoDTzevT0CB1HXbU4RVdkOUuGCut+GMxw7LY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706603946; x=1707208746; h=in-reply-to:content-disposition:mime-version:references :mail-followup-to:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TE8g68bLoogToLshL4JAe9mPYk5p/5wsw2SHoYT3R4c=; b=bXFdAS6i48JbBozqgUfJ9bmttbeX+dLpJSUx6JmtXAoJeabOuXfY1O+TY8AtXVs0Qy ARANU7PPWbWG46GM4H3b6azlUN1JMwYQCprpJSUrJmvXwGPeYydjnoRH2vwsPh+ZWjsH GgnKetx2OxC3Y3rvOHzcP3QvgKXk0XiNzz11S8pMkPVpq3uRAsx2ItmV+9ePfB/uyzir zn6XceHqqYn4iieG9wVPOwBR3ZcWA5LUWWfvYJJ6H8LAiIgFERDr+Ry9fcf3fds5W9YY kJT40+P5w1NxT9cuYVDCJ4S6w+wDP6+ZWrW0NO3N16TD+3kAt49njmpGAYRyMlrCgxN3 ShTQ== X-Gm-Message-State: AOJu0YxAKmKSrf3eFaFf2Z+3mpBwS3alGagMa2VE5S5cCzVJdJ0+uuMO hAmv+SsWqfCYIzjoMalB6ylfCe1pnbTpIyPlHRvXkATPgS69I5EIHbxcdkqrcJ4= X-Received: by 2002:a17:906:6d01:b0:a35:561d:cf5a with SMTP id m1-20020a1709066d0100b00a35561dcf5amr5688909ejr.6.1706603945702; Tue, 30 Jan 2024 00:39:05 -0800 (PST) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id s8-20020a17090699c800b00a351828ca32sm4271064ejn.118.2024.01.30.00.39.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 00:39:05 -0800 (PST) Date: Tue, 30 Jan 2024 09:39:03 +0100 From: Daniel Vetter To: Boris Brezillon Cc: Dmitry Osipenko , David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Christian =?iso-8859-1?Q?K=F6nig?= , 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: Mail-Followup-To: Boris Brezillon , Dmitry Osipenko , David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Christian =?iso-8859-1?Q?K=F6nig?= , 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> <20240125100703.76d802ad@collabora.com> 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-Disposition: inline In-Reply-To: <20240125100703.76d802ad@collabora.com> X-Operating-System: Linux phenom 6.6.11-amd64 On Thu, Jan 25, 2024 at 10:07:03AM +0100, Boris Brezillon wrote: > 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) Might be good to explain where to call drm_sched_job_arm() here for drivers using drm/sched, since that also needs to be at a very specific point. Probably best to flesh out the details here by linking to the relevant drm/sched and gpuvm functions as examples. > 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. Yeah I think the comment needs to explain how this ties together with dma_resv locking and dma_resv fences, otherwise it just doesn't make much sense. This holds even more so given that some of the earlier drivers derived from i915-gem code (and i915-gem itself) use _pin() both for these more permanent pinnings, and also to temporarily put the memory in place before it all gets fenced and then unpinned&unlocked. So would be really good to have the sharpest possible nomeclatura here we can get, and link between all the related concepts and functions in the kerneldoc. Some overview flow like Boris sketched above in a DOC: section would also be great. Cheers, Sima > > > */ > > int drm_gem_shmem_get_pages(struct drm_gem_shmem_object *shmem) -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch