Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7543948rwd; Tue, 20 Jun 2023 02:47:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4wdMTIwEFiVJYP18OpEgp0SS6r91xbjwh3dI/TA/muQbCHo0UcqGUrznLeGabz+Krs3NZu X-Received: by 2002:a05:6358:e9c:b0:130:e4f3:b888 with SMTP id 28-20020a0563580e9c00b00130e4f3b888mr3068913rwg.29.1687254423285; Tue, 20 Jun 2023 02:47:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687254423; cv=none; d=google.com; s=arc-20160816; b=sxTWGm6emPw+seGxVpYnO9yn7Z2trEEZD+b0Oscli0oe+xSS33CTwucl8ndSw2tdGc SJ8r9YjsmPX6ADkqxbcoLvtRQBBhCfR0fuMqAs04AT7TfOdmd1GFtHb7dzh90UQOp1+f oEVVK/AgUPXaopJBkD23dMR+BnLSpIe3pSpjqLenH9Sa9KSti63Ens31RCQsYLYJKLsr ljThSWpDcPDetcu2Mlp+8kYJrOfJq4x/2ioqEpkh1RiQnC8AP3QGtuuJd3PSFIw9ApOq JXGw9q3XlQWjBiBLvtq9YfXtNnDI82LcuQ5YEXr/89D9M+DKDaqYK/C6LHGKB8XLItmq /BHQ== 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=qCVVL3C0DZsRF9OazXGnGiYF9tGXGgUu4l3EImJeYTk=; b=PsWwHuxE7BpGyAg9IV8By65qM6xpqOzd6pQj2Q7hUV4DVzNPIUpXELq4ceKTleqoyT 3L/Nv3wjiFMVd6nRKByixtm2ZoIhZHzeLPQ2V+YyhYGOnTEhcQ+265uveib/IwIJN5IC +BasBAY82IiAjsgbCvHYiuteUY/f9+I1AZcT6IwqLm2kJ9FyAjnX75ZQynDrZFTc6Fsk tmDqiXp5ZJjhSLV3sj7TRdzg4vQ5XHmfO9kHI1H8yDm/J3d+/jHVeinOToLAMEQ8atmS w5PA7BvJjK0ifg0WRhg/tqmSz0n0w0U8Sz34rC2uoThpY9h5BlqiASS/nT9U5dBWYOrW jfYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=TKRbQjOi; 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 g19-20020a633753000000b00543cba6043asi1372961pgn.151.2023.06.20.02.46.49; Tue, 20 Jun 2023 02:47:03 -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=TKRbQjOi; 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 S231972AbjFTJMl (ORCPT + 99 others); Tue, 20 Jun 2023 05:12:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231953AbjFTJMa (ORCPT ); Tue, 20 Jun 2023 05:12:30 -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 77655199E; Tue, 20 Jun 2023 02:12:08 -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=qCVVL3C0DZsRF9OazXGnGiYF9tGXGgUu4l3EImJeYTk=; b=TKRbQjOiPPXkKbjrt/96y46r0Z VlNQIZDpZlZkqjS46akOPzFaSs/7O9ACT8D/Vu0FyLT7nTXV+do7Q6tjtyrHmiCAYCzXPU6auiAa2 aOb4cgUyi8JjmxP/Ef17hhmVY/Mh6oiyZerrNffD9Jro16egeI+0GoaBYCs1pPHwPT4ehw6EE2UkM I8+0AY/tggflicXD/z/SZvDvRzk/mPX16pni7U5u2H91pGa9t//1Qa2OW9y3gfks6vrEOmmRPRcaM QnscQ36+ZMJPMDzo93mANTl1mlr5BF4D7rICa06GxDYVWMtdllh0ZyKLO6OYmuY4HUlfRs6bDqafg Lt9aBKTQ==; 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 1qBXOm-00G0u8-0a; Tue, 20 Jun 2023 09:11:41 +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 37FBB300274; Tue, 20 Jun 2023 11:11:39 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 1B347213E05C9; Tue, 20 Jun 2023 11:11:39 +0200 (CEST) Date: Tue, 20 Jun 2023 11:11:39 +0200 From: Peter Zijlstra To: Swapnil Sapkal Cc: linux-kernel@vger.kernel.org, linux-tip-commits@vger.kernel.org, Aaron Lu , Mathieu Desnoyers , x86@kernel.org Subject: Re: [tip: sched/core] sched: Fix performance regression introduced by mm_cid Message-ID: <20230620091139.GZ4253@hirez.programming.kicks-ass.net> References: <168214940343.404.10896712987516429042.tip-bot2@tip-bot2> <09e0f469-a3f7-62ef-75a1-e64cec2dcfc5@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <09e0f469-a3f7-62ef-75a1-e64cec2dcfc5@amd.com> 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,T_SCC_BODY_TEXT_LINE,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 Tue, Jun 20, 2023 at 01:44:32PM +0530, Swapnil Sapkal wrote: > Hello Mathieu, > > On 4/22/2023 1:13 PM, tip-bot2 for Mathieu Desnoyers wrote: > > The following commit has been merged into the sched/core branch of tip: > > > > Commit-ID: 223baf9d17f25e2608dbdff7232c095c1e612268 > > Gitweb: https://git.kernel.org/tip/223baf9d17f25e2608dbdff7232c095c1e612268 > > Author: Mathieu Desnoyers > > AuthorDate: Thu, 20 Apr 2023 10:55:48 -04:00 > > Committer: Peter Zijlstra > > CommitterDate: Fri, 21 Apr 2023 13:24:20 +02:00 > > > > sched: Fix performance regression introduced by mm_cid > > > > Introduce per-mm/cpu current concurrency id (mm_cid) to fix a PostgreSQL > > sysbench regression reported by Aaron Lu. > > > > Keep track of the currently allocated mm_cid for each mm/cpu rather than > > freeing them immediately on context switch. This eliminates most atomic > > operations when context switching back and forth between threads > > belonging to different memory spaces in multi-threaded scenarios (many > > processes, each with many threads). The per-mm/per-cpu mm_cid values are > > serialized by their respective runqueue locks. > > > > Thread migration is handled by introducing invocation to > > sched_mm_cid_migrate_to() (with destination runqueue lock held) in > > activate_task() for migrating tasks. If the destination cpu's mm_cid is > > unset, and if the source runqueue is not actively using its mm_cid, then > > the source cpu's mm_cid is moved to the destination cpu on migration. > > > > Introduce a task-work executed periodically, similarly to NUMA work, > > which delays reclaim of cid values when they are unused for a period of > > time. > > > > Keep track of the allocation time for each per-cpu cid, and let the task > > work clear them when they are observed to be older than > > SCHED_MM_CID_PERIOD_NS and unused. This task work also clears all > > mm_cids which are greater or equal to the Hamming weight of the mm > > cidmask to keep concurrency ids compact. > > > > Because we want to ensure the mm_cid converges towards the smaller > > values as migrations happen, the prior optimization that was done when > > context switching between threads belonging to the same mm is removed, > > because it could delay the lazy release of the destination runqueue > > mm_cid after it has been replaced by a migration. Removing this prior > > optimization is not an issue performance-wise because the introduced > > per-mm/per-cpu mm_cid tracking also covers this more specific case. > > > > Fixes: af7f588d8f73 ("sched: Introduce per-memory-map concurrency ID") > > Reported-by: Aaron Lu > > Signed-off-by: Mathieu Desnoyers > > Signed-off-by: Peter Zijlstra (Intel) > > Tested-by: Aaron Lu > > Link: https://lore.kernel.org/lkml/20230327080502.GA570847@ziqianlu-desk2/ > > I run standard benchmarks as a part of kernel performance regression > testing. When I run these benchmarks against v6.3.0 to v6.4-rc1, > I have seen performance regression in hackbench running with threads. When I did > git bisect it pointed to this commit and reverting this commit helps regains > the performance. This regression is not seen with hackbench processes. Well, *this* commit was supposed to help fix the horrible contention on cid_lock that was introduced with af7f588d8f73. > Following are the results from 1 Socket 4th generation EPYC > Processor(1 X 96C/192T) configured in NPS1 mode. This regression > becomes more severe as the number of core count increases. > > The numbers on a 1 Socket Bergamo (1 X 128 cores/256 threads) is significantly worse. > > Threads: > > Test: With-mmcid-patch Without-mmcid-patch > 1-groups: 5.23 (0.00 pct) 4.61 (+11.85 pct) > 2-groups: 4.99 (0.00 pct) 4.72 (+5.41 pct) > 4-groups: 5.96 (0.00 pct) 4.87 (+18.28 pct) > 8-groups: 6.58 (0.00 pct) 5.44 (+17.32 pct) > 16-groups: 11.48 (0.00 pct) 8.07 (+29.70 pct) I'm really confused, so you're saying that having a process wide spinlock is better than what this patch does? Or are you testing against something without mm-cid entirely?