From patchwork Mon Sep 20 16:44:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 514373 Delivered-To: patch@linaro.org Received: by 2002:a02:c816:0:0:0:0:0 with SMTP id p22csp2336495jao; Mon, 20 Sep 2021 11:45:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwl/Rx2+SQUJIDSff0j5wZ3qOesXAi1eTjsPaeBZd84+nTEMbmHy5Ui1rfjpfOsUaqC+OjB X-Received: by 2002:a17:907:20cb:: with SMTP id qq11mr29239676ejb.488.1632163516257; Mon, 20 Sep 2021 11:45:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632163516; cv=none; d=google.com; s=arc-20160816; b=lxEk5n0Bw9GRxZcx2eTqk0B/qGsk9OIGjY3R/u1UnGorAEBhJw49RyJO40zdSxR9Vt lja3fPhnfjzdsDs9Tk5bf851aJ15/Puzwz4s4iJJ01ltyr6UZOHVfihmAkHxBw8RIxtF wB7FVSyuZD3qXlQ47rxksXOYLt/rvc69Bq1ZrwcCFB6jccdaLwyWWFdNK5Ue4ZqeStgE 3cP9wMkJKRXexqkYgLC9h7F//gf/upfdyIx6rlC5YEGmZ8Ud21bY9bc+y8jDE6TlOKT0 CF+LzergZQ0F2m28aR7+XsDhlamPWFNRzQ0MRAHIPO7TkqVYaQ0ux5KBvUzv8kat/D0s X+JQ== 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=34ujAlPILJF3zX+kpkVxTZIwkR1tgKy3A1MnpfUAWt4=; b=f4XI4u0oWUKcKpFCjBaZY2GbrB9B9vjKSwBKjQV45vcIzovcw9XLbMUw55Ix4Gd2fu Wx8S25WrpQGjlbP7xxecV0/2NeM1RpFRenTS2kfx0rzjkiU1Q7oc/hgVkHKa2M+GCeCF ZBpdDbbgCTcKm+mNCOftvhQnoIenPSgCwYun4ir4p6cee9uaQBgd41cZ2LMQBD//2vaL hcioCpjVZD8zsNy6asOAtmkZuYuL6cErS9KT6sD0hNAszAK0KNGN6gt7zCV9Ro39tqF3 soCubQo09aGGPv2R5JSvO4zMFpcR/P/0z+vuoHQxptbmUSlwCoVoOunZIID9DQy11KeW szjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kmSifqKx; 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 b13si11716020ede.572.2021.09.20.11.45.16; Mon, 20 Sep 2021 11:45:16 -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=kmSifqKx; 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 S1384125AbhITSqi (ORCPT + 11 others); Mon, 20 Sep 2021 14:46:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:59876 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383439AbhITSoc (ORCPT ); Mon, 20 Sep 2021 14:44:32 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B09E36335B; Mon, 20 Sep 2021 17:32:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632159179; bh=/ylWhQgWilVG54d1ELp7na5y0xNTpbUxviz6hlHmaiY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kmSifqKx4IVZo4AOFDFeVkXOPE23RhJdgJo3Ce5ad9MFSCNjtny2RmxYcxZLRIi/h YuD+6W4NNy2zoLInjfzdoMv7+iXKGh1WtTfl4bOrERtHKxpkRxG4NAHIKCqPruii/R dJ0Gpo9DD9zvtHhxj7h52Fz+b0hazfFrNKRbqp+k= 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.14 113/168] block, bfq: honor already-setup queue merges Date: Mon, 20 Sep 2021 18:44:11 +0200 Message-Id: <20210920163925.352279771@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163921.633181900@linuxfoundation.org> References: <20210920163921.633181900@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 9360c65169ff..3a1038b6eeb3 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -2662,6 +2662,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; } @@ -2724,6 +2733,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 @@ -2825,9 +2838,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;