Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp205046rwb; Mon, 28 Nov 2022 19:22:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf7VMUouyS9euzgFuuub4x0brLixs5Z/RjDnkAaUoHoC8+LnJmGD9pN5IBGXuWe9fjwp+vw8 X-Received: by 2002:a05:6402:1117:b0:46b:6da7:e8a9 with SMTP id u23-20020a056402111700b0046b6da7e8a9mr2628066edv.401.1669692158375; Mon, 28 Nov 2022 19:22:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669692158; cv=none; d=google.com; s=arc-20160816; b=ZWcSf0i/qyIPQ/mYsTQe279QaahHkyM2hLCKQBi4q4DMLftbRR0UmQk7kWm16XSzpF kImXVoSzCyvNbK7VriWwfUVKr95rGRRnDqeq2WFcx/1xYnCnv5Msi1w32jZKwo/tUAeB AO/a2OhOaq0NSM8FwLg77O7oQ9BDOs5GonfUY/6zNDLFi7exBUfsGmN9asShR+rxxw4d esDvP8E/M3DrAAUrGv1tv+mz3nTpoLdLJm8DZsMTijoR7+n+/Jn/fxWQEoBZUhxR52i1 iW/J6HFfZG1QqfMIiH/gIg8VFC4VCgQZfI/Uu+rGpDfUWg/CACdZPJf7eh/ZFEcuTEHb UmbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=d5/X4b4v5p1MG25H4IG3atyWjYcr8tJMCXl7vn6DZro=; b=mfGdBniBVj9f20a3KkcOTJYsoNnzGdPzGKumjRQ1cvurCoam9mrKGlDiT53uFjbjPS Ki9iznysI2cWhYzpz98Ff1s9PnfTqrErLhhwi/Ezclz1Yb2au4CXhzC2GvLYkLndE5gP igQUc9ZN2lHzAgDHFYL6B08V/miIJsRSzfrPxC1d4S0hRD5ZQCIRbnGIDjKAvMMqlDF5 rWmovs0eLGAAwnJnjTV6r5cwdMNT1PM0dHaEgv+zm5pmu6EaAv2cnvaXdRGTDOEf6Jc5 AWZouRA/qj2MIMaM0YElD9z2ZFMl2s0pWSEz4UU7Lr9KcE/VbO2rdfDAIxk+Se3ESyiA u0Jg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qo14-20020a170907874e00b0073dd7598686si10001163ejc.270.2022.11.28.19.22.15; Mon, 28 Nov 2022 19:22:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235375AbiK2DCQ (ORCPT + 83 others); Mon, 28 Nov 2022 22:02:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235291AbiK2DBy (ORCPT ); Mon, 28 Nov 2022 22:01:54 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1509845097; Mon, 28 Nov 2022 19:01:54 -0800 (PST) Received: from kwepemi500016.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NLnCt1XVRz15MpD; Tue, 29 Nov 2022 11:01:14 +0800 (CST) Received: from huawei.com (10.174.178.129) by kwepemi500016.china.huawei.com (7.221.188.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 29 Nov 2022 11:01:51 +0800 From: Kemeng Shi To: , , CC: , , , Subject: [PATCH v2 03/10] blk-throttle: ignore cgroup without io queued in blk_throtl_cancel_bios Date: Tue, 29 Nov 2022 11:01:40 +0800 Message-ID: <20221129030147.27400-4-shikemeng@huawei.com> X-Mailer: git-send-email 2.14.1.windows.1 In-Reply-To: <20221129030147.27400-1-shikemeng@huawei.com> References: <20221129030147.27400-1-shikemeng@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.178.129] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemi500016.china.huawei.com (7.221.188.220) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Ignore cgroup without io queued in blk_throtl_cancel_bios for two reasons: 1. Save cpu cycle for trying to dispatch cgroup which is no io queued. 2. Avoid non-consistent state that cgroup is inserted to service queue without THROTL_TG_PENDING set as tg_update_disptime will unconditional re-insert cgroup to service queue. If we are on the default hierarchy, IO dispatched from child in tg_dispatch_one_bio will trigger inserting cgroup to service queue without erase first and ruin the tree. Signed-off-by: Kemeng Shi Acked-by: Tejun Heo --- block/blk-throttle.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/block/blk-throttle.c b/block/blk-throttle.c index d516a37e82fb..ee7dc1a0adfd 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -1738,7 +1738,18 @@ void blk_throtl_cancel_bios(struct gendisk *disk) * Set the flag to make sure throtl_pending_timer_fn() won't * stop until all throttled bios are dispatched. */ - blkg_to_tg(blkg)->flags |= THROTL_TG_CANCELING; + tg->flags |= THROTL_TG_CANCELING; + + /* + * Do not dispatch cgroup without THROTL_TG_PENDING or cgroup + * will be inserted to service queue without THROTL_TG_PENDING + * set in tg_update_disptime below. Then IO dispatched from + * child in tg_dispatch_one_bio will trigger double insertion + * and corrupt the tree. + */ + if (!(tg->flags & THROTL_TG_PENDING)) + continue; + /* * Update disptime after setting the above flag to make sure * throtl_select_dispatch() won't exit without dispatching. -- 2.30.0