From patchwork Fri Jan 31 09:24:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valente X-Patchwork-Id: 11359503 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7E7B914E3 for ; Fri, 31 Jan 2020 09:25:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5C431215A4 for ; Fri, 31 Jan 2020 09:25:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="cg+0ln31" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728247AbgAaJZV (ORCPT ); Fri, 31 Jan 2020 04:25:21 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:54275 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728259AbgAaJY7 (ORCPT ); Fri, 31 Jan 2020 04:24:59 -0500 Received: by mail-wm1-f67.google.com with SMTP id g1so7068804wmh.4 for ; Fri, 31 Jan 2020 01:24:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wqMailTmZiDzGAaQzZRxkipnoj+fRUU9PJ6V3DKETq8=; b=cg+0ln31NwklwCB7MdEWW8MYShl/I69uRq/+lHKzxdRZ96HLCFrwcuZLt+lSqzk7nW qcnS1o0KGzDAJ3Zx4vC3/JQYx7272k6nDjqQZ3fmMVmfmsHLeOQAMrO28UnGbNi3gM15 CpFeDHgtWvJUnC2HffD6RGczVRbyy9SPQC7gBzHEasBRS3e+1VLcGcmPnhfIu/1Kqswk uKU/+fDMpNyB3VUZUWW4p13Iv+F36S3KJ6rMIrmUAD3czTDhzESGp07SwXHe4Ty/0bVA A8+3DKtLQtwv9phsvdLm3L6H8F3EbbqjlWpIvD9vARKaGPlD44fJsEsMzNkWhrV/MAgS thQw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=wqMailTmZiDzGAaQzZRxkipnoj+fRUU9PJ6V3DKETq8=; b=YR/aSMo6JveJXQxJqP5eef8wzmnhHaDbEPMnaA8DzpJ3+va3AJcBBPzrTuL3yWxGvc hhYQPOMR3OBbLhi7bIds8SlEjrV/2QZuI3Z9z+ewhRmt4YhweAsg7GdeNBi8zL+bMGo2 3TFIuNc9nuwgiTXxQmx+ActIAXVFccDvhPsu1Miu+e8jmtg/kV2//pQcQ5hlfCFR9KI6 auvy4OMXZDV3i72q6Xz++wAJ98PR9m1aPeMLXtrk977CY/lFtqv53QmXgLMK1kAXiSCu HB7+9aMzBgVaHB68ABf7zPiwG9IEwF50t8Eb3/OzCRBp84JGhsb9+L1bPWiJv2G82F3m zsgA== X-Gm-Message-State: APjAAAWNUc+YVRzKLUU8diwElJBaN9FFnq7QXzWhLv/swzJf5r52ulZK cBMCZARZ0iirYQS6AlUrshKrMg== X-Google-Smtp-Source: APXvYqwrdqLrYbDRrX76bBTfOceHiNyXfbVom/20wFvv7o5waUNKFqTZ4kzC62WNF3Jm9I2zZXHVvA== X-Received: by 2002:a05:600c:2109:: with SMTP id u9mr11380404wml.183.1580462696845; Fri, 31 Jan 2020 01:24:56 -0800 (PST) Received: from localhost.localdomain (88-147-73-186.dyn.eolo.it. [88.147.73.186]) by smtp.gmail.com with ESMTPSA id 16sm10144364wmi.0.2020.01.31.01.24.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Jan 2020 01:24:56 -0800 (PST) From: Paolo Valente To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, bfq-iosched@googlegroups.com, oleksandr@natalenko.name, patdung100@gmail.com, cevich@redhat.com, Paolo Valente Subject: [PATCH BUGFIX 1/6] block, bfq: do not plug I/O for bfq_queues with no proc refs Date: Fri, 31 Jan 2020 10:24:04 +0100 Message-Id: <20200131092409.10867-2-paolo.valente@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200131092409.10867-1-paolo.valente@linaro.org> References: <20200131092409.10867-1-paolo.valente@linaro.org> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Commit 478de3380c1c ("block, bfq: deschedule empty bfq_queues not referred by any process") fixed commit 3726112ec731 ("block, bfq: re-schedule empty queues if they deserve I/O plugging") by descheduling an empty bfq_queue when it remains with not process reference. Yet, this still left a case uncovered: an empty bfq_queue with not process reference that remains in service. This happens for an in-service sync bfq_queue that is deemed to deserve I/O-dispatch plugging when it remains empty. Yet no new requests will arrive for such a bfq_queue if no process sends requests to it any longer. Even worse, the bfq_queue may happen to be prematurely freed while still in service (because there may remain no reference to it any longer). This commit solves this problem by preventing I/O dispatch from being plugged for the in-service bfq_queue, if the latter has no process reference (the bfq_queue is then prevented from remaining in service). Fixes: 3726112ec731 ("block, bfq: re-schedule empty queues if they deserve I/O plugging") Reported-by: Patrick Dung Tested-by: Patrick Dung Signed-off-by: Paolo Valente --- block/bfq-iosched.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index 4686b68b48b4..55d4328e7c12 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -3443,6 +3443,10 @@ static void bfq_dispatch_remove(struct request_queue *q, struct request *rq) static bool idling_needed_for_service_guarantees(struct bfq_data *bfqd, struct bfq_queue *bfqq) { + /* No point in idling for bfqq if it won't get requests any longer */ + if (unlikely(!bfqq_process_refs(bfqq))) + return false; + return (bfqq->wr_coeff > 1 && (bfqd->wr_busy_queues < bfq_tot_busy_queues(bfqd) || @@ -4076,6 +4080,10 @@ static bool idling_boosts_thr_without_issues(struct bfq_data *bfqd, bfqq_sequential_and_IO_bound, idling_boosts_thr; + /* No point in idling for bfqq if it won't get requests any longer */ + if (unlikely(!bfqq_process_refs(bfqq))) + return false; + bfqq_sequential_and_IO_bound = !BFQQ_SEEKY(bfqq) && bfq_bfqq_IO_bound(bfqq) && bfq_bfqq_has_short_ttime(bfqq); @@ -4169,6 +4177,10 @@ static bool bfq_better_to_idle(struct bfq_queue *bfqq) struct bfq_data *bfqd = bfqq->bfqd; bool idling_boosts_thr_with_no_issue, idling_needed_for_service_guar; + /* No point in idling for bfqq if it won't get requests any longer */ + if (unlikely(!bfqq_process_refs(bfqq))) + return false; + if (unlikely(bfqd->strict_guarantees)) return true; From patchwork Fri Jan 31 09:24:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valente X-Patchwork-Id: 11359499 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 759CD13B4 for ; Fri, 31 Jan 2020 09:25:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 53141215A4 for ; Fri, 31 Jan 2020 09:25:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="evcl4rc0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728281AbgAaJZB (ORCPT ); Fri, 31 Jan 2020 04:25:01 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:33842 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728258AbgAaJY7 (ORCPT ); Fri, 31 Jan 2020 04:24:59 -0500 Received: by mail-wr1-f66.google.com with SMTP id t2so7778444wrr.1 for ; Fri, 31 Jan 2020 01:24:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+Kno0Ufwl1kAKmD9m5umt2SU5mWhcoh+53Gn8TLVtdo=; b=evcl4rc0NAC7KoG7W+hHO+yYLgoIWhsULe3VHo8ZfCPzYl32U5h2vCJyYiJErq0zZi QwpxFwr37Q4gwnpYI5GlKMw5gDoK5/OpuBsaSWew36bydz4zJ46ur/THHH6yFtl8ukK0 eelQXn/EOVQPRzSGpkUh3LtUhmue8RWsfMkYrJGivUmsVaRQR/6Axd3OvjTZg503Ff4a +m7rFqdSk6EWppY1EUmL+dsI9TBttxIRgOd2aKpp92TGwK/LYC0EKLjZQu4LWqmytuJm y7EsLlLfcMqUC4oFai2Ds+HZ53A+MOA7b34gEgg2Mhh7woMRKPhUSAao3wfBtSdCfUxp Qd3Q== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=+Kno0Ufwl1kAKmD9m5umt2SU5mWhcoh+53Gn8TLVtdo=; b=OGY1JuilKGcm2vdWobDhNRn72Wzse2k43SHhgvtkAc7FqrRla5RFAEx7Ht0TA4guxk nA6IH5ySHCj+tkuQiQ1WonXYaR07/QTtvD2jkqmI42hQ6cL45X0kypQWEjpeJ/xCEITJ F4PAI7myMJPrhmpPcsTzabfDU5RVyVDUAksx0wyGpHkEoM1UWsWZ3wT5QuDVKMcNVlPG FmPXnMQvvBntI3y/XjPzgVceakXpHwQg7L9z0ja5gTIuALpOiVmTJDEAKT6J0GaDFqm7 R56lx+bHVP2QO9s83fsbe5hiPiTtyXO/7MmKOnGmGHuX/LklOyA5o8xurWveUJhUtOJG cbGg== X-Gm-Message-State: APjAAAU2pS5eUwcYBS1jdkPWNDDjhJe0uMjNAa9sVvijadJR9fKxz1hK humvBibUJPOW+8F8A0AeGThn6Q== X-Google-Smtp-Source: APXvYqxF+WeknTEzrs+NFH97PzIldGWLGI86YDyqDlVHFCExejPHiKfuK1zhZ6neZ8xBPN1vG/Hy8Q== X-Received: by 2002:adf:cd04:: with SMTP id w4mr11638814wrm.219.1580462698078; Fri, 31 Jan 2020 01:24:58 -0800 (PST) Received: from localhost.localdomain (88-147-73-186.dyn.eolo.it. [88.147.73.186]) by smtp.gmail.com with ESMTPSA id 16sm10144364wmi.0.2020.01.31.01.24.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Jan 2020 01:24:57 -0800 (PST) From: Paolo Valente To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, bfq-iosched@googlegroups.com, oleksandr@natalenko.name, patdung100@gmail.com, cevich@redhat.com, Paolo Valente Subject: [PATCH BUGFIX 2/6] block, bfq: do not insert oom queue into position tree Date: Fri, 31 Jan 2020 10:24:05 +0100 Message-Id: <20200131092409.10867-3-paolo.valente@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200131092409.10867-1-paolo.valente@linaro.org> References: <20200131092409.10867-1-paolo.valente@linaro.org> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org BFQ maintains an ordered list, implemented with an RB tree, of head-request positions of non-empty bfq_queues. This position tree, inherited from CFQ, is used to find bfq_queues that contain I/O close to each other. BFQ merges these bfq_queues into a single shared queue, if this boosts throughput on the device at hand. There is however a special-purpose bfq_queue that does not participate in queue merging, the oom bfq_queue. Yet, also this bfq_queue could be wrongly added to the position tree. So bfqq_find_close() could return the oom bfq_queue, which is a source of further troubles in an out-of-memory situation. This commit prevents the oom bfq_queue from being inserted into the position tree. Tested-by: Patrick Dung Signed-off-by: Paolo Valente --- block/bfq-iosched.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index 55d4328e7c12..15dfb0844644 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -613,6 +613,10 @@ bfq_pos_tree_add_move(struct bfq_data *bfqd, struct bfq_queue *bfqq) bfqq->pos_root = NULL; } + /* oom_bfqq does not participate in queue merging */ + if (bfqq == &bfqd->oom_bfqq) + return; + /* * bfqq cannot be merged any longer (see comments in * bfq_setup_cooperator): no point in adding bfqq into the From patchwork Fri Jan 31 09:24:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valente X-Patchwork-Id: 11359497 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 45CAE13B4 for ; Fri, 31 Jan 2020 09:25:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2327C20705 for ; Fri, 31 Jan 2020 09:25:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="iRXRSb4D" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728284AbgAaJZB (ORCPT ); Fri, 31 Jan 2020 04:25:01 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:35633 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728274AbgAaJZB (ORCPT ); Fri, 31 Jan 2020 04:25:01 -0500 Received: by mail-wm1-f68.google.com with SMTP id b17so7864685wmb.0 for ; Fri, 31 Jan 2020 01:25:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9S9BwHx5UyCKJX2JPPBf1rlNAUg9PfPZ0MUkcYcdubg=; b=iRXRSb4DE5RRgBR+1dzaU40ae0vmJbAJrH7ssWKCDoti6cVtCXOhHrRgtxLuu74K7I Tw3sJ1uQbf05gkl/PqtpOVRtDGHMsSlfL9YBa91dbcrDEUTDRl7PR0uucmawserg4suP dVsMWzYSzrUpjPPNlKlnyl9QLhCqdHohs4I5rQ4ngR46zzjF+o6Iro7l0p9RQ+jqhj3t GCHSdSsbC9Ez9HMVWP5wRpZO2Mm7sYiWuL0BTzrWlE8QkhY6/PtCQ7lUy4k+/ZmhuXjI msLBIUrrrUE62KX/PYyadwpxp/5qeUMb/NCwLHBukakYpsIZHrjnt5ZcWgkKTa+3iIxE HuUQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=9S9BwHx5UyCKJX2JPPBf1rlNAUg9PfPZ0MUkcYcdubg=; b=Wlf8c2cyWkSK28fPqT9e0P2bFT6vPsnDWlYejvQI8KLnFA6kh0riB74w1UV0Hv6A/6 1JFae26+C+ak1Bzh8yzgjWnzAbkb7F6LijQYxAKYpg56xDAwDkFb4GzwTQJu1OSSa8wo vr7hdxgyrQONwyXr7R+HNN1IrKUwCMYKbJGzzOQOGs6hVHTDZYxldzoCyMULh0Lfmk9p sxS0crw/cEM5LlRISxiKXj2wCF84i2E/rmGYrRnSgz4J0VZcB5Zl0yxBOlg0Fo5M/nKy 6QyePw1n3VmBysQ+bFQvSA+7qHFrvYsudHPtnOHqrMq6IhOQw1jXMXrAmxg8mCqZScE+ EZZg== X-Gm-Message-State: APjAAAXaDj8M9FIh3RqJH2SMoi43wb2RQ/X3F9j3kbfYrKN/s9rB7kzl fNeKRjzHt1WDXwp05xJnYWsaIQ== X-Google-Smtp-Source: APXvYqxB4qSPUHX306OsPESk96PbfKWReeeWyRX+ZbnNBODPZNtLG1E8CogAmQhcBFk6/5MNcZOwqQ== X-Received: by 2002:a1c:545d:: with SMTP id p29mr11760504wmi.91.1580462699266; Fri, 31 Jan 2020 01:24:59 -0800 (PST) Received: from localhost.localdomain (88-147-73-186.dyn.eolo.it. [88.147.73.186]) by smtp.gmail.com with ESMTPSA id 16sm10144364wmi.0.2020.01.31.01.24.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Jan 2020 01:24:58 -0800 (PST) From: Paolo Valente To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, bfq-iosched@googlegroups.com, oleksandr@natalenko.name, patdung100@gmail.com, cevich@redhat.com, Paolo Valente Subject: [PATCH BUGFIX 3/6] block, bfq: get extra ref to prevent a queue from being freed during a group move Date: Fri, 31 Jan 2020 10:24:06 +0100 Message-Id: <20200131092409.10867-4-paolo.valente@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200131092409.10867-1-paolo.valente@linaro.org> References: <20200131092409.10867-1-paolo.valente@linaro.org> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org In bfq_bfqq_move(), the bfq_queue, say Q, to be moved to a new group may happen to be deactivated in the scheduling data structures of the source group (and then activated in the destination group). If Q is referred only by the data structures in the source group when the deactivation happens, then Q is freed upon the deactivation. This commit addresses this issue by getting an extra reference before the possible deactivation, and releasing this extra reference after Q has been moved. Tested-by: Chris Evich Signed-off-by: Paolo Valente --- block/bfq-cgroup.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/block/bfq-cgroup.c b/block/bfq-cgroup.c index e1419edde2ec..8ab7f18ff8cb 100644 --- a/block/bfq-cgroup.c +++ b/block/bfq-cgroup.c @@ -651,6 +651,12 @@ void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq, bfq_bfqq_expire(bfqd, bfqd->in_service_queue, false, BFQQE_PREEMPTED); + /* + * get extra reference to prevent bfqq from being freed in + * next possible deactivate + */ + bfqq->ref++; + if (bfq_bfqq_busy(bfqq)) bfq_deactivate_bfqq(bfqd, bfqq, false, false); else if (entity->on_st) @@ -670,6 +676,8 @@ void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq, if (!bfqd->in_service_queue && !bfqd->rq_in_driver) bfq_schedule_dispatch(bfqd); + /* release extra ref taken above */ + bfq_put_queue(bfqq); } /** From patchwork Fri Jan 31 09:24:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valente X-Patchwork-Id: 11359495 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 622AE112B for ; Fri, 31 Jan 2020 09:25:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3679C215A4 for ; Fri, 31 Jan 2020 09:25:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="WEc5i+wM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728324AbgAaJZO (ORCPT ); Fri, 31 Jan 2020 04:25:14 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:52122 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728279AbgAaJZC (ORCPT ); Fri, 31 Jan 2020 04:25:02 -0500 Received: by mail-wm1-f68.google.com with SMTP id t23so7095515wmi.1 for ; Fri, 31 Jan 2020 01:25:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EYMuqQIhNyGIyUO9+d/0zXKDzQMWFHlzvVLFhG2VePE=; b=WEc5i+wMCiAyLuk0tSUYxfVp66mFw8A7FGbPTItb8JCJX8wGBEY81gDxK9JNBsW+Hc hhyQtR6a7WYFoSrkKUat+wBmuKUegtsjerK2gqF79tbjgYCJ9rIrHvwUklvZx2U5b6Gs tHZRxWq+df3pKHA/3FNK87d0wzzLoChmf5Q51517VgVC2noembzyD1zVCJrshupZRJZQ EcNP6zW7NmeT5lGlA9dgFjIqXgeMp38ymYFXv6bk8pCWgyOS9NieRF0Hik3Gr6ivNWrC AEcYPvW68s9NDVXoKNqBAA8zunGXTmO7xxb6qreV7M6reHq9uyE05zY2gns/vZ5pVVdX F76g== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=EYMuqQIhNyGIyUO9+d/0zXKDzQMWFHlzvVLFhG2VePE=; b=t99v19VXZL3GGfbeQLMkhAB3MrYekEyqk9dfMa4A3oqnYhAaO6YjhXgV+LQhb/O4HO MW5cx429Rnzk6+eH2gnQiKE+fXiigNii+qXssGmLmd4l0jJP5C0BrIzQnYpLd5fgVuZW kdO1IuARbOXW8fM59FJxW6GJW24yfI6LQtUlVL1zTmvd5b3kMJfUpJGAy1T43WsKabsk vmOMDY4k9WSL0k9ewHXQqMxomv8NUSNDr7kY4SoXm2wFGchdifak6EoNl2s3fiPbT1/m 8zk+Iep4mKCF3tIWUs90JdAI+OFGu4x2yhlr2H24DsZCXlsTQ59AeoR6LlXgtUE0JqyQ IyKg== X-Gm-Message-State: APjAAAUp7aMyexQ5kJsrxxILHhIQP1WtYbVsidC5Y1Jm+cqxXbWuEGhC u/2IK1a+j2KlMV1t0liYls1fug== X-Google-Smtp-Source: APXvYqwAzr3TIiTKUwDgtKvzj4Ik3+GCPAkjxsrEqUp6NEGoz0CfTNgDeLNnEFSoxKU74ROWUheixw== X-Received: by 2002:a1c:7c18:: with SMTP id x24mr11661261wmc.185.1580462700684; Fri, 31 Jan 2020 01:25:00 -0800 (PST) Received: from localhost.localdomain (88-147-73-186.dyn.eolo.it. [88.147.73.186]) by smtp.gmail.com with ESMTPSA id 16sm10144364wmi.0.2020.01.31.01.24.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Jan 2020 01:24:59 -0800 (PST) From: Paolo Valente To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, bfq-iosched@googlegroups.com, oleksandr@natalenko.name, patdung100@gmail.com, cevich@redhat.com, Paolo Valente Subject: [PATCH BUGFIX 4/6] block, bfq: extend incomplete name of field on_st Date: Fri, 31 Jan 2020 10:24:07 +0100 Message-Id: <20200131092409.10867-5-paolo.valente@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200131092409.10867-1-paolo.valente@linaro.org> References: <20200131092409.10867-1-paolo.valente@linaro.org> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org The flag on_st in the bfq_entity data structure is true if the entity is on a service tree or is in service. Yet the name of the field, confusingly, does not mention the second, very important case. Extend the name to mention the second case too. Signed-off-by: Paolo Valente --- block/bfq-cgroup.c | 2 +- block/bfq-iosched.c | 2 +- block/bfq-iosched.h | 2 +- block/bfq-wf2q.c | 11 +++++++---- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/block/bfq-cgroup.c b/block/bfq-cgroup.c index 8ab7f18ff8cb..c818c64766e5 100644 --- a/block/bfq-cgroup.c +++ b/block/bfq-cgroup.c @@ -659,7 +659,7 @@ void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq, if (bfq_bfqq_busy(bfqq)) bfq_deactivate_bfqq(bfqd, bfqq, false, false); - else if (entity->on_st) + else if (entity->on_st_or_in_serv) bfq_put_idle_entity(bfq_entity_service_tree(entity), entity); bfqg_and_blkg_put(bfqq_group(bfqq)); diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index 15dfb0844644..28770ec7c06f 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -1059,7 +1059,7 @@ bfq_bfqq_resume_state(struct bfq_queue *bfqq, struct bfq_data *bfqd, static int bfqq_process_refs(struct bfq_queue *bfqq) { - return bfqq->ref - bfqq->allocated - bfqq->entity.on_st - + return bfqq->ref - bfqq->allocated - bfqq->entity.on_st_or_in_serv - (bfqq->weight_counter != NULL); } diff --git a/block/bfq-iosched.h b/block/bfq-iosched.h index 8526f20c53bc..f1cb89def7f8 100644 --- a/block/bfq-iosched.h +++ b/block/bfq-iosched.h @@ -150,7 +150,7 @@ struct bfq_entity { * Flag, true if the entity is on a tree (either the active or * the idle one of its service_tree) or is in service. */ - bool on_st; + bool on_st_or_in_serv; /* B-WF2Q+ start and finish timestamps [sectors/weight] */ u64 start, finish; diff --git a/block/bfq-wf2q.c b/block/bfq-wf2q.c index ffe9ce9faa89..26776bdbdf36 100644 --- a/block/bfq-wf2q.c +++ b/block/bfq-wf2q.c @@ -645,7 +645,7 @@ static void bfq_forget_entity(struct bfq_service_tree *st, { struct bfq_queue *bfqq = bfq_entity_to_bfqq(entity); - entity->on_st = false; + entity->on_st_or_in_serv = false; st->wsum -= entity->weight; if (bfqq && !is_in_service) bfq_put_queue(bfqq); @@ -999,7 +999,7 @@ static void __bfq_activate_entity(struct bfq_entity *entity, */ bfq_get_entity(entity); - entity->on_st = true; + entity->on_st_or_in_serv = true; } #ifdef CONFIG_BFQ_GROUP_IOSCHED @@ -1165,7 +1165,10 @@ bool __bfq_deactivate_entity(struct bfq_entity *entity, bool ins_into_idle_tree) struct bfq_service_tree *st; bool is_in_service; - if (!entity->on_st) /* entity never activated, or already inactive */ + if (!entity->on_st_or_in_serv) /* + * entity never activated, or + * already inactive + */ return false; /* @@ -1620,7 +1623,7 @@ bool __bfq_bfqd_reset_in_service(struct bfq_data *bfqd) * service tree either, then release the service reference to * the queue it represents (taken with bfq_get_entity). */ - if (!in_serv_entity->on_st) { + if (!in_serv_entity->on_st_or_in_serv) { /* * If no process is referencing in_serv_bfqq any * longer, then the service reference may be the only From patchwork Fri Jan 31 09:24:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valente X-Patchwork-Id: 11359491 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F06D813B4 for ; Fri, 31 Jan 2020 09:25:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CD4EF20705 for ; Fri, 31 Jan 2020 09:25:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="cZvFOVTG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728304AbgAaJZF (ORCPT ); Fri, 31 Jan 2020 04:25:05 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:37374 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728298AbgAaJZE (ORCPT ); Fri, 31 Jan 2020 04:25:04 -0500 Received: by mail-wm1-f68.google.com with SMTP id f129so7847995wmf.2 for ; Fri, 31 Jan 2020 01:25:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uWgUp93q0TxBVqmJmgne8WprxYrbN7oKCMa4FCVu+FE=; b=cZvFOVTG2wAkUzmD+l5ISrTahaofiW5nU3Lah/OikxnKfbOzrSdIhM3GhA0jVmgEIs w/9AKwzF702bVUW1oFkXq92YlJNZbmPcEaMJXw2ESM1hJqBiHGCq9I+D4io7LCrDa+76 Uvm63wGfl/zTuhQqEoOvDoJYr2MsHdZEK6YMyEB+4RvG22VRKJYW2KUnRvwCfkvcyGFL jqwJA07ybsiAVFg5SLggI1sFD1cWweG4rZf9yW6SlokSyB89pO7uIZF0f7c+zkJML9tw Adrsozr0AqOYY/t6qomr9CyC6nw8xEgshG9yVUeSgHH0AeRHmwJwj3VqQ4JZ8kU1YthK a3aQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=uWgUp93q0TxBVqmJmgne8WprxYrbN7oKCMa4FCVu+FE=; b=HFz4a2FPaw0Pr3IBowOmLLyQ5x52aAews3ePhlkpHkKq1LPWwAI7t2pmjyseRXh3pc /4e++g39deiM9JHG9BIGTuKN9r7xrqpW+YCeWNz9l6Gtepiunfp7Y2M5TwswsNrkeLWg t4UkXMsCUbkliZ3yOkXW4Z0tIJq7w0F39awP/DQItvn8oPMd8efBhXTdCwAtrUaXfWoO aTAwHDGlIFcPu7+IIb9npQQsfxlu+GLcf8kWAh2dN9m2HLrDGVwT+c5oD6xXEk/MAFqx e43V++HLpMHNs4jaH8FlozqT3urhN/w2lzmrcgPqh7aSUjOHvd08b4asd7PDL8Fk6HzB kK6w== X-Gm-Message-State: APjAAAW4qy61SbwzmFxFJ6Ym0IX5xd9b6/5O5Byvamc8YUnRUGSq1/fQ iJ0NNELLCT9LqFjHF+oR1XfKNQ== X-Google-Smtp-Source: APXvYqxEJphFjQzJzYlTW6+ZjuBCQ4jxe8AA1Oejq3lY8Mp34gOMX+FS3cy7WyrtheyMRpt2O7Oiow== X-Received: by 2002:a7b:c7c9:: with SMTP id z9mr11423354wmk.175.1580462701852; Fri, 31 Jan 2020 01:25:01 -0800 (PST) Received: from localhost.localdomain (88-147-73-186.dyn.eolo.it. [88.147.73.186]) by smtp.gmail.com with ESMTPSA id 16sm10144364wmi.0.2020.01.31.01.25.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Jan 2020 01:25:01 -0800 (PST) From: Paolo Valente To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, bfq-iosched@googlegroups.com, oleksandr@natalenko.name, patdung100@gmail.com, cevich@redhat.com, Paolo Valente Subject: [PATCH BUGFIX 5/6] block, bfq: get a ref to a group when adding it to a service tree Date: Fri, 31 Jan 2020 10:24:08 +0100 Message-Id: <20200131092409.10867-6-paolo.valente@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200131092409.10867-1-paolo.valente@linaro.org> References: <20200131092409.10867-1-paolo.valente@linaro.org> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org BFQ schedules generic entities, which may represent either bfq_queues or groups of bfq_queues. When an entity is inserted into a service tree, a reference must be taken, to make sure that the entity does not disappear while still referred in the tree. Unfortunately, such a reference is mistakenly taken only if the entity represents a bfq_queue. This commit takes a reference also in case the entity represents a group. Tested-by: Chris Evich Signed-off-by: Paolo Valente --- block/bfq-cgroup.c | 2 +- block/bfq-iosched.h | 1 + block/bfq-wf2q.c | 16 +++++++++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/block/bfq-cgroup.c b/block/bfq-cgroup.c index c818c64766e5..f85b25fd06f2 100644 --- a/block/bfq-cgroup.c +++ b/block/bfq-cgroup.c @@ -332,7 +332,7 @@ static void bfqg_put(struct bfq_group *bfqg) kfree(bfqg); } -static void bfqg_and_blkg_get(struct bfq_group *bfqg) +void bfqg_and_blkg_get(struct bfq_group *bfqg) { /* see comments in bfq_bic_update_cgroup for why refcounting bfqg */ bfqg_get(bfqg); diff --git a/block/bfq-iosched.h b/block/bfq-iosched.h index f1cb89def7f8..b9627ec7007b 100644 --- a/block/bfq-iosched.h +++ b/block/bfq-iosched.h @@ -984,6 +984,7 @@ struct bfq_group *bfq_find_set_group(struct bfq_data *bfqd, struct blkcg_gq *bfqg_to_blkg(struct bfq_group *bfqg); struct bfq_group *bfqq_group(struct bfq_queue *bfqq); struct bfq_group *bfq_create_group_hierarchy(struct bfq_data *bfqd, int node); +void bfqg_and_blkg_get(struct bfq_group *bfqg); void bfqg_and_blkg_put(struct bfq_group *bfqg); #ifdef CONFIG_BFQ_GROUP_IOSCHED diff --git a/block/bfq-wf2q.c b/block/bfq-wf2q.c index 26776bdbdf36..ef06e0d34b5b 100644 --- a/block/bfq-wf2q.c +++ b/block/bfq-wf2q.c @@ -533,7 +533,13 @@ static void bfq_get_entity(struct bfq_entity *entity) bfqq->ref++; bfq_log_bfqq(bfqq->bfqd, bfqq, "get_entity: %p %d", bfqq, bfqq->ref); +#ifdef CONFIG_BFQ_GROUP_IOSCHED + } else + bfqg_and_blkg_get(container_of(entity, struct bfq_group, + entity)); +#else } +#endif } /** @@ -647,8 +653,16 @@ static void bfq_forget_entity(struct bfq_service_tree *st, entity->on_st_or_in_serv = false; st->wsum -= entity->weight; - if (bfqq && !is_in_service) + if (is_in_service) + return; + + if (bfqq) bfq_put_queue(bfqq); +#ifdef CONFIG_BFQ_GROUP_IOSCHED + else + bfqg_and_blkg_put(container_of(entity, struct bfq_group, + entity)); +#endif } /** From patchwork Fri Jan 31 09:24:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valente X-Patchwork-Id: 11359493 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0FB1F13B4 for ; Fri, 31 Jan 2020 09:25:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E1C2E217BA for ; Fri, 31 Jan 2020 09:25:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="qw7cjjs1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728302AbgAaJZE (ORCPT ); Fri, 31 Jan 2020 04:25:04 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:52124 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728297AbgAaJZE (ORCPT ); Fri, 31 Jan 2020 04:25:04 -0500 Received: by mail-wm1-f66.google.com with SMTP id t23so7095628wmi.1 for ; Fri, 31 Jan 2020 01:25:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DCb/xDvlwv6fnMWcXIG/HuzVabukmnqhy19nDjpW0Wc=; b=qw7cjjs1E8pWma/72zrvOGI0LqLcmxYxDNX+xebO0ZXD6XnnEZrYR2icMTWMxOo11x F+wRvfqULKxmJcGxieJbO086EJay6OGEsbHP6tHgABYafP/Teswf2cZwWrXYsa7SqmbI 3bb4SNv6etWoSXR/9ozFtALKoJGqTFLxUICBAguPNVkhjtXoXRCf+uvvKvyk6AHNgbkU DaJzmtjCJbLCCnejvJ9bAecH55lijryvFRtmRABSNSaMqWMXNiitRQ2SsZd20oAw28M5 T4AFoEMW+8wabyt5BGv0AeHmdzruE70Hpd+8bQ2XK30FWlM68XNb17vgB/rWvtraOpGx buiw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=DCb/xDvlwv6fnMWcXIG/HuzVabukmnqhy19nDjpW0Wc=; b=GBFobLnEF+O/ygdVJvqXCk72SwQZyhXq0apEauWhRqPZNxH4iOmpanKxsGOwVod2u0 reFA+mkMwMxQB2BQMRSrQY/OvbcFkusFNS9dxEBMy8K+d6XBYr2XOHYBgAyCOjOKx43s xBOk7cflLUKa/u5OtF0FI+LoyS1XXNbhZb2KLDDYekUWfE6cmsVNmJWFSkrUL24goLpG grPngodZvnShSQRe21OYoUu7kT9AfDY+Sw8rVqOn4P+eGxYspDFw/geowNGuYDYvVzv9 yWLClhXx0QuG7N9AckJJCwdi1d6Naw8bFirVLeKGYSaY/Fq4oKBVaJLgTlGOenkzKigd Ni3g== X-Gm-Message-State: APjAAAVEOeGJpkbS4lLZNE+HgayaPH2CZ5J+edx404f+pzury7Pcieh9 cYQAQmofvtLYOtnZ9bnQ5FY/9g== X-Google-Smtp-Source: APXvYqwccI1zx5QiGLNXp4CTKPCYw4Fm19ZA2sJEKNWeNsHlMN4OdFKxyBQLewXej8EjpkXXtknjmA== X-Received: by 2002:a7b:c4cc:: with SMTP id g12mr11728395wmk.68.1580462703028; Fri, 31 Jan 2020 01:25:03 -0800 (PST) Received: from localhost.localdomain (88-147-73-186.dyn.eolo.it. [88.147.73.186]) by smtp.gmail.com with ESMTPSA id 16sm10144364wmi.0.2020.01.31.01.25.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Jan 2020 01:25:02 -0800 (PST) From: Paolo Valente To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, bfq-iosched@googlegroups.com, oleksandr@natalenko.name, patdung100@gmail.com, cevich@redhat.com, Paolo Valente Subject: [PATCH BUGFIX 6/6] block, bfq: clarify the goal of bfq_split_bfqq() Date: Fri, 31 Jan 2020 10:24:09 +0100 Message-Id: <20200131092409.10867-7-paolo.valente@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200131092409.10867-1-paolo.valente@linaro.org> References: <20200131092409.10867-1-paolo.valente@linaro.org> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org The exact, general goal of the function bfq_split_bfqq() is not that apparent. Add a comment to make it clear. Signed-off-by: Paolo Valente --- block/bfq-iosched.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index 28770ec7c06f..347e96292117 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -5983,6 +5983,8 @@ static void bfq_finish_requeue_request(struct request *rq) } /* + * Removes the association between the current task and bfqq, assuming + * that bic points to the bfq iocontext of the task. * Returns NULL if a new bfqq should be allocated, or the old bfqq if this * was the last process referring to that bfqq. */