Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp2401707rdf; Mon, 6 Nov 2023 13:07:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IFl1lp5XOn7yukZsibQd2sKmGoXfDDWLG/C39J26/1jveI8+G2hCx2AvJ1IUo4WGuzLPhb3 X-Received: by 2002:a05:6870:4f:b0:1e9:919d:83ec with SMTP id 15-20020a056870004f00b001e9919d83ecmr639836oaz.28.1699304855942; Mon, 06 Nov 2023 13:07:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699304855; cv=none; d=google.com; s=arc-20160816; b=nB2DBqFnJmeRJ9lY7gRvcH4pVxT5J99ToIWbbXROTzGnQF6OeCJYEOrCrYJj6+RiG2 il+/wBFBdLc/g2NpF/JAl2SFVXt6AFa1OUPWjYaHqvizN5QUDeBpmF9xAXN/qlvou4gZ YiJrqlrJyxUl5/QNLsmAEjecIErZAzOKjSu1mXUcHnX2cBSZ5HJBUS+sLOHKBrOButWG mSuTi+agpnMPmpglmMn/tKpEJR0TIVqi6D06cbku7v3vri147jyqGhYT5vjmrjMIsjFb tEkMEOXxTjW9YpQdeHFJdPmxLXGTtOXGqJH3sjGb1x5ETesd35hsCGkgMw11c2WiDoJ3 /Buw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=XmQVU6t74ex4eso68OgbidZVE99nykXUpQNQesplaTI=; fh=vy39GFVfO6UaqrntP4AkYjitNZbWGjYvUyBXYh7mu0A=; b=Mk340DH607r5rWCjE9OHcHteMcl7YnRK8M0npFcsAY2BFekEBWsd5Dp5lFqBP7BgUd B4J/dhEiK2Hbs86GasPCqyWXZQlvLxyep+J7VKVXCcckbkL2ace0E+nxZYDb5aAQ4peH UN6xOcwd+qH1wUOP/9vM4tv7nb7bh4v4DIyc2hz3Sgbt1b4/iKDsg82rw6lXYFVxlSJD SmdRvskl8d/9lm9GcKG7KMEGtWBIevFcA4cpJWXyJOFImyUfRiS6ueEF8NSJmf8tWlPr ryfG3wmxLhlP9VVq8UFjsYJdCGKoT4BjwPUd0MnN7WvR6RT24p91N9JVXrHPz3leaxmx fIKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Vuj+fMfO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id v202-20020a6361d3000000b005859f850b2csi469049pgb.38.2023.11.06.13.07.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 13:07:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Vuj+fMfO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 55C18808EE79; Mon, 6 Nov 2023 13:07:26 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233040AbjKFVHE (ORCPT + 99 others); Mon, 6 Nov 2023 16:07:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56966 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233069AbjKFVHB (ORCPT ); Mon, 6 Nov 2023 16:07:01 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F668D78 for ; Mon, 6 Nov 2023 13:06:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699304773; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XmQVU6t74ex4eso68OgbidZVE99nykXUpQNQesplaTI=; b=Vuj+fMfO0up3UOfyeYBZObUGeidF1Z6QqupBtbwNxabgwNiiVScvJGqKQ9jM6KNs/+Y/zf o2NJOL70KMslc4wo8mD3hAoFgR7zXDyCznmUgejx+iTR5tBraVkPEG8X5VlzlVmGZzhvg4 LAWT/wEXVeBb1XGY16EZmSnkyj2YwE4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-639-gw2tMBDePVuaeSbAcBUdnw-1; Mon, 06 Nov 2023 16:06:10 -0500 X-MC-Unique: gw2tMBDePVuaeSbAcBUdnw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B38D9845DCE; Mon, 6 Nov 2023 21:06:09 +0000 (UTC) Received: from llong.com (unknown [10.22.17.168]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4781FC1290F; Mon, 6 Nov 2023 21:06:09 +0000 (UTC) From: Waiman Long To: Tejun Heo , Zefan Li , Johannes Weiner Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Joe Mario , Sebastian Jug , Yosry Ahmed , Waiman Long Subject: [PATCH v4 3/3] cgroup: Avoid false cacheline sharing of read mostly rstat_cpu Date: Mon, 6 Nov 2023 16:05:43 -0500 Message-Id: <20231106210543.717486-4-longman@redhat.com> In-Reply-To: <20231106210543.717486-1-longman@redhat.com> References: <20231106210543.717486-1-longman@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 06 Nov 2023 13:07:26 -0800 (PST) The rstat_cpu and also rstat_css_list of the cgroup structure are read mostly variables. However, they may share the same cacheline as the subsequent rstat_flush_next and *bstat variables which can be updated frequently. That will slow down the cgroup_rstat_cpu() call which is called pretty frequently in the rstat code. Add a CACHELINE_PADDING() line in between them to avoid false cacheline sharing. A parallel kernel build on a 2-socket x86-64 server is used as the benchmarking tool for measuring the lock hold time. Below were the lock hold time frequency distribution before and after the patch: Run time Before patch After patch -------- ------------ ----------- 0-01 us 14,594,545 15,484,707 01-05 us 439,926 207,382 05-10 us 5,960 3,174 10-15 us 3,543 3,006 15-20 us 1,397 1,066 20-25 us 25 15 25-30 us 12 10 It can be seen that the patch further pushes the lock hold time towards the lower end. Signed-off-by: Waiman Long --- include/linux/cgroup-defs.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h index ff4b4c590f32..a4adc0580135 100644 --- a/include/linux/cgroup-defs.h +++ b/include/linux/cgroup-defs.h @@ -491,6 +491,13 @@ struct cgroup { struct cgroup_rstat_cpu __percpu *rstat_cpu; struct list_head rstat_css_list; + /* + * Add padding to separate the read mostly rstat_cpu and + * rstat_css_list into a different cacheline from the following + * rstat_flush_next and *bstat fields which can have frequent updates. + */ + CACHELINE_PADDING(_pad_); + /* * A singly-linked list of cgroup structures to be rstat flushed. * This is a scratch field to be used exclusively by -- 2.39.3