Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp6565238ybx; Mon, 11 Nov 2019 11:03:01 -0800 (PST) X-Google-Smtp-Source: APXvYqyRZIWqN/G2AE90Ypz0j5x5qDozkdrsGcPVNSAwdF71ZBK17ijrl8gzhfRJwJZuDkkgLng+ X-Received: by 2002:aa7:c3d0:: with SMTP id l16mr28338894edr.18.1573498981419; Mon, 11 Nov 2019 11:03:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573498981; cv=none; d=google.com; s=arc-20160816; b=mdgIiaKKTZ/o8au+ZUoUzlgToByGOCZbTYj2v3ox21qiwaqvkcRY6hMUPKdsTUwzXu nQNRbMTLXtbOJJEU0bIVe0sAtRBu+tf2DwP/925W9y+sQKQd2NCODiX7Hm97P1BtMmme cLtFzsWKUzdMbUUPSrMqSHb/ATABeOufLcU69XmydwoRR1R13M5qCeDfrBWLTUN3VRCj 21NW/2GflwYRyusagE2Yk/s8lXq4AvFwttggAfR2iXh07hMbLUn63t/7Gky/5xIgLavB clTon6Izg7PFU7MXojgmQKWaoHVkhPcUQf8hm+VtWqia9N4BAknBCtqPJhGYirO15X4U h1jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vGM96LOH0E8UjtYIPkfl5DNk0Mth9JPRn2UJQns8Ct8=; b=y9grPyv09eSuQtvAn/KMWIPyGghnp7wQG7o80f11ltjARbvHUNJVTDahKcG55PHRfO 0vKeXwdHYW8+rHxkyDtXPaVjQpB+Mvt7RZvPBodJyZiBRYnoaEWjQfEb9u0FC/mqlO1e M+s3IbE30rgHyaDhvzXR2S+MwiMl1Tcod+cZ0jWAo9jgOZW56Wta9DX0H8HBmDVqwi3u ospQALWqftwcGtsgboOP3aT//1I/FvYIdmrfGSSu97o8js49owWQRipyXclhZLEZqnlz 3jJxJyHFJl8MTI92hSTX4uxx+nmUgBhQuIG4Hj8qcKxnP2xGb2dQppCGG/nzC9t7Q6Gi tLZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="rIGtEdO/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l4si10010432edr.286.2019.11.11.11.02.33; Mon, 11 Nov 2019 11:03:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="rIGtEdO/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729942AbfKKSvH (ORCPT + 99 others); Mon, 11 Nov 2019 13:51:07 -0500 Received: from mail.kernel.org ([198.145.29.99]:45092 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730399AbfKKSvF (ORCPT ); Mon, 11 Nov 2019 13:51:05 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D20A621783; Mon, 11 Nov 2019 18:51:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1573498264; bh=nOdb0morVCevoRgj9jdt1Se5t/PhgfuBFny6rZQK4ao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rIGtEdO/Bmee4kh9MYTKOzFK2VzGxZeFhrGb+WhPk7AtRR9/DqzBTRN31A/JUyG45 MmJ4FWtraPl6HPf+hq6ipGqOmj0NT5cNQkPbQUP22SKMtSMFlmpghSDokMcH2T9f7k fjdIA0UuH4938APHvku50BAjyVC7S2RBoFz+PztY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mel Gorman , Michal Hocko , Vlastimil Babka , David Hildenbrand , Matt Fleming , Thomas Gleixner , Borislav Petkov , Qian Cai , Andrew Morton , Linus Torvalds Subject: [PATCH 5.3 030/193] mm, meminit: recalculate pcpu batch and high limits after init completes Date: Mon, 11 Nov 2019 19:26:52 +0100 Message-Id: <20191111181502.532468342@linuxfoundation.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191111181459.850623879@linuxfoundation.org> References: <20191111181459.850623879@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mel Gorman commit 3e8fc0075e24338b1117cdff6a79477427b8dbed upstream. Deferred memory initialisation updates zone->managed_pages during the initialisation phase but before that finishes, the per-cpu page allocator (pcpu) calculates the number of pages allocated/freed in batches as well as the maximum number of pages allowed on a per-cpu list. As zone->managed_pages is not up to date yet, the pcpu initialisation calculates inappropriately low batch and high values. This increases zone lock contention quite severely in some cases with the degree of severity depending on how many CPUs share a local zone and the size of the zone. A private report indicated that kernel build times were excessive with extremely high system CPU usage. A perf profile indicated that a large chunk of time was lost on zone->lock contention. This patch recalculates the pcpu batch and high values after deferred initialisation completes for every populated zone in the system. It was tested on a 2-socket AMD EPYC 2 machine using a kernel compilation workload -- allmodconfig and all available CPUs. mmtests configuration: config-workload-kernbench-max Configuration was modified to build on a fresh XFS partition. kernbench 5.4.0-rc3 5.4.0-rc3 vanilla resetpcpu-v2 Amean user-256 13249.50 ( 0.00%) 16401.31 * -23.79%* Amean syst-256 14760.30 ( 0.00%) 4448.39 * 69.86%* Amean elsp-256 162.42 ( 0.00%) 119.13 * 26.65%* Stddev user-256 42.97 ( 0.00%) 19.15 ( 55.43%) Stddev syst-256 336.87 ( 0.00%) 6.71 ( 98.01%) Stddev elsp-256 2.46 ( 0.00%) 0.39 ( 84.03%) 5.4.0-rc3 5.4.0-rc3 vanilla resetpcpu-v2 Duration User 39766.24 49221.79 Duration System 44298.10 13361.67 Duration Elapsed 519.11 388.87 The patch reduces system CPU usage by 69.86% and total build time by 26.65%. The variance of system CPU usage is also much reduced. Before, this was the breakdown of batch and high values over all zones was: 256 batch: 1 256 batch: 63 512 batch: 7 256 high: 0 256 high: 378 512 high: 42 512 pcpu pagesets had a batch limit of 7 and a high limit of 42. After the patch: 256 batch: 1 768 batch: 63 256 high: 0 768 high: 378 [mgorman@techsingularity.net: fix merge/linkage snafu] Link: http://lkml.kernel.org/r/20191023084705.GD3016@techsingularity.netLink: http://lkml.kernel.org/r/20191021094808.28824-2-mgorman@techsingularity.net Signed-off-by: Mel Gorman Acked-by: Michal Hocko Acked-by: Vlastimil Babka Acked-by: David Hildenbrand Cc: Matt Fleming Cc: Thomas Gleixner Cc: Borislav Petkov Cc: Qian Cai Cc: [4.1+] Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/page_alloc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1947,6 +1947,14 @@ void __init page_alloc_init_late(void) wait_for_completion(&pgdat_init_all_done_comp); /* + * The number of managed pages has changed due to the initialisation + * so the pcpu batch and high limits needs to be updated or the limits + * will be artificially small. + */ + for_each_populated_zone(zone) + zone_pcp_update(zone); + + /* * We initialized the rest of the deferred pages. Permanently disable * on-demand struct page initialization. */ @@ -8479,7 +8487,6 @@ void free_contig_range(unsigned long pfn WARN(count != 0, "%d pages are still in use!\n", count); } -#ifdef CONFIG_MEMORY_HOTPLUG /* * The zone indicated has a new number of managed_pages; batch sizes and percpu * page high values need to be recalulated. @@ -8493,7 +8500,6 @@ void __meminit zone_pcp_update(struct zo per_cpu_ptr(zone->pageset, cpu)); mutex_unlock(&pcp_batch_high_lock); } -#endif void zone_pcp_reset(struct zone *zone) {