From patchwork Mon Jun 19 05:56:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valente X-Patchwork-Id: 9795221 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5B7876020B for ; Mon, 19 Jun 2017 05:56:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3306627FA5 for ; Mon, 19 Jun 2017 05:56:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 24DBD27FB1; Mon, 19 Jun 2017 05:56:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E62127FA5 for ; Mon, 19 Jun 2017 05:56:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751058AbdFSF4b (ORCPT ); Mon, 19 Jun 2017 01:56:31 -0400 Received: from mail-wm0-f50.google.com ([74.125.82.50]:38871 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751013AbdFSF4a (ORCPT ); Mon, 19 Jun 2017 01:56:30 -0400 Received: by mail-wm0-f50.google.com with SMTP id u195so51708680wmd.1 for ; Sun, 18 Jun 2017 22:56:29 -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=n2svQ6n/6nA4aAjuxjyjfB3SPaUoNOOhyfsamQjxj+k=; b=SkFSx8pWrAtiMOzg3DNZ3rolSeD/Q+sU17ISd0Ryr2pPZLio7qgDotK4mdXHoOyi6+ FQDgNv6Z6WbX7Vd6w2T0chaW/kwB/HNl0vonBwaqUjZKiX1LBcZQkDWza93IA/ImrT1X colLibcBvnKtPhkDH5Y8Z8OLPQm4Fuqzy5JD4= 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=n2svQ6n/6nA4aAjuxjyjfB3SPaUoNOOhyfsamQjxj+k=; b=foNfkWFmCQqX2DVWDwNevCLBUVjpHWiglOBP+EOkbT2le4tC/1rlf1a1r71Zmm0Vlq Y2pps04gHh1iYyvSmeSn1X7vqmw/ZPESCKzOV/AKu0a1+hHxM0csRLDxcMzS4Tri1oxW aGs7it9+o8Fw3DcJ4qhdKaF3RenKNNY/bEPR7opSYP8ENNvCmXlM4MK57jZUe9Ubeqg2 wab5AzMXTOpy9myK9olazYmRnYK/aP++KXKPvTmTpwXRdQBgxsQz6jvYxoEgEwRjjxVr qmKIQwIIj+MLBXOHpAmtQP/b/R+FvvHkg+iYLMqGzW/fp8FRwp6YAh44vYvEnA3V0fCa P1TA== X-Gm-Message-State: AKS2vOyyVhDtuYPbpRxU5eT5BR2V3ZJL6x7r4KtfQ8MJ0UeYkk4oSM9z yLXc19IVcnEkNErZ X-Received: by 10.28.10.78 with SMTP id 75mr13788406wmk.66.1497851788874; Sun, 18 Jun 2017 22:56:28 -0700 (PDT) Received: from localhost.localdomain ([185.14.11.239]) by smtp.gmail.com with ESMTPSA id p187sm13411892wmd.20.2017.06.18.22.56.26 (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 18 Jun 2017 22:56:27 -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] block, bfq: update wr_busy_queues if needed on a queue split Date: Mon, 19 Jun 2017 07:56:12 +0200 Message-Id: <20170619055612.1106-1-paolo.valente@linaro.org> X-Mailer: git-send-email 2.10.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index ed93da2..4731cfb 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; + bool busy = bfq_already_existing && bfq_bfqq_busy(bfqq); + if (bic->saved_idle_window) bfq_mark_bfqq_idle_window(bfqq); else @@ -737,6 +741,9 @@ bfq_bfqq_resume_state(struct bfq_queue *bfqq, struct bfq_io_cq *bic) else bfq_clear_bfqq_IO_bound(bfqq); + if (unlikely(busy)) + old_wr_coeff = bfqq->wr_coeff; + bfqq->ttime = bic->saved_ttime; bfqq->wr_coeff = bic->saved_wr_coeff; bfqq->wr_start_at_switch_to_srt = bic->saved_wr_start_at_switch_to_srt; @@ -754,6 +761,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 +4417,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 +4447,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 +4474,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); } }