Received: by 2002:a05:6520:4d:b0:139:a872:a4c9 with SMTP id i13csp2566240lkm; Mon, 20 Sep 2021 18:53:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygnQhBK/HRAetWMWix/178j2CY+jLx5K9uPtQ65kWky27VlBIVlTksnQJgNcF8LRpoDGdb X-Received: by 2002:a05:6638:34a6:: with SMTP id t38mr22131712jal.19.1632189095873; Mon, 20 Sep 2021 18:51:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632189095; cv=none; d=google.com; s=arc-20160816; b=xTD2N5pmZgMpYbIPF0LZdSGbJJTM/DTWmDoMc1V/0eZiYoeQJ+bTAhcYyTWpyX7C+e VWSx5JTpFXZY8XtlWiT/HO7nU9cCsL5cMA6jLFW3qwe+632w4JGyZzDjMMDk7gufaH3t m/PJlSH7W21wTTW1uhqzyXgUIDNfEFxTGxVB+WtdzikK+33MeB0AusocNTE8Nf5SxFfO MijJvA5DIAXQq+BH7MW5ng5R9MYirv3Qff+8xV6hVVACn+8s31gGn7cOEwth02UpS6gw XE8qXsTBXecFWiGZKo4yxPtoeD+RwD4n5Yxf5TDw4NLfeIoKfn3c+b/Mt5FjfpEW+FXy Ht7g== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mXovP2SDQgv4rGSJ6ZdzDAg11J+5+Cb/kpuXcKoCRZ8=; b=Kcq09nAEaXXnEkdU5UBn/x5KGkZFwS1gEhXQdc20cjNpCdpGrFqw96nmazsFoiNNqA TkawQjOsUM/D9HQdQut0F00Xy7vE8/gbfD5tlJSDLW1/YDUO/+/Yf5o7Lms6HBJ+mJ6S niDZIxtIOEbcJ569jBj6Hoto+Xh0d4odaoTb+TqY0zGJobYDqhXTjOjdzTG4UCN8PEak eCUQfT1HaPb82wkE4yCJCC8eyoEqy3WT49JGqUTvjyCQUu+a3+DXeaEk9l3W85vf/E5F sXQKM0Jdc2b5eOLM/f+tPPz+nZuj56JJhjZcTrlAKKorEoxrInbsHYgY62becznmbnup U2DA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eoZB5ACH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w3si9477139ilg.44.2021.09.20.18.51.23; Mon, 20 Sep 2021 18:51:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eoZB5ACH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357985AbhITSFR (ORCPT + 99 others); Mon, 20 Sep 2021 14:05:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:57658 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355975AbhITR54 (ORCPT ); Mon, 20 Sep 2021 13:57:56 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0C90863216; Mon, 20 Sep 2021 17:14:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158099; bh=ax2mhvkpee7ckuHwy+/FhcIhJe52nfgBGEDZ1nqYX9Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eoZB5ACHcVc8hB8pXSBCX498JnHxnl8kAuSP25hEVL2h6WmxVK7oAj5bn+qQMXumm K6dEPzs0P7AVZemaHTT2FsbCmvWeGKNNTUa1yuuvISmSZEjzm/eqeClz62MASt423r lRs6burllrrfhxw8yz6DbMMA8GeLzCgDB8ymm0gQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Davide Zini , Paolo Valente , Jens Axboe , Sasha Levin Subject: [PATCH 4.19 279/293] block, bfq: honor already-setup queue merges Date: Mon, 20 Sep 2021 18:44:01 +0200 Message-Id: <20210920163942.966284849@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163933.258815435@linuxfoundation.org> References: <20210920163933.258815435@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paolo Valente [ Upstream commit 2d52c58b9c9bdae0ca3df6a1eab5745ab3f7d80b ] The function bfq_setup_merge prepares the merging between two bfq_queues, say bfqq and new_bfqq. To this goal, it assigns bfqq->new_bfqq = new_bfqq. Then, each time some I/O for bfqq arrives, the process that generated that I/O is disassociated from bfqq and associated with new_bfqq (merging is actually a redirection). In this respect, bfq_setup_merge increases new_bfqq->ref in advance, adding the number of processes that are expected to be associated with new_bfqq. Unfortunately, the stable-merging mechanism interferes with this setup. After bfqq->new_bfqq has been set by bfq_setup_merge, and before all the expected processes have been associated with bfqq->new_bfqq, bfqq may happen to be stably merged with a different queue than the current bfqq->new_bfqq. In this case, bfqq->new_bfqq gets changed. So, some of the processes that have been already accounted for in the ref counter of the previous new_bfqq will not be associated with that queue. This creates an unbalance, because those references will never be decremented. This commit fixes this issue by reestablishing the previous, natural behaviour: once bfqq->new_bfqq has been set, it will not be changed until all expected redirections have occurred. Signed-off-by: Davide Zini Signed-off-by: Paolo Valente Link: https://lore.kernel.org/r/20210802141352.74353-2-paolo.valente@linaro.org Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/bfq-iosched.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index b2bad345c523..c8c94e8e0f72 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -2137,6 +2137,15 @@ bfq_setup_merge(struct bfq_queue *bfqq, struct bfq_queue *new_bfqq) * are likely to increase the throughput. */ bfqq->new_bfqq = new_bfqq; + /* + * The above assignment schedules the following redirections: + * each time some I/O for bfqq arrives, the process that + * generated that I/O is disassociated from bfqq and + * associated with new_bfqq. Here we increases new_bfqq->ref + * in advance, adding the number of processes that are + * expected to be associated with new_bfqq as they happen to + * issue I/O. + */ new_bfqq->ref += process_refs; return new_bfqq; } @@ -2196,6 +2205,10 @@ bfq_setup_cooperator(struct bfq_data *bfqd, struct bfq_queue *bfqq, { struct bfq_queue *in_service_bfqq, *new_bfqq; + /* if a merge has already been setup, then proceed with that first */ + if (bfqq->new_bfqq) + return bfqq->new_bfqq; + /* * Prevent bfqq from being merged if it has been created too * long ago. The idea is that true cooperating processes, and @@ -2210,9 +2223,6 @@ bfq_setup_cooperator(struct bfq_data *bfqd, struct bfq_queue *bfqq, if (bfq_too_late_for_merging(bfqq)) return NULL; - if (bfqq->new_bfqq) - return bfqq->new_bfqq; - if (!io_struct || unlikely(bfqq == &bfqd->oom_bfqq)) return NULL; -- 2.30.2