Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp97192iof; Sun, 5 Jun 2022 22:16:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwuyeE3JvqW3JBwKSpHFM+sDwT7Og0ZbpoRJeQOuhuPI9agYI1S+FyVbGrF9Lctcg4d35zM X-Received: by 2002:a17:902:ab1b:b0:167:77aa:d3da with SMTP id ik27-20020a170902ab1b00b0016777aad3damr5357344plb.97.1654492578636; Sun, 05 Jun 2022 22:16:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654492578; cv=none; d=google.com; s=arc-20160816; b=qyoz3dDjcOn5yGIQIyNsFZ23VIWKw0p4YtxqcdLgh5B+9SiECwW5xNgjDosRg8Sihv yZL361l88SAWvZ7NdGsoOH2v3hH32cvCyxvagFOKX15jQMxA0st7V99Pu6IYNcH3fDr8 8KackNsIVG0k0J+B5ljViZwJsaE8D0RFm4LG/iPZN2sgZLK5A8gSp/4bXh9PRkSFEQ2W rlL7dXU7hSgnMftrBPaAH4n+LSH41FrmjzPaTxP+ckugJJUQ+ptc8L75mbE6XELOZkRo cFSK+zkmJKEgSl641M/inlbUEKeG+hQoKUXpEvi015RxsEAViQd2uT5zgfvbrTxFFmUv dGfA== 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=k29yc7w9b88p8N/STUF61jAqzTNY+1ywx+KU40xq0aA=; b=qIT1AgdziYFOIbyFqKAWBRtz4VCDrc3CwiTeI8HC0E85NGqsbx3VEsLreFPW6M+fAk u1uE/UYaf1oe2KjWO1ynsI5oIQtKcwX7Ot/LS2YU+gcSMWd0i8tm17H5Ao/SvDtaYgcY N+Tspq1eJUFYZyd+EvWpAuacMKekCdmVcDs6Kg0xx80GRd2H1yy4iEAuQywA9rHFr1ic xTl+K8V31UGWPZk46rzUN1sDNWZRkNND3tBTMatG2YU0F8aU8LBsqNiiqURZSax4ii6m lfsK6OjZPWnHCm0Dr+k/avtv08QrWrW4U8Z9nVL6Zh20rDTfIIjdk6i4uQqHkVe/uVcE Y1xQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AusE0J6d; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id q199-20020a632ad0000000b003fca85f8c05si18379886pgq.487.2022.06.05.22.16.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 22:16:18 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AusE0J6d; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EB91E1796DD; Sun, 5 Jun 2022 21:22:36 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352289AbiFFDQp (ORCPT + 99 others); Sun, 5 Jun 2022 23:16:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237315AbiFFDQo (ORCPT ); Sun, 5 Jun 2022 23:16:44 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A84644F473 for ; Sun, 5 Jun 2022 20:16:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654485402; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=k29yc7w9b88p8N/STUF61jAqzTNY+1ywx+KU40xq0aA=; b=AusE0J6ds82lzQAKPgPOg7OPKFfy4Gdcc2XeBI833LxDiLSxdGvBxLnT7jRTi1vu/STYbm wSjVBTYh04BaHb0dHi/zxRF4enryGuMxtOXiPHahts8fVlIg2t3xABqTHmmsbAzuMceF5n WOtlG00/yJI8Jn7dWqz4pbNNWej+ECU= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-591-G2OsmNNaN5a1mKdR3Rp8sQ-1; Sun, 05 Jun 2022 23:16:39 -0400 X-MC-Unique: G2OsmNNaN5a1mKdR3Rp8sQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BB2DD3C02187; Mon, 6 Jun 2022 03:16:38 +0000 (UTC) Received: from T590 (ovpn-8-19.pek2.redhat.com [10.72.8.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9020E2026D64; Mon, 6 Jun 2022 03:16:34 +0000 (UTC) Date: Mon, 6 Jun 2022 11:16:29 +0800 From: Ming Lei To: Waiman Long Cc: Tejun Heo , Jens Axboe , cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v6 3/3] blk-cgroup: Optimize blkcg_rstat_flush() Message-ID: References: <20220602192020.166940-1-longman@redhat.com> <20220602192020.166940-4-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220602192020.166940-4-longman@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 02, 2022 at 03:20:20PM -0400, Waiman Long wrote: > For a system with many CPUs and block devices, the time to do > blkcg_rstat_flush() from cgroup_rstat_flush() can be rather long. It > can be especially problematic as interrupt is disabled during the flush. > It was reported that it might take seconds to complete in some extreme > cases leading to hard lockup messages. > > As it is likely that not all the percpu blkg_iostat_set's has been > updated since the last flush, those stale blkg_iostat_set's don't need > to be flushed in this case. This patch optimizes blkcg_rstat_flush() > by keeping a lockless list of recently updated blkg_iostat_set's in a > newly added percpu blkcg->lhead pointer. > > The blkg_iostat_set is added to the lockless list on the update side > in blk_cgroup_bio_start(). It is removed from the lockless list when > flushed in blkcg_rstat_flush(). Due to racing, it is possible that > blk_iostat_set's in the lockless list may have no new IO stats to be > flushed. To protect against destruction of blkg, a percpu reference is > gotten when putting into the lockless list and put back when removed. > > A blkg_iostat_set can determine if it is in a lockless list by checking > the content of its lnode.next pointer which will be non-NULL when in > a lockless list. This requires the presence of a special llist_last > sentinel node to be put at the end of the lockless list. > > When booting up an instrumented test kernel with this patch on a > 2-socket 96-thread system with cgroup v2, out of the 2051 calls to > cgroup_rstat_flush() after bootup, 1788 of the calls were exited > immediately because of empty lockless list. After an all-cpu kernel > build, the ratio became 6295424/6340513. That was more than 99%. > > Signed-off-by: Waiman Long > Acked-by: Tejun Heo Reviewed-by: Ming Lei Thanks, Ming