From patchwork Sat Mar 21 09:45:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valente X-Patchwork-Id: 11450811 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 A5DBD14B4 for ; Sat, 21 Mar 2020 09:45:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 835C92076F for ; Sat, 21 Mar 2020 09:45:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="g0wF+ou+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728376AbgCUJpQ (ORCPT ); Sat, 21 Mar 2020 05:45:16 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:46975 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728238AbgCUJpP (ORCPT ); Sat, 21 Mar 2020 05:45:15 -0400 Received: by mail-wr1-f65.google.com with SMTP id j17so6896121wru.13 for ; Sat, 21 Mar 2020 02:45:14 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=3aRXmKaWpCikyhPB1r1OmE2K1u3/BRFi1kHB95qxuFw=; b=g0wF+ou+Z581+cBmPEU9Ede5RC7dNifbbFNqvzLutBgtLAn120kUaMH0t4rxT+JlH4 Mn5DNctfVE8t7kUofJeoSEOlHwMPXgyE/bb36JYczb2ot/a5MmIk1EYpkCa7wHjaHmYF DutIkIG2KE7GqcdZfou7rHwDDJouipWqQP4BNLdoA17IK5NxsFaudtxDUgXdfaNnVzUD OLRV6jOj9B6USC7AWKqnBQQDwoL+bTGXklYXJkqC8JVh/0+NDTjXpvSotK4Z02cqIqhE FDm8fEyv1A0lnRbI/pSBaUlLnd+iyciDalVskfkqUK2I2WK95UIwAw3hXJ1lcIdQzSuM OV4w== 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=3aRXmKaWpCikyhPB1r1OmE2K1u3/BRFi1kHB95qxuFw=; b=GfLf5TJzlnt2XM5B4Z1pYpEcL0dMtvKUdPPECzx7FUBAJ2sdU5r834HV2xjMePoGkl aUCF9N29fbV+HT+I3TJh6SOTNocP1rYkjv0jDHkA/lqTEcPGuxboArrMDsTsMIF1L/de UsU/RDvllmnykkP2kV7LtK6/vF7FbZ0V2tec7rK7G2NgTsTnbBxLt/CX3ywI0Unxqkzb NCGzoJWAtxVhmvT7Eoua8D476TfbIrz4Ax7/COgtq4tszrlWAWgAYCLZjgXZ9BwkQY8k +jlSUoPEMJ/fHyYup6RrJbTw0zDj2px4BtRfKxQryAmj4UQRIYKWGhMzVOq8bZwQ4zTs xDIA== X-Gm-Message-State: ANhLgQ3hodm663y+6V+Cqc+ckk8+slZk+X9UnnPTpb5RFXT6jeG/g640 tWQnggBUcq/iXau3X8LwZC40dw== X-Google-Smtp-Source: ADFU+vt6T6nUeI6bl3t9eRMr9wGqBkGoytGMG7fogvZ6K4Vx2wN+9uT8zFhopeIu3DiGK0gsaJu5Nw== X-Received: by 2002:a5d:5106:: with SMTP id s6mr15497200wrt.24.1584783913506; Sat, 21 Mar 2020 02:45:13 -0700 (PDT) Received: from localhost.localdomain ([84.33.129.193]) by smtp.gmail.com with ESMTPSA id z203sm5396378wmg.12.2020.03.21.02.45.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Mar 2020 02:45:12 -0700 (PDT) From: Paolo Valente To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, bfq-iosched@googlegroups.com, oleksandr@natalenko.name, rasibley@redhat.com, vkabatov@redhat.com, xzhou@redhat.com, jstancek@redhat.com, Paolo Valente , cki-project@redhat.com Subject: [PATCH BUGFIX 1/4] block, bfq: move forward the getting of an extra ref in bfq_bfqq_move Date: Sat, 21 Mar 2020 10:45:18 +0100 Message-Id: <20200321094521.85986-2-paolo.valente@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200321094521.85986-1-paolo.valente@linaro.org> References: <20200321094521.85986-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 ecedd3d7e199 ("block, bfq: get extra ref to prevent a queue from being freed during a group move") gets an extra reference to a bfq_queue before possibly deactivating it (temporarily), in bfq_bfqq_move(). This prevents the bfq_queue from disappearing before being reactivated in its new group. Yet, the bfq_queue may also be expired (i.e., its service may be stopped) before the bfq_queue is deactivated. And also an expiration may lead to a premature freeing. This commit fixes this issue by simply moving forward the getting of the extra reference already introduced by commit ecedd3d7e199 ("block, bfq: get extra ref to prevent a queue from being freed during a group move"). Reported-by: cki-project@redhat.com Tested-by: cki-project@redhat.com Signed-off-by: Paolo Valente --- block/bfq-cgroup.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/block/bfq-cgroup.c b/block/bfq-cgroup.c index f0ff6654af28..9d963ed518d1 100644 --- a/block/bfq-cgroup.c +++ b/block/bfq-cgroup.c @@ -642,6 +642,12 @@ void bfq_bfqq_move(struct bfq_data *bfqd, struct bfq_queue *bfqq, { struct bfq_entity *entity = &bfqq->entity; + /* + * Get extra reference to prevent bfqq from being freed in + * next possible expire or deactivate. + */ + bfqq->ref++; + /* If bfqq is empty, then bfq_bfqq_expire also invokes * bfq_del_bfqq_busy, thereby removing bfqq and its entity * from data structures related to current group. Otherwise we @@ -652,12 +658,6 @@ 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_or_in_serv) @@ -677,7 +677,7 @@ 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 */ + /* release extra ref taken above, bfqq may happen to be freed now */ bfq_put_queue(bfqq); } From patchwork Sat Mar 21 09:45:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valente X-Patchwork-Id: 11450805 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 5B66C14B4 for ; Sat, 21 Mar 2020 09:45:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3978920774 for ; Sat, 21 Mar 2020 09:45:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="xIzznXjB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728422AbgCUJpS (ORCPT ); Sat, 21 Mar 2020 05:45:18 -0400 Received: from mail-wm1-f53.google.com ([209.85.128.53]:50545 "EHLO mail-wm1-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728382AbgCUJpS (ORCPT ); Sat, 21 Mar 2020 05:45:18 -0400 Received: by mail-wm1-f53.google.com with SMTP id d198so3188891wmd.0 for ; Sat, 21 Mar 2020 02:45:15 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=CI7HoertAKDvDZptslfp0+rHp2j/ODCsoGqu9t32OVA=; b=xIzznXjBpVqlsSgITTHirE1Sy4Fs9Eq0jjeti/9RQ34hINQMBNDK45QbyL71xMp1Ga UdQJfcu3yepa89j8aNhVmA/ptVz0hvsnsEGrSx0LeM0tqygBQOcefDXfkCwFTIPyuIq6 1J5OoJIF2Em+DVvFEDxdDMPbJvAYcYylVLqqo+QyHKQ1qcjfW4KpIeY+qsippp4ia7jN HQHq+uviEZynA1ENrrotZ0+cD6kCTNrK1hfVZecnnd0yXnlbdxfzVhbmxXtUIPSLCxma 7utrhXJ70hzBOWNmvB0JF2mR1Daro2EzT3y2esVTTPLC/3idnISqZHMjTtVkhGNx7P1I Dhtg== 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=CI7HoertAKDvDZptslfp0+rHp2j/ODCsoGqu9t32OVA=; b=NKpNtqREL5/vhSq45HhlpFCV6TWh4N/i1Ozi7oEO25p7QYyNTC/S1WsQmoUF48qodY dlkPCrSApQtxbWtH//GHBZTabhIDeZOrSm9EieG1dDXy2Zv5MSPgSnP5FjfzmalIC78u IAF3HkDKKJXK00LyLfMhNHDGyxyf877hfgCRIbQTSzqZFy889UruVDz91fICHiSIjbiw fCvSRIP/3u/+HnHTm1IhDWSmnOyCQtVRv073/6oCo5TF3Cyqw62QolSXqkgpjDNeqjYh JMGvtj2O8DP6KmiQ6IkuGiOtwTCA5wi+yT4YWN/7QpRvrgeJTupVrplekEuQfLn87s3/ o51A== X-Gm-Message-State: ANhLgQ0FlDzgbz/kxsmWIt6iaHHlG1kAUNcpRx3Rp6JL48yex/xwtvIk z57aKxNcJd6+yEp3Q9yJpth19w== X-Google-Smtp-Source: ADFU+vv6bvYY4jRRrfXkVi6gsEcDn8amDvUoHr2R0oWUCp2iV/CPK3ppMwEW4FRSSww4KLKpWABAnQ== X-Received: by 2002:a1c:f607:: with SMTP id w7mr911618wmc.162.1584783914934; Sat, 21 Mar 2020 02:45:14 -0700 (PDT) Received: from localhost.localdomain ([84.33.129.193]) by smtp.gmail.com with ESMTPSA id z203sm5396378wmg.12.2020.03.21.02.45.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Mar 2020 02:45:14 -0700 (PDT) From: Paolo Valente To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, bfq-iosched@googlegroups.com, oleksandr@natalenko.name, rasibley@redhat.com, vkabatov@redhat.com, xzhou@redhat.com, jstancek@redhat.com, Paolo Valente , cki-project@redhat.com Subject: [PATCH BUGFIX 2/4] block, bfq: turn put_queue into release_process_ref in __bfq_bic_change_cgroup Date: Sat, 21 Mar 2020 10:45:19 +0100 Message-Id: <20200321094521.85986-3-paolo.valente@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200321094521.85986-1-paolo.valente@linaro.org> References: <20200321094521.85986-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 A bfq_put_queue() may be invoked in __bfq_bic_change_cgroup(). The goal of this put is to release a process reference to a bfq_queue. But process-reference releases may trigger also some extra operation, and, to this goal, are handled through bfq_release_process_ref(). So, turn the invocation of bfq_put_queue() into an invocation of bfq_release_process_ref(). Tested-by: cki-project@redhat.com Signed-off-by: Paolo Valente --- block/bfq-cgroup.c | 5 +---- block/bfq-iosched.c | 2 -- block/bfq-iosched.h | 1 + 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/block/bfq-cgroup.c b/block/bfq-cgroup.c index 9d963ed518d1..72c6151ace96 100644 --- a/block/bfq-cgroup.c +++ b/block/bfq-cgroup.c @@ -714,10 +714,7 @@ static struct bfq_group *__bfq_bic_change_cgroup(struct bfq_data *bfqd, if (entity->sched_data != &bfqg->sched_data) { bic_set_bfqq(bic, NULL, 0); - bfq_log_bfqq(bfqd, async_bfqq, - "bic_change_group: %p %d", - async_bfqq, async_bfqq->ref); - bfq_put_queue(async_bfqq); + bfq_release_process_ref(bfqd, async_bfqq); } } diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index 8c436abfaf14..d9c1899cf05b 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -2716,8 +2716,6 @@ static void bfq_bfqq_save_state(struct bfq_queue *bfqq) } } - -static void bfq_release_process_ref(struct bfq_data *bfqd, struct bfq_queue *bfqq) { /* diff --git a/block/bfq-iosched.h b/block/bfq-iosched.h index d1233af9c684..cd224aaf9f52 100644 --- a/block/bfq-iosched.h +++ b/block/bfq-iosched.h @@ -955,6 +955,7 @@ void bfq_bfqq_expire(struct bfq_data *bfqd, struct bfq_queue *bfqq, bool compensate, enum bfqq_expiration reason); void bfq_put_queue(struct bfq_queue *bfqq); void bfq_end_wr_async_queues(struct bfq_data *bfqd, struct bfq_group *bfqg); +void bfq_release_process_ref(struct bfq_data *bfqd, struct bfq_queue *bfqq); void bfq_schedule_dispatch(struct bfq_data *bfqd); void bfq_put_async_queues(struct bfq_data *bfqd, struct bfq_group *bfqg); From patchwork Sat Mar 21 09:45:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valente X-Patchwork-Id: 11450809 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 A3F4614B4 for ; Sat, 21 Mar 2020 09:45:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 774B02076F for ; Sat, 21 Mar 2020 09:45:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="H7CXwvgv" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728432AbgCUJpT (ORCPT ); Sat, 21 Mar 2020 05:45:19 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:39943 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728370AbgCUJpT (ORCPT ); Sat, 21 Mar 2020 05:45:19 -0400 Received: by mail-wm1-f67.google.com with SMTP id a81so3161806wmf.5 for ; Sat, 21 Mar 2020 02:45:17 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=cdw3Jk/AH3aPTxIWA1ECRCyWdOQJNXNVF8wpPDgyPN8=; b=H7CXwvgvlikXWm2OU7FFaknqW7yU3usmnqwnHiLMYZ2bKFnZqm2G+S9YMSkC5cxHtG sD6WprWxh/CLduwjgZA0zewGWw13VLmbfS92PgwgjNCXvZYxydf4NglpP4WQEr1CQnL5 y0V2579wllnZUQU0raaeqU7DWd8QDaQL8MjqGQ3iM+pItsMsLCmzLJt6oxDuYo7HO/FT Qxz9jH9PDC++VDsJ5jvcy2YPv0x+0eXJkyNOA+p/WEMMRHY+wWa04mf/QyRMIv1ZikbS UuZwKEKB93S961rs+nyhzHmOXSLl6jm5zP7amwJWuOUOeLJOyMXFn7fQK5lg2/Eg16NR tixA== 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=cdw3Jk/AH3aPTxIWA1ECRCyWdOQJNXNVF8wpPDgyPN8=; b=CIQSbkvu3nnBs2UlaDwYOa8764yJ6MkvQ1tDzcY/3wXqQQWAw4UAsFw14w0dHFs7nm 6vWP+7wTdZB0pKl8J81n9YIAF178OwWbdmIlLQ+dLtvKvZxqs3Bhow0aeXAD+jOSiA4p 366X7zL4zfAlfcZfTifcw2iNQDG2TOpVu9LjPW2J8oHxnvkAnHITRD9o4W2FYmF1S0az FYqroJsFCCtGKt9563IBYwJvu9sgjfQz3sVxd1GE8ojfqZGym54yru1CRz7zTyfnNcl/ d7h64icFoKXrkdX+TnpyafH09vmH/8jPqvocQyHI/u7twiLxHGeBIhldYKReknl1RNyh 1HAA== X-Gm-Message-State: ANhLgQ17lqeF3sfAYc6uP+jo1c9TqdzfI/HeiMEWYA7XO0du1cxDzMt9 +3mHO5EF5SioMa+N5OoIYDiocA== X-Google-Smtp-Source: ADFU+vtpSs1hWZbNJ6MMyxkZ/2yT/xobzl37JvigJkVu2u0PIYUyOF4QS/0H3i4yXUZz3lTYHL1XWA== X-Received: by 2002:a1c:3d6:: with SMTP id 205mr16222392wmd.155.1584783916449; Sat, 21 Mar 2020 02:45:16 -0700 (PDT) Received: from localhost.localdomain ([84.33.129.193]) by smtp.gmail.com with ESMTPSA id z203sm5396378wmg.12.2020.03.21.02.45.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Mar 2020 02:45:15 -0700 (PDT) From: Paolo Valente To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, bfq-iosched@googlegroups.com, oleksandr@natalenko.name, rasibley@redhat.com, vkabatov@redhat.com, xzhou@redhat.com, jstancek@redhat.com, Paolo Valente , cki-project@redhat.com Subject: [PATCH BUGFIX 3/4] block, bfq: make reparent_leaf_entity actually work only on leaf entities Date: Sat, 21 Mar 2020 10:45:20 +0100 Message-Id: <20200321094521.85986-4-paolo.valente@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200321094521.85986-1-paolo.valente@linaro.org> References: <20200321094521.85986-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_reparent_leaf_entity() reparents the input leaf entity (a leaf entity represents just a bfq_queue in an entity tree). Yet, the input entity is guaranteed to always be a leaf entity only in two-level entity trees. In this respect, because of the error fixed by commit 14afc5936197 ("block, bfq: fix overwrite of bfq_group pointer in bfq_find_set_group()"), all (wrongly collapsed) entity trees happened to actually have only two levels. After the latter commit, this does not hold any longer. This commit fixes this problem by modifying bfq_reparent_leaf_entity(), so that it searches an active leaf entity down the path that stems from the input entity. Such a leaf entity is guaranteed to exist when bfq_reparent_leaf_entity() is invoked. Tested-by: cki-project@redhat.com Signed-off-by: Paolo Valente --- block/bfq-cgroup.c | 48 ++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/block/bfq-cgroup.c b/block/bfq-cgroup.c index 72c6151ace96..efb89db7ba24 100644 --- a/block/bfq-cgroup.c +++ b/block/bfq-cgroup.c @@ -815,39 +815,53 @@ static void bfq_flush_idle_tree(struct bfq_service_tree *st) /** * bfq_reparent_leaf_entity - move leaf entity to the root_group. * @bfqd: the device data structure with the root group. - * @entity: the entity to move. + * @entity: the entity to move, if entity is a leaf; or the parent entity + * of an active leaf entity to move, if entity is not a leaf. */ static void bfq_reparent_leaf_entity(struct bfq_data *bfqd, - struct bfq_entity *entity) + struct bfq_entity *entity, + int ioprio_class) { - struct bfq_queue *bfqq = bfq_entity_to_bfqq(entity); + struct bfq_queue *bfqq; + struct bfq_entity *child_entity = entity; + + while (child_entity->my_sched_data) { /* leaf not reached yet */ + struct bfq_sched_data *child_sd = child_entity->my_sched_data; + struct bfq_service_tree *child_st = child_sd->service_tree + + ioprio_class; + struct rb_root *child_active = &child_st->active; + child_entity = bfq_entity_of(rb_first(child_active)); + + if (!child_entity) + child_entity = child_sd->in_service_entity; + } + + bfqq = bfq_entity_to_bfqq(child_entity); bfq_bfqq_move(bfqd, bfqq, bfqd->root_group); } /** - * bfq_reparent_active_entities - move to the root group all active - * entities. + * bfq_reparent_active_queues - move to the root group all active queues. * @bfqd: the device data structure with the root group. * @bfqg: the group to move from. - * @st: the service tree with the entities. + * @st: the service tree to start the search from. */ -static void bfq_reparent_active_entities(struct bfq_data *bfqd, - struct bfq_group *bfqg, - struct bfq_service_tree *st) +static void bfq_reparent_active_queues(struct bfq_data *bfqd, + struct bfq_group *bfqg, + struct bfq_service_tree *st, + int ioprio_class) { struct rb_root *active = &st->active; - struct bfq_entity *entity = NULL; - - if (!RB_EMPTY_ROOT(&st->active)) - entity = bfq_entity_of(rb_first(active)); + struct bfq_entity *entity; - for (; entity ; entity = bfq_entity_of(rb_first(active))) - bfq_reparent_leaf_entity(bfqd, entity); + while ((entity = bfq_entity_of(rb_first(active)))) + bfq_reparent_leaf_entity(bfqd, entity, ioprio_class); if (bfqg->sched_data.in_service_entity) bfq_reparent_leaf_entity(bfqd, - bfqg->sched_data.in_service_entity); + bfqg->sched_data.in_service_entity, + ioprio_class); } /** @@ -898,7 +912,7 @@ static void bfq_pd_offline(struct blkg_policy_data *pd) * There is no need to put the sync queues, as the * scheduler has taken no reference. */ - bfq_reparent_active_entities(bfqd, bfqg, st); + bfq_reparent_active_queues(bfqd, bfqg, st, i); } __bfq_deactivate_entity(entity, false); From patchwork Sat Mar 21 09:45:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Valente X-Patchwork-Id: 11450807 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 6856D14B4 for ; Sat, 21 Mar 2020 09:45:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 44E8F20775 for ; Sat, 21 Mar 2020 09:45:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="zdXLpXQc" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728448AbgCUJpW (ORCPT ); Sat, 21 Mar 2020 05:45:22 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:39833 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728424AbgCUJpU (ORCPT ); Sat, 21 Mar 2020 05:45:20 -0400 Received: by mail-wm1-f66.google.com with SMTP id a9so5857477wmj.4 for ; Sat, 21 Mar 2020 02:45:19 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=p07172ZoAYLhgL8MhlQdQDPQm1FytxKJ4TUV9O0POto=; b=zdXLpXQcmYSY7ZbBRXUOXbyjJ6V4owIHKwkhSp5juYJCLE0AaXgek+6PXgKKrLdwwd 2X6dU/PbshRwWKHUipBZ0UKJmMpzKbJQN9fW44JFPIDGQZ2i8NAImsWRN0w/gQt9M6LY LWqA1VNcWBXl7WtBw6nsN5in5dKCG/zWK2LzR/cOQmZenyrQmRjh+wp5lTfDqzaAQEH+ xdOQ/VOSghP5CeLTG5s7/hMnz1b25ZPKBf0FDc3u1Cfz7Vfsfi9/BB8FJKGwXAEL2yuD K+0Y88lobxoddQ/vTyjNKI4f1b3eCjAPzXNlVjH3z3A5MvCFm54LaRS6Jcd6IBb3/qZL FgOw== 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=p07172ZoAYLhgL8MhlQdQDPQm1FytxKJ4TUV9O0POto=; b=bDbY/0gW0YV2KrVzX+25MGEWzfQ/Mr+6buYkMM0aBGzSNcwGauEHjrHne4MfB5SD8M H9uY+OVrSTcEOfogXh8xnxkE2gsQ2wITj1GK6wzUeb4+kksYwef73NgIzw9JO/3Zz1oY QgEYPnQ1Nw/bF+KUN43ECSIGtiCLqxwDcNcfsLxoDmVy/dzr2rP6CjgmEI4kKcSb+kSO wgC/hPA7DzPq56IxnPSbZllWKwSqwPuzkLhrqLmoffmrPa6e7TWG/1m3BETRnt1eWxJq 2ff/R0q/z++AP5vxza8VtJQ1Cggv455iC5E6tbNh572+P8hMEH/zEfPfXWJPhMty+2d9 wk+A== X-Gm-Message-State: ANhLgQ2o7SJ5m/ojxvdd32vurPdp4L5vtVqFt220DTVapHbgStQ6cK1O QrkSgp9QhWZctQm0bMmnoWhsMw== X-Google-Smtp-Source: ADFU+vuMvU0VAEsp5NxIjE3HoyKfXnehkLji93VVgZ1i9x4FykxgYwnmFfxgCFWyRurhFhB9d4xvtA== X-Received: by 2002:a1c:7209:: with SMTP id n9mr15153060wmc.188.1584783918623; Sat, 21 Mar 2020 02:45:18 -0700 (PDT) Received: from localhost.localdomain ([84.33.129.193]) by smtp.gmail.com with ESMTPSA id z203sm5396378wmg.12.2020.03.21.02.45.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Mar 2020 02:45:17 -0700 (PDT) From: Paolo Valente To: Jens Axboe Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, bfq-iosched@googlegroups.com, oleksandr@natalenko.name, rasibley@redhat.com, vkabatov@redhat.com, xzhou@redhat.com, jstancek@redhat.com, Paolo Valente , cki-project@redhat.com Subject: [PATCH BUGFIX 4/4] block, bfq: invoke flush_idle_tree after reparent_active_queues in pd_offline Date: Sat, 21 Mar 2020 10:45:21 +0100 Message-Id: <20200321094521.85986-5-paolo.valente@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200321094521.85986-1-paolo.valente@linaro.org> References: <20200321094521.85986-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_pd_offline(), the function bfq_flush_idle_tree() is invoked to flush the rb tree that contains all idle entities belonging to the pd (cgroup) being destroyed. In particular, bfq_flush_idle_tree() is invoked before bfq_reparent_active_queues(). Yet the latter may happen to add some entities to the idle tree. It happens if, in some of the calls to bfq_bfqq_move() performed by bfq_reparent_active_queues(), the queue to move is empty and gets expired. This commit simply reverses the invocation order between bfq_flush_idle_tree() and bfq_reparent_active_queues(). Tested-by: cki-project@redhat.com Signed-off-by: Paolo Valente --- block/bfq-cgroup.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/block/bfq-cgroup.c b/block/bfq-cgroup.c index efb89db7ba24..68882b9b8f11 100644 --- a/block/bfq-cgroup.c +++ b/block/bfq-cgroup.c @@ -893,13 +893,6 @@ static void bfq_pd_offline(struct blkg_policy_data *pd) for (i = 0; i < BFQ_IOPRIO_CLASSES; i++) { st = bfqg->sched_data.service_tree + i; - /* - * The idle tree may still contain bfq_queues belonging - * to exited task because they never migrated to a different - * cgroup from the one being destroyed now. - */ - bfq_flush_idle_tree(st); - /* * It may happen that some queues are still active * (busy) upon group destruction (if the corresponding @@ -913,6 +906,19 @@ static void bfq_pd_offline(struct blkg_policy_data *pd) * scheduler has taken no reference. */ bfq_reparent_active_queues(bfqd, bfqg, st, i); + + /* + * The idle tree may still contain bfq_queues + * belonging to exited task because they never + * migrated to a different cgroup from the one being + * destroyed now. In addition, even + * bfq_reparent_active_queues() may happen to add some + * entities to the idle tree. It happens if, in some + * of the calls to bfq_bfqq_move() performed by + * bfq_reparent_active_queues(), the queue to move is + * empty and gets expired. + */ + bfq_flush_idle_tree(st); } __bfq_deactivate_entity(entity, false);