Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp592289rdb; Thu, 30 Nov 2023 12:44:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IHelslhw9kDpaRgBjzddscl+0ZMIo9smhSll5wX0bPvr44xyDE5cV7Taehso8Psv97yMq71 X-Received: by 2002:a05:6a00:188f:b0:6cd:dfff:19b3 with SMTP id x15-20020a056a00188f00b006cddfff19b3mr6565800pfh.32.1701377054818; Thu, 30 Nov 2023 12:44:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701377054; cv=none; d=google.com; s=arc-20160816; b=Fil6zuk9FVr+fwIOpjTNv4p0o1VqRr9Ml5GsTHokAl3ts1V69gF8hXLuzvIdb3dP3A Vrq6oOW4yHIkxCPnSBg294c9xMGjdumvzI9F278NKUrM0XpV1kaPo0LQwXVXyjRCXL38 thJWaeRdana1NJpX+r8Z1QXcQ2a/0FLwP6A2qCoDisncUY/9/Qa8ttcWqH9y7UvwcAWs AyzUX91bcdpAN5QOp1vGbxk9MAM6m9wUH9JxJ22W712jChavBLClw27TwnCSWjvSxkmB H45vglto6shG9SU90f5hdack96G21DpeSuiSpYzPkx6bOyEh8TH2CigJZF1nQfdxip1g 9BGA== 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=DlJxse7VR/q1n51PSliVgyIuHZ/VI5Kr3VkztHHMLrk=; fh=vy39GFVfO6UaqrntP4AkYjitNZbWGjYvUyBXYh7mu0A=; b=ygDI60FaLDDBEjErqVcTjs3Dt94ZleiBc5Z97fJkdUEDQ18ITS99+VjG8YuYnxbYKs fHEBJp+xvuieplC45Wqq8JWl5nKcc9VtstZu9JJOb7jXVsaXKsDjyt2CTpo96d5GtIdV BW9Zy8P52UU5N4Lsz1JXJIonvp99IYoAoG1bWg6z0vOL54V+Em0JVvxhSEJRVmliLYwf ni11simF6ikH25uid6hcT0Bm4HGs8P4gOtFJY+HqWuZ5GH+pSydOZHahUaPnbFDtjwpI 80HBwYqXjVnwgeI7uHUE7kMlDZDJcMHl6YiqvM2Fkg5ZD61OFYHvkG0jPYmcOveTZ/db elZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PlUujg4H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id v71-20020a63894a000000b005c6125b1731si1997828pgd.547.2023.11.30.12.44.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 12:44:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=PlUujg4H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 2A01A801C8BD; Thu, 30 Nov 2023 12:44:11 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376755AbjK3Unu (ORCPT + 99 others); Thu, 30 Nov 2023 15:43:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376408AbjK3Uno (ORCPT ); Thu, 30 Nov 2023 15:43:44 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71C43171D for ; Thu, 30 Nov 2023 12:43:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701377029; 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=DlJxse7VR/q1n51PSliVgyIuHZ/VI5Kr3VkztHHMLrk=; b=PlUujg4HuExQyzI+8Qk9BynFsuH4LQQBw19QfnMjqhN2cT5xMQk/Ha3OKicIdBJb7tocW0 HVgsl8DbKLHqbblq3d7TU7OhffiDHVyII9l+a1NGuFF8gznf4MbD5tKp2WQ0cCPt4l6fob jzrpejI34OItPiIBxct34DI7PbtDhQQ= 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-516-iFhoK-N_OQq3aTIK0XPlnA-1; Thu, 30 Nov 2023 15:43:45 -0500 X-MC-Unique: iFhoK-N_OQq3aTIK0XPlnA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (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 A8020185A785; Thu, 30 Nov 2023 20:43:44 +0000 (UTC) Received: from llong.com (unknown [10.22.9.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3269E40C6EB9; Thu, 30 Nov 2023 20:43:44 +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-cgroup v5 2/2] cgroup: Avoid false cacheline sharing of read mostly rstat_cpu Date: Thu, 30 Nov 2023 15:43:27 -0500 Message-Id: <20231130204327.494249-3-longman@redhat.com> In-Reply-To: <20231130204327.494249-1-longman@redhat.com> References: <20231130204327.494249-1-longman@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Thu, 30 Nov 2023 12:44:11 -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 9,928,562 9,820,428 01-05 us 110,151 50,935 05-10 us 270 93 10-15 us 273 146 15-20 us 135 76 20-25 us 0 2 25-30 us 1 0 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 37518436cfe7..5a97ea95b564 100644 --- a/include/linux/cgroup-defs.h +++ b/include/linux/cgroup-defs.h @@ -496,6 +496,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