public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@collabora.com>
To: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Cc: "David Airlie" <airlied@gmail.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Gurchetan Singh" <gurchetansingh@chromium.org>,
	"Chia-I Wu" <olvaffe@gmail.com>,
	"Daniel Vetter" <daniel@ffwll.ch>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"Christian König" <christian.koenig@amd.com>,
	"Qiang Yu" <yuq825@gmail.com>,
	"Steven Price" <steven.price@arm.com>,
	"Emma Anholt" <emma@anholt.net>, "Melissa Wen" <mwen@igalia.com>,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	kernel@collabora.com, virtualization@lists.linux-foundation.org
Subject: Re: [PATCH v17 13/18] drm/shmem-helper: Add memory shrinker
Date: Tue, 26 Sep 2023 09:43:07 +0200	[thread overview]
Message-ID: <20230926094307.506f4b93@collabora.com> (raw)
In-Reply-To: <64e8708a-bb73-96ae-90af-f7b51317613b@collabora.com>

On Tue, 26 Sep 2023 03:37:22 +0300
Dmitry Osipenko <dmitry.osipenko@collabora.com> wrote:

> On 9/15/23 11:46, Boris Brezillon wrote:
> >> -static int drm_gem_shmem_get_pages_locked(struct drm_gem_shmem_object *shmem)
> >> +static int
> >> +drm_gem_shmem_acquire_pages(struct drm_gem_shmem_object *shmem, bool init)
> >>  {
> >>  	struct drm_gem_object *obj = &shmem->base;
> >>  	struct page **pages;
> >>  
> >>  	dma_resv_assert_held(shmem->base.resv);
> >>  
> >> -	if (refcount_inc_not_zero(&shmem->pages_use_count))
> >> +	if (shmem->madv < 0) {
> >> +		drm_WARN_ON(obj->dev, shmem->pages);
> >> +		return -ENOMEM;
> >> +	}
> >> +
> >> +	if (shmem->pages) {
> >> +		drm_WARN_ON(obj->dev, !shmem->evicted);
> >>  		return 0;
> >> +	}
> >> +
> >> +	if (drm_WARN_ON(obj->dev, !(init ^ refcount_read(&shmem->pages_use_count))))
> >> +		return -EINVAL;  
> > OOC, why do we care? Is there any difference between initial and re-pin
> > that make the page allocation impossible? Feels like, if there's a
> > check to do, it should be done in the caller instead, and you can drop
> > the init param here.  
> 
> This is a sanity check that addresses additional refcnt tracking
> complexity imposed by shrinker.
> 
> This function is used by both init and re-pin that is invoked from
> several places in the code. It's not trivial to move that check to the
> callers.

drm_gem_shmem_acquire_pages() is called twice, once with init=false,
once with init=true. If you really care about this check, it can
be moved to the callers so

1/ it's clearer (the XOR operation between init and refcount to check if
refcount is zero on init and non-zero otherwise is convoluted)
2/ it doesn't leak to the function whose purpose it to [re-]acquire
pages


  reply	other threads:[~2023-09-26  7:43 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-14 23:27 [PATCH v17 00/18] Add generic memory shrinker to VirtIO-GPU and Panfrost DRM drivers Dmitry Osipenko
2023-09-14 23:27 ` [PATCH v17 01/18] drm/gem: Change locked/unlocked postfix of drm_gem_v/unmap() function names Dmitry Osipenko
2023-09-14 23:27 ` [PATCH v17 02/18] drm/gem: Add _locked postfix to functions that have unlocked counterpart Dmitry Osipenko
2023-09-14 23:27 ` [PATCH v17 03/18] drm/shmem-helper: Make all exported symbols GPL Dmitry Osipenko
2023-09-14 23:27 ` [PATCH v17 04/18] drm/shmem-helper: Refactor locked/unlocked functions Dmitry Osipenko
2023-09-14 23:27 ` [PATCH v17 05/18] drm/shmem-helper: Remove obsoleted is_iomem test Dmitry Osipenko
2023-09-14 23:27 ` [PATCH v17 06/18] drm/shmem-helper: Add and use pages_pin_count Dmitry Osipenko
2023-09-14 23:27 ` [PATCH v17 07/18] drm/shmem-helper: Use refcount_t for pages_use_count Dmitry Osipenko
2023-09-15  7:06   ` Boris Brezillon
2023-09-14 23:27 ` [PATCH v17 08/18] drm/shmem-helper: Add and use lockless drm_gem_shmem_get_pages() Dmitry Osipenko
2023-09-14 23:27 ` [PATCH v17 09/18] drm/shmem-helper: Switch drm_gem_shmem_vmap/vunmap to use pin/unpin Dmitry Osipenko
2023-09-14 23:27 ` [PATCH v17 10/18] drm/shmem-helper: Use refcount_t for vmap_use_count Dmitry Osipenko
2023-09-26  4:50   ` kernel test robot
2023-09-14 23:27 ` [PATCH v17 11/18] drm/shmem-helper: Improve drm_gem_shmem_vmap_locked() error handling Dmitry Osipenko
2023-09-15  7:18   ` Boris Brezillon
2023-09-14 23:27 ` [PATCH v17 12/18] drm/shmem-helper: Prepare drm_gem_shmem_free() to shrinker addition Dmitry Osipenko
2023-09-15  7:27   ` Boris Brezillon
2023-09-14 23:27 ` [PATCH v17 13/18] drm/shmem-helper: Add memory shrinker Dmitry Osipenko
2023-09-15  8:46   ` Boris Brezillon
2023-09-26  0:30     ` Dmitry Osipenko
2023-09-26  7:35       ` Boris Brezillon
2023-10-02 19:28         ` Dmitry Osipenko
2023-10-03 11:09           ` Boris Brezillon
2023-10-05 17:28             ` Dmitry Osipenko
2023-10-03  0:31         ` Dmitry Osipenko
2023-10-03  9:00           ` Boris Brezillon
2023-10-08 21:32             ` Dmitry Osipenko
2023-09-26  0:37     ` Dmitry Osipenko
2023-09-26  7:43       ` Boris Brezillon [this message]
2023-09-14 23:27 ` [PATCH v17 14/18] drm/shmem-helper: Export drm_gem_shmem_get_pages_sgt_locked() Dmitry Osipenko
2023-09-15  8:47   ` Boris Brezillon
2023-09-14 23:27 ` [PATCH v17 15/18] drm/virtio: Pin display framebuffer BO Dmitry Osipenko
2023-09-14 23:27 ` [PATCH v17 16/18] drm/virtio: Attach shmem BOs dynamically Dmitry Osipenko
2023-09-14 23:27 ` [PATCH v17 17/18] drm/virtio: Support memory shrinking Dmitry Osipenko
2023-09-14 23:27 ` [PATCH v17 18/18] drm/panfrost: Switch to generic memory shrinker Dmitry Osipenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230926094307.506f4b93@collabora.com \
    --to=boris.brezillon@collabora.com \
    --cc=airlied@gmail.com \
    --cc=christian.koenig@amd.com \
    --cc=daniel@ffwll.ch \
    --cc=dmitry.osipenko@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=emma@anholt.net \
    --cc=gurchetansingh@chromium.org \
    --cc=kernel@collabora.com \
    --cc=kraxel@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=mwen@igalia.com \
    --cc=olvaffe@gmail.com \
    --cc=steven.price@arm.com \
    --cc=tzimmermann@suse.de \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=yuq825@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox