From patchwork Tue Mar 14 02:26:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 69261 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1525034wrd; Mon, 13 Mar 2023 19:37:39 -0700 (PDT) X-Google-Smtp-Source: AK7set+zWvejLfNhPBV3gOUKxHMMDwgh+UfGmyp6110LvUnThYLgINPXSf42u4HBJUHaaVOOYeE6 X-Received: by 2002:a62:6504:0:b0:5ac:41d5:ded2 with SMTP id z4-20020a626504000000b005ac41d5ded2mr25806069pfb.1.1678761458794; Mon, 13 Mar 2023 19:37:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678761458; cv=none; d=google.com; s=arc-20160816; b=jw1V6iCGQcWpZetgPRYG3xwQAmuvJrv3CK7gg3txxrPTeZ12JXktQl+vP7cAXZWT6E t+kJxgAj7GTLp8j/9vupEJGzweshZRewEH+QrAAHZLSsquT3wjQHn4EL0hV/JuHeZz31 TsovPBOYaBUpqUiwxzDFLL8X3lpX6u64gX+A0bnvDbH605YUVOUrl49mcdQ9Uyy0D2pd 1RVj1h/p1KQJ6oJQ1ugDdCOP3h50py4C+HpMhEWGFVJp5Z9mCFidSnWxvqyb11AlNgX2 J08Jg39YaHUwp26PC4Ap0DqXueZQ/87Y+IU3WFLbPWu2KcK3jS7NyEw/v84j9rBVA+wx +ooA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=V/xHX5v0bKTbtBSv2SJlZT5itrGCCJAiO07OVM955Qk=; b=TCQJZkTC8UvMWSWtC4/uy8eg28tXCLmgHiL5dMx7L3gdl2xrET0cp1QCurjj37aSqp NoWz7+M/wouN0pcbDZXGYX/RUBMMB3LsE0e0Sw1vMr665UEXYnDEq7DP0qS+25TizbIi ZsVZDN5G1+hZPlGc/bkp8pIFT5T1IrfOJSsdvREpvH7Rdc9JjlMPMpXFVlErz9/Mperp tNn47w8+KBPFSLmB290rvl1sXq/HwET2fHODxCNjEYFcOX5YqQd2i9GyJrtywq472ClW dN3ZSYkSzZYsgvNM8RcY2Apvb/jemYmMRm4O5fRaf2exjWlGuTGUrsZ6MpUutdR3jm99 LP6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=KTuTyVxe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x22-20020aa79ad6000000b00593e4fbaa3esi1079919pfp.69.2023.03.13.19.37.26; Mon, 13 Mar 2023 19:37:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=KTuTyVxe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229709AbjCNC2a (ORCPT + 99 others); Mon, 13 Mar 2023 22:28:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229997AbjCNC2O (ORCPT ); Mon, 13 Mar 2023 22:28:14 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EB2494A5F for ; Mon, 13 Mar 2023 19:28:13 -0700 (PDT) Received: from workpc.. (109-252-120-116.nat.spd-mgts.ru [109.252.120.116]) (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 513866603009; Tue, 14 Mar 2023 02:28:10 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1678760892; bh=MV/O+8pOyXVa+dmpov2mAO88pJCXCdMvjM1OMaUHA+k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KTuTyVxexWP2uC9Mtr6VxTzkBmKB8v2DQWKqDb57KRkNvR1E6TGcHekXMM5M+BiA5 Q8sQYHgBtZHdsAK1pUN/cVjVADLA3BAw9dW4KS35K8sx3ruZzmDm/CqFJk8nLvl0uB 6xYeUnUYxySBmoQGghpN2wkq3CW7mNALyRSqIpFNCjqHoGNgoHzrl6s7a3XtIBuR5B yV20Gro0At/9hn3NxbvgE9m8sDi6nWvLD/4oYFSekLfNKtVy7GgODsUb5lrnbZ3h/l uV3WQih/cFHabJeb5iZ+b6XJ1SdJEg6ddLQ0IUERnN2+LpeVHSXGu+2wexR3dzFrtp fwq+bpUGv04lw== 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 Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, kernel@collabora.com, virtualization@lists.linux-foundation.org, intel-gfx@lists.freedesktop.org Subject: [PATCH v13 03/10] drm/shmem-helper: Add pages_pin_count field Date: Tue, 14 Mar 2023 05:26:52 +0300 Message-Id: <20230314022659.1816246-4-dmitry.osipenko@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230314022659.1816246-1-dmitry.osipenko@collabora.com> References: <20230314022659.1816246-1-dmitry.osipenko@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760308975544634777?= X-GMAIL-MSGID: =?utf-8?q?1760308975544634777?= And new pages_pin_count field to struct drm_gem_shmem_object that will determine whether pages are evictable by memory shrinker. The pages will be evictable only when pages_pin_count=0. This patch prepares code for addition of the memory shrinker that will utilize the new field. Signed-off-by: Dmitry Osipenko --- drivers/gpu/drm/drm_gem_shmem_helper.c | 7 +++++++ include/drm/drm_gem_shmem_helper.h | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/drivers/gpu/drm/drm_gem_shmem_helper.c b/drivers/gpu/drm/drm_gem_shmem_helper.c index 4da9c9c39b9a..81d61791f874 100644 --- a/drivers/gpu/drm/drm_gem_shmem_helper.c +++ b/drivers/gpu/drm/drm_gem_shmem_helper.c @@ -277,6 +277,8 @@ static int drm_gem_shmem_pin_locked(struct drm_gem_shmem_object *shmem) drm_WARN_ON(obj->dev, obj->import_attach); ret = drm_gem_shmem_get_pages(shmem); + if (!ret) + shmem->pages_pin_count++; return ret; } @@ -289,7 +291,12 @@ static void drm_gem_shmem_unpin_locked(struct drm_gem_shmem_object *shmem) drm_WARN_ON(obj->dev, obj->import_attach); + if (drm_WARN_ON_ONCE(obj->dev, !shmem->pages_pin_count)) + return; + drm_gem_shmem_put_pages(shmem); + + shmem->pages_pin_count--; } /** diff --git a/include/drm/drm_gem_shmem_helper.h b/include/drm/drm_gem_shmem_helper.h index 20ddcd799df9..7d823c9fc480 100644 --- a/include/drm/drm_gem_shmem_helper.h +++ b/include/drm/drm_gem_shmem_helper.h @@ -39,6 +39,15 @@ struct drm_gem_shmem_object { */ unsigned int pages_use_count; + /** + * @pages_pin_count: + * + * Reference count on the pinned pages table. + * The pages allowed to be evicted by memory shrinker + * only when the count is zero. + */ + unsigned int pages_pin_count; + /** * @madv: State for madvise *