Received: by 2002:ab2:7a09:0:b0:1f8:46dc:890e with SMTP id k9csp55248lqo; Wed, 15 May 2024 07:36:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUP/qqNmLA0oV7XKfmGzv5QErty4paXIf1QQatud9AFlvq3kIErtKqKqfK4GgCVU2m3BLDbitYLMn3bAJjEZ++h2AOhct0xIsJZx4RxIw== X-Google-Smtp-Source: AGHT+IGeViebG4rl/jqqZrvTfPZCFX6Z7p9VNt1CK/bLZbytn6fV9xlJmVJkZEH5Q/rj5ovtry2z X-Received: by 2002:a17:902:ea01:b0:1f0:84e3:a602 with SMTP id d9443c01a7336-1f084e3a87fmr63492905ad.63.1715783788999; Wed, 15 May 2024 07:36:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715783788; cv=pass; d=google.com; s=arc-20160816; b=vPOAMXUar0qoW6CPL8K/mGCIZcYYNIEYnJB9xoPgY9dEQ1WEaPFMH4P/rujrdP6/e4 x8rD9HOgt/jfouDGIYdjaByy4jvCGsDZTcAbJSBjCW1I7iOzYw+jZ6cvHkKy/EAYTNJL RTkT/PADd616Xpa1RSIdiFZPkuVoUMGqkHuDaANqbQoh21r1DXOFOjTFC0MVk6BV971A YnLXpUpPW49XM6tTa5676qxkvP03piS3Q25XdopVfH0VXqzlKvd5yYG6q/qTM31pkbjM 9BgVOF0XFUhuEbI1+/YekBnEjvMIOSVwRo3RU+jKvm/CuDC+ePyBKeI1fuEwmEva4l+A xSUg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=Sc9fEb2mK7PfNta2o/2kA9lq5+CKKqFEWMN/clrZxT8=; fh=SA9D337+W7M516VhrnSy17SzYXdyaqWMfmNTOiPpqZo=; b=bx3llpuA8jJlOMRAyuf+5iWTaZxdE6sp0aBu1S8YoWSyQ39xfbXhswOZp/WQZMBpPm HfCkSEuGsKbAYB/96wVTZv1Hmsz6eblLiyiwN1O9pTSyv59l2+h1xbi+SFjguzlkYUvZ f1YZk89gawWS6ljwDCfhC4iNUe1lDPOG6k+7fmQAmjZrPbbAX5CXDjsSuswFbF3mLSiH Y0PGi/AQMSWY0SeL22O8yhJwdEKwa+E4B5H/8xY/0LkQat8CudcbckpfuOF0KC1AlHtR pS9PCpGOZiYDQ/8ksMnDBOMmmyQMEWadyQVt6KxC3N8blnxUc8nd0wp/rqwOCz76DqUQ Kfqw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="S/TsJrOE"; 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-180014-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180014-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d9443c01a7336-1ef0bf31602si140868445ad.294.2024.05.15.07.36.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 07:36:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-180014-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="S/TsJrOE"; 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-180014-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180014-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id CD18628185D for ; Wed, 15 May 2024 14:35:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DA4E115572E; Wed, 15 May 2024 14:35:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="S/TsJrOE" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 88601154BEC for ; Wed, 15 May 2024 14:35:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715783737; cv=none; b=sVK1hgwJCJqDQOmsyAho9lZov8jIcELsHoWoo1F0A1qpkQT+8nrBqBAF5UPvDtUQzUb2GSKtAvKLTVwSYFeSgFVUag+BxJ0K/bd7xCeiQy7Z5sAq1MNWa1CZaB2pG4dgeog4I5gsJ9zqBbytTosc//Hn37BELC/eM4W3mQF6XH4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715783737; c=relaxed/simple; bh=XrEHWXzHYH414DvlVESjOtx15TYA6noXORpfTNUMgRU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=aiNuZkNbSrvZTD3HDRqVNKHk3BWg1IGdOMxeKZait6zKCPt7JGJk8kE5qco3zfGfqKn6K+O733qpNwdWdquOa71sO6ktNHCZMWV4PN27oX/pE4mxxsypqThA4xBi58qAhO8FzJy9QtFlI1+VC3muJad/ZRQF6wxZjuj0LCU//OY= 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=S/TsJrOE; arc=none smtp.client-ip=170.10.133.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=1715783734; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Sc9fEb2mK7PfNta2o/2kA9lq5+CKKqFEWMN/clrZxT8=; b=S/TsJrOE3TJ7wf9kbNxBSBoHT0g33UJiPpskQPuZhE8npc/UFb1zL3CbovXDG9RAPozKiD ywQZI0EtxTA76MWdEztdTDftCOZVuGvxUl1k67TS+EMPb/xb/0NSv2RBo9ea3657dmTirt FAc4FFHX63OA4lBKGifBcYMmXKJTp+c= 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-658-OvT26MQQMRis29XSB5ZWXA-1; Wed, 15 May 2024 10:35:21 -0400 X-MC-Unique: OvT26MQQMRis29XSB5ZWXA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (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 77A5D1C3F0EE; Wed, 15 May 2024 14:35:20 +0000 (UTC) Received: from [10.22.33.50] (unknown [10.22.33.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD231200A08E; Wed, 15 May 2024 14:35:19 +0000 (UTC) Message-ID: <7ab67d43-84af-4328-8aca-9383afa2d6df@redhat.com> Date: Wed, 15 May 2024 10:35:19 -0400 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] blk-cgroup: Properly propagate the iostat update up the hierarchy 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 References: <20240515143059.276677-1-longman@redhat.com> Content-Language: en-US From: Waiman Long In-Reply-To: <20240515143059.276677-1-longman@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 On 5/15/24 10:30, 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; > + } > + } > } > raw_spin_unlock_irqrestore(&blkg_stat_lock, flags); > out: Note that this patch will conflict with Ming's patch (https://lore.kernel.org/linux-block/20240515013157.443672-3-ming.lei@redhat.com/). Will send out an updated version later on to synchronize with his patch. Cheers, Longman