From patchwork Wed Sep 20 06:18:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13392109 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 31B15CE79AE for ; Wed, 20 Sep 2023 06:19:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA4D66B010D; Wed, 20 Sep 2023 02:19:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B52AE6B010E; Wed, 20 Sep 2023 02:19:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9F4176B010F; Wed, 20 Sep 2023 02:19:45 -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 89E7A6B010D for ; Wed, 20 Sep 2023 02:19:45 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 618661A097E for ; Wed, 20 Sep 2023 06:19:45 +0000 (UTC) X-FDA: 81255974730.19.30BB63B Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by imf29.hostedemail.com (Postfix) with ESMTP id BFD8B12001A for ; Wed, 20 Sep 2023 06:19:41 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=cF9ll9AY; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf29.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695190782; 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=36opLWR6CJOCDKHWsDafiwu7OGcLAly4+3YEuY6IXMM=; b=6JUktXmoqd/sLGBlMJkGZOvh4EJANW718PHvnKfDOEo9MqYAdX5zP/4N7xnv0vS+xRJEQK asmRFNOPamkgSBjfulv3grbvmoKd6mogQHSkyEVYFpFeKjXK0CWk5+yw+OgVoymb774k7X s/BcKfSph7UWPlYsqKdigdADgTlk17M= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=cF9ll9AY; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf29.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.126 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695190782; a=rsa-sha256; cv=none; b=xbrku065KoV6tJVoO+Y/+9lgwgHM5ZpCKV+RU4MWWa4xbMxuxwDtRrbsITG568LOnCHgjB Dcp9MrJptQ78vAaZzcQaS4zdpMQapDEwW67KopaYSERtjLjb53xinzqhJ1agJHoRiOD9Pp BHOLV45VC61uxTIZMcaCgPhCa0d46Cc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695190782; x=1726726782; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lVKcfu7RB9vKN2Hm50wym0zo99YnMLypq+qR+yt7FI8=; b=cF9ll9AYPa0FoiN6yPwlUYTQHQG1UA3RII1tPtTmo/qQ5Qxbg/F5fsUs HFle/Sanicwb2vATBXtJezlGKnqOIqbDSsfJY/rdIjXFSL0YARA1jET/Y n8rK5NwoCBannG4N9HivZ+mTBnqKuDc9C20K5d4ZY/TY69MxjtUMAKJ1E cSlMCtEttxdYQFiuNoZ+BSw98taVhuuHNpPlUej5wvY6Rml7vuWbhSWhh DQGv31rPlI6BuLXoP/i3/qdVp9ldmaMH/ARJt/q9F8yG0qWAPvEzkl3zj EwW9bgblQbLscKcFlGAvD30tkVHzm9A5HUdIeThv1VGYvReHHjvqopurz g==; X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="365187603" X-IronPort-AV: E=Sophos;i="6.02,161,1688454000"; d="scan'208";a="365187603" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2023 23:19:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="740060521" X-IronPort-AV: E=Sophos;i="6.02,161,1688454000"; d="scan'208";a="740060521" Received: from yhuang6-mobl2.sh.intel.com ([10.238.6.133]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Sep 2023 23:19:37 -0700 From: Huang Ying To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Arjan Van De Ven , Huang Ying , Sudeep Holla , Andrew Morton , Mel Gorman , Vlastimil Babka , David Hildenbrand , Johannes Weiner , Dave Hansen , Michal Hocko , Pavel Tatashin , Matthew Wilcox , Christoph Lameter Subject: [PATCH 02/10] cacheinfo: calculate per-CPU data cache size Date: Wed, 20 Sep 2023 14:18:48 +0800 Message-Id: <20230920061856.257597-3-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230920061856.257597-1-ying.huang@intel.com> References: <20230920061856.257597-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: BFD8B12001A X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 331dupq7iu9cymrw8w9yu19s98im6gmr X-HE-Tag: 1695190781-484236 X-HE-Meta: U2FsdGVkX19P4anaS+lfUN1aqviqBnOuieRbnxHzptCATbsJL1NH9RI8ZJP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mqnwuwJ/1QJDK/k9I+ixGJ78QQjOExRn/NBxp09PF6IIEaBfHZIbgt1MkFrBx2M1U3O4ZG3gwxVCeAMQsXWmiTSZFSSUhnNmPwOnqA2vl8U90y7cq2AsKP9vDQvEgxT9W/3Jnpgxes1WVqjWGenxnxcC5PiBgICoskIf2EYcbN6NUCasBQH/mf2T7OR4aA/Ihwnh6f4jHCIZb7hJzwbcUd4KEVtwRDsI3g+LNr8aT4BZ2Vaw1DaYIsBS2WSc7jOTV3cTN8sLmHakWDWZdOccTBSy7KWS+T+kK6GurcI6EGfRBje7G/H4L12aPh49gVDjlRdkwv1hruLzK4uszLuAOV1/kWbXNGpYg+hfFYldak/7VM0aAeEPox6VIrFuq3GRJKQBhHTdF4ktwNZq0ni04AmNIqh29GNlQFc24bO1QL7FO9OiKDC78gBjW8sxPFmWwCNpm3j1 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: Per-CPU data cache size is useful information. For example, it can be used to determine per-CPU cache size. So, in this patch, the data cache size for each CPU is calculated via data_cache_size / shared_cpu_weight. A brute-force algorithm to iterate all online CPUs is used to avoid to allocate an extra cpumask, especially in offline callback. Signed-off-by: "Huang, Ying" Cc: Sudeep Holla Cc: Andrew Morton Cc: Mel Gorman Cc: Vlastimil Babka Cc: David Hildenbrand Cc: Johannes Weiner Cc: Dave Hansen Cc: Michal Hocko Cc: Pavel Tatashin Cc: Matthew Wilcox Cc: Christoph Lameter --- drivers/base/cacheinfo.c | 42 ++++++++++++++++++++++++++++++++++++++- include/linux/cacheinfo.h | 1 + 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c index cbae8be1fe52..3e8951a3fbab 100644 --- a/drivers/base/cacheinfo.c +++ b/drivers/base/cacheinfo.c @@ -898,6 +898,41 @@ static int cache_add_dev(unsigned int cpu) return rc; } +static void update_data_cache_size_cpu(unsigned int cpu) +{ + struct cpu_cacheinfo *ci; + struct cacheinfo *leaf; + unsigned int i, nr_shared; + unsigned int size_data = 0; + + if (!per_cpu_cacheinfo(cpu)) + return; + + ci = ci_cacheinfo(cpu); + for (i = 0; i < cache_leaves(cpu); i++) { + leaf = per_cpu_cacheinfo_idx(cpu, i); + if (leaf->type != CACHE_TYPE_DATA && + leaf->type != CACHE_TYPE_UNIFIED) + continue; + nr_shared = cpumask_weight(&leaf->shared_cpu_map); + if (!nr_shared) + continue; + size_data += leaf->size / nr_shared; + } + ci->size_data = size_data; +} + +static void update_data_cache_size(bool cpu_online, unsigned int cpu) +{ + unsigned int icpu; + + for_each_online_cpu(icpu) { + if (!cpu_online && icpu == cpu) + continue; + update_data_cache_size_cpu(icpu); + } +} + static int cacheinfo_cpu_online(unsigned int cpu) { int rc = detect_cache_attributes(cpu); @@ -906,7 +941,11 @@ static int cacheinfo_cpu_online(unsigned int cpu) return rc; rc = cache_add_dev(cpu); if (rc) - free_cache_attributes(cpu); + goto err; + update_data_cache_size(true, cpu); + return 0; +err: + free_cache_attributes(cpu); return rc; } @@ -916,6 +955,7 @@ static int cacheinfo_cpu_pre_down(unsigned int cpu) cpu_cache_sysfs_exit(cpu); free_cache_attributes(cpu); + update_data_cache_size(false, cpu); return 0; } diff --git a/include/linux/cacheinfo.h b/include/linux/cacheinfo.h index a5cfd44fab45..4e7ccfa0c36d 100644 --- a/include/linux/cacheinfo.h +++ b/include/linux/cacheinfo.h @@ -73,6 +73,7 @@ struct cacheinfo { struct cpu_cacheinfo { struct cacheinfo *info_list; + unsigned int size_data; unsigned int num_levels; unsigned int num_leaves; bool cpu_map_populated;