From patchwork Tue Oct 1 05:32:20 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: 13817485 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 5E0C0CEB2FE for ; Tue, 1 Oct 2024 05:37:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 854786B00F5; Tue, 1 Oct 2024 01:37:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 803576B0100; Tue, 1 Oct 2024 01:37:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6300C6B00F7; Tue, 1 Oct 2024 01:37:16 -0400 (EDT) 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 33B406B00EA for ; Tue, 1 Oct 2024 01:37:16 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id CBB401607A0 for ; Tue, 1 Oct 2024 05:37:15 +0000 (UTC) X-FDA: 82623925230.21.81DF3C1 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) by imf05.hostedemail.com (Postfix) with ESMTP id 9BE48100006 for ; Tue, 1 Oct 2024 05:37:13 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=bmsupbOl; spf=pass (imf05.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 192.198.163.11 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=1727760906; 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=n3lpT5wzGF+b1pa3hoTUzlSMa9Vzwo4wZdujvqkC3ms=; b=tGjRmnSgyY1tyw6cVv4dgmuOL+lLdj0uTEOq/CzAqDNh3XVPr71UW6HKbNk75k1qt9gmf7 ViYpLjF5CEqFyB2uQc0wY6YErOWIJ2ihYffPhxMJfa3DtoEgj8oy/THVdAvKZXPash/eeU TLxFl1FLRQY3CxL7Dg6POXuQH/B9mbg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727760906; a=rsa-sha256; cv=none; b=1bkaEuRdAg8PNJ2kZPe4eDDnqx6rgvdcK7eMSXOiljn8GX4d5DuYd/qjDTtgPS81qEzmuE SQgWdoGsHWTyEFRO+PVdjvwJF/018V3Hi+LUB01nFxMpuF4IFaHnfIisb1rzbs6GZzTWb9 5dDUcMQjJfjXC4CGOJVODPU/ivzZ78M= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=bmsupbOl; spf=pass (imf05.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 192.198.163.11 as permitted sender) smtp.mailfrom=kanchana.p.sridhar@intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1727761034; x=1759297034; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fh13koWj73Qksnj2l+56lXO4bpj9lkhBiLj2Y16CgXI=; b=bmsupbOlmhe+qPfK0jwF3tShAtINmP2ZSu8wGrNQJGOdV9ur4ykju5mr 274P7bhydRfV8Aec2ynvdV2qqfPuTGnKLrnQPNU2om4aWOVXzzO8t6j1G exqfcJ/VtYFodOOu4QV1HAETeCJ6k9vz6roF5qqV53RBc5Ej+QaDDiluN T+iCrxgFPGEPydJxV2D4k0DLV86pruAdKJu8MFb2hHYxc1mHp/MLrTN+0 LxjZD+R/tsC/Nto0RfMl7M7L/ZmoVzQ5twfk5WwptoVxZ3LSA8aQ2Rh7i 4AG0PZfgSvBY6DmcojnwJ6/D9abzWZ5bKkME+q996WwvdD6eW+2o/4rnq A==; X-CSE-ConnectionGUID: DXX/k+OiSa6HQU/0fPDz/A== X-CSE-MsgGUID: OKu7FXetRz2FY65aq5q+hg== X-IronPort-AV: E=McAfee;i="6700,10204,11211"; a="37465117" X-IronPort-AV: E=Sophos;i="6.11,167,1725346800"; d="scan'208";a="37465117" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Sep 2024 22:32:26 -0700 X-CSE-ConnectionGUID: kM2GQueiQaqyj/KDhjFPcA== X-CSE-MsgGUID: kqT1lRAiTy6kXLW9DrzM5g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,167,1725346800"; d="scan'208";a="73205808" Received: from jf5300-b11a338t.jf.intel.com ([10.242.51.6]) by fmviesa007.fm.intel.com with ESMTP; 30 Sep 2024 22:32:25 -0700 From: Kanchana P Sridhar To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, hannes@cmpxchg.org, yosryahmed@google.com, nphamcs@gmail.com, chengming.zhou@linux.dev, usamaarif642@gmail.com, shakeel.butt@linux.dev, ryan.roberts@arm.com, ying.huang@intel.com, 21cnbao@gmail.com, akpm@linux-foundation.org, willy@infradead.org Cc: nanhai.zou@intel.com, wajdi.k.feghali@intel.com, vinodh.gopal@intel.com, kanchana.p.sridhar@intel.com Subject: [PATCH v10 5/7] mm: zswap: Modify zswap_stored_pages to be atomic_long_t. Date: Mon, 30 Sep 2024 22:32:20 -0700 Message-Id: <20241001053222.6944-6-kanchana.p.sridhar@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20241001053222.6944-1-kanchana.p.sridhar@intel.com> References: <20241001053222.6944-1-kanchana.p.sridhar@intel.com> MIME-Version: 1.0 X-Stat-Signature: 8s1ok8ai7eobqgjx73uo1tc1xn5gcuty X-Rspamd-Queue-Id: 9BE48100006 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1727761033-821236 X-HE-Meta: U2FsdGVkX19OD/ld+8MgISjJq+a9poEhWmRSSfbxIfIp+FwvVdlzm5zi7pppXmDMyr6tiMoNBZTCoH8b5zgi8qLORbY8Oy/VfQ7vK7KmBGpbhY3jk1pknC/ueLJsz9S+S7LpHMHo5/VT3D8Nelhk80AkhOvrXaWTNOzOz+wmVLTPyo9NY+AKbZ9CCyr/Vp4hyG8nRqtst88PnBVYxW1QYHMBc+VpSbBwSHHPV6xEfbnIIpGNyCPiUhNFf2uwtQJGDpUWorSV9CM9EnJSgnkOQRLhqUC0InRHrhhAJEZkpMgOPzMHSkH4eTdhqINK1SxqC+RP/zZec4YU9NC53Dxbx8mjl1vpgEjcMyN5hojRzbsVAL+E0Ae1hiMN0AX/WlDbhJ7sRZkk1BwEeeOxKOyoIgQo2EGD5aztqd85PJ8ZCJp43YYNTrje1LHzIUxCKRQfiIkLeqdIO64+2bTS1Vobiba5dKowdZDZXqVdEizNWAJKoYhcG3Ms5FktnB9QZ8SWiO1HOe7R6uRmQXsuaypq4jL/BhRDCTdCdIOsB0Tq0aAiiYrnegv1ybGmepp/jgpakzC50uVlmK9teP1Hbvsr9jB+Uj3to+Wb8FC9fzWgsRoRIXDWHx/Wa8UhTKnGhHEHWH7o2CqbuqBDPRlhulRcIJfEXCtqZcM9SKKPYVtIlT3r5A3Cenzt97mcD6ix+kkss47xApkY9m5/ehecBiTyE4YfifovprWHulpqut0FyXNSHE9bRWN1IvDY6uAOQGtj6qBdJ+HomUaBWezvj+G8nXeQslYLDIFBSC73d3ZwrD18F9odmjPIBApr0cdKswn+eYmf9xfkXdbt3ERv2IootwAOuzUUxK0ca4aR8nG4ZQJHcwA0LyS6eoEXJweM6/lKwRiwNa0/8rBj9fvI6wP24kw49UOtbNi60aEfdSwMOwmUQEL5vZzaRFDc97vHfY7nGGmd97AJjdsjlj3MqZg XcLxWdsL imZEAKfDY/OkmFw7a9yYar9cHyj9po/GCQxjLZ8Jj5UyIJ5qqnDjsYalhN998vuM1gM7DFIwYW4LK3HWQDUawm73xGDsnUKulRuuwrrfLLtHGo5ZUCYtRQhDFibA3wq+qTrAmdYyG6Gp0C8rGEnTNs05k2ElVzIBVnp3PT3Ts7w8T0bC0n5Z3n+cL/RdfQEEQ0qTNmlktn++fzGNt8aphU637sEPzRUTxZu3m0VpRVw+hB7DRYtxjfQAgnPC8kYLyWiVwdxCf6BMOLANRvYr+ZY9rBwBnXfToRdWfQ5o1zUFqfVSddPCedCAjBbaV9suFxgZ0oBcNIig+jU600oZuObXIAw== 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: For zswap_store() to support large folios, we need to be able to do a batch update of zswap_stored_pages upon successful store of all pages in the folio. For this, we need to add folio_nr_pages(), which returns a long, to zswap_stored_pages. Signed-off-by: Kanchana P Sridhar Acked-by: Yosry Ahmed Acked-by: Johannes Weiner Reviewed-by: Nhat Pham --- fs/proc/meminfo.c | 2 +- include/linux/zswap.h | 2 +- mm/zswap.c | 19 +++++++++++++------ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c index 245171d9164b..8ba9b1472390 100644 --- a/fs/proc/meminfo.c +++ b/fs/proc/meminfo.c @@ -91,7 +91,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v) #ifdef CONFIG_ZSWAP show_val_kb(m, "Zswap: ", zswap_total_pages()); seq_printf(m, "Zswapped: %8lu kB\n", - (unsigned long)atomic_read(&zswap_stored_pages) << + (unsigned long)atomic_long_read(&zswap_stored_pages) << (PAGE_SHIFT - 10)); #endif show_val_kb(m, "Dirty: ", diff --git a/include/linux/zswap.h b/include/linux/zswap.h index 9cd1beef0654..d961ead91bf1 100644 --- a/include/linux/zswap.h +++ b/include/linux/zswap.h @@ -7,7 +7,7 @@ struct lruvec; -extern atomic_t zswap_stored_pages; +extern atomic_long_t zswap_stored_pages; #ifdef CONFIG_ZSWAP diff --git a/mm/zswap.c b/mm/zswap.c index 69b9c025fd47..2b8da50f6322 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -43,7 +43,7 @@ * statistics **********************************/ /* The number of compressed pages currently stored in zswap */ -atomic_t zswap_stored_pages = ATOMIC_INIT(0); +atomic_long_t zswap_stored_pages = ATOMIC_INIT(0); /* * The statistics below are not protected from concurrent access for @@ -802,7 +802,7 @@ static void zswap_entry_free(struct zswap_entry *entry) obj_cgroup_put(entry->objcg); } zswap_entry_cache_free(entry); - atomic_dec(&zswap_stored_pages); + atomic_long_dec(&zswap_stored_pages); } /********************************* @@ -1232,7 +1232,7 @@ static unsigned long zswap_shrinker_count(struct shrinker *shrinker, nr_stored = memcg_page_state(memcg, MEMCG_ZSWAPPED); } else { nr_backing = zswap_total_pages(); - nr_stored = atomic_read(&zswap_stored_pages); + nr_stored = atomic_long_read(&zswap_stored_pages); } if (!nr_stored) @@ -1501,7 +1501,7 @@ bool zswap_store(struct folio *folio) } /* update stats */ - atomic_inc(&zswap_stored_pages); + atomic_long_inc(&zswap_stored_pages); count_vm_event(ZSWPOUT); return true; @@ -1650,6 +1650,13 @@ static int debugfs_get_total_size(void *data, u64 *val) } DEFINE_DEBUGFS_ATTRIBUTE(total_size_fops, debugfs_get_total_size, NULL, "%llu\n"); +static int debugfs_get_stored_pages(void *data, u64 *val) +{ + *val = atomic_long_read(&zswap_stored_pages); + return 0; +} +DEFINE_DEBUGFS_ATTRIBUTE(stored_pages_fops, debugfs_get_stored_pages, NULL, "%llu\n"); + static int zswap_debugfs_init(void) { if (!debugfs_initialized()) @@ -1673,8 +1680,8 @@ static int zswap_debugfs_init(void) zswap_debugfs_root, &zswap_written_back_pages); debugfs_create_file("pool_total_size", 0444, zswap_debugfs_root, NULL, &total_size_fops); - debugfs_create_atomic_t("stored_pages", 0444, - zswap_debugfs_root, &zswap_stored_pages); + debugfs_create_file("stored_pages", 0444, + zswap_debugfs_root, NULL, &stored_pages_fops); return 0; }