From patchwork Mon Oct 16 05:29:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13422489 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 6B14DCDB482 for ; Mon, 16 Oct 2023 05:30:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED34C8D0031; Mon, 16 Oct 2023 01:30:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E82CB8D0001; Mon, 16 Oct 2023 01:30:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CFD018D0031; Mon, 16 Oct 2023 01:30:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id BF63F8D0001 for ; Mon, 16 Oct 2023 01:30:30 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 88698B5C4C for ; Mon, 16 Oct 2023 05:30:30 +0000 (UTC) X-FDA: 81350199420.10.F42D52F Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by imf20.hostedemail.com (Postfix) with ESMTP id 84C0C1C0005 for ; Mon, 16 Oct 2023 05:30:28 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=iYoG2A0+; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf20.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.65 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697434228; a=rsa-sha256; cv=none; b=CxoyLjpYIuCAUnjk5DNpj480OyIYuWC+Q426LbbiACdxcCxDHX+m5LbyZ3hN15Bbwo+mgW cfq/uCixAyDcPIquxj874ydXztJW1MZgPwe/1Rh7b4ggIAdKfrInQbZxWAeoUgvpySkkP3 cD047XRvJHt+OZ9Dvs/SEXan6ttbb/I= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=iYoG2A0+; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf20.hostedemail.com: domain of ying.huang@intel.com designates 134.134.136.65 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=1697434228; 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=vS+5z0LlkNcs1oXgpimJY+oGfBhKaMajeoAc4AHTtxs=; b=6TPP+vZea+xUwKvMMMhGDzhRYVbKfaH9/EbdU3+DkjdLV1zEjSkWvV90unGvkuNKdo68Ab 8V54ZDpxidHiDNKGuktNy5vOcjCsho9fBbKNz/EpFBniMtfA+f+s9d3HuInpKezG+/LE1+ RND4tArXToDbLLaUQkG4ypchHFeADJQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697434228; x=1728970228; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Td3CNuYVe/DvxEXYqqfRgCRBE8gOU4QwgmItjh0k3pc=; b=iYoG2A0+6p9dCy508NVMiEt7DUNdUlVtblyxKHYs+tR2+bQTr4W+rE10 vC3rpxBY8+Ny0HXscUcYwgo4mOdY4Dpn71tsLU4DkfLTP3stVAPVlVSkG MEaJ4fnXIaFNch6ACCk9N3NAkwkjDfjS2gvlrBeuBRvGLlu0oz8KKxSGh g6KamcepkvKhZ7iOSFwM1pAfC84v+XOdWuM5aWFSuXVo0MaGFAL8RjZ2H 1sdIcXOy6wAZQM07PBUm/7Ya0nzNraALAowNEyNw3hDJ+LfXdC2mKVoq9 1ETUPfB1pk0dRxowItQSU4h7DeYBJyc7IA8NacZswo6abbriNRHRXXzBm A==; X-IronPort-AV: E=McAfee;i="6600,9927,10863"; a="389307967" X-IronPort-AV: E=Sophos;i="6.03,228,1694761200"; d="scan'208";a="389307967" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Oct 2023 22:30:27 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10863"; a="899356650" X-IronPort-AV: E=Sophos;i="6.03,228,1694761200"; d="scan'208";a="899356650" Received: from yhuang6-mobl2.sh.intel.com ([10.238.6.133]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Oct 2023 22:28:25 -0700 From: Huang Ying To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Arjan Van De Ven , Huang Ying , Sudeep Holla , Mel Gorman , Vlastimil Babka , David Hildenbrand , Johannes Weiner , Dave Hansen , Michal Hocko , Pavel Tatashin , Matthew Wilcox , Christoph Lameter Subject: [PATCH -V3 2/9] cacheinfo: calculate size of per-CPU data cache slice Date: Mon, 16 Oct 2023 13:29:55 +0800 Message-Id: <20231016053002.756205-3-ying.huang@intel.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231016053002.756205-1-ying.huang@intel.com> References: <20231016053002.756205-1-ying.huang@intel.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 84C0C1C0005 X-Stat-Signature: wk6p8cy6trm5mfihsyua8tgfb7h89csa X-HE-Tag: 1697434228-735281 X-HE-Meta: U2FsdGVkX1+1Jh9zfkP8V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V9pK6Sy5Md4by3YCVdCZ2L/1Y/PZmgSrz7gqifnQUnBBgFgMhcVwWtVoGWKeMN+CiEQbR5lJWqpZ+GpvLmiv4O8yC3lxmzyiY+EIRA8qEfoDOS9stunU9IIgJ0Xjyu1nEWkcbIMDs/ODlH1tpYKxW1tzoCjyKHYI9qko8ygklVXBPBNGqntnAWwt0wVb1gXQA9jef0khdtOkZK2FGpg+wrdNjE6HCZVxkj5Bu2qJKFXLh/vDbFSr3soFH9IvyMnBSVORa/lZmoDt35unUQ3mM6nuFG6YBfxvuNoOHnXnwxdjz+Jg2S4d34nxm0xfhjYtC84fQOEjxhbta43n46z36kJz5+gby6T3q1fj40iW94hzyJOZThU710kijj6krrtCoW4DQkkZRpa9kZI4f+Rtv8K7dc24ODGSB4hTu+SO4pYhqpVk1r0XUNXwIjyNNdf7kSvrdww7MptkuONrjyiI+pp6aCjHUG9X6+MM7GRwA 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: This can be used to estimate the size of the data cache slice that can be used by one CPU under ideal circumstances. Both DATA caches and UNIFIED caches are used in calculation. So, the users need to consider the impact of the code cache usage. Because the cache inclusive/non-inclusive information isn't available now, we just use the size of the per-CPU slice of LLC to make the result more predictable across architectures. This may be improved when more cache information is available in the future. 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 Acked-by: Mel Gorman --- drivers/base/cacheinfo.c | 49 ++++++++++++++++++++++++++++++++++++++- include/linux/cacheinfo.h | 1 + 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c index cbae8be1fe52..585c66fce9d9 100644 --- a/drivers/base/cacheinfo.c +++ b/drivers/base/cacheinfo.c @@ -898,6 +898,48 @@ static int cache_add_dev(unsigned int cpu) return rc; } +/* + * Calculate the size of the per-CPU data cache slice. This can be + * used to estimate the size of the data cache slice that can be used + * by one CPU under ideal circumstances. UNIFIED caches are counted + * in addition to DATA caches. So, please consider code cache usage + * when use the result. + * + * Because the cache inclusive/non-inclusive information isn't + * available, we just use the size of the per-CPU slice of LLC to make + * the result more predictable across architectures. + */ +static void update_per_cpu_data_slice_size_cpu(unsigned int cpu) +{ + struct cpu_cacheinfo *ci; + struct cacheinfo *llc; + unsigned int nr_shared; + + if (!last_level_cache_is_valid(cpu)) + return; + + ci = ci_cacheinfo(cpu); + llc = per_cpu_cacheinfo_idx(cpu, cache_leaves(cpu) - 1); + + if (llc->type != CACHE_TYPE_DATA && llc->type != CACHE_TYPE_UNIFIED) + return; + + nr_shared = cpumask_weight(&llc->shared_cpu_map); + if (nr_shared) + ci->per_cpu_data_slice_size = llc->size / nr_shared; +} + +static void update_per_cpu_data_slice_size(bool cpu_online, unsigned int cpu) +{ + unsigned int icpu; + + for_each_online_cpu(icpu) { + if (!cpu_online && icpu == cpu) + continue; + update_per_cpu_data_slice_size_cpu(icpu); + } +} + static int cacheinfo_cpu_online(unsigned int cpu) { int rc = detect_cache_attributes(cpu); @@ -906,7 +948,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_per_cpu_data_slice_size(true, cpu); + return 0; +err: + free_cache_attributes(cpu); return rc; } @@ -916,6 +962,7 @@ static int cacheinfo_cpu_pre_down(unsigned int cpu) cpu_cache_sysfs_exit(cpu); free_cache_attributes(cpu); + update_per_cpu_data_slice_size(false, cpu); return 0; } diff --git a/include/linux/cacheinfo.h b/include/linux/cacheinfo.h index a5cfd44fab45..d504eb4b49ab 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 per_cpu_data_slice_size; unsigned int num_levels; unsigned int num_leaves; bool cpu_map_populated;