From patchwork Wed Feb 15 16:13:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Hellstrom X-Patchwork-Id: 13141852 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA525C636CC for ; Wed, 15 Feb 2023 16:15:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C6A06B0087; Wed, 15 Feb 2023 11:15:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 677856B0088; Wed, 15 Feb 2023 11:15:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 517AA6B0089; Wed, 15 Feb 2023 11:15:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 3FD846B0087 for ; Wed, 15 Feb 2023 11:15:23 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 1B4401607AB for ; Wed, 15 Feb 2023 16:15:23 +0000 (UTC) X-FDA: 80470026126.15.2B67674 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by imf09.hostedemail.com (Postfix) with ESMTP id 0634A14001A for ; Wed, 15 Feb 2023 16:15:20 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=m2WiEg0P; spf=none (imf09.hostedemail.com: domain of thomas.hellstrom@linux.intel.com has no SPF policy when checking 134.134.136.31) smtp.mailfrom=thomas.hellstrom@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676477721; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wrGxT6nP3tAzkR0jY6ZblWH9JrSdLQ7XuNoLPtnofGI=; b=sIdYbRgOgnNu/R00SwpAJZ7fs8zHKA2SuX0UrWRehngSsbtXodrQxkc5VHrSR4Fe95jjdJ Uf4JHI+56YxHCGQjEbjRW43S65s+yWot74cBVsHDAs69CuXEPu0q9Pl7lhrUleh53BJv+I qhYLaOKQiaSyg+F/K1dyqTzR5KkSTp0= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=m2WiEg0P; spf=none (imf09.hostedemail.com: domain of thomas.hellstrom@linux.intel.com has no SPF policy when checking 134.134.136.31) smtp.mailfrom=thomas.hellstrom@linux.intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676477721; a=rsa-sha256; cv=none; b=JsswDdglvrXB6mXPrfOuOq8UkRLjs9Lorb20wVP91F8SlbqnULoj2K6wGrZBVC0r5D7CiJ 3M29sMFnG1H2ZSxw5/FZJ6TZyObUM7CUox6obTC32GWWM8QcAF1LrbBofhxxd4JPMHuAIx PGdLJ07tyRnauRlGNf03t0Rb4REb2yM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676477721; x=1708013721; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+J9Q8IYoZ1+1On4d1sDlco0YPYtSi+y9zkG53x3D21Y=; b=m2WiEg0Pv/mlFRAEoiHTxOdRMbZBttsXxh6wqsIXwWQqYk8yzwM3fVy0 vd5IA8GrJCt6RbUP805DA8EnuY34Yk9R4g5WMhwSP/fj+CzD5Fj+FNEYb DqGmuPoJXllRhgSt4HAGxRUayYx8su9U6DEoybh4pvRY/TbyWKnEeYY09 f3nz9goGrFlc2Wj16HsFMfSPLN5lazsuHGHug9BCORXwvUfxSw/dJiHcO ePnAI98NUmvAhvcn3ROynfUe2K6YIY2NsWJtrXDhilXt2ANDilpYHxYIa EEftA/hFSt8NRC0+uWSDA3mpvo/cVG+rlhjqR4CC3d2+g0YjbCn83Wnrv w==; X-IronPort-AV: E=McAfee;i="6500,9779,10622"; a="393871011" X-IronPort-AV: E=Sophos;i="5.97,300,1669104000"; d="scan'208";a="393871011" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Feb 2023 08:15:20 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10622"; a="758472532" X-IronPort-AV: E=Sophos;i="5.97,300,1669104000"; d="scan'208";a="758472532" Received: from auliel-mobl1.ger.corp.intel.com (HELO thellstr-mobl1.intel.com) ([10.249.254.14]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Feb 2023 08:15:15 -0800 From: =?utf-8?q?Thomas_Hellstr=C3=B6m?= To: dri-devel@lists.freedesktop.org Cc: =?utf-8?q?Thomas_Hellstr=C3=B6m?= , Andrew Morton , "Matthew Wilcox (Oracle)" , Miaohe Lin , David Hildenbrand , Johannes Weiner , Peter Xu , NeilBrown , Daniel Vetter , Christian Koenig , Dave Airlie , Dave Hansen , Matthew Auld , linux-graphics-maintainer@vmware.com, linux-mm@kvack.org, intel-gfx@lists.freedesktop.org Subject: [RFC PATCH 10/16] drm/ttm: Remove pinned bos from shrinkable accounting Date: Wed, 15 Feb 2023 17:13:59 +0100 Message-Id: <20230215161405.187368-11-thomas.hellstrom@linux.intel.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230215161405.187368-1-thomas.hellstrom@linux.intel.com> References: <20230215161405.187368-1-thomas.hellstrom@linux.intel.com> MIME-Version: 1.0 X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GCKdjlxjVasBSh+GGvfTYiDAS5PuqtMMtniyF7 9bV4/A4m RjWuJZqFNFgwZbgC7D/W9Y9UDk8i3Cka+ZRtwzOk4A+4C/ZZYMkRqTE4975LRyKZCLHaFHaCd6OKlroJtm1DX8n9vvA/2yJM1gacnLIT1rJApo0QVRBtQEHfZh33k9jLhh56nVAJNLUESWTV1q1d91bLNo4jIzzWMTFcNskBpufdlqBYLW9M3ETGsObq7QSOxvWz2 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Pinned bos aren't shinkable and needs to be removed from the shrinkable accounting. Do that, and in the process constify the tt argument to ttm_tt_is_populated. Signed-off-by: Thomas Hellström --- drivers/gpu/drm/ttm/ttm_bo.c | 7 +++++++ drivers/gpu/drm/ttm/ttm_tt.c | 22 ++++++++++++++++++++++ include/drm/ttm/ttm_tt.h | 6 +++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c index e5c0970564c0..e59e2a4605d0 100644 --- a/drivers/gpu/drm/ttm/ttm_bo.c +++ b/drivers/gpu/drm/ttm/ttm_bo.c @@ -650,6 +650,10 @@ void ttm_bo_pin(struct ttm_buffer_object *bo) { dma_resv_assert_held(bo->base.resv); WARN_ON_ONCE(!kref_read(&bo->kref)); + + if (!bo->pin_count && bo->ttm) + ttm_tt_set_pinned(bo->bdev, bo->ttm); + spin_lock(&bo->bdev->lru_lock); if (bo->resource) ttm_resource_del_bulk_move(bo->resource, bo); @@ -671,6 +675,9 @@ void ttm_bo_unpin(struct ttm_buffer_object *bo) if (WARN_ON_ONCE(!bo->pin_count)) return; + if (bo->pin_count == 1 && bo->ttm) + ttm_tt_set_unpinned(bo->bdev, bo->ttm); + spin_lock(&bo->bdev->lru_lock); --bo->pin_count; if (bo->resource) diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c index 848adf2a623e..a39c617c7a8e 100644 --- a/drivers/gpu/drm/ttm/ttm_tt.c +++ b/drivers/gpu/drm/ttm/ttm_tt.c @@ -83,6 +83,28 @@ static void ttm_tt_mod_shrinkable_pages(long shrinkable, long purgeable) write_unlock(&shrinkable_lock); } +/** + * ttm_tt_set_pinned() - Modify the shinkable accounting when pinning a bo. + * @bdev: The TTM device. + * @tt: The struct tt_tt used by the pinned bo. + */ +void ttm_tt_set_pinned(const struct ttm_device *bdev, const struct ttm_tt *tt) +{ + if (ttm_tt_shrinkable(bdev, tt) && ttm_tt_is_populated(tt)) + ttm_tt_mod_shrinkable_pages(-(long)tt->num_pages, 0); +} + +/** + * ttm_tt_set_unpinned() - Modify the shinkable accounting when unpinning a bo. + * @bdev: The TTM device. + * @tt: The struct tt_tt used by the no longer pinned bo. + */ +void ttm_tt_set_unpinned(const struct ttm_device *bdev, const struct ttm_tt *tt) +{ + if (ttm_tt_shrinkable(bdev, tt) && ttm_tt_is_populated(tt)) + ttm_tt_mod_shrinkable_pages(tt->num_pages, 0); +} + /* * Allocates a ttm structure for the given BO. */ diff --git a/include/drm/ttm/ttm_tt.h b/include/drm/ttm/ttm_tt.h index 3f99787e2b93..69467671c2dd 100644 --- a/include/drm/ttm/ttm_tt.h +++ b/include/drm/ttm/ttm_tt.h @@ -118,7 +118,7 @@ struct ttm_kmap_iter_tt { pgprot_t prot; }; -static inline bool ttm_tt_is_populated(struct ttm_tt *tt) +static inline bool ttm_tt_is_populated(const struct ttm_tt *tt) { return tt->page_flags & TTM_TT_FLAG_PRIV_POPULATED; } @@ -238,6 +238,10 @@ static inline bool ttm_tt_purgeable(struct ttm_tt *tt) return tt->page_flags & TTM_TT_FLAG_DONTNEED; } +void ttm_tt_set_pinned(const struct ttm_device *bdev, const struct ttm_tt *tt); + +void ttm_tt_set_unpinned(const struct ttm_device *bdev, const struct ttm_tt *tt); + #if IS_ENABLED(CONFIG_AGP) #include