From patchwork Mon Sep 20 16:44:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 514356 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp2316418jao; Mon, 20 Sep 2021 11:21:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytOtB2sh2ci4ACK8p0cgJNtGIvss67SkruVVdUY3CDU0oCzRlJAPUSD4mGR24HbjU7E3En X-Received: by 2002:a05:6402:1011:: with SMTP id c17mr30968567edu.144.1632162066380; Mon, 20 Sep 2021 11:21:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632162066; cv=none; d=google.com; s=arc-20160816; b=O5oA1GFOei+b0xm0RM1sTxZ9WqsuH/q104/H80iHINaWldvjMxlXhE8eCnrxTGtcZd yuAF0pZsCUtGZ3CON44LsdHXmoY3uzfcwK/g96BsKg6+Wvdrzhz0kTW8ys6JiEUIgCYR RFrxMLw/gSXQAUI1p8gl1LD/JtIUhRAN9Lw0teL6YJLyuiaxZo3Y7X81jwfMywzB65nk rxffysLYJUzf1XSbcCeNqpIpgpNRphzNm7Yk23BXVqIO7azM0kdAaFVky7NcaTfq1puz NE5lLy1t9L21D802klWKiJ16xvoJNNsG/sIV8xVJ70WM2ZblpL75OPRh2NCGHdBV4daF vOMA== 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=ZW3Ro1SAoZW8OlB7As6oM/WacLzZhgl4wwKacOR85h8=; b=gWUbxFdRV56i7WdwkIE68W5vEB5RsaIGb3IIVzqAugvUkxG6q+sCY+eT0Jr2wrymTu Om9TQcFHfX2lQI6QZaYW45wm5S8o7lv2IysAFOcurszZRS8yiNak2MSevO/akEO1nfMz vuA9oUdYk0VpJM5oRKL6f1IuZr0bqbdbTKKEj8woOY7rQDn+LjfATgDpgjdZlgaIqzq3 nMPp56y1c0GAhogMmnV6UI2csaAA5TmscE//tTFdlMDmfZVhVMOUgHUoVqbhBHFwvYZE 5fuC+GkDzGHdub29xn+hhmF6wdCd+RaHBzEH5+TaiH5RFjBJaIyvRnjtWCtxJ0cRL1yE Ynhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=KBqrhjHr; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 n7si16605055ejl.237.2021.09.20.11.21.05; Mon, 20 Sep 2021 11:21:06 -0700 (PDT) Received-SPF: pass (google.com: domain of stable-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=KBqrhjHr; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-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 S1376692AbhITSW2 (ORCPT + 11 others); Mon, 20 Sep 2021 14:22:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:40570 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377713AbhITSUZ (ORCPT ); Mon, 20 Sep 2021 14:20:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9DE6C632B2; Mon, 20 Sep 2021 17:23:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158626; bh=4D7BOZ3sSydsNKGX4MRKuDj3nyP3kE/+lJpPsxELm9A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KBqrhjHrO9vuNydqYUkqmxu4IkX7yToHLYkEqn6Hc2R1e8kxMUbXY8P8/4TaUTBmr AUgGkaiNQCLTsmcqRGlq4B9LaAkyVDZL6SaCHndBAG2tvv8XSlcKcp07Y3n64pfY5a McD4hB6109CnOV6EdabNyOvI6tgtmXuQL2rBo6Oc= 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 5.4 242/260] block, bfq: honor already-setup queue merges Date: Mon, 20 Sep 2021 18:44:20 +0200 Message-Id: <20210920163939.350851487@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163931.123590023@linuxfoundation.org> References: <20210920163931.123590023@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@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(-) -- 2.30.2 diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index 73bffd7af15c..8dee243e639f 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -2523,6 +2523,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; } @@ -2582,6 +2591,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; + /* * Do not perform queue merging if the device is non * rotational and performs internal queueing. In fact, such a @@ -2636,9 +2649,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;