Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp1006532rwl; Wed, 12 Apr 2023 07:08:37 -0700 (PDT) X-Google-Smtp-Source: AKy350ZNMdzv8A9S28XlBMSAtQLvcYTJSqQkxr4fBJCJLm1zEZi+S+UcH6BmbdtANCrkWGr6EHy5 X-Received: by 2002:a05:6402:1154:b0:504:c269:1497 with SMTP id g20-20020a056402115400b00504c2691497mr2420036edw.27.1681308517458; Wed, 12 Apr 2023 07:08:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681308517; cv=none; d=google.com; s=arc-20160816; b=mz8AAZVJSuCcp13OwpBK1Wlc1RvCuGHxL9nizH4NP1NEqga1KscWfOUHtbKIvNKyeW jq13+jCmqMm2nJ+QZTrFTQGdnc8cBn0U5BoFJHDOOmKBbcf0xErqBQCshfSAViHtaXvv Aayppi8lHwDbp7ty4qNC7OlKKzkfkaMVrLzBCaBW9gfGwu4u/1krOBk14pe7OTUEKNld 0QjI4mLAtHMWnoZnWnwWZ5NiPUlEbrRptaGbL3NiSgZ43wCtscoP9KkobyxAMz97dVXd 9glG9ZqY5aI6T2pbLeIDxQgLM3jYSOriHl8oucTF0CmgA8rYtc5mEFMND9XKCfttHX+C mg7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=qYl5ekyLj7iQo8GlRLOVDEB8fB577eS6HixCK1lG4No=; b=Dc/WdUsN2jmHs8ueUpF1dJshvgneUQyRmOLgcOsrAH+fxQNRdHdCek7w/3EUn++EFk 6zNLzci30jtGToBS0XwQahgYIzxkqRMFtaXzhf9OqLxPQ/l3FF4uXjpeyLuC7hY2clUH VChZ0LKg7kKEJQqgaMFauHYjJ37+366XHZ+waWamL2XuRAKjg4OgwLOupOVZ3XzB4QlM F4bvZtcWDWUSlrfqzfFDLJ0uvBhxh4O/0KSJTK56Wz+hhNO1hlUTKuU4RmeZRIm8f0gn p1yYT7VKsea6aBVCAoiVhJD9HLWikqFtw3qx5WLz/U3EmLHGVdQ2qyl+BIrlOI1tTGCa HJrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=orZuSzpU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e8-20020a17090658c800b0094e4586003asi1850632ejs.610.2023.04.12.07.08.10; Wed, 12 Apr 2023 07:08:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=orZuSzpU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230167AbjDLN6y (ORCPT + 99 others); Wed, 12 Apr 2023 09:58:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229707AbjDLN6x (ORCPT ); Wed, 12 Apr 2023 09:58:53 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A21B383F0 for ; Wed, 12 Apr 2023 06:58:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=qYl5ekyLj7iQo8GlRLOVDEB8fB577eS6HixCK1lG4No=; b=orZuSzpUOPEWh+QSjssey7Xg2/ p9j7M+8XFzvErQ6S1ZCL/QeuBlghz2x/b/Omg2ky4zfBLABZk69RLHLO8UUvslAHzXGD88ljeRMjR mZrMyz0N3QN0J6o5XNMOHYI3puAbM9f4FhasfVMiy/1xh+m3OQ7VE67ETaMNxEpRpHRppKocpChUW kuGGzlSqctuTiLjhQQrM2+PQ+NUySa93PkDMxzHyJyE8ePCzxBU/76ox5pWSZm5wpr3kbfxV29WSy gdCxBi/hmC2e2PzE5IBo/+53aYn4zeGCCGhUTSvNFQRxOPS5uojmR9zu+uBl5YmFudX2yuSIRH2+4 uWmoldYg==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1pmazV-00DwJs-1P; Wed, 12 Apr 2023 13:58:29 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 5FC73300274; Wed, 12 Apr 2023 15:58:28 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 1B67F2095F655; Wed, 12 Apr 2023 15:58:28 +0200 (CEST) Date: Wed, 12 Apr 2023 15:58:28 +0200 From: Peter Zijlstra To: Aaron Lu Cc: Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Tim Chen , Nitin Tekchandani , Waiman Long , Yu Chen , linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH] sched/fair: Make tg->load_avg per node Message-ID: <20230412135828.GB629496@hirez.programming.kicks-ass.net> References: <20230327053955.GA570404@ziqianlu-desk2> <20230412115936.GC628377@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230412115936.GC628377@hirez.programming.kicks-ass.net> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 12, 2023 at 01:59:36PM +0200, Peter Zijlstra wrote: > On Mon, Mar 27, 2023 at 01:39:55PM +0800, Aaron Lu wrote: > > When using sysbench to benchmark Postgres in a single docker instance > > with sysbench's nr_threads set to nr_cpu, it is observed there are times > > update_cfs_group() and update_load_avg() shows noticeable overhead on > > cpus of one node of a 2sockets/112core/224cpu Intel Sapphire Rapids: > > > > 10.01% 9.86% [kernel.vmlinux] [k] update_cfs_group > > 7.84% 7.43% [kernel.vmlinux] [k] update_load_avg > > > > While cpus of the other node normally sees a lower cycle percent: > > > > 4.46% 4.36% [kernel.vmlinux] [k] update_cfs_group > > 4.02% 3.40% [kernel.vmlinux] [k] update_load_avg > > > > Annotate shows the cycles are mostly spent on accessing tg->load_avg > > with update_load_avg() being the write side and update_cfs_group() being > > the read side. > > > > The reason why only cpus of one node has bigger overhead is: task_group > > is allocated on demand from a slab and whichever cpu happens to do the > > allocation, the allocated tg will be located on that node and accessing > > to tg->load_avg will have a lower cost for cpus on the same node and > > a higer cost for cpus of the remote node. > > > > Tim Chen told me that PeterZ once mentioned a way to solve a similar > > problem by making a counter per node so do the same for tg->load_avg. > > Yeah, I send him a very similar patch (except horrible) some 5 years ago > for testing. > > > After this change, the worst number I saw during a 5 minutes run from > > both nodes are: > > > > 2.77% 2.11% [kernel.vmlinux] [k] update_load_avg > > 2.72% 2.59% [kernel.vmlinux] [k] update_cfs_group > > Nice! > > > Another observation of this workload is: it has a lot of wakeup time > > task migrations and that is the reason why update_load_avg() and > > update_cfs_group() shows noticeable cost. Running this workload in N > > instances setup where N >= 2 with sysbench's nr_threads set to 1/N nr_cpu, > > task migrations on wake up time are greatly reduced and the overhead from > > the two above mentioned functions also dropped a lot. It's not clear to > > me why running in multiple instances can reduce task migrations on > > wakeup path yet. > > If there is *any* idle time, we're rather agressive at moving tasks to > idle CPUs in an attempt to avoid said idle time. If you're running at > about the number of CPUs there will be a fair amount of idle time and > hence significant migrations. > > When you overload, there will no longer be idle time and hence no more > migrations. > > > Reported-by: Nitin Tekchandani > > Signed-off-by: Aaron Lu > > If you want to make things more complicated you can check > num_possible_nodes()==1 on boot and then avoid the indirection, but ... finishing emails is hard :-) I think I meant to say we should check if there's measurable overhead on single-node systems before we go overboard or somesuch.