From patchwork Wed Sep 20 06:18:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Ying" X-Patchwork-Id: 13392110 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 8B822CE79AD for ; Wed, 20 Sep 2023 06:19:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 22DB46B010E; Wed, 20 Sep 2023 02:19:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1DDD66B0111; Wed, 20 Sep 2023 02:19:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 058316B0110; Wed, 20 Sep 2023 02:19:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E29856B010E for ; Wed, 20 Sep 2023 02:19:47 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C0014A0F54 for ; Wed, 20 Sep 2023 06:19:47 +0000 (UTC) X-FDA: 81255974814.05.E000399 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by imf29.hostedemail.com (Postfix) with ESMTP id C9BFD120013 for ; Wed, 20 Sep 2023 06:19:45 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="lz/q40Zs"; 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=1695190786; 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=l/RqypTBqoKRXw8P4mlR7VW0p5EEkP7aW82SstOT+vs=; b=Ni1RjkCTLEz1PnHYeXEKFe4t9ko2IJ4KptbPM7nTJkhf+z0HIEBvkXgu5AlQrGX8ydBEgf N+kBRrIogpAq2CecBh8XfJY7NOHD3EFoJCALBpS9x4y9ugU8zuz7Q5kRChXGquKqP68xMx bB3Jf9j+fGiAIplRqlGnMM6L8ITS8x4= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b="lz/q40Zs"; 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=1695190786; a=rsa-sha256; cv=none; b=dZ5Qg0cZOobJyNwZKBO9fY9RbTtRbkVb2iDraIrViHOZ2CevahNbe2E7kp/UwZrhjOZj+n X0eu9obHoxEp942roLFn0zB705ygIrDgf7yw5tpVl8GtDaaDKw0maXW2qtvrmingPFwMlm OaLGj5b+e3K4hyz5KRU9nDlalxYgmuo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695190786; x=1726726786; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Gl8Dsupvu0i/ycW4/TMF2HWHASVPpn6wN7AOIH8Z+Fc=; b=lz/q40Zs/rG/bcUGqypFN+9GBkSj0uuSnsMCVFi+yJi0jTPdsFb+MReB 8C4whZRmOcH/DnURRLkt9MEHxicvKIxIlmeGIgteukhWQlWrgCMCAFQFO LmL4dTFCUiRY/gV2Nmwy9vOQlteYihcNRi98lzervSvst3WwL2MoZyWXK Nmslqq6djYSVIkyVbqSeIvrT15OVtGESP7o2FindposlQyCkg1Ny8FPaW R1bxkjZsy3aPNLcc0YXXrxZgSE7WqYcwmi2YXBUABCujVNjRWBWLVtRJn KCe87J7HgXaPwgwpis1V/Q4YUe2v96HccXvDSnS0vtq9K9ZeJNyMIp4t2 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="365187624" X-IronPort-AV: E=Sophos;i="6.02,161,1688454000"; d="scan'208";a="365187624" 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:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="740060540" X-IronPort-AV: E=Sophos;i="6.02,161,1688454000"; d="scan'208";a="740060540" 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:41 -0700 From: Huang Ying To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Arjan Van De Ven , Huang Ying , Andrew Morton , Mel Gorman , Vlastimil Babka , David Hildenbrand , Johannes Weiner , Dave Hansen , Michal Hocko , Pavel Tatashin , Matthew Wilcox , Christoph Lameter Subject: [PATCH 03/10] mm, pcp: reduce lock contention for draining high-order pages Date: Wed, 20 Sep 2023 14:18:49 +0800 Message-Id: <20230920061856.257597-4-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: C9BFD120013 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: kmjb4xgggp6a4mhbmeq6t1881i1peedb X-HE-Tag: 1695190785-975136 X-HE-Meta: U2FsdGVkX18LMtrAA51zoMms1tno9GPuOP5OxYHKMXikvjoUigaO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RvVXJMVawymyV6CKH1cV7I5D2jLA0LXclIPzbUqmHv/yZDx5YONnqera3wLMO8fgN/lnoAGu5M/fXs7l8bvdpUMONUrxxEIgjznObQ/rf7IfinbkGTSVzivLSE0zig6Maldv4ZieuVtbFWILPyz179y/fOi6eSdniwWnbg1CYIE8f8FSUblI5N68IrtVE25kdcyVCnADyC+FYyzjfB341hJHlIhNSzz+EPS3BxnxWq3q5RBaWOZLs2xZ2+acPGFRRu+fw30Q4zXp88Rhca1iL4S4OyF5eQsLIfi6mDRAmQ7JkKagw4pwcOgAfuakZDv0aRP8v99jXZdwQh4vbtVzXZIPWuy2gxm0Ma/y5dfyDD6y1ryVmp7kiepyb0Cr//B5DBTznhZ1Y6bn4JIpOX3LlZnDk6RQiNR5oubaSdo 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 commit f26b3fa04611 ("mm/page_alloc: limit number of high-order pages on PCP during bulk free"), the PCP (Per-CPU Pageset) will be drained when PCP is mostly used for high-order pages freeing to improve the cache-hot pages reusing between page allocating and freeing CPUs. On system with small per-CPU data cache, pages shouldn't be cached before draining to guarantee cache-hot. But on a system with large per-CPU data cache, more pages can be cached before draining to reduce zone lock contention. So, in this patch, instead of draining without any caching, "batch" pages will be cached in PCP before draining if the per-CPU data cache size is more than "4 * batch". On a 2-socket Intel server with 128 logical CPU, with the patch, the network bandwidth of the UNIX (AF_UNIX) test case of lmbench test suite with 16-pair processes increase 72.2%. The cycles% of the spinlock contention (mostly for zone lock) decreases from 45.8% to 21.2%. The number of PCP draining for high order pages freeing (free_high) decreases 89.8%. The cache miss rate keeps 0.3%. Signed-off-by: "Huang, Ying" 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 | 2 ++ include/linux/gfp.h | 1 + include/linux/mmzone.h | 1 + mm/page_alloc.c | 37 ++++++++++++++++++++++++++++++++++++- 4 files changed, 40 insertions(+), 1 deletion(-) diff --git a/drivers/base/cacheinfo.c b/drivers/base/cacheinfo.c index 3e8951a3fbab..a55b2f83958b 100644 --- a/drivers/base/cacheinfo.c +++ b/drivers/base/cacheinfo.c @@ -943,6 +943,7 @@ static int cacheinfo_cpu_online(unsigned int cpu) if (rc) goto err; update_data_cache_size(true, cpu); + setup_pcp_cacheinfo(); return 0; err: free_cache_attributes(cpu); @@ -956,6 +957,7 @@ static int cacheinfo_cpu_pre_down(unsigned int cpu) free_cache_attributes(cpu); update_data_cache_size(false, cpu); + setup_pcp_cacheinfo(); return 0; } diff --git a/include/linux/gfp.h b/include/linux/gfp.h index 665f06675c83..665edc11fb9f 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -325,6 +325,7 @@ void drain_all_pages(struct zone *zone); void drain_local_pages(struct zone *zone); void page_alloc_init_late(void); +void setup_pcp_cacheinfo(void); /* * gfp_allowed_mask is set to GFP_BOOT_MASK during early boot to restrict what diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 64d5ed2bb724..4132e7490b49 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -677,6 +677,7 @@ enum zone_watermarks { #define wmark_pages(z, i) (z->_watermark[i] + z->watermark_boost) #define PCPF_PREV_FREE_HIGH_ORDER 0x01 +#define PCPF_FREE_HIGH_BATCH 0x02 struct per_cpu_pages { spinlock_t lock; /* Protects lists field */ diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 828dcc24b030..06aa9c5687e0 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -52,6 +52,7 @@ #include #include #include +#include #include #include "internal.h" #include "shuffle.h" @@ -2385,7 +2386,9 @@ static void free_unref_page_commit(struct zone *zone, struct per_cpu_pages *pcp, */ if (order && order <= PAGE_ALLOC_COSTLY_ORDER) { free_high = (pcp->free_factor && - (pcp->flags & PCPF_PREV_FREE_HIGH_ORDER)); + (pcp->flags & PCPF_PREV_FREE_HIGH_ORDER) && + (!(pcp->flags & PCPF_FREE_HIGH_BATCH) || + pcp->count >= READ_ONCE(pcp->batch))); pcp->flags |= PCPF_PREV_FREE_HIGH_ORDER; } else if (pcp->flags & PCPF_PREV_FREE_HIGH_ORDER) { pcp->flags &= ~PCPF_PREV_FREE_HIGH_ORDER; @@ -5418,6 +5421,38 @@ static void zone_pcp_update(struct zone *zone, int cpu_online) mutex_unlock(&pcp_batch_high_lock); } +static void zone_pcp_update_cacheinfo(struct zone *zone) +{ + int cpu; + struct per_cpu_pages *pcp; + struct cpu_cacheinfo *cci; + + for_each_online_cpu(cpu) { + pcp = per_cpu_ptr(zone->per_cpu_pageset, cpu); + cci = get_cpu_cacheinfo(cpu); + /* + * If per-CPU data cache is large enough, up to + * "batch" high-order pages can be cached in PCP for + * consecutive freeing. This can reduce zone lock + * contention without hurting cache-hot pages sharing. + */ + spin_lock(&pcp->lock); + if ((cci->size_data >> PAGE_SHIFT) > 4 * pcp->batch) + pcp->flags |= PCPF_FREE_HIGH_BATCH; + else + pcp->flags &= ~PCPF_FREE_HIGH_BATCH; + spin_unlock(&pcp->lock); + } +} + +void setup_pcp_cacheinfo(void) +{ + struct zone *zone; + + for_each_populated_zone(zone) + zone_pcp_update_cacheinfo(zone); +} + /* * Allocate per cpu pagesets and initialize them. * Before this call only boot pagesets were available.