From patchwork Mon Feb 27 06:02:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 13152868 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CA5E5C64ED8 for ; Mon, 27 Feb 2023 06:03:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7BFBB10E1AA; Mon, 27 Feb 2023 06:03:18 +0000 (UTC) Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by gabe.freedesktop.org (Postfix) with ESMTPS id 593C610E1A6 for ; Mon, 27 Feb 2023 06:03:11 +0000 (UTC) Received: from workpc.. (109-252-117-89.nat.spd-mgts.ru [109.252.117.89]) (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: dmitry.osipenko) by madras.collabora.co.uk (Postfix) with ESMTPSA id 84ABD6602E18; Mon, 27 Feb 2023 06:03:08 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1677477790; bh=vjtXW+MPhe7FCQQixJ64rJGO1Kdcwxp6cjHxk692qng=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kLerpws1gaypjvr0hKheY5ecYT7fK6ihqfpOx1jeXZewnqOEY8h0+CC35fPETorm5 e7g/3o48fWs7yRZxwzkBiFWo71M3RMyfvV1Geks6Si0bQgBEy4MSTHc39rmBiELSiJ dkMJFVPwWOzFJU1RUeFAIMTHn6sFN6I+cFFnoUjXFcGHIE4IK+KGIf/z0WhNJTfPPl Uev5QSL8oEfdAGZV13RhVqrTse2YN9s0AJuqxScWWF+TKbzqweiTN3Q+AXLMrq1ehT CZk7hGMm7WOa006yp8lmRbYuRmgyh0eID/6sTgvFmoQrVUqcONeyLyYf0OL/m1LIV+ tNOuHAjt3gvNg== From: Dmitry Osipenko To: David Airlie , Gerd Hoffmann , Gurchetan Singh , Chia-I Wu , Daniel Vetter , Daniel Almeida , Gustavo Padovan , Daniel Stone , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , Qiang Yu , Steven Price , Alyssa Rosenzweig , Rob Herring Subject: [PATCH v11 04/10] drm/shmem-helper: Factor out unpinning part from drm_gem_shmem_purge() Date: Mon, 27 Feb 2023 09:02:13 +0300 Message-Id: <20230227060219.904986-5-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230227060219.904986-1-dmitry.osipenko@collabora.com> References: <20230227060219.904986-1-dmitry.osipenko@collabora.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kernel@collabora.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, virtualization@lists.linux-foundation.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Factor out pages unpinning code from drm_gem_shmem_purge() into new drm_gem_shmem_unpin_pages(). This prepares code for addition of memory shrinker support. The new common function will be used by shrinker for eviction of shmem pages. Signed-off-by: Dmitry Osipenko --- drivers/gpu/drm/drm_gem_shmem_helper.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c index 2b1eef335bf6..fc1cfd5f5e7a 100644 --- a/drivers/gpu/drm/drm_gem_shmem_helper.c +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c @@ -463,25 +463,29 @@ int drm_gem_shmem_madvise(struct drm_gem_shmem_object *shmem, int madv) } EXPORT_SYMBOL(drm_gem_shmem_madvise); -void drm_gem_shmem_purge(struct drm_gem_shmem_object *shmem) +static void drm_gem_shmem_unpin_pages(struct drm_gem_shmem_object *shmem) { struct drm_gem_object *obj = &shmem->base; struct drm_device *dev = obj->dev; dma_resv_assert_held(shmem->base.resv); - drm_WARN_ON(obj->dev, !drm_gem_shmem_is_purgeable(shmem)); - dma_unmap_sgtable(dev->dev, shmem->sgt, DMA_BIDIRECTIONAL, 0); + drm_gem_shmem_release_pages(shmem); + drm_vma_node_unmap(&obj->vma_node, dev->anon_inode->i_mapping); + sg_free_table(shmem->sgt); kfree(shmem->sgt); shmem->sgt = NULL; +} - drm_gem_shmem_put_pages(shmem); +void drm_gem_shmem_purge(struct drm_gem_shmem_object *shmem) +{ + struct drm_gem_object *obj = &shmem->base; - shmem->madv = -1; + drm_WARN_ON(obj->dev, !drm_gem_shmem_is_purgeable(shmem)); - drm_vma_node_unmap(&obj->vma_node, dev->anon_inode->i_mapping); + drm_gem_shmem_unpin_pages(shmem); drm_gem_free_mmap_offset(obj); /* Our goal here is to return as much of the memory as @@ -492,6 +496,8 @@ void drm_gem_shmem_purge(struct drm_gem_shmem_object *shmem) shmem_truncate_range(file_inode(obj->filp), 0, (loff_t)-1); invalidate_mapping_pages(file_inode(obj->filp)->i_mapping, 0, (loff_t)-1); + + shmem->madv = -1; } EXPORT_SYMBOL(drm_gem_shmem_purge);