From patchwork Wed Aug 14 06:28:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sridhar, Kanchana P" X-Patchwork-Id: 13762877 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 6109EC52D7F for ; Wed, 14 Aug 2024 06:28:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F06C6B0088; Wed, 14 Aug 2024 02:28:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 452EF6B0089; Wed, 14 Aug 2024 02:28:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2CCA06B008A; Wed, 14 Aug 2024 02:28:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 07A0F6B0088 for ; Wed, 14 Aug 2024 02:28:41 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A5F4DA75DA for ; Wed, 14 Aug 2024 06:28:40 +0000 (UTC) X-FDA: 82449872400.09.4114BC5 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by imf18.hostedemail.com (Postfix) with ESMTP id 8B7AD1C000F for ; Wed, 14 Aug 2024 06:28:38 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=OLGTYPNE; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf18.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 198.175.65.9 as permitted sender) smtp.mailfrom=kanchana.p.sridhar@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723616865; a=rsa-sha256; cv=none; b=Ygt0Nbmk9MOi6N9AWUqlBcrzoB/4KdX3SUVGaj6AmTJ7iprwnDNdwnzVmLXpuqGhmkKfPf Yrcz08IczSr+4jyuS1G6TKlncj70UZloHteNkoUZZ1krk10xhHYW3GbVYHY0Rhqqs04kjW OwCntp9wZMEL43kvJHxPqMzetezucjY= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=OLGTYPNE; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf18.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 198.175.65.9 as permitted sender) smtp.mailfrom=kanchana.p.sridhar@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723616865; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=nSeAi+6uplwjZyxeomo8uEiWzUJl3sO34C/KGjO3TVk=; b=G6onuN2ZFd0p+TMn82FlrzIXlkEWy3k28JByxweDUAEEDl9izo1EaSaOmTdX9OdohZVj0n i7s9AiR0JvOzx2rtfJ4yjCXD1QBi3oVGsJm4oUs8YFw+mxJqRQEFj1W/joHWhKcSJMzLBS uuS5P6oviXjhlhX2L7pV0kGRFusR5uQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1723616919; x=1755152919; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oe1u+d7vabSLdycsD7ncPotAgciyDo4K/Y5B+/jbgp0=; b=OLGTYPNENVVLG+Ipz+AiO8VSNS7lASWiXuLgQgzISjELernYSBx5fFJp q+oN9qThXazBuKL+uPkRgIBTGGM4OCS9PZ2QSAAbMbjkF2aKDXbExSiz9 wqvjvK3lbgTHKkaGj/j0MeBG0wS6hk5WkmVHIAErQGN6T6+drw4erMytk TRbHyOE9VIqGSSOQYAuggyZ5NNo2qSbUA/oJujK9Mq4Wzd+9ymrdyivwN 6EdmN0YvDxQJjGUGgIE8gWEA6sqFtyOhbBMDFUAQPebrjL5UFGaEKExe/ Ioq8HThSCWZ8VjVxr30IRXgrkAeZmfo+UrIrJjomrEBlKbsRJtZZHXaUU g==; X-CSE-ConnectionGUID: 3gFAk32/QL6vXbXnVHeLmA== X-CSE-MsgGUID: pHn1iqR5ToqFwLHyEzYsqA== X-IronPort-AV: E=McAfee;i="6700,10204,11163"; a="44333006" X-IronPort-AV: E=Sophos;i="6.09,288,1716274800"; d="scan'208";a="44333006" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Aug 2024 23:28:33 -0700 X-CSE-ConnectionGUID: kzgamZ+BQ3SH8LR1nuZ/yg== X-CSE-MsgGUID: ClU524GxSxK+fXEp+PHjlw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,288,1716274800"; d="scan'208";a="63568749" Received: from jf5300-b11a338t.jf.intel.com ([10.242.51.6]) by fmviesa004.fm.intel.com with ESMTP; 13 Aug 2024 23:28:32 -0700 From: Kanchana P Sridhar To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, hannes@cmpxchg.org, yosryahmed@google.com, nphamcs@gmail.com, ryan.roberts@arm.com, ying.huang@intel.com, 21cnbao@gmail.com, akpm@linux-foundation.org Cc: nanhai.zou@intel.com, wajdi.k.feghali@intel.com, vinodh.gopal@intel.com, kanchana.p.sridhar@intel.com Subject: [RFC PATCH v1 1/4] mm: zswap: zswap_is_folio_same_filled() takes an index in the folio. Date: Tue, 13 Aug 2024 23:28:27 -0700 Message-Id: <20240814062830.26833-2-kanchana.p.sridhar@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240814062830.26833-1-kanchana.p.sridhar@intel.com> References: <20240814062830.26833-1-kanchana.p.sridhar@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 8B7AD1C000F X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 69753yjbcd7yc96ke451kf4nc9m8iuxq X-HE-Tag: 1723616918-262381 X-HE-Meta: U2FsdGVkX1+HEh3ubaM3tQjEtcAcjIAzu2PjHs51DU7fop+jiDEwXAkS4wVk3WPbb/SCUmRYok7AkuYZryZJUPBefwSRHS3FNn5e8mvRTRn+U73xFLy/T+iV5djbvJLfD11iqiLVVqc4iObwBR3Skkz+wuqqDRyUwDEqM7vHOpSUu8vDilwEYl8hrp85KwO0p/RbDaTVZt0QnC881VbtPzKWWzp2pr19gmta26grbVOozGwLi3689CcXiJpqqcP9zbuCXXaafG2zRHqcnoLOhsM+F7eZsFEwNKxDWKDpY+I8WG1k+iFWdx8Q2raMjrjyBxpXGtlYv8bA1l4JUdbu9MENQSxVk8sbVAvA2ky80RbdXSxaJxJfeGX3h2ZA6HP6pMa7YJyg0SYNg55UES5xauymO1FY0h7qqVxuoM4w/xoCDIWxDcxAYZ6fV64gpFa4PQMk16S1TAo3msj/Q/j5wPTVVFYx+Gb2JyWUzwBJfF7+NgZj5Tdqpd+TYleLWX4ZOSWm1wgUfq+CGpzl5YLI+FY+9IvC5FkMFwtYHFqjJDNhGacYNAE2/T+CvEvD5tgs8Dl1EP+xC6WX1rkA0l4SzVBv/8oP1CNjAbXTZX5B4fcI31QXWKOr8iG0MWKZnQw434OVXHnDF2DSQUgph7vtHP8b0JUzxtdKi99dD07g3C4C2sav8qfynDWDOw1O+f2+AZWLSei6nYsM15ffwV7rW2XY8NTqlI1hTzdaLNVokEPhBrU1BhSBRPNFqlloM0Mp7SZwu4EIkaK794STw5zhwKU8S/qSxtwoe3W3VCCdUKwfstWMbLRh8sB6uy4PeAZKeid9OCf+6dkm9rWRU805qRSU0hs9SX64GYycV6W6h+oRL2mESMl8TmHVAoHklINwHP8Ds3HyVVLv/mjEbJ2F1+dMNK4Ehzpkklg9+qxui+r3961K02nWPgzMmGhRtk/xrw7BRO+fia3lFEZfz9Z eXnpV5HY Pu0avDpu/DxImDCiwOFA/V9vFd3wL6XUhYLKLohazTdo+nIVAUjLKRk4WSwyX/nJCvWYFBJUdtMHCbqOc8XHLqc6LGTyMkE4z6dZCaDbn+AOEouZi4Yh8SwM9+dJkw3mbTk5g0NXb3S6U3qTxgsTc6tz6VCpv9ATRGWNgEt+bg4LJejzVBZ3WYnHx5mBNk0YTR+3/swzsYouP+ow= 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: List-Subscribe: List-Unsubscribe: This change is being made so that zswap_store can process mTHP folios. Modified zswap_is_folio_same_filled() to work for any-order folios, by accepting an additional "index" parameter to arrive at the page within the folio to run the same-filled page check. Signed-off-by: Kanchana P Sridhar --- mm/zswap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index a50e2986cd2f..a6b0a7c636db 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1373,14 +1373,14 @@ static void shrink_worker(struct work_struct *w) /********************************* * same-filled functions **********************************/ -static bool zswap_is_folio_same_filled(struct folio *folio, unsigned long *value) +static bool zswap_is_folio_same_filled(struct folio *folio, long index, unsigned long *value) { unsigned long *page; unsigned long val; unsigned int pos, last_pos = PAGE_SIZE / sizeof(*page) - 1; bool ret = false; - page = kmap_local_folio(folio, 0); + page = kmap_local_folio(folio, index * PAGE_SIZE); val = page[0]; if (val != page[last_pos]) @@ -1450,7 +1450,7 @@ bool zswap_store(struct folio *folio) goto reject; } - if (zswap_is_folio_same_filled(folio, &value)) { + if (zswap_is_folio_same_filled(folio, 0, &value)) { entry->length = 0; entry->value = value; atomic_inc(&zswap_same_filled_pages); From patchwork Wed Aug 14 06:28:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sridhar, Kanchana P" X-Patchwork-Id: 13762876 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 13EF5C3DA4A for ; Wed, 14 Aug 2024 06:28:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 602526B0083; Wed, 14 Aug 2024 02:28:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5B1936B0085; Wed, 14 Aug 2024 02:28:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 452466B0088; Wed, 14 Aug 2024 02:28:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 258B46B0083 for ; Wed, 14 Aug 2024 02:28:40 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A9DE1A0CA5 for ; Wed, 14 Aug 2024 06:28:39 +0000 (UTC) X-FDA: 82449872358.28.783FEB0 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by imf23.hostedemail.com (Postfix) with ESMTP id 7711C140008 for ; Wed, 14 Aug 2024 06:28:37 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=UjqA8Pzi; spf=pass (imf23.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 198.175.65.9 as permitted sender) smtp.mailfrom=kanchana.p.sridhar@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=1723616905; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=GWQ26oeJqSObrMx2L85OU3m3MfCNX7McU5Oc1hPM3kQ=; b=m8dDcLo0hlPS9StNj6wK0L+BZWSQXw6XZ1wIdk/t0aTvFYxcH8E/5Y+EMtX4l9cSVwtoTC boWkjisfiUV4FaAPiTSHf3zsoFEWvw5G4IB7qIa+0nC+CZMIYPhtxpEiOPFfcO7BVTvXkF ANSZ9gI7iuTfxsAHLVhh/72mNZi9gvA= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=UjqA8Pzi; spf=pass (imf23.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 198.175.65.9 as permitted sender) smtp.mailfrom=kanchana.p.sridhar@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723616905; a=rsa-sha256; cv=none; b=7AHt7gu7ljUA9ZQ3QYY0IcvqVvufJx4HA9lzqAV4vt2GNaQeLZ7MyupCLho+2wSPtRPjMM aB/2LfbuAGX5psPAlSBJ7IPq9tvgnerrHuFxbMseBAF5K5OKhdY/m5cHb4kESK/mcnyufO s59GHFoaF2PmGlTR1SAobT0lCrJMOsU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1723616918; x=1755152918; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uqrNeGBRRJSKgfNeNGYme2bhngEOXyV0SlU+NTOqopU=; b=UjqA8Pzi/sMN4qT1mj5Fx+ZqyvBcd+Zz7hPPWu9eejI3EeH4jNDo5X1y IfOcpLPX64KvryrXCTDXQuSROHJZCnx7BSYHoaWKdWqKK5uxdqcdPjRaD frnmRdIB3VSLJ85zkIizOEgH72h9wxaS4DcoYlUDZWlTOkXiOmU4QTBX7 XbA/s9P71WFjyD/6H7t76Ga4GKWQhAekZBvYd6weQXVeVv00xPFA8lbfr tGOqpanrqba8mml9W3hmGK5v+QgWDwrXZ8/trKsdt+6efiUKMMGS40d8d q5SFqTaUZrgTbT1ejQ6IfqUfYnsAh9QVKzdZMRCplNX9hAcHBr4DBcfJP w==; X-CSE-ConnectionGUID: C2oUarP7TdedR3Te+oMyIQ== X-CSE-MsgGUID: FXAYNQX1TrqEvMeZH4iXoQ== X-IronPort-AV: E=McAfee;i="6700,10204,11163"; a="44333008" X-IronPort-AV: E=Sophos;i="6.09,288,1716274800"; d="scan'208";a="44333008" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Aug 2024 23:28:33 -0700 X-CSE-ConnectionGUID: OhOjY6yjTM6kgTZgOGWk0w== X-CSE-MsgGUID: 0vYFo0pvQu2aqwWrMol5Rg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,288,1716274800"; d="scan'208";a="63568753" Received: from jf5300-b11a338t.jf.intel.com ([10.242.51.6]) by fmviesa004.fm.intel.com with ESMTP; 13 Aug 2024 23:28:32 -0700 From: Kanchana P Sridhar To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, hannes@cmpxchg.org, yosryahmed@google.com, nphamcs@gmail.com, ryan.roberts@arm.com, ying.huang@intel.com, 21cnbao@gmail.com, akpm@linux-foundation.org Cc: nanhai.zou@intel.com, wajdi.k.feghali@intel.com, vinodh.gopal@intel.com, kanchana.p.sridhar@intel.com Subject: [RFC PATCH v1 2/4] mm: vmstat: Per mTHP-size zswap_store vmstat event counters. Date: Tue, 13 Aug 2024 23:28:28 -0700 Message-Id: <20240814062830.26833-3-kanchana.p.sridhar@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240814062830.26833-1-kanchana.p.sridhar@intel.com> References: <20240814062830.26833-1-kanchana.p.sridhar@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: eb7iy9efni4h7q9unjt7sjnhh5zw8ykp X-Rspamd-Queue-Id: 7711C140008 X-Rspamd-Server: rspam11 X-HE-Tag: 1723616917-834930 X-HE-Meta: U2FsdGVkX1/qS2MfEs0xlQJta9BKRCkoESC6LH9ak+EQdwAH1D4rI/yDwbpR8ntLLQkfLcHf+6c/B84SeVasBpVKG0NGGYrVc+fLc+wE1nzp6/DmQv3LkjS6gI/T72sy0kJuZpapxytOAhw92cP2+18AEvrCB+jRrncpbp8zkhy8s0/BvJICq67IDJTyJnKTTRgI2Qx9GZkPGyi7Ru+87CDPcmgrNaIUbXesKBqCmk3W5cA0Ae1aMlzDEctw+kTAwmbvNBB44pr3znWRgXr5VY2yqYj+NHHigwuPPtopcrvtTYTcnHN90//mZJGtKnhNrZAxhaQK6CQ1La4eYhcbtTcO5TXbOOsuGWMvXyR0vC9V1IPxnftG6fKjOnXXSeLyqz9EMl/+f3CNjCo7J9FsEJMgVt+/Sf5z33UE3mGlbRQCj+zApyz9EmzXdermpokiSkGPUjXORXuTp5cRmgV0oFPbqW89UoAnFFzjL3adGehg74kZKIS9JpuzQQMSKJ0tdkiYi4b9ZmpKKgai8uPtpubZGq7RRpTmPcAzT3SLntVBOuL0MFKAk+NwD+WsREC4mm+LgGRi5QWIq7GRk3Af3lCPR0mcyurdtnoV3g2HD4z6qW4+uBBNbcPEaaU5DNLOd+7vDHdHpPj/q6kjuH8NRdg4sg55v+z2HW7n7l+44I7o12q7E8Q96eSUYl5Ps7Dl1KuV0kwNODKZiCBHjKHAjO/aS0a9V9T3l/L45YnkYfBLjQejkUq2JEI4ucDYZHhOnIm6sBUGqHbpJzNpzc6RKdvKmf88/Lro6he45pQAjuvDoibXAq9EHJhXBCnotHNkK5XRNIEoBOFUBVBVS3cUGRD1mfG3Sf7xMRwugFbysr7a4j4FgNMOhRr6dhtWOU/jjSk2Iqt6Oj37B5fr+fQIB8ssF1ChiNYUD4EwUcM+FHo9izCqF7WjztujRiSrU7hiwFYo17neXc8KgMqNI33 8+0WX1lJ SXkKo8CLRGdVHQ2frWyn7J/HNLcaWl88+pUGmL8O96KIqE6C4z69TI1e4lNWD0BzMgQoTtKH9WPrRLWDaJ4oVctR8pbnfADI+qKntg/yWVhQoZM/ZKVzh3THnv0XBB3pwSvkjYIuiKLGT8MU7KBDju/P5nuPkD4/63oIbmk0DYNthB/6qPEJfvWKLaHV5ToF8SPKU87EBoraS2LU= 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: List-Subscribe: List-Unsubscribe: Added vmstat event counters per mTHP-size that can be used to account for folios of different sizes being successfully stored in ZSWAP. For this RFC, it is not clear if these zswpout counters should instead be added as part of the existing mTHP stats in /sys/kernel/mm/transparent_hugepage/hugepages-*kB/stats. The following is also a viable option, should it make better sense, for instance, as: /sys/kernel/mm/transparent_hugepage/hugepages-*kB/stats/zswpout. If so, we would be able to distinguish between mTHP zswap and non-zswap swapouts through: /sys/kernel/mm/transparent_hugepage/hugepages-*kB/stats/zswpout and /sys/kernel/mm/transparent_hugepage/hugepages-*kB/stats/swpout respectively. Comments would be appreciated as to which approach is preferable. Signed-off-by: Kanchana P Sridhar --- include/linux/vm_event_item.h | 15 +++++++++++++++ mm/vmstat.c | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h index 747943bc8cc2..2451bcfcf05c 100644 --- a/include/linux/vm_event_item.h +++ b/include/linux/vm_event_item.h @@ -114,6 +114,9 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT, THP_ZERO_PAGE_ALLOC, THP_ZERO_PAGE_ALLOC_FAILED, THP_SWPOUT, +#ifdef CONFIG_ZSWAP + ZSWPOUT_PMD_THP_FOLIO, +#endif THP_SWPOUT_FALLBACK, #endif #ifdef CONFIG_MEMORY_BALLOON @@ -143,6 +146,18 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT, ZSWPIN, ZSWPOUT, ZSWPWB, + ZSWPOUT_4KB_FOLIO, +#ifdef CONFIG_THP_SWAP + mTHP_ZSWPOUT_8kB, + mTHP_ZSWPOUT_16kB, + mTHP_ZSWPOUT_32kB, + mTHP_ZSWPOUT_64kB, + mTHP_ZSWPOUT_128kB, + mTHP_ZSWPOUT_256kB, + mTHP_ZSWPOUT_512kB, + mTHP_ZSWPOUT_1024kB, + mTHP_ZSWPOUT_2048kB, +#endif #endif #ifdef CONFIG_X86 DIRECT_MAP_LEVEL2_SPLIT, diff --git a/mm/vmstat.c b/mm/vmstat.c index 8507c497218b..0e66c8b0c486 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1375,6 +1375,9 @@ const char * const vmstat_text[] = { "thp_zero_page_alloc", "thp_zero_page_alloc_failed", "thp_swpout", +#ifdef CONFIG_ZSWAP + "zswpout_pmd_thp_folio", +#endif "thp_swpout_fallback", #endif #ifdef CONFIG_MEMORY_BALLOON @@ -1405,6 +1408,18 @@ const char * const vmstat_text[] = { "zswpin", "zswpout", "zswpwb", + "zswpout_4kb_folio", +#ifdef CONFIG_THP_SWAP + "mthp_zswpout_8kb", + "mthp_zswpout_16kb", + "mthp_zswpout_32kb", + "mthp_zswpout_64kb", + "mthp_zswpout_128kb", + "mthp_zswpout_256kb", + "mthp_zswpout_512kb", + "mthp_zswpout_1024kb", + "mthp_zswpout_2048kb", +#endif #endif #ifdef CONFIG_X86 "direct_map_level2_splits", From patchwork Wed Aug 14 06:28:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sridhar, Kanchana P" X-Patchwork-Id: 13762878 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 DB4B8C52D7F for ; Wed, 14 Aug 2024 06:28:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A24CC6B0089; Wed, 14 Aug 2024 02:28:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D0AB6B008A; Wed, 14 Aug 2024 02:28:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7127B6B0092; Wed, 14 Aug 2024 02:28:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 4D8326B0089 for ; Wed, 14 Aug 2024 02:28:42 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id F359A1A0C5F for ; Wed, 14 Aug 2024 06:28:41 +0000 (UTC) X-FDA: 82449872442.07.689F542 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by imf23.hostedemail.com (Postfix) with ESMTP id B27B1140007 for ; Wed, 14 Aug 2024 06:28:39 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=MXLxDP9s; spf=pass (imf23.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 198.175.65.9 as permitted sender) smtp.mailfrom=kanchana.p.sridhar@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=1723616907; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Ebj5GFDs/74o0qRFKlK9Fp6ADE9sHKKOQfDE5ev/VP8=; b=t8+7KZxarqRv15ilIYNmIAgxQLFp01AYZgTWVqZT0ATGP2GIcOg+TqOyO2xfRUeCDKKb4E dJGKz8zF28dSHVyBwSU/xRBgWQkGoP/rOZhqOfiL5uJLaaIKnOCY6/W4JZluqlYWxn2vji GfedYG+mlsdUNcAOONntipO4KGxeqi8= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=MXLxDP9s; spf=pass (imf23.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 198.175.65.9 as permitted sender) smtp.mailfrom=kanchana.p.sridhar@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723616907; a=rsa-sha256; cv=none; b=8m3tTNb5TTqmB7hLsAKQjiGWVJl3oLdaMdULlRPelils3pb91Nc9jzTHVsKAZ13F4ROCmq qKtpKSlyuZr56687qcakAGs0a7YN518phzxCoQSftI1keVc4V49BDudgcy/Dv5wQiB6aWQ pvzt365veKO4BBLCOaMFhg4Icom5iQ0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1723616920; x=1755152920; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=b0exLTLKXempeXy+88HdDHRjQzo5T2XSUscqTXLuQAo=; b=MXLxDP9sXMu0B7G99rsBLFW7xinv8X4uuF//3ToX+SjXAjgCtBRnpLxd 5VSSjTtwxB8AtzAcHCNeDRAT0rHUirVcTwMfN4PVdJiRerczRBDzbe1pP T+O+oaQOasCP1tsqx14x9/mz8UA07aaXRhmbV/PuyP7/2eme39Nx0HPAJ 1XUzFMi5oNcrs2Pv+C31doRUtTrWVPwm44RaIjUGrE/acXYuynZVDAFr5 cc1YH8aX8OTuajOYY4Obllmaw0u78LwhNmxORnhCq0hAN/R1MTxEBwvRA Ajk2Eo1pFN3rsP8KK6uRz+0qDglYcQGeXAuXYEzG1HxV1WL1+sMudFwor g==; X-CSE-ConnectionGUID: dqPmvxYxSRmHBlnMg+Yq2A== X-CSE-MsgGUID: 3d13CpWDSzyfZpaZ88cVLQ== X-IronPort-AV: E=McAfee;i="6700,10204,11163"; a="44333019" X-IronPort-AV: E=Sophos;i="6.09,288,1716274800"; d="scan'208";a="44333019" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Aug 2024 23:28:33 -0700 X-CSE-ConnectionGUID: v572F++PQd+9e4jrfr8uVg== X-CSE-MsgGUID: nrg/9K0lRlityO7atqhYpQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,288,1716274800"; d="scan'208";a="63568759" Received: from jf5300-b11a338t.jf.intel.com ([10.242.51.6]) by fmviesa004.fm.intel.com with ESMTP; 13 Aug 2024 23:28:33 -0700 From: Kanchana P Sridhar To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, hannes@cmpxchg.org, yosryahmed@google.com, nphamcs@gmail.com, ryan.roberts@arm.com, ying.huang@intel.com, 21cnbao@gmail.com, akpm@linux-foundation.org Cc: nanhai.zou@intel.com, wajdi.k.feghali@intel.com, vinodh.gopal@intel.com, kanchana.p.sridhar@intel.com Subject: [RFC PATCH v1 3/4] mm: zswap: zswap_store() extended to handle mTHP folios. Date: Tue, 13 Aug 2024 23:28:29 -0700 Message-Id: <20240814062830.26833-4-kanchana.p.sridhar@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240814062830.26833-1-kanchana.p.sridhar@intel.com> References: <20240814062830.26833-1-kanchana.p.sridhar@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: r3kyz5ohucouz56zcykwqaeigsqckao1 X-Rspamd-Queue-Id: B27B1140007 X-Rspamd-Server: rspam11 X-HE-Tag: 1723616919-351119 X-HE-Meta: U2FsdGVkX1+V/HiCaImm05MJVP09zm7qFB111JxPp3gUaHwizcYkZi4h9B+WpYHRTBpWU0GRIt4pdvQBVDqDh+c2oj0qjRjsUQHSsdIkXwQwd0R9NAYFSdCNOvZ63ptxrjHKEozMfxtAHW24SsS+d6jtQxeoQUE4wOpDAYYMUxPIGtNcGJDLrlTJNXDMNIv4Nc5JEkh08l2bqqHFVQNy5nH8hNOOhtB5XXt8W0vBm6mXzuPojGFSqPBjSBaShU3GsN04RuFFEvRTWxMjhxDVgcfn65l1OQD+c8hOQqr4midG8Fls6w67a6/5bZz//6KNaS+AkgPgdFJJEscQbRapQfMi9xTG7NIslvTFcp8mR9/ZtaMePMfsE7XO/0rFkkdojDYGCc/Y95uK782zbaYXE+qiWWbxt9s6muSSXlTJA1Q7FJBghs6TEGtaTY9uEAM6HK7K9MSf6Yd+GMO1XOc59g0racNFqTaiBxiF8w8iz+Vao73hRH3gWX42aYvDDZpUgnputUy59rv4SdBVD/CGVqUrKlBp1DOP8gYwyQojVps6ubwFMyl/bATDeYFvN4bwSGhKtoS7MYJ6GOF0ScSv2vLr/BD0vDA/i+vWD13hIoIxxZLAq1OeNCKe19wbRA8AfxJ7gRkfizzPts35oxq4phTaBZPWVAkDq9AZXwkEZk+ZTjtLHOFU3sTiqZM/vqRYXjlI3xktBX6WJcxNcJj6uzdN94UARt4/ZfJ80KYaEVnuuv0MxoaAJk7Tu5baa+RTPb6LM4EnowQ8VEaeTTd3IYpPL9ffZty7FNf1XvPMsK+NB1k+vREZmmmNnyJLkv9hq2LiIkctdQvKP9h0G4W6t5+q8Qh+iezr8n8ZEQo2FBlipbZnAVoD9wx/joismmyeQ8yr6JEKRSX2dE6W5ZRqNfPkhFLA0if3zQrbIInjhaGL3lNvL4BX9A6VB2/2evQ16FMER7KLeEvE/Ttb0Al 6uC0IM4H GgVoUf1CdYUxUt6A8nEU3VBOxNX8v39EslxliyiVSZjx/ZZ7s2Fi9L+L2K6uGGPwF9nSL5377U5yiC+KI89Pp4oV47FiNjIH5XibqBQrsZg24jFdajo+oTHly9gl+BEdDICrgpcoGcEtaZQq6FUpr75xRWZhCYbgOWMuCJQD7Ml97VVZMQGcasjihGAfDq9C998qihqJcZN0VAMLnqXOV/gBjB+f5C4ghLxGOLuU1Hp62M3w6plHiZ/2vaf0WvgMkjDrmngPFMfi9NIVyS5cPt7LeQ454YVxqWeXbMtW8vxeWADF7D/Vc5YOsmGbafhShMzoZ 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: List-Subscribe: List-Unsubscribe: zswap_store() will now process and store mTHP and PMD-size THP folios. This change reuses and adapts the functionality in Ryan Roberts' RFC patch [1]: "[RFC,v1] mm: zswap: Store large folios without splitting" [1] https://lore.kernel.org/linux-mm/20231019110543.3284654-1-ryan.roberts@arm.com/T/#u This patch provides a sequential implementation of storing an mTHP in zswap_store() by iterating through each page in the folio to compress and store it in the zswap zpool. Towards this goal, zswap_compress() is modified to take a page instead of a folio as input. Each page's swap offset is stored as a separate zswap entry. If an error is encountered during the store of any page in the mTHP, all previous pages/entries stored will be invalidated. Thus, an mTHP is either entirely stored in ZSWAP, or entirely not stored in ZSWAP. This forms the basis for building batching of pages during zswap store of large folios, by compressing batches of up to say, 8 pages in an mTHP in parallel in hardware, with the Intel In-Memory Analytics Accelerator (Intel IAA). Co-developed-by: Ryan Roberts Signed-off-by: Signed-off-by: Kanchana P Sridhar --- mm/zswap.c | 219 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 157 insertions(+), 62 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index a6b0a7c636db..98ff98b485f5 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -899,7 +899,7 @@ static int zswap_cpu_comp_dead(unsigned int cpu, struct hlist_node *node) return 0; } -static bool zswap_compress(struct folio *folio, struct zswap_entry *entry) +static bool zswap_compress(struct page *page, struct zswap_entry *entry) { struct crypto_acomp_ctx *acomp_ctx; struct scatterlist input, output; @@ -917,7 +917,7 @@ static bool zswap_compress(struct folio *folio, struct zswap_entry *entry) dst = acomp_ctx->buffer; sg_init_table(&input, 1); - sg_set_page(&input, &folio->page, PAGE_SIZE, 0); + sg_set_page(&input, page, PAGE_SIZE, 0); /* * We need PAGE_SIZE * 2 here since there maybe over-compression case, @@ -1409,36 +1409,82 @@ static void zswap_fill_page(void *ptr, unsigned long value) /********************************* * main API **********************************/ -bool zswap_store(struct folio *folio) + +/* + * Returns true if the entry was successfully + * stored in the xarray, and false otherwise. + */ +static bool zswap_store_entry(struct xarray *tree, + struct zswap_entry *entry) { - swp_entry_t swp = folio->swap; - pgoff_t offset = swp_offset(swp); - struct xarray *tree = swap_zswap_tree(swp); - struct zswap_entry *entry, *old; - struct obj_cgroup *objcg = NULL; - struct mem_cgroup *memcg = NULL; - unsigned long value; + struct zswap_entry *old; + pgoff_t offset = swp_offset(entry->swpentry); - VM_WARN_ON_ONCE(!folio_test_locked(folio)); - VM_WARN_ON_ONCE(!folio_test_swapcache(folio)); + old = xa_store(tree, offset, entry, GFP_KERNEL); - /* Large folios aren't supported */ - if (folio_test_large(folio)) + if (xa_is_err(old)) { + int err = xa_err(old); + + WARN_ONCE(err != -ENOMEM, "unexpected xarray error: %d\n", err); + zswap_reject_alloc_fail++; return false; + } - if (!zswap_enabled) - goto check_old; + /* + * We may have had an existing entry that became stale when + * the folio was redirtied and now the new version is being + * swapped out. Get rid of the old. + */ + if (old) + zswap_entry_free(old); - /* Check cgroup limits */ - objcg = get_obj_cgroup_from_folio(folio); - if (objcg && !obj_cgroup_may_zswap(objcg)) { - memcg = get_mem_cgroup_from_objcg(objcg); - if (shrink_memcg(memcg)) { - mem_cgroup_put(memcg); - goto reject; - } - mem_cgroup_put(memcg); + return true; +} + +/* + * If the zswap store fails or zswap is disabled, we must invalidate the + * possibly stale entry which was previously stored at this offset. + * Otherwise, writeback could overwrite the new data in the swapfile. + * + * This is called after the store of the i-th offset + * in a large folio, has failed. All entries from + * [i-1 .. 0] must be deleted. + * + * This is also called if zswap_store() is called, + * but zswap is not enabled. All offsets for the folio + * are deleted from zswap in this case. + */ +static void zswap_delete_stored_offsets(struct xarray *tree, + pgoff_t offset, + long nr_pages) +{ + struct zswap_entry *entry; + long i; + + for (i = 0; i < nr_pages; ++i) { + entry = xa_erase(tree, offset + i); + if (entry) + zswap_entry_free(entry); } +} + +/* + * Stores the page at specified "index" in a folio. + */ +static bool zswap_store_page(struct folio *folio, long index, + struct obj_cgroup *objcg, + struct zswap_pool *pool) +{ + swp_entry_t swp = folio->swap; + int type = swp_type(swp); + pgoff_t offset = swp_offset(swp) + index; + struct page *page = folio_page(folio, index); + struct xarray *tree = swap_zswap_tree(swp); + struct zswap_entry *entry; + unsigned long value; + + if (objcg) + obj_cgroup_get(objcg); if (zswap_check_limits()) goto reject; @@ -1450,7 +1496,7 @@ bool zswap_store(struct folio *folio) goto reject; } - if (zswap_is_folio_same_filled(folio, 0, &value)) { + if (zswap_is_folio_same_filled(folio, index, &value)) { entry->length = 0; entry->value = value; atomic_inc(&zswap_same_filled_pages); @@ -1458,42 +1504,20 @@ bool zswap_store(struct folio *folio) } /* if entry is successfully added, it keeps the reference */ - entry->pool = zswap_pool_current_get(); - if (!entry->pool) + if (!zswap_pool_get(pool)) goto freepage; - if (objcg) { - memcg = get_mem_cgroup_from_objcg(objcg); - if (memcg_list_lru_alloc(memcg, &zswap_list_lru, GFP_KERNEL)) { - mem_cgroup_put(memcg); - goto put_pool; - } - mem_cgroup_put(memcg); - } + entry->pool = pool; - if (!zswap_compress(folio, entry)) + if (!zswap_compress(page, entry)) goto put_pool; store_entry: - entry->swpentry = swp; + entry->swpentry = swp_entry(type, offset); entry->objcg = objcg; - old = xa_store(tree, offset, entry, GFP_KERNEL); - if (xa_is_err(old)) { - int err = xa_err(old); - - WARN_ONCE(err != -ENOMEM, "unexpected xarray error: %d\n", err); - zswap_reject_alloc_fail++; + if (!zswap_store_entry(tree, entry)) goto store_failed; - } - - /* - * We may have had an existing entry that became stale when - * the folio was redirtied and now the new version is being - * swapped out. Get rid of the old. - */ - if (old) - zswap_entry_free(old); if (objcg) { obj_cgroup_charge_zswap(objcg, entry->length); @@ -1527,7 +1551,7 @@ bool zswap_store(struct folio *folio) else { zpool_free(zswap_find_zpool(entry), entry->handle); put_pool: - zswap_pool_put(entry->pool); + zswap_pool_put(pool); } freepage: zswap_entry_cache_free(entry); @@ -1535,16 +1559,87 @@ bool zswap_store(struct folio *folio) obj_cgroup_put(objcg); if (zswap_pool_reached_full) queue_work(shrink_wq, &zswap_shrink_work); -check_old: + + return false; +} + +/* + * Modified to store mTHP folios. + * Each page in the mTHP will be compressed + * and stored sequentially. + */ +bool zswap_store(struct folio *folio) +{ + long nr_pages = folio_nr_pages(folio); + swp_entry_t swp = folio->swap; + pgoff_t offset = swp_offset(swp); + struct xarray *tree = swap_zswap_tree(swp); + struct obj_cgroup *objcg = NULL; + struct mem_cgroup *memcg = NULL; + struct zswap_pool *pool; + bool ret = false; + long index; + + VM_WARN_ON_ONCE(!folio_test_locked(folio)); + VM_WARN_ON_ONCE(!folio_test_swapcache(folio)); + /* - * If the zswap store fails or zswap is disabled, we must invalidate the - * possibly stale entry which was previously stored at this offset. - * Otherwise, writeback could overwrite the new data in the swapfile. + * If zswap is disabled, we must invalidate the possibly stale entry + * which was previously stored at this offset. Otherwise, writeback + * could overwrite the new data in the swapfile. */ - entry = xa_erase(tree, offset); - if (entry) - zswap_entry_free(entry); - return false; + if (!zswap_enabled) + goto reject; + + /* Check cgroup limits */ + objcg = get_obj_cgroup_from_folio(folio); + if (objcg && !obj_cgroup_may_zswap(objcg)) { + memcg = get_mem_cgroup_from_objcg(objcg); + if (shrink_memcg(memcg)) { + mem_cgroup_put(memcg); + goto put_objcg; + } + mem_cgroup_put(memcg); + } + + if (zswap_check_limits()) + goto put_objcg; + + pool = zswap_pool_current_get(); + if (!pool) + goto put_objcg; + + if (objcg) { + memcg = get_mem_cgroup_from_objcg(objcg); + if (memcg_list_lru_alloc(memcg, &zswap_list_lru, GFP_KERNEL)) { + mem_cgroup_put(memcg); + goto put_pool; + } + mem_cgroup_put(memcg); + } + + /* + * Store each page of the folio as a separate entry. If we fail to store + * a page, unwind by removing all the previous pages we stored. + */ + for (index = 0; index < nr_pages; ++index) { + if (!zswap_store_page(folio, index, objcg, pool)) + goto put_pool; + } + + ret = true; + +put_pool: + zswap_pool_put(pool); +put_objcg: + obj_cgroup_put(objcg); + if (zswap_pool_reached_full) + queue_work(shrink_wq, &zswap_shrink_work); +reject: + if (!ret) + zswap_delete_stored_offsets(tree, offset, nr_pages); + + return ret; } bool zswap_load(struct folio *folio) From patchwork Wed Aug 14 06:28:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sridhar, Kanchana P" X-Patchwork-Id: 13762879 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 F3012C52D7F for ; Wed, 14 Aug 2024 06:28:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 739DE6B008A; Wed, 14 Aug 2024 02:28:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6EAD96B0092; Wed, 14 Aug 2024 02:28:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 566F96B0093; Wed, 14 Aug 2024 02:28:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 2D81B6B008A for ; Wed, 14 Aug 2024 02:28:43 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A9FB7A5DE2 for ; Wed, 14 Aug 2024 06:28:42 +0000 (UTC) X-FDA: 82449872484.15.60D5D3B Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by imf03.hostedemail.com (Postfix) with ESMTP id 7E8CD20003 for ; Wed, 14 Aug 2024 06:28:40 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="ciWu3/20"; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf03.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 198.175.65.9 as permitted sender) smtp.mailfrom=kanchana.p.sridhar@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723616867; a=rsa-sha256; cv=none; b=fQ8F7q3AlfI0IXMG5FAegb2xglWI9kI2wDv1CZV9FP+srsup3IU6wiTl8O/mvQdKtwaLDS w2UPAqpPXrEoWsbmL3joh8Ofkm8snRY6LmgJx3O+YKCwePXYYF7/OeTDnzJyx5my4Cd8O6 /aeBYlbvSTfe7m90Eyopfs35CtIbLPU= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="ciWu3/20"; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf03.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 198.175.65.9 as permitted sender) smtp.mailfrom=kanchana.p.sridhar@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723616867; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NnIOYOJcae/XJVFDtoPVRP3OqiwFgt+Z74TkZx2hdWg=; b=aLN65OEQOBFI62ztxV82mC7QCZnK0NHtQnwbRoIEA9uCmROe0xODIWVOPaPhmMXRT+fjTh iu6uz8WowrR8s5SchBx+wmU6/CWqBH+w38nsQ1iceYYaWc+Ch2ORW/nZMDerIshn8hxr5O /AmMk7J8eukqmxP5qZzOvu/1uA5Ydzk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1723616921; x=1755152921; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=K2v1VkFvaq+3TScgsmYP670KxeFAd1V81S4yNBh/NTc=; b=ciWu3/20KyLGylHzrBXL9f4dWSjQSWSmwWBdl2izeATlTlK2IK8hvVbU +AnIHIxkDAWYo/COo08UIU+0imFfT8hHQrT6MDPPLk+dNxF+TfkvP7BBX joMQjtIkSVN6RLL5ZuitvJefKVvBl9ZWRXDr3w0NEmvXu+fttMF43n19K iqHBFPi8x/udfvKVFttwFVCVVuaCQqFAHLLbC4p5wcsVvOlzINDmfI5PH B5P72XS/SsVb0gUDhq/A8XCtaphydvaPVjy4QrW7sDLal34zF/x6QVueI sfh/2F+Vmz+gPmrHVgSvEA4yAJ0gYv8AFQ+16t7ctLDd/EfEeOf3ulUaU A==; X-CSE-ConnectionGUID: Q0lqJYM4T3qKgR4K0yTYqg== X-CSE-MsgGUID: vlyZd5LCQfSGzUCHrqINBg== X-IronPort-AV: E=McAfee;i="6700,10204,11163"; a="44333024" X-IronPort-AV: E=Sophos;i="6.09,288,1716274800"; d="scan'208";a="44333024" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Aug 2024 23:28:33 -0700 X-CSE-ConnectionGUID: 2zyx+9DPTjmnHtf37Gg14Q== X-CSE-MsgGUID: Jy9a/cZJQdGV9YY2ZGhG0w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,288,1716274800"; d="scan'208";a="63568762" Received: from jf5300-b11a338t.jf.intel.com ([10.242.51.6]) by fmviesa004.fm.intel.com with ESMTP; 13 Aug 2024 23:28:33 -0700 From: Kanchana P Sridhar To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, hannes@cmpxchg.org, yosryahmed@google.com, nphamcs@gmail.com, ryan.roberts@arm.com, ying.huang@intel.com, 21cnbao@gmail.com, akpm@linux-foundation.org Cc: nanhai.zou@intel.com, wajdi.k.feghali@intel.com, vinodh.gopal@intel.com, kanchana.p.sridhar@intel.com Subject: [RFC PATCH v1 4/4] mm: page_io: Count successful mTHP zswap stores in vmstat. Date: Tue, 13 Aug 2024 23:28:30 -0700 Message-Id: <20240814062830.26833-5-kanchana.p.sridhar@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240814062830.26833-1-kanchana.p.sridhar@intel.com> References: <20240814062830.26833-1-kanchana.p.sridhar@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 7E8CD20003 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: xu4akkoy3c4jwerugcukzrom5nzjshxn X-HE-Tag: 1723616920-356366 X-HE-Meta: U2FsdGVkX18t0GyYeVOR727E1TofmCoxaqvz7U1rQ75tvclIwQYzxGalqGFo4WnHG60N/N2MBb9pJ2k6vXJ8TW8NUN2ELDdq6603i/nYfJSgKGsP22x+zH+6yLQc6A+pLVw4MSoXYgFjCj695bDyIicFd6MLJrs51H9eyJ+4XLYfYxZi2Zk6jhFGDniYydpZtcCKZX7CpD13dadz94CRnRH3YtmIPK2ja7WOvdEZqYNPOaEhLu16wLicAqT+0k2ijXoFEH1LxDNtWz/QdqDt4u+PMnlgewmqxrFE/tJJICKfiLVSVZbob7xHKKAVplmcAH/EHxaVGWMRqxxfe1WU9XMSPqMd6Rljja4yCYaQb61zFNKUm7Q9YvqMOs9wZPebcsiOLHfk24zPybbENem0Wy/K5VxV/4e2Eweo1chEmNlihKXRSFpjz8Xg7ItqPo+n0hr4Rffl7Kib9gIROHjSCgUuju1SfCOLhb3q0sEnfziTu3Vxgrgpgl9GuKIWiAt9t/+zOfTLbqpw6O2wp4cnSYfbusctQw26vCdZqggtX/HjafgCmVZ3ypHG5c8W6YNrHUqj/kWZXAxInSiX4GbYtC2d9vafsT9cJ/d9AjZtFuh8o6n7tymW0PCmd091cFiauPgLoVlB1xMyAtDJEd9jte5xw6PXrKSJrV5ITd7gTehYxl/p3pgUCEHhonlN2OMbMl4Ncc3wS4VEO3ggVxwVeE3GcBxCkDD5n4BiUGktR1NCDj6faTaeQtxj+Rxxj2GGgAZxrcZUEB4PKclLnkGNRwzzxUde478N10OqnRVfD6oh8GuH/0hYsS7+FoR/csV4p7YBfOASid4t1v+PVQSgYdEpAusTUONl07KhWCuSb8a1o0lEuLqghVmUKiQ4FBoLkw/K3HwHntEeMJKFA/O3TS3JjS/4CShvBEUbEPIqWF/NQKPLfc4oNfK2NifjnAFiv47oLz3JBqqXU08J8WH kv1dBjyQ GiANNe+I4l/YOli106NVaMokjzb8jsHgzWby5UpP7YL43raWjgbWdmowc5u8uhjIJVb9tnvU9P0YjTViBCicVJg9PLZ3jHvK1V9xf00U4mpIEfYkLdQB2mVX+oLW9R8INq2MxcirMvzCmmy2ndB+KyJCXDi4rMJtgXfEIY0nbM/7nvDJFQ8Bl3QaK6RL+4Nrfe9CqvkqcZf5j8oE= 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: List-Subscribe: List-Unsubscribe: Added count_zswap_thp_swpout_vm_event() that will increment the appropriate mTHP/PMD vmstat event counters if zswap_store succeeds for a large folio: zswap_store mTHP order [0, HPAGE_PMD_ORDER-1] will increment these vmstat event counters: ZSWPOUT_4KB_FOLIO mTHP_ZSWPOUT_8kB mTHP_ZSWPOUT_16kB mTHP_ZSWPOUT_32kB mTHP_ZSWPOUT_64kB mTHP_ZSWPOUT_128kB mTHP_ZSWPOUT_256kB mTHP_ZSWPOUT_512kB mTHP_ZSWPOUT_1024kB zswap_store of a PMD-size THP, i.e., mTHP order HPAGE_PMD_ORDER, will increment both these vmstat event counters: ZSWPOUT_PMD_THP_FOLIO mTHP_ZSWPOUT_2048kB Signed-off-by: Kanchana P Sridhar --- mm/page_io.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/mm/page_io.c b/mm/page_io.c index 0a150c240bf4..ab54d2060cc4 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -172,6 +172,49 @@ int generic_swapfile_activate(struct swap_info_struct *sis, goto out; } +/* + * Count vmstats for ZSWAP store of large folios (mTHP and PMD-size THP). + */ +static inline void count_zswap_thp_swpout_vm_event(struct folio *folio) +{ + if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && folio_test_pmd_mappable(folio)) { + count_vm_event(ZSWPOUT_PMD_THP_FOLIO); + count_vm_event(mTHP_ZSWPOUT_2048kB); + } else if (folio_order(folio) == 0) { + count_vm_event(ZSWPOUT_4KB_FOLIO); + } else if (IS_ENABLED(CONFIG_THP_SWAP)) { + switch (folio_order(folio)) { + case 1: + count_vm_event(mTHP_ZSWPOUT_8kB); + break; + case 2: + count_vm_event(mTHP_ZSWPOUT_16kB); + break; + case 3: + count_vm_event(mTHP_ZSWPOUT_32kB); + break; + case 4: + count_vm_event(mTHP_ZSWPOUT_64kB); + break; + case 5: + count_vm_event(mTHP_ZSWPOUT_128kB); + break; + case 6: + count_vm_event(mTHP_ZSWPOUT_256kB); + break; + case 7: + count_vm_event(mTHP_ZSWPOUT_512kB); + break; + case 8: + count_vm_event(mTHP_ZSWPOUT_1024kB); + break; + case 9: + count_vm_event(mTHP_ZSWPOUT_2048kB); + break; + } + } +} + /* * We may have stale swap cache pages in memory: notice * them here and get rid of the unnecessary final write. @@ -196,6 +239,7 @@ int swap_writepage(struct page *page, struct writeback_control *wbc) return ret; } if (zswap_store(folio)) { + count_zswap_thp_swpout_vm_event(folio); folio_start_writeback(folio); folio_unlock(folio); folio_end_writeback(folio);