From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8E85C43381 for ; Thu, 28 Jan 2021 04:15:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9C15764DD8 for ; Thu, 28 Jan 2021 04:15:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231337AbhA1EPe (ORCPT ); Wed, 27 Jan 2021 23:15:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231345AbhA1EPR (ORCPT ); Wed, 27 Jan 2021 23:15:17 -0500 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78F95C06178C for ; Wed, 27 Jan 2021 19:51:35 -0800 (PST) Received: by mail-pl1-x634.google.com with SMTP id h15so2579775pli.8 for ; Wed, 27 Jan 2021 19:51:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=5/5Nw0RKDmqtkW6U2OGztqbU4sbce483ba0fNg4jHmE=; b=2H7Jq4BRpHGb4e6Zb8JdRsmhcW7tJMAZ3DsQEqjU3qgSQ87DRhATbE7momvtGaeN8z cPULqYS074E3yQVmL5k6TYZPM6AidXedpyNUvlChoDSqENwiuwSQrBYH7lp9UNoDynhw fWShW6Egc2g6ih5k/bpBQKHXksEo8dbQKY2UcVirufVtgWOQmwBArln9Afr3RiUW4Rbj myJI9z8Qsb+7DQ3RylIpWIgHz3dNfscCkRnObDsLkiOjpQoNYwJ0p2Q4SZWSuTnzQQcI 6NrT0iNdOXxxK1M3aeVfjA1IEJ2EA0ClNxWrors1RdQe4CXQCR65hUjIL/x/V5pK+ODr WATw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=5/5Nw0RKDmqtkW6U2OGztqbU4sbce483ba0fNg4jHmE=; b=Iw7pQ0qQIc2+1qKVCM4waxkLfZZJKuwe0WXU6qyoeWC+a7VuFOEj1A5LYChMAcfkOF KUezipNtT6V/iLSoLa7xAh6eksTvA2RNJtrEKIymV8Mk/MUsCI71T8nKWHDf9Q7UGJOh Wc/EhBLHaRchhBWGkg1zTOxNQQTZ50HQV4j0uV31yQwYaCG03Ua996ibS4QSoSyWCKuY ZsRggcRGhxYbNg6ihiC+jIz4FFVA5OUzZZwf9ki8K+4QhO4YosRQAfs8oPlgB06bzMpG Ss/O4uAiQdP8LVaAVhF5bpwjZJDtD4xOrgnX3xxo8XoDerBvUMFBMtkwYhV7nAb+tWJB JpYg== X-Gm-Message-State: AOAM532AlCkE9gYAmbKMuGZpF0RrVpqYMKXg6THtQcEIrhUUik1A+bSy F4KlawD6R1QMYP398/yGaKYkJQ== X-Google-Smtp-Source: ABdhPJzvONeZ3sIE3s9ZX7koPMUSTsnSHN1rf92uuGfpU7wGgGioX0P8v9i3I4oQFoJl2lABlGl/oA== X-Received: by 2002:a17:90b:368b:: with SMTP id mj11mr9050989pjb.76.1611805894673; Wed, 27 Jan 2021 19:51:34 -0800 (PST) Received: from [192.168.4.41] (cpe-72-132-29-68.dc.res.rr.com. [72.132.29.68]) by smtp.gmail.com with ESMTPSA id b65sm4012946pfg.3.2021.01.27.19.51.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 27 Jan 2021 19:51:34 -0800 (PST) Subject: Re: [PATCH v2] blk-cgroup: Use cond_resched() when destroy blkgs To: Baolin Wang , tj@kernel.org Cc: joseph.qi@linux.alibaba.com, linux-block@vger.kernel.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org References: <8e8a0c4644d5eb01b7f79ec9b67c2b240f4a6434.1611798287.git.baolin.wang@linux.alibaba.com> <3f3c12de-b5fb-a9ad-9324-55f5bf9d7453@kernel.dk> From: Jens Axboe Message-ID: <36d23f2a-4696-ff74-4423-6719b9670208@kernel.dk> Date: Wed, 27 Jan 2021 20:51:32 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org On 1/27/21 8:49 PM, Baolin Wang wrote: > > > 在 2021/1/28 11:41, Jens Axboe 写道: >> On 1/27/21 8:22 PM, Baolin Wang wrote: >>> On !PREEMPT kernel, we can get below softlockup when doing stress >>> testing with creating and destroying block cgroup repeatly. The >>> reason is it may take a long time to acquire the queue's lock in >>> the loop of blkcg_destroy_blkgs(), or the system can accumulate a >>> huge number of blkgs in pathological cases. We can add a need_resched() >>> check on each loop and release locks and do cond_resched() if true >>> to avoid this issue, since the blkcg_destroy_blkgs() is not called >>> from atomic contexts. >>> >>> [ 4757.010308] watchdog: BUG: soft lockup - CPU#11 stuck for 94s! >>> [ 4757.010698] Call trace: >>> [ 4757.010700] blkcg_destroy_blkgs+0x68/0x150 >>> [ 4757.010701] cgwb_release_workfn+0x104/0x158 >>> [ 4757.010702] process_one_work+0x1bc/0x3f0 >>> [ 4757.010704] worker_thread+0x164/0x468 >>> [ 4757.010705] kthread+0x108/0x138 >> >> Kind of ugly with the two clauses for dropping the blkcg lock, one >> being a cpu_relax() and the other a resched. How about something >> like this: >> >> >> diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c >> index 031114d454a6..4221a1539391 100644 >> --- a/block/blk-cgroup.c >> +++ b/block/blk-cgroup.c >> @@ -1016,6 +1016,8 @@ static void blkcg_css_offline(struct cgroup_subsys_state *css) >> */ >> void blkcg_destroy_blkgs(struct blkcg *blkcg) >> { >> + might_sleep(); >> + >> spin_lock_irq(&blkcg->lock); >> >> while (!hlist_empty(&blkcg->blkg_list)) { >> @@ -1023,14 +1025,20 @@ void blkcg_destroy_blkgs(struct blkcg *blkcg) >> struct blkcg_gq, blkcg_node); >> struct request_queue *q = blkg->q; >> >> - if (spin_trylock(&q->queue_lock)) { >> - blkg_destroy(blkg); >> - spin_unlock(&q->queue_lock); >> - } else { >> + if (need_resched() || !spin_trylock(&q->queue_lock)) { >> + /* >> + * Given that the system can accumulate a huge number >> + * of blkgs in pathological cases, check to see if we >> + * need to rescheduling to avoid softlockup. >> + */ >> spin_unlock_irq(&blkcg->lock); >> - cpu_relax(); >> + cond_resched(); >> spin_lock_irq(&blkcg->lock); >> + continue; >> } >> + >> + blkg_destroy(blkg); >> + spin_unlock(&q->queue_lock); >> } >> >> spin_unlock_irq(&blkcg->lock); >> > > Looks better to me. Do I need resend with your suggestion? Thanks. Probably best, gives Tejun another chance to sign off on it :-) -- Jens Axboe