Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp325125pxb; Sat, 11 Sep 2021 06:19:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyyw1qXquLmEivar1XJB7QjjLjxhcolJ/5Arn/CxSKTyn/QaG4z/KODc5hYz3/BANtkOpK0 X-Received: by 2002:a17:906:ecb8:: with SMTP id qh24mr2930520ejb.88.1631366374930; Sat, 11 Sep 2021 06:19:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631366374; cv=none; d=google.com; s=arc-20160816; b=MVviCVOGvkiqfSS4GzH2ceUOMd2w81M8ozSCVP2mqfxVnpxYQXv0Nh5xVNFtt6M0XN Oe+C71eOKsr7ALT/YF5L9ePkbzXEj6wZnbfd1so0WT+UgKVMwgTNwE6uPEVwxYoEn6rE 6tsOMut8ApU9z0uVCLr8pKPWxJxOqdcTZMe/3/z3kJw061mtTI4TdpRnbIXAdEHb1nI+ FwfJ+0d/TS2kb9UmY+WxcsQAvOpuhSoEB/KhPZOwgNQgSN2tVkGxxMTz96swZzT+yZDm FP8/k4BfHbO9Vsd1iI4xYLVuRfCrw1dW3PSiavmbu3v8z6gdgf+ozqOL7oeXPNnGHkdh i6eg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6qBuo1Ug9kwkIcjOAlpB4Ylrpqj3s9/sj15Xook0Whg=; b=V+Ehb1qGOmIAC/q045/yqFzA+XPHjhvTQv/FTCeSVgReAgk/gPlI1KSIwoW05Libq0 W5rxot8Qc6Ghxvi0hfTTGMhK2FtEW7HlykYIP27vDbMQpvAcjmjOPvk3Rab4EoRnjPDO MPrQFp/u/mlowlUwtjeFcVIi8tTulEADiQLyeoMbtNGwOWuf4GJc6s+mnfEte6VRJYTv XheOK6VRn/1t4+9uucwvW5qb6kMQ6CO73JUDG09h0Y8ULpZtxvlKtra1WP4iyzVQzuO1 hzXdZ1NenVXrZGy4BKV6wt2Tbi5QbGyheXisqDtWpKI9L8VWASRgKVIclqrhx95IuUs1 vn8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=U0vRmuA1; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b25si1813423edn.132.2021.09.11.06.19.11; Sat, 11 Sep 2021 06:19:34 -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=@kernel.org header.s=k20201202 header.b=U0vRmuA1; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236609AbhIKNOQ (ORCPT + 99 others); Sat, 11 Sep 2021 09:14:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:37760 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236238AbhIKNNf (ORCPT ); Sat, 11 Sep 2021 09:13:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 72EE8611BF; Sat, 11 Sep 2021 13:12:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631365943; bh=1lER5U1URVwqHEHX8YR2oWa3ASTDOq2WHBg4RUMgXtI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U0vRmuA1+tYON50Pjh/eSVKNzwcvyv3SCzYEXNnvjODAsl8rf2OJt1XyE+ibW0QMm y4gNTLaS59vdyKt6zpbsOAO+eLbAGJkVbQ0N68KCYEB1ShrmGOpugCWD1Sa5fHUYzv 3zgPpHT84dgy/fCv41UkhmZnFpATuWhPrtHk5WLifuHPqga7nzx06VU7bOBHWvDxse ROr+OIAOaOFeC9XrFtwvvhEoL8y7lRd/61SdTMptwM3q3i94td8EsW6IY7TWVrFt0t Rdyl7+xA/xupb/FS9MKm/QJy3mEqqX/OumqRuHCIQzmIIbnh81idAy0pIe8Oqb8HF4 XVBSSXlYpENPQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Paolo Valente , Davide Zini , Jens Axboe , Sasha Levin , linux-block@vger.kernel.org Subject: [PATCH AUTOSEL 5.14 25/32] block, bfq: honor already-setup queue merges Date: Sat, 11 Sep 2021 09:11:42 -0400 Message-Id: <20210911131149.284397-25-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210911131149.284397-1-sashal@kernel.org> References: <20210911131149.284397-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 727955918563..08d9122dd4c0 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -2659,6 +2659,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; } @@ -2721,6 +2730,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; + /* * Check delayed stable merge for rotational or non-queueing * devs. For this branch to be executed, bfqq must not be @@ -2822,9 +2835,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