From patchwork Mon Jun 19 11:43:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valente X-Patchwork-Id: 105829 Delivered-To: patch@linaro.org Received: by 10.140.91.2 with SMTP id y2csp830508qgd; Mon, 19 Jun 2017 04:43:36 -0700 (PDT) X-Received: by 10.101.90.75 with SMTP id z11mr26130457pgs.254.1497872615968; Mon, 19 Jun 2017 04:43:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497872615; cv=none; d=google.com; s=arc-20160816; b=FeIwc6I9jQDq+tq4C+iIPz4y1r2RSm9Ww6pG4vq93cKDcF4/F5nr/KbQa1PnzQRSF2 rZCow10rVNBkDzKEQQdx79JCoGkLdBEEdkaJ/tKJSHGhCxdokpXhoEtNam1uFEJ3iTNm xLlbauHUOoWfDR8ICQcJPC3TE7UTPLCJ/7bak83YArDjWopXkJXG3f4xUxIGoc1tigUs FnDKIxHEgZBsahFZE43UeXXHq1BljM1mcDHHJyvBJJPT7vmXPJHdtd+q/I8SW+XzYbVH Nk5vz7cmBmGB4neKdSCzJjG+wrmHBVc0EFhjqPrgC8mvUhfpdbvMfZRdVwZTRev7RJuh d9VA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=SNqQMjWOSmmWcG+sD9OsZjvPaiPO4+x8T7EjjPSl8AI=; b=Py192bvCkD1yVy7kwwodaHMQ1L0cwWcWHD9EFV9cYartBMC3xHytiXhngqkdvw6VWL jAG/I/bVXLkNJ+HpVijwC4eCSsKhFCQXgdWNtq4V3EEEgwFjPonwPNasPzbotLYWpiEl 6pdXcbXdaXVmU/Smda3KYPRY4mgcTFMT2M1ZZuflztVmrxZwNLKG2nRT1Dp08U1DJeRF qFaSCBE+3k6PPaBChQa04voxM0FAq+xvWpKPK39K6OVUFXAl2FRDadiwBSM7RCTQLMkq hRsAZoAdrnFv0Y6WZ9hWRWk+1Z8QfEOY0gmCTddl9xRAWnKS9vuiJ6sCx9b2OpouRZK6 mitA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=grFKUDjV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u11si6260839pgb.54.2017.06.19.04.43.35; Mon, 19 Jun 2017 04:43:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=grFKUDjV; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754020AbdFSLn2 (ORCPT + 25 others); Mon, 19 Jun 2017 07:43:28 -0400 Received: from mail-wm0-f50.google.com ([74.125.82.50]:36153 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753976AbdFSLn0 (ORCPT ); Mon, 19 Jun 2017 07:43:26 -0400 Received: by mail-wm0-f50.google.com with SMTP id m125so77253485wmm.1 for ; Mon, 19 Jun 2017 04:43:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=SNqQMjWOSmmWcG+sD9OsZjvPaiPO4+x8T7EjjPSl8AI=; b=grFKUDjViMGsnX27OnrAzODCG0kAP8pFo1lOof3rLeh2AejIM6YuAifhIoD8dfl+DH zJSBm9LFAW/H4oYy4dO7JebTvhf2wunfp09wA3cKBTpPTxIcHcFEJbnxQ58MUuHkS2Xd 3UjEp86CPtvYqQmrWCM8g5RQrJXOfKYeJGZwU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=SNqQMjWOSmmWcG+sD9OsZjvPaiPO4+x8T7EjjPSl8AI=; b=eS0ZgYVomYgxQKz1cmiJRAZs0ErVWwLHYblJ98mQiRuCv24X6hRhYd5rXhE0ylLHzD 7S5oaJUdGm8OYJcPIHV14ggM2IYRD+LYMQC63u0YQxoLHiSsBigPmFAIJis2TnMKuW1t n49AcHtpgEwDnYlbQbryz4Zth4M5afg6vxydOxjsXPCq3iQS58m+k3GniCTA4Vu6iK72 Vz30b4Q7+RfkZaFgbZocGscSzgLk+Vl6sKDarhakv202KwaxO58bN+TqeLjuaibD1/MP GT6ODiLSq2gTmtyYmatUzdk29gQmsuwgcmstjXfV5IOmpJJatVcuoXoMWc3oqBBKPUfG 774g== X-Gm-Message-State: AKS2vOyH66ljLXb84uqECgSawrfHSz3IbwtcKwh8KbrqmzypiqOeG/kQ 5lwbZ+44YtURyxDf X-Received: by 10.28.54.204 with SMTP id y73mr15797312wmh.53.1497872605076; Mon, 19 Jun 2017 04:43:25 -0700 (PDT) Received: from localhost.localdomain (labtegrak1.mat.unimo.it. [155.185.5.3]) by smtp.gmail.com with ESMTPSA id v13sm8897918wmd.5.2017.06.19.04.43.24 (version=TLS1 cipher=AES128-SHA bits=128/128); Mon, 19 Jun 2017 04:43:24 -0700 (PDT) From: Paolo Valente To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, ulf.hansson@linaro.org, broonie@kernel.org, Paolo Valente Subject: [PATCH BUGFIX V2] block, bfq: update wr_busy_queues if needed on a queue split Date: Mon, 19 Jun 2017 13:43:16 +0200 Message-Id: <20170619114316.2587-1-paolo.valente@linaro.org> X-Mailer: git-send-email 2.10.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This commit fixes a bug triggered by a non-trivial sequence of events. These events are briefly described in the next two paragraphs. The impatiens, or those who are familiar with queue merging and splitting, can jump directly to the last paragraph. On each I/O-request arrival for a shared bfq_queue, i.e., for a bfq_queue that is the result of the merge of two or more bfq_queues, BFQ checks whether the shared bfq_queue has become seeky (i.e., if too many random I/O requests have arrived for the bfq_queue; if the device is non rotational, then random requests must be also small for the bfq_queue to be tagged as seeky). If the shared bfq_queue is actually detected as seeky, then a split occurs: the bfq I/O context of the process that has issued the request is redirected from the shared bfq_queue to a new non-shared bfq_queue. As a degenerate case, if the shared bfq_queue actually happens to be shared only by one process (because of previous splits), then no new bfq_queue is created: the state of the shared bfq_queue is just changed from shared to non shared. Regardless of whether a brand new non-shared bfq_queue is created, or the pre-existing shared bfq_queue is just turned into a non-shared bfq_queue, several parameters of the non-shared bfq_queue are set (restored) to the original values they had when the bfq_queue associated with the bfq I/O context of the process (that has just issued an I/O request) was merged with the shared bfq_queue. One of these parameters is the weight-raising state. If, on the split of a shared bfq_queue, 1) a pre-existing shared bfq_queue is turned into a non-shared bfq_queue; 2) the previously shared bfq_queue happens to be busy; 3) the weight-raising state of the previously shared bfq_queue happens to change; the number of weight-raised busy queues changes. The field wr_busy_queues must then be updated accordingly, but such an update was missing. This commit adds the missing update. Reported-by: Luca Miccio Signed-off-by: Paolo Valente --- block/bfq-iosched.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) -- 2.10.0 diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index ed93da2..bbeaf52 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -725,8 +725,12 @@ static void bfq_updated_next_req(struct bfq_data *bfqd, } static void -bfq_bfqq_resume_state(struct bfq_queue *bfqq, struct bfq_io_cq *bic) +bfq_bfqq_resume_state(struct bfq_queue *bfqq, struct bfq_data *bfqd, + struct bfq_io_cq *bic, bool bfq_already_existing) { + unsigned int old_wr_coeff = bfqq->wr_coeff; + bool busy = bfq_already_existing && bfq_bfqq_busy(bfqq); + if (bic->saved_idle_window) bfq_mark_bfqq_idle_window(bfqq); else @@ -754,6 +758,14 @@ bfq_bfqq_resume_state(struct bfq_queue *bfqq, struct bfq_io_cq *bic) /* make sure weight will be updated, however we got here */ bfqq->entity.prio_changed = 1; + + if (likely(!busy)) + return; + + if (old_wr_coeff == 1 && bfqq->wr_coeff > 1) + bfqd->wr_busy_queues++; + else if (old_wr_coeff > 1 && bfqq->wr_coeff == 1) + bfqd->wr_busy_queues--; } static int bfqq_process_refs(struct bfq_queue *bfqq) @@ -4402,7 +4414,7 @@ static int bfq_get_rq_private(struct request_queue *q, struct request *rq, const int is_sync = rq_is_sync(rq); struct bfq_queue *bfqq; bool new_queue = false; - bool split = false; + bool bfqq_already_existing = false, split = false; spin_lock_irq(&bfqd->lock); @@ -4432,6 +4444,8 @@ static int bfq_get_rq_private(struct request_queue *q, struct request *rq, bfqq = bfq_get_bfqq_handle_split(bfqd, bic, bio, true, is_sync, NULL); + else + bfqq_already_existing = true; } } @@ -4457,7 +4471,8 @@ static int bfq_get_rq_private(struct request_queue *q, struct request *rq, * queue: restore the idle window and the * possible weight raising period. */ - bfq_bfqq_resume_state(bfqq, bic); + bfq_bfqq_resume_state(bfqq, bfqd, bic, + bfqq_already_existing); } }