Received: by 2002:ab2:7a09:0:b0:1f8:46dc:890e with SMTP id k9csp57430lqo; Wed, 15 May 2024 07:40:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVK/ov2oicMQTNtEG+ebCSnvnW5B8OjG78OpHroGlPuGUeJR7b8ioml40savKjmcCQiePU5NNx76Jhf6nYw5dixD6HyToSxczEDEftuWA== X-Google-Smtp-Source: AGHT+IEvfcJ5FgGuTYHKHAo7O7OmBUXNFiEKz6wksgMUdlgkqfddPtTIFgEjWMRJpnCmHJPg4N2X X-Received: by 2002:a05:6a20:d494:b0:1b0:18e6:ac24 with SMTP id adf61e73a8af0-1b018e6ada4mr3457343637.37.1715784005697; Wed, 15 May 2024 07:40:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715784005; cv=pass; d=google.com; s=arc-20160816; b=EZJEjvNZb+wj9nj3ftRK1ClRBrXiGQNPGCr190ZfHGVdnNdsiU1mWd+46RuXSo8FLU BDiCHlP82dsRD36nJFrRSGnr7sP1kddis6GkuuYZ8WRsgOpRElADkVq1lZN/GhrXpc4m fCBhbjgIjPJ6MFdE8rwD/E2yMApcL+rGLBxY5xsPnCocfFlt6yeoHZ/N3+oqi44lFgoY 8MJWJ7IV3rFO6h+pGcpiSZG0t0TVDfyk+94d7/xTSDZJfRZx5H1YjY7jEWIHeQy7SilR 5KkWs3TtLlr/3jGk6iObZp+G1R6JcfANTq8rdS3eR3C1+wC7jA+seFYpv/7RjiQg46q2 ikHg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=6D0kM1W2IVqoV/ykSNuolWPIzDpABZdm4eW8Ou5+aG0=; fh=QJG39neEge1ELfZqwv9IV9Vk1DuTM6C0hguaE6MkvNo=; b=AWQLPFFUMA41r91pPTr5IjJQiLpEquKPEQ3i6DWFr/EPhs3xOv1JHS7dutgnUkqyAY 5cPVNZKtY5GWFFWblMbX3N7eNzXapz9Ad0diAYFYMXg6EidEBw427bcb2rLNsCTN8Wg/ 7wyRHIx2/K5ou9Mm3zbM1xG6GGKrnZkCW5NaKCkD3gOTFMQ/6tKdWSr6J0zM7/je/w2d rynfzGrZx6WV4eolQSbriwtQMegiB9n7wtdz9bPbVPwzJSB4F8J07jrUIU9u8QXKERGm YytmyF0g5FbZowU/beCAYahUI3Qg5UApOD7HZ4llEJXQboCU6+b/8vApV8+4TrAzLnHS jeew==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JLQbEqrK; 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-180005-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180005-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-63413d72a15si13718605a12.804.2024.05.15.07.40.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 07:40:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-180005-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JLQbEqrK; 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-180005-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180005-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 71A55B234BA for ; Wed, 15 May 2024 14:31:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3F05F1428EE; Wed, 15 May 2024 14:31:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JLQbEqrK" 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 9F92C1422B9 for ; Wed, 15 May 2024 14:31:26 +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=1715783489; cv=none; b=BYdsna/ZIhG6nD5s+dPonnhdE0IFE+vXBAKJ5FQ6EtjWToRdnfI+N+zuFw6siVTn2edxX2ZJ892br60wJVTqxokIUYVRNb2ghAcKx1mpoqlk49udnHR4hKZT7OkIQGjCQjAxGrdWetDJntR4g1/gBwyE0vo4k0E3WIsH0ad7E/A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715783489; c=relaxed/simple; bh=knddn969BjEL1cGIM/hhNec75ASOhQ8q9F478YWF4D0=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=psaGMC1iAkduBMHt2yGuKnZ9QM6dNYOEVj6NrR+pXb0fJZe/PNrS+JUzU4tTBr82SCStmblwcPz8MgIROSryR5NmTZkiuQ7QZ3nPnE0WiOFR1tfMx7i4Nsstt0TtxdFgHfzFv9poWo1Adw8QV6kDggklP/bDPQfZ673EyhVDdJI= 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=JLQbEqrK; 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=1715783485; 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; bh=6D0kM1W2IVqoV/ykSNuolWPIzDpABZdm4eW8Ou5+aG0=; b=JLQbEqrKiAj0WZ/uqSyyVfxzkXZ0crbitbdapuTnZ+XvzcE5INLCOjPBAqSRBG+YuGmAo3 rJR2AcbvuObQgdAwc6wXLiD8OZbt/JJ9i4h0NDh2J0wGQnnmRfqIgnExNgTxqFJ39vrLYZ +tRmrnsHgOWO1YC5IBcMQee9RSQi8Lw= 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-135-kQSitauyNaqCbg0FNlS48w-1; Wed, 15 May 2024 10:31:24 -0400 X-MC-Unique: kQSitauyNaqCbg0FNlS48w-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 8110B8016FA; Wed, 15 May 2024 14:31:23 +0000 (UTC) Received: from llong.com (unknown [10.22.33.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id 91A67400057; Wed, 15 May 2024 14:31:22 +0000 (UTC) From: Waiman Long To: Jens Axboe , Tejun Heo , Josef Bacik Cc: cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Dan Schatzberg , Ming Lei , Waiman Long Subject: [PATCH] blk-cgroup: Properly propagate the iostat update up the hierarchy Date: Wed, 15 May 2024 10:30:59 -0400 Message-Id: <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-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 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; + } + } } raw_spin_unlock_irqrestore(&blkg_stat_lock, flags); out: -- 2.39.3