Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp885211rdf; Fri, 3 Nov 2023 20:14:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF91d8kWJusDXyQY3d3asDJdYRdguv5vBwxmcmz7nLbi2//vY5aP/7mnhHvA9UuYRMh+x/P X-Received: by 2002:a17:903:18a:b0:1cc:4402:9e7c with SMTP id z10-20020a170903018a00b001cc44029e7cmr7116566plg.15.1699067673691; Fri, 03 Nov 2023 20:14:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699067673; cv=none; d=google.com; s=arc-20160816; b=ibWhyEdQrsxDq9IHj3p4ofKZ9pW4B3qW+Ib35R4jQ+7zW/yaLDwXGaEtAV2X7xc3Ue IPF+khflb4jv8brOME0Uv0u+5HEWqlBpy9dJ9KhpSDI7cJt8pSNXcoWOWDaj8df89bxP ivlg9dJJ+5uvR8OdZ91gJKrr440CWyCBwyxEdOEy6THotQW805zjpC9AfXo7CVx7tQfn mF2aMEzP7nb+KGUp32r2aSgCbSz9TSO9JVMU8FYGTNqav+dsXXEIotDOegrVVr8pG/DA thUbsflWe7G9Fybs6q2KQtsNf89O2XnI/z6mxMv19Q+hX6oSb/SFo7QfjDMLmsSRCV75 TyNg== 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=hS4kJte8gk1GCOKjzV5i1FwejHRsJSLuVKpVg9S++l3D/9Zkb8WDTWNhXm54tuv1Sm 0f3penJM6dYxLeoUi01u6bm3oAsruiNVqFdfPU+1MxcTH+cTo6dxf+of4TnAjXKmoSkO L4KKWTdoZU8I4nY+gep1FUhZlarc2YuOtT2LtpARxZBf3708oBqWOVqc8KwOivSVdd2U CRntBgBlt0ZWkj6bZ/IPGRTnC/BDZTe106V2Awjyhf27aHtqcihHY/glrWzxtI2IBU+U gAo2+b/3DEYhEhSgg/4RXr6jHWTtO58ogMIiLyrGtkDCw1pk0sxqjkrKWEyO+e/eCZT9 7LIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MfhWmoQE; 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 k7-20020a170902c40700b001c32fe6cdf9si3142267plk.386.2023.11.03.20.14.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 20:14:33 -0700 (PDT) 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=MfhWmoQE; 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 D0A5A8243B4E; Fri, 3 Nov 2023 20:14:30 -0700 (PDT) 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 S1345010AbjKDDOX (ORCPT + 99 others); Fri, 3 Nov 2023 23:14:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235095AbjKDDOP (ORCPT ); Fri, 3 Nov 2023 23:14:15 -0400 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 00A73D6C for ; Fri, 3 Nov 2023 20:13:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699067603; 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=MfhWmoQEMiiewXFHr0+pWOsUiZ0JJq+sLGdg8DwztwkARIWC+gBwun3UiCf7X2moDRLkn7 fE1uRFrG9XqEq4mUevGEZFmfWEF1wTsq6yKW17OpbSNQuT1FCdNfKBDzRFfese57cUQ63o HPBiI17VrYke9LyAwwLslHtuXD5gEAA= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-682-OUuOja0NPyqBrgMW7m7vhg-1; Fri, 03 Nov 2023 23:13:19 -0400 X-MC-Unique: OUuOja0NPyqBrgMW7m7vhg-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 0D11B1C05148; Sat, 4 Nov 2023 03:13:19 +0000 (UTC) Received: from llong.com (unknown [10.22.33.74]) by smtp.corp.redhat.com (Postfix) with ESMTP id 987BAC1290F; Sat, 4 Nov 2023 03:13:18 +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 v3 3/3] cgroup: Avoid false cacheline sharing of read mostly rstat_cpu Date: Fri, 3 Nov 2023 23:13:03 -0400 Message-Id: <20231104031303.592879-4-longman@redhat.com> In-Reply-To: <20231104031303.592879-1-longman@redhat.com> References: <20231104031303.592879-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=-1.3 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]); Fri, 03 Nov 2023 20:14:31 -0700 (PDT) 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