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, 3 Oct 2023 11:00:55 +0200	[thread overview]
Message-ID: <20231003110055.346fd94c@collabora.com> (raw)
In-Reply-To: <bbbd82a5-41bf-4ca3-476d-e5039e94631b@collabora.com>

Hello Dmitry,

On Tue, 3 Oct 2023 03:31:32 +0300
Dmitry Osipenko <dmitry.osipenko@collabora.com> wrote:

> On 9/26/23 10:35, Boris Brezillon wrote:
> >>>> +	__drm_gem_shmem_release_pages(shmem);    
> >>> Make sure you drop the implicit pages_use_count ref the sgt had, this
> >>> way you can still tie the necessity to drop the pages to sgt != NULL in
> >>> drm_gem_shmem_free().    
> >> This will require further refcnt re-initialization when pages are
> >> restored if it's dropped to zero. I don't see how this will improve
> >> anything.  
> > Sorry to disagree, but I do think it matters to have a clear ownership
> > model, and if I look at the code (drm_gem_shmem_get_pages_sgt_locked()),
> > the sgt clearly owns a reference to the pages it points to.  
> 
> It creates too much unnecessary trouble because, again, pages_use_count
> can't drop to zero easily.

Not saying pages_use_count should drop to zero, I'm just saying the
reference that was owned by the sgt should be released when this sgt is
freed, no matter if this sgt destruction is triggered by a GEM eviction,
or because the GEM object is freed entirely.

> Shrinker doesn't own the refcnt and not
> allowed to touch it.

I'm not asking the shrinker to own a reference on the pages either.
It's really the sgt that owns this reference.

> The pages_use_count is then used by things like
> mmap() and etc that use get_pages(), which can be invoked for evicted GEM.

Yes, and I still have a hard time seeing how this interferes with what
I'm suggesting to be honest.

> 
> I'd prefer to keep refcounting as is, don't see how to implement your
> suggestion.

Can you be more specific? I don't really see what the problem is with
decrementing pages_use_count when you free the sgt (eviction), and
re-incrementing it when the sgt is restored (swapin).

Regards,

Boris

  reply	other threads:[~2023-10-03  9:01 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 [this message]
2023-10-08 21:32             ` Dmitry Osipenko
2023-09-26  0:37     ` Dmitry Osipenko
2023-09-26  7:43       ` Boris Brezillon
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=20231003110055.346fd94c@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