From patchwork Wed Feb 15 16:14:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Hellstr=C3=B6m?= X-Patchwork-Id: 13141853 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 30DECC636D7 for ; Wed, 15 Feb 2023 16:15:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C94116B0088; Wed, 15 Feb 2023 11:15:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C447A6B0089; Wed, 15 Feb 2023 11:15:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AE41B6B008A; Wed, 15 Feb 2023 11:15:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 9F6F46B0088 for ; Wed, 15 Feb 2023 11:15:28 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 68F03A03FC for ; Wed, 15 Feb 2023 16:15:28 +0000 (UTC) X-FDA: 80470026336.25.5A11D09 Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by imf09.hostedemail.com (Postfix) with ESMTP id 302D2140021 for ; Wed, 15 Feb 2023 16:15:25 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=MdTDt4G+; 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=1676477726; 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=c6Py7e+eNhvKVgXNX/JYAJuxmA7IPgDWfDUqirK79DQ=; b=D/IQoGRXCdJpNrogC6lJoqP5stdiciY9NOxcj3J6CTY3YdlokSsAXVJeat/Tw9etzx4/O4 0O4iXahrw0lpg8RqTyEQmBoIWoyypvZ06123rMDQQwhM8m0Mi4l+80E2kb92b1vW6SKzBv 6PuY1LheBkx5+24r+JyomdSuvxoNpTU= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=MdTDt4G+; 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=1676477726; a=rsa-sha256; cv=none; b=EK0j5ECM6A+2TQ3VJTlyjJrfF1qHWGhwRfg+3dEjX08MeepKay5jzJkA+QTqyFPpv5r8NE t9xg/aXuUsTySmA88HPfvsOaK2DYu01gnWBuqXBUU5yxrbeQuvU+rqs749hqFKhVpqd61D cLpU3aX0LDSRE2q34aj5bt0lGf1Z6Ss= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676477726; x=1708013726; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xm8ETaxZeJqXVpmDZaBdgzwHZhDfpl++98/mmYFZhMY=; b=MdTDt4G+Cts9G6KE9KowH6y9E/0q8fH4Xnow0VqszvAWal9rZKgHOzNo XTpi8rCOHvEziQAswHTXjAMcA7NJJtKWsiUV2Trn2xzl8JKmpVLSt0sBM q9jjDrja+z46SFncSAXzYNA/CultyxRseIVy1Wa2+r3XI+FQuTLJAjchX RxguWk/4q2qatmrcNT+w777bNmfDB/rjgeunGEwrqoPAiqvzsH0fhQ+oX 3L4ydiPBnAzFNfFMCrWnOi8aYDFNe9+aDfrQnzXLolz+Y+JBoFV0EutFw E34gkBZAMUcmAlNRYeXiwtzyWCmVro1XFqxfwiJDWcCjlerHEXVjKJTlp Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10622"; a="393871048" X-IronPort-AV: E=Sophos;i="5.97,300,1669104000"; d="scan'208";a="393871048" 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:25 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10622"; a="758472576" X-IronPort-AV: E=Sophos;i="5.97,300,1669104000"; d="scan'208";a="758472576" 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:20 -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 11/16] drm/ttm: Add a simple api to set / clear purgeable ttm_tt content Date: Wed, 15 Feb 2023 17:14:00 +0100 Message-Id: <20230215161405.187368-12-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-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 302D2140021 X-Stat-Signature: 67yt59h59b6yp6be78j59jm85a48huq5 X-HE-Tag: 1676477725-644725 X-HE-Meta: U2FsdGVkX19DB/VxpU6d5Jit6I0La7LVi8D8eqn84KdUsV/DxuFKHZsKlSe9gV63BqOuQlUxoYcPdJbIiSubkTYH7/oswkEmQkDzY9+AO+0c3zkFmorppSyHwW6WBHJZBwWiZ+aE91PFj57K0z7k9BcdtEiMs8rjPWyLS8394BDKIQyWaIv65mMImrr0yIjkX5f1ipZjgL/eHj1QmKof6B1tAS9kE8lRDtKmFV2z69G4D7dtAr38HQIMaYBAhH6cGvvUnyY7vSkOIf78GBNEMPNkAK+jEEKS7HpZvO1FKMmI5LdLi6E7TbGACdC9QkmxrhuLgQLvzAIW1lc3NLkS25TP0q2y6jLBADGTZqY2U7sLNbHpdYsdFwEHH9D+q0UXxwMLxvWRFy/yApPwv5O94jP4+WS9ggoqwl1CaUMAqaXXH4fYRuS16AeuBSh4dv1ctdsIyLp/bp3f2PkK8Qd5rk7GsWAH41RmAORBxpszQFclJGV4Q/TAFtRxqOKDgfsb3fxqSPx2I306Z5tRX+QgEsfFGHs6iXyXWPeEdhVQAp8Z7ArtEIuQ3foXbKdOPjsXVKo67ltb6t5ECfOKONJjzQazU6T2leOjm+IeFI6eQtlc50TGK88pqCn7bcJouY04wf+5Frl9RmvaFXZloLnQOFmG4GNLWhBy8/xd/5DTkQfgEucf509njb8yM6Zm3T8SZraK7UoMHZLjIzLlwozWfvKLcEbKZIaTwD+uZ8yi42l+CsYunFZKt8sbwGmSPJDOJXQvtDsXB7A1rV5+UE0iPbLG8ainV28xWIEUHUfLG2OfrlFV+fHnMnr/AZk9WrvqnXVJE/3ZriD7uddDbNCPwEogj52qdwWu0bolQpKLdUvTswGC288mPp0P45oJ83VwLh2Efa73v9Rm1Lgz10fnA5doUpRTnGwuoaPGrG9iX6p45kWC5vwtSQV62KHRsYXBd+VUYfSR9W21bc819Vu Sd/mkZes YTiEy7raz4MyS+zSm+9eEFO7XwELFVDIHuS/AqsdOKp2hutipVoUxgHHZD2egqZEWdDw5rGJwBhzjv6JzIxwdlNd0rtgb1L7HbrlHe2sMil3kr88s8gLshqW+b+k4dyj+rf33UCuYnK30g2oMtq9NU8rbV4dtSP2SbcNfdQgCc0YSKKloCbxrHhd3KbRXCgy13BTer+Zx8+dn2wFpJiDS7VA2UJgZELVjUj54zMtDeEjX3TD/zDOwkDlNCw== 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: In the absence of free swap space, a shrinker could still efficiently free memory the content of which is no longer needed, and graphics drivers typically has an interface to mark buffer object content as no longer needed. Add a possibility to propagate this to TTM, so that the shrinker accounting and shrinker actions can be updated accordingly. Moving forward, we will probably want this interface on the bo level and have bo move support for it, but for now we strictly only need it for the shrinker. Another option would be to have the drivers do the purgeable vs shrinkable accounting. This still leaves the responsibility to the driver to assign proper LRU priority to purgeable buffer object so that the shrinker finds those objects early during LRU traversal. Signed-off-by: Thomas Hellström --- drivers/gpu/drm/ttm/ttm_tt.c | 59 ++++++++++++++++++++++++++++++++++++ include/drm/ttm/ttm_tt.h | 3 ++ 2 files changed, 62 insertions(+) diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c index a39c617c7a8e..c63be8f5ed2a 100644 --- a/drivers/gpu/drm/ttm/ttm_tt.c +++ b/drivers/gpu/drm/ttm/ttm_tt.c @@ -105,6 +105,65 @@ void ttm_tt_set_unpinned(const struct ttm_device *bdev, const struct ttm_tt *tt) ttm_tt_mod_shrinkable_pages(tt->num_pages, 0); } +/** + * ttm_tt_set_dontneed() - Mark ttm_tt content as not needed. + * @bdev: The ttm device. + * @tt: The struct ttm_tt. + * + * Mark the ttm_tt content as not needed for the shrinker accounting. + * This also means that the content will not be backed up on shrinking, + * but rather freed immediately. + * + * Return: 0 if successful, -EALREADY if content was never present or + * already backed up and was purged by this call. + */ +int ttm_tt_set_dontneed(const struct ttm_device *bdev, struct ttm_tt *tt) +{ + if (ttm_tt_is_populated(tt)) { + if (!ttm_tt_purgeable(tt)) { + tt->page_flags |= TTM_TT_FLAG_DONTNEED; + if (ttm_tt_shrinkable(bdev, tt)) + ttm_tt_mod_shrinkable_pages(-(long)tt->num_pages, + tt->num_pages); + } + return 0; + } + + if (tt->swap_storage) + fput(tt->swap_storage); + tt->swap_storage = NULL; + + return -EALREADY; +} +EXPORT_SYMBOL(ttm_tt_set_dontneed); + +/** + * ttm_tt_set_willneed() - Mark tt_tt content as needed. + * @bdev: The ttm device. + * @tt: The struct ttm_tt. + * + * Mark the ttm_tt content as needed and update the shrinker accounting + * accordingly. + * + * Return: 0 if successful, -EALREADY if content was never present or + * was already purged. + */ +int ttm_tt_set_willneed(const struct ttm_device *bdev, struct ttm_tt *tt) +{ + if (ttm_tt_is_populated(tt)) { + if (ttm_tt_purgeable(tt)) { + tt->page_flags &= ~TTM_TT_FLAG_DONTNEED; + if (ttm_tt_shrinkable(bdev, tt)) + ttm_tt_mod_shrinkable_pages(tt->num_pages, + -(long)tt->num_pages); + } + return 0; + } + + return -EALREADY; +} +EXPORT_SYMBOL(ttm_tt_set_willneed); + /* * 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 69467671c2dd..abb17527f76c 100644 --- a/include/drm/ttm/ttm_tt.h +++ b/include/drm/ttm/ttm_tt.h @@ -241,6 +241,9 @@ static inline bool ttm_tt_purgeable(struct ttm_tt *tt) 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); +int ttm_tt_set_dontneed(const struct ttm_device *bdev, struct ttm_tt *tt); + +int ttm_tt_set_willneed(const struct ttm_device *bdev, struct ttm_tt *tt); #if IS_ENABLED(CONFIG_AGP) #include