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: 105795 Delivered-To: patch@linaro.org Received: by 10.140.91.2 with SMTP id y2csp727216qgd; Sun, 18 Jun 2017 22:56:40 -0700 (PDT) X-Received: by 10.98.193.129 with SMTP id i123mr23723257pfg.138.1497851800519; Sun, 18 Jun 2017 22:56:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1497851800; cv=none; d=google.com; s=arc-20160816; b=xFJLdNunseRLbGBdr703cXKllbbwqH963DU1BKLq/kWRClhyaqjmhdIlhv4iz8Jmi6 pPBj9egoFYE1LJQgxQjcm3ErivbbiXX22Sf+sBIU4Tu3biFUlHCbM7Kmx5F9zml4R8rZ Q6Q5zg85bX3AJDH1IThHLKxCGIyH8ojCw3ZmB7zK83vZKbA5F7+cTfg5TMWl5iYDPLbk +5fFzmVA2gF0YEbl7gip6ZTUV0DDM6W6Ct6aEFTI+tVgTgh9JV6bh1QfOuixEd2PD8Rw Rc/YSV/KH3Fe3UtlZqoaSsj7EE5WQV3SorbxKlQ+7zJFW9TJTnQEMMET+2zPRd1IMzeI 5SmQ== 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=n2svQ6n/6nA4aAjuxjyjfB3SPaUoNOOhyfsamQjxj+k=; b=OcasUl3MtnZNvBEDTsj3JGTu1i7f5XQ9hd8v1r4ZYJpPiacwjsPNUYZDf8Nep62CtU nZSxMkRtCycWbVKFC+se1SZLbsAf4LGnH8dsQ3/diehQXpV/Kes6F/ZtVhBN+GFk6b3m k1ht4htSje/6Oel+yGo0pK33F1gu0PRVCSYX1Pdquqr6ekIB8i4PLo8+UNTPFoalphcZ bI9HAO1G1P8HValrTlScE33VL73uVqOhDgibdV9c8ooWszlo1N2pCHBPZDKn5Sj769KP n4Iz81pKirytNh2RuQNd8QjDHSNAzEcQb9CNeAIFd9f5kdZI4g8FIYAdyuSR/pn9+4/4 XS2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=SkFSx8pW; 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 96si2970646pld.592.2017.06.18.22.56.40; Sun, 18 Jun 2017 22:56:40 -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=SkFSx8pW; 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 S1751196AbdFSF4c (ORCPT + 25 others); Mon, 19 Jun 2017 01:56:32 -0400 Received: from mail-wm0-f53.google.com ([74.125.82.53]:35947 "EHLO mail-wm0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751024AbdFSF4a (ORCPT ); Mon, 19 Jun 2017 01:56:30 -0400 Received: by mail-wm0-f53.google.com with SMTP id m125so69115569wmm.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=gehQs/JsKdvTPhvrzkCodXFF7QVMaIKPqJusyFTI2lrND1HM2ECF+mhMbYJFXpY4iw 5fnec8nCQtvj2xueY9QYm5YnESPkkNSwvAhiJSFslEShav22pIPAQZVnVNYAEw+RT1d/ yINu6k4dOd5GBh7phzGxSkzAD/HkyI22RZRroxdpCLCFLIm8Udqsg+6Mq9HOnjsgRtJ4 V+9TuUbacEu+vNjNCKTIcckxFTi8R/VIZTU2PWcdVK7dgNINRoagmjbpkFk1RpTUlrvB PimIz97qomqanZrmk9lw/Yrk74uaeqAEgarMIgnINYlRqTVX2vbDTZkPDpLXp0rFr4Lw yNtg== X-Gm-Message-State: AKS2vOxuapaZx45H971wVxdFYtoJ9aAPjWyA5/fnTwolNWlBhx2saUUP lLD9EgbaSmGm0d5A 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-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 | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) -- 2.10.0 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); } }