Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp1142lqo; Wed, 15 May 2024 18:13:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVSrZ4CiZ9Np8nVfZYrwhPHJjAQPdcmlwDJKFIvVfUexsnl+4GgEJ0ygRZI3c1nMtDen0yWPGu7OgXX8HsDI+Q3wdOIuxurf7gdSjd2HQ== X-Google-Smtp-Source: AGHT+IE7Y1YdmxcqNzOEtdLcFwrZvo8fIX86lao9Ylo5bx5Gqu0z1R7BA5P8vHreyMWf0CVjTrrW X-Received: by 2002:a05:622a:1a1b:b0:43a:b1bf:4762 with SMTP id d75a77b69052e-43dfdababe1mr190605671cf.5.1715822015893; Wed, 15 May 2024 18:13:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715822015; cv=pass; d=google.com; s=arc-20160816; b=Cn9RDoE6RZ4DYjFZP7IHJCi6bGgcpYmwR9i8cfcBIMF22BSzBGz8CWLcE5oQTu8px5 P4udcXKq06rvGGur7jWnGiHFPywrRSOJCNIf4ZIj//ebKkkt0ycaXi/ZXq+6m0gO4VW4 PmLHsfKNkvQod13ba+3krU/E4axrjBa9v8w6+dCVNsPFOnMzmtbACQdte8X5QZbECGf5 ze4ItphKgK4MH2bxdkR7M11S0czNYpHd638sbPK7jm8OTl/VqU2EuzUveCc9ARY8h7Tq 6UbB6N5wLznwr9hlvWBHt7R4akS/74eYbHMlGUbe+XG2Vf8+rq5SAIrK48KTj7XUPa+X V0dw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=V9idPTsI7t4AJ0FvbhcpdhNgeAHxtx1gXNf8WyfuOVQ=; fh=00YMzrOU22/KV6BEB1s5AOroO+LPPZFKovRttpJ68s0=; b=IyVhwpPcn4fMYZnuSnobCFpoSOrEg+t0y+toCf0o9EwhavwqtsCvI4czn9/LGc/kcL uFBDVINWoUoOshPohmBoP4yqTNPTc1uBm/q10FlzGhgCzYjId4MIF1tbPvZUzQESImuC oZmPop3MybDqG/BJqyblxcRLMTiYipiW/p2QZuEtcJDDq+uiJOoR0bAwl25CJNW5Lxoo 3Xu0nN7FfSDZVifWYku0D28L/Ob8deYIl8/gOP2pb+5BBrO+bX96R0DCQF+9UdUsFPsB YyIulxB7Q58QoeIal6umiU9t0AYcRzuT/WRmjB0u3s4pPnCAoyQhw0y8FXMD9ssYGmlL D4CQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XVhlPfbb; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-180541-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180541-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-43e2460fe7dsi61609341cf.432.2024.05.15.18.13.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 18:13:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-180541-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=XVhlPfbb; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-180541-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180541-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 9C6AD1C21AE4 for ; Thu, 16 May 2024 01:13:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7D4ED138C; Thu, 16 May 2024 01:13:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XVhlPfbb" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3872310F2 for ; Thu, 16 May 2024 01:13:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715822011; cv=none; b=N+Mzf2sez0s2jL22In2xDCdmC7C9LCmerd+K3ndSZhgC0kMJxSz2tnrx2R5POLeH5/C5khuDMoVLN1IwqpCma1EOrKxHrkrRbAWPsoy2tmGWj7aSFmX/5T8vJqZZ0rmuY8ybbTrJv2iORJnSjD9QOdQyzl6eclP6M2r0J0Up56c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715822011; c=relaxed/simple; bh=aU4bIrypo3fSMNvIVeRGR0akyO7b61BZ7RtJMzkJ7gI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ElrXftBDTf52G9LlDwAF1aVfYXjJffwUXOlnp8hYjnSaIiJ6HhDggdxAwIGhMELrTRujEWioyNCtbazGGg6qSeDl+RxcQyM4pNGVraFtdyqIYFcbGFIDyqkicsEbbu+P5M826SJ8yrtnpqSLi26Rp4hR9q/prHEgfm/E3kCJDTw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=XVhlPfbb; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715822009; 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=V9idPTsI7t4AJ0FvbhcpdhNgeAHxtx1gXNf8WyfuOVQ=; b=XVhlPfbbSqMLfIFimkttO7eyvZpd2OdpvVBU1GxJfNcFFEtAQb/MGTff6jO4ufeWSJryk8 31U2ISMwTg3RVqlXO+PV94hfaUAVwoVi2kKOanvSEdQTBH4MJwDfUC7+2q+y4M5/Ebdy27 veuh8gT5uGiA8139nakotD1XvB45Hpg= 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-587-janpmtJhOAa1J5JL1Yb_6w-1; Wed, 15 May 2024 21:13:23 -0400 X-MC-Unique: janpmtJhOAa1J5JL1Yb_6w-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 041FD101A525; Thu, 16 May 2024 01:13:23 +0000 (UTC) Received: from fedora (unknown [10.72.116.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E3F8F1C00A90; Thu, 16 May 2024 01:13:18 +0000 (UTC) Date: Thu, 16 May 2024 09:13:14 +0800 From: Ming Lei To: Waiman Long Cc: Jens Axboe , Tejun Heo , Josef Bacik , cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Dan Schatzberg Subject: Re: [PATCH] blk-cgroup: Properly propagate the iostat update up the hierarchy Message-ID: References: <20240515143059.276677-1-longman@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240515143059.276677-1-longman@redhat.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 On Wed, May 15, 2024 at 10:30:59AM -0400, Waiman Long wrote: > During a cgroup_rstat_flush() call, the lowest level of nodes are flushed > first before their parents. Since commit 3b8cc6298724 ("blk-cgroup: > Optimize blkcg_rstat_flush()"), iostat propagation was still done to > the parent. Grandparent, however, may not get the iostat update if the > parent has no blkg_iostat_set queued in its lhead lockless list. > > Fix this iostat propagation problem by queuing the parent's global > blkg->iostat into one of its percpu lockless lists to make sure that > the delta will always be propagated up to the grandparent and so on > toward the root blkcg. > > Note that successive calls to __blkcg_rstat_flush() are serialized by > the cgroup_rstat_lock. So no special barrier is used in the reading > and writing of blkg->iostat.lqueued. > > Fixes: 3b8cc6298724 ("blk-cgroup: Optimize blkcg_rstat_flush()") > Reported-by: Dan Schatzberg > Closes: https://lore.kernel.org/lkml/ZkO6l%2FODzadSgdhC@dschatzberg-fedora-PF3DHTBV/ > Signed-off-by: Waiman Long > --- > block/blk-cgroup.c | 19 ++++++++++++++++++- > 1 file changed, 18 insertions(+), 1 deletion(-) > > diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c > index 059467086b13..2a7624c32a1a 100644 > --- a/block/blk-cgroup.c > +++ b/block/blk-cgroup.c > @@ -323,6 +323,7 @@ static struct blkcg_gq *blkg_alloc(struct blkcg *blkcg, struct gendisk *disk, > blkg->q = disk->queue; > INIT_LIST_HEAD(&blkg->q_node); > blkg->blkcg = blkcg; > + blkg->iostat.blkg = blkg; > #ifdef CONFIG_BLK_CGROUP_PUNT_BIO > spin_lock_init(&blkg->async_bio_lock); > bio_list_init(&blkg->async_bios); > @@ -1025,6 +1026,8 @@ static void __blkcg_rstat_flush(struct blkcg *blkcg, int cpu) > unsigned int seq; > > WRITE_ONCE(bisc->lqueued, false); > + if (bisc == &blkg->iostat) > + goto propagate_up; /* propagate up to parent only */ > > /* fetch the current per-cpu values */ > do { > @@ -1034,10 +1037,24 @@ static void __blkcg_rstat_flush(struct blkcg *blkcg, int cpu) > > blkcg_iostat_update(blkg, &cur, &bisc->last); > > +propagate_up: > /* propagate global delta to parent (unless that's root) */ > - if (parent && parent->parent) > + if (parent && parent->parent) { > blkcg_iostat_update(parent, &blkg->iostat.cur, > &blkg->iostat.last); > + /* > + * Queue parent->iostat to its blkcg's lockless > + * list to propagate up to the grandparent if the > + * iostat hasn't been queued yet. > + */ > + if (!parent->iostat.lqueued) { > + struct llist_head *plhead; > + > + plhead = per_cpu_ptr(parent->blkcg->lhead, cpu); > + llist_add(&parent->iostat.lnode, plhead); > + parent->iostat.lqueued = true; > + } > + } Reviewed-by: Ming Lei Thanks, Ming