From patchwork Tue Jun 6 05:36:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13268250 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0C1AC7EE24 for ; Tue, 6 Jun 2023 05:37:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232670AbjFFFhD (ORCPT ); Tue, 6 Jun 2023 01:37:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229596AbjFFFhB (ORCPT ); Tue, 6 Jun 2023 01:37:01 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B141F1AD for ; Mon, 5 Jun 2023 22:37:00 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1b038064d97so51185355ad.0 for ; Mon, 05 Jun 2023 22:37:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=slowstart.org; s=google; t=1686029819; x=1688621819; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=t+KVA8d2QzjjtOm41L/n6eTGzIQ0QopCkCyI/fnIOaI=; b=eKajPzfcAnTwX0beRBEneGsd94AEoe4RtQkuSjc1EePM5llGeEgPReG/3EmGEa47dR XqQP990+jiPL0jRYIsl5jyG7+n+vteeFGkq0YPvjmK2SREtFsse4DBOGDZmR7id+6Kz6 yNe3iee7zXGHDwmRHr1ItIoDgOjWOuV7oGTArhgJz9MoAMnN0TkQRlFNuWKqqyogfz/m ek6B6Fjh2fa+iUjjgMrvquwQCCZqaZWs49M1TdKlQo0u8eO9Iw+ZckPY3fEBW9iWzuxP eb//5Qr7NsmjgoWnx3Eh7OKk2pHd4Ae7jM82sDTKytQsttQEg+87nDcGSHbfFSCXecvh dMvQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=elisp-net.20221208.gappssmtp.com; s=20221208; t=1686029819; x=1688621819; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=t+KVA8d2QzjjtOm41L/n6eTGzIQ0QopCkCyI/fnIOaI=; b=0pIEX0v6Wsc375sYB7ofCtthJ+WCnrCFP3N04lnDfMHBH3zoJvnkNRiBf5SwAC3XZs stBpZDm5BkdAgo/gk9NiYVsWWV1OUalEyh3t9AO17UBDX0fO8KEtOjN6hYZK6FfmOVRh hmW7nVzTfDK2GpE46/2yhWRW7tJqNz/zdUxtYzymNxN1PeJiOjfnF31BllBF9VncCGSb ynD6jiUNg/WcHGKrxQrhVbsL1Rc97HkyDXocb0XEDhUHWr3YZAa1PJs4kIxOgHiZmGVv wZV4uwpGHlE6269/Xcz2/viV97TdhxhcnwmXGl12uqOYbpB1ULk9gkWTgOrPqXak69Ex Os9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686029819; x=1688621819; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=t+KVA8d2QzjjtOm41L/n6eTGzIQ0QopCkCyI/fnIOaI=; b=eVXOiZMo+iIjuy3dMVtoCVs5+/k+xeCms71JzRJIDpvC/oycxL6oNhDLgDHk7NBF1I FNogQ6HmOu5BXsAspA6ZAJygbvpLo8TulJRgRchRhd5nZkrn68BasiZuPRtmncOjySZq 7kHa2UgnemZReh6AnV+k+ONooU4Kls6Q9PoDecCa3XvJ3nJCUD08l27LtXMLEKk34yl8 +54fU/fuzWOEplGFTi6dgjI55AhydXQ6zzzrGftIVgfM1fVAuwe7KsPeTviZBjrZS0E8 eFjyyHHCRIt9TwuTnOoj7DJI4p/S3p6bqXfVPoL8AcS6gWEiegATa9aq9VRDWUzS4SNB 8ihQ== X-Gm-Message-State: AC+VfDwlZDSYfhqkfv9je3qkgRn+aljyQuc8MkQHPDRXxZCCUrYpVWTI 1NNHFQoIFPp6veGcyNY+Tjr5ksohOUlX92oWPoUy4KdOn0dY7g7Pm1LeGqVRerbh22kyDgsxX+8 0Fgaja9j2IsTM6KrlZPtd73OrfVHpQW+buHO4iCOwS3lkvHmhFvYl7HE0h/mX7JZZsh/mlXt0nu vgnb2aNhsE2xCz X-Google-Smtp-Source: ACHHUZ5bNCa6zgqXpINtNlMi0jzc7iqaM9NQBeIhDpCezvbIKVfcuXd9EF9zIS2PJFcaoJ1mLubn5Q== X-Received: by 2002:a17:902:9887:b0:1a9:80a0:47ef with SMTP id s7-20020a170902988700b001a980a047efmr7963910plp.20.1686029819452; Mon, 05 Jun 2023 22:36:59 -0700 (PDT) Received: from naota-xeon.wdc.com (fp96936df3.ap.nuro.jp. [150.147.109.243]) by smtp.gmail.com with ESMTPSA id d9-20020a170902cec900b001b06f7f5333sm7521853plg.1.2023.06.05.22.36.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jun 2023 22:36:58 -0700 (PDT) Sender: Naohiro Aota From: Naohiro Aota X-Google-Original-From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 1/4] btrfs: delete unused BGs while reclaiming BGs Date: Tue, 6 Jun 2023 14:36:33 +0900 Message-Id: <06288ff9c090a5bfe76e0a2080eb1fbd640cdd62.1686028197.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The reclaiming process only starts after the FS volumes are allocated to a certain level (75% by default). Thus, the list of reclaiming target block groups can build up so huge at the time the reclaim process kicks in. On a test run, there were over 1000 BGs in the reclaim list. As the reclaim involves rewriting the data, it takes really long time to reclaim the BGs. While the reclaim is running, btrfs_delete_unused_bgs() won't proceed because the reclaim side is holding fs_info->reclaim_bgs_lock. As a result, we will have a large number of unused BGs kept in the unused list. On my test run, I got 1057 unused BGs. Since deleting a block group is relatively easy and fast work, we can call btrfs_delete_unused_bgs() while it reclaims BGs, to avoid building up unused BGs. Fixes: 18bb8bbf13c1 ("btrfs: zoned: automatically reclaim zones") CC: stable@vger.kernel.org # 5.15+ Signed-off-by: Naohiro Aota Reviewed-by: Filipe Manana Reviewed-by: Johannes Thumshirn --- fs/btrfs/block-group.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index 618ba7670e66..c5547da0f6eb 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -1824,10 +1824,24 @@ void btrfs_reclaim_bgs_work(struct work_struct *work) next: btrfs_put_block_group(bg); + + mutex_unlock(&fs_info->reclaim_bgs_lock); + /* + * Reclaiming all the BGs in the list can take really long. + * Prioritize cleanning up unused BGs. + */ + btrfs_delete_unused_bgs(fs_info); + /* + * If we are interrupted by a balance, we can just bail out. The + * cleaner thread call me again if necessary. + */ + if (!mutex_trylock(&fs_info->reclaim_bgs_lock)) + goto end; spin_lock(&fs_info->unused_bgs_lock); } spin_unlock(&fs_info->unused_bgs_lock); mutex_unlock(&fs_info->reclaim_bgs_lock); +end: btrfs_exclop_finish(fs_info); sb_end_write(fs_info->sb); } From patchwork Tue Jun 6 05:36:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13268252 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C096C7EE2A for ; Tue, 6 Jun 2023 05:37:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233008AbjFFFhF (ORCPT ); Tue, 6 Jun 2023 01:37:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229596AbjFFFhD (ORCPT ); Tue, 6 Jun 2023 01:37:03 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C9291A7 for ; Mon, 5 Jun 2023 22:37:02 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6532671ccc7so4652720b3a.2 for ; Mon, 05 Jun 2023 22:37:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=slowstart.org; s=google; t=1686029821; x=1688621821; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=A3+xiEI337AU8hRkvpfals6+m/yNEy48+V0XCft029k=; b=ag+3DBEmYwlaxBM1tsekRFA6MsgLYYuHFB3f7CcHdch/bOcwG2KSJjDxV0h/aHXpWb XKr1xbgUKbwE8xvYHm1q6L9pLLyemGxJmv6WUdbJ283tFQKdfMB75JV80OaUhhQp0ST3 1DVjSnWpl0nnUSuKRfu9myL804u9BhoUXURHPu4TriEjLiCq35ivoAW3w5BmBgLE6Dn+ JV49tO2vw1ObEqBP1hdbqaPOVsdFTI95Cw2X3wWWc2Pc+i4Wbi/uTP9EVeyfrGS8dZOm gW44Eb3vk2BR59Yy/kVMHciPMs9g/T596m6pi1h/pWYsyV1AwWyu9RLEeAkAOG8xSs35 erFQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=elisp-net.20221208.gappssmtp.com; s=20221208; t=1686029821; x=1688621821; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=A3+xiEI337AU8hRkvpfals6+m/yNEy48+V0XCft029k=; b=Ye90u+m4bPTi/sK5WUFx4IxLqhV12NMJ9QT/tMa4guMFmqPtB+Dxx1Hg6WiBWcgPxb VSl/2o2V2cPo/CWYDS+KgjfjfynJ3SF3BKbgs9aPNxlaqa8//AzMY8yPhBxEQWYiH1p6 p8EObT155UPUHDSbIOK2BhEl19N4lY6ZUguBnXlWmTWeEmdlRPzzx3ZE4Wppt/NnAJNH 0rKWc4CbIp5F0WaM+7PWNRUWopM6EMoUVoqwKV8A0qxY37J8N2AKIt5DgmrqaUH8jlVz lw+p60s25591vNBc7Eawz4bP47SY3/OA5jMEsYQwS5ABnKmMVfaOzN/qH4PIYjdZ7+rn FEMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686029821; x=1688621821; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=A3+xiEI337AU8hRkvpfals6+m/yNEy48+V0XCft029k=; b=lQku+oKPgzopIC09EKDnVxZN8sqQLIYA6r1TYdUSTYB2yeoQ1TMS1R0CYF5rbThqKK rk7bP4A9pvSgUU651k1bUTkWHz2L6pxIlhnGft7jHWWYeBk+ahB9EdzgPw4K8Qk1ocwp q7n+V5XA0j9U+aI78E2VdSaUJSn0CnyZF2jsx7/Xh6ZkOCn/4hUAwZutlVYTQkCXsJ36 /Wa6jGDWoC1nKixH0FJDu+Q7r9JySUPMNFInAfbpv8aqnjgf7djm0Z+CtgwyYMB/FcFf iJWQgTeFBqaEpwrbpigM4Tby8wKEyqqy9y8LvrEA3EJeThMxZgk49xDKyg/KAdK0iBAm 6Z/g== X-Gm-Message-State: AC+VfDzKlK8G9AHdY3feZxTSEIe5EpgqlVqh8fg9I9U+JNPL0DCwTkPz FRfRIQGGQZBqcIGm/TP/F22W+Wb+lrIQnh92CrjPbtVFcgrEwmYjAdzPmsb9ly/YbyqoTbuEkKm dW5oAy99ElpMCS4tz+2REYhUFuj/0GWzMCvpNiLNXfxaW0KCWYM4lfWxgewoIze2w03IPkZkodZ aMMbpqxhMcVPxM X-Google-Smtp-Source: ACHHUZ6nwCiH9rUT/q6CJovbceh6mcJOSkH4ntDuXrvX1YTJFydLIX5ToN2C6Ur4Mc39uzJlag9Zow== X-Received: by 2002:a05:6a21:6704:b0:10d:d18b:95ce with SMTP id wh4-20020a056a21670400b0010dd18b95cemr1389972pzb.22.1686029821292; Mon, 05 Jun 2023 22:37:01 -0700 (PDT) Received: from naota-xeon.wdc.com (fp96936df3.ap.nuro.jp. [150.147.109.243]) by smtp.gmail.com with ESMTPSA id d9-20020a170902cec900b001b06f7f5333sm7521853plg.1.2023.06.05.22.36.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jun 2023 22:37:00 -0700 (PDT) Sender: Naohiro Aota From: Naohiro Aota X-Google-Original-From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 2/4] btrfs: move out now unused BG from the reclaim list Date: Tue, 6 Jun 2023 14:36:34 +0900 Message-Id: <6a25b9266b8fb08ff990214aae9efd04fed6b549.1686028197.git.naohiro.aota@wdc.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org An unused block group is easy to remove to free up space and should be reclaimed fast. Such block group can often already be a target of the reclaim process. As we check list_empty(&bg->bg_list), we keep it in the reclaim list. That block group is never reclaimed until the file system is filled e.g, 75%. Instead, we can move unused block group to the unused list and delete it fast. Fixes: 18bb8bbf13c1 ("btrfs: zoned: automatically reclaim zones") CC: stable@vger.kernel.org # 5.15+ Signed-off-by: Naohiro Aota Reviewed-by: Filipe Manana Reviewed-by: Johannes Thumshirn --- fs/btrfs/block-group.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index c5547da0f6eb..d5bba02167be 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -1633,11 +1633,14 @@ void btrfs_mark_bg_unused(struct btrfs_block_group *bg) { struct btrfs_fs_info *fs_info = bg->fs_info; + trace_btrfs_add_unused_block_group(bg); spin_lock(&fs_info->unused_bgs_lock); if (list_empty(&bg->bg_list)) { btrfs_get_block_group(bg); - trace_btrfs_add_unused_block_group(bg); list_add_tail(&bg->bg_list, &fs_info->unused_bgs); + } else { + /* Pull out the BG from the reclaim_bgs list. */ + list_move_tail(&bg->bg_list, &fs_info->unused_bgs); } spin_unlock(&fs_info->unused_bgs_lock); } From patchwork Tue Jun 6 05:36:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13268253 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1AB5C77B7A for ; Tue, 6 Jun 2023 05:37:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233348AbjFFFhH (ORCPT ); Tue, 6 Jun 2023 01:37:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231954AbjFFFhF (ORCPT ); Tue, 6 Jun 2023 01:37:05 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A2AE1B5 for ; Mon, 5 Jun 2023 22:37:04 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-651ffcc1d3dso3320991b3a.3 for ; Mon, 05 Jun 2023 22:37:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=slowstart.org; s=google; t=1686029823; x=1688621823; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=JXKzwEXEdvAPRSAB3ExrTenXQvkL0l7z/jj4ezUDKfg=; b=DSPBYC3vZuqe/DD66MinjQ6Yi6qqc7Yr+EY8xywsmFrUxiK/ztwuxP/KXy+nuZLII2 1OU/Z7+Yfl45nDgZ2Vk+biuDT68uxun/pMf6u2c3CVdbBg7Hy8SuLIzBjBpf7zZ1rk/J KFSx/N/XH6KLifREjfXsomOCtRf8it03pfLBUHOuhGXqemQc7M8JZqaZ0nC+3gGJaa09 5TetfltJBUed4STAKupqX4itqP0Kcr+X/hskCXirnGerm93ZO1PBUWCdbwNzNdc8lPDn mGovM9UT+lFxc/psTr9ftRPw6fLEQW6dKnnXDmFyHpJ/KLI6XgBsB7eK8tiOSvQO76SE xMQg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=elisp-net.20221208.gappssmtp.com; s=20221208; t=1686029823; x=1688621823; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=JXKzwEXEdvAPRSAB3ExrTenXQvkL0l7z/jj4ezUDKfg=; b=CW1RYJW2cshp/qJGxTlxS6AlE10CSrIBMeqtYEKTjaUTJ4A2Y0aQLYrv3L0GR3RoSO o0XiZ3OTzZ+xU4i2lnC6urEpC0j2PknBmtbbpJ8ZmwGXIJpJxUOLEWVjFxq5saCCwBkW GEoXM6dN4aWQ9qwUzh4S9Cn28EEywvIRkX58MxNswUKNXUqHvKKYvx/0bOZgMyX4kdYm 1dOj1/0ntw08s9fwTPPoVO4VEV8EscDx8uHT85FXCDeYdrx+TKFQ9QxlIyxqX1CM2qGM 0315NAaIyrzQeMip/UzY/OBtD3lK6x9ZGmqHXxX+brFVm+lmoXHWo1/It2ZQ23jl98HF WfCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686029823; x=1688621823; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=JXKzwEXEdvAPRSAB3ExrTenXQvkL0l7z/jj4ezUDKfg=; b=WyeQsQQyfDTt2wS/VNSJ2R2ZKFVXJ9LCJpodML4Kl9tyMowEuqW63nU7GTIfMVxcfs 6WmG3zQANOobMoOasSbaSM0RpbFKbplFkdZjaxQvp9hReE2Q2InquqVkKRzeBRhffE7d CW1jDu0KzooaiY1DiW18QcKKPCjCiiXPv7gdA/jP0aYmMxxXymEabPpbqaQZj405dI1/ ZrYdSOJMaMLvwWsmXpllxS0C7Av0wlWsoZf2PQNcTEdQ0d79rr+OL6bW0Zc9DTaY7aXc H70RV49cSt4IbvqsO3xvT4mXxOktyGNToSFVbI5mPHatMDp18FIFvSnpMARpzUSiSMGs cMQQ== X-Gm-Message-State: AC+VfDxLE9Uf//HpjdWTLXXtQpLUpwX0vOdKpjKQzb9I+E9mPYrUe6x+ 1IS3hMvwa40G1xPQO9bIlVLeXtf6+HicuLgGhobXe7LIJe1AjBhq2U+UgwB8CbH998K3kV+aHP0 SLv3rqCw4xkPU8RUSMBR/DcAlJojT8ME8TK3NNPPR5v9q3F/zTXnTbmyjZO/l6JMuccekvA7+R7 Y1cS+AKjtyK9mr X-Google-Smtp-Source: ACHHUZ6Y9ec2FSHqVrhOPajJK8g1fyjHZnN4ZygM4dzuEDuwUJ/+qUX02q+eOWFku4Bs1BDyWsLR/A== X-Received: by 2002:a05:6a21:3718:b0:10e:96b5:45fa with SMTP id yl24-20020a056a21371800b0010e96b545famr805410pzb.43.1686029822967; Mon, 05 Jun 2023 22:37:02 -0700 (PDT) Received: from naota-xeon.wdc.com (fp96936df3.ap.nuro.jp. [150.147.109.243]) by smtp.gmail.com with ESMTPSA id d9-20020a170902cec900b001b06f7f5333sm7521853plg.1.2023.06.05.22.37.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jun 2023 22:37:02 -0700 (PDT) Sender: Naohiro Aota From: Naohiro Aota X-Google-Original-From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 3/4] btrfs: bail out reclaim process if filesystem is read-only Date: Tue, 6 Jun 2023 14:36:35 +0900 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org When a filesystem is read-only, we cannot reclaim a block group as it cannot rewrite the data. Just bail out in that case. Note that it can drop BGs in this case. As we did sb_start_write(), read-only filesystem means we got a fatal error and forced read-only. There is no chance to reclaim them again. Fixes: 18bb8bbf13c1 ("btrfs: zoned: automatically reclaim zones") CC: stable@vger.kernel.org # 5.15+ Signed-off-by: Naohiro Aota Reviewed-by: Filipe Manana Reviewed-by: Johannes Thumshirn --- fs/btrfs/block-group.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index d5bba02167be..db9bee071434 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -1794,8 +1794,15 @@ void btrfs_reclaim_bgs_work(struct work_struct *work) } spin_unlock(&bg->lock); - /* Get out fast, in case we're unmounting the filesystem */ - if (btrfs_fs_closing(fs_info)) { + /* + * Get out fast, in case we're read-only or unmounting the + * filesystem. It is OK to drop block groups from the list even + * for the read-only case. As we did sb_start_write(), "mount -o + * ro" won't happen and read-only FS means it is forced + * read-only due to a fatal error. So, it never get back to + * read-write to let us reclaime again. + */ + if (btrfs_need_cleaner_sleep(fs_info)) { up_write(&space_info->groups_sem); goto next; } From patchwork Tue Jun 6 05:36:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naohiro Aota X-Patchwork-Id: 13268254 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2934FC7EE2E for ; Tue, 6 Jun 2023 05:37:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229783AbjFFFhI (ORCPT ); Tue, 6 Jun 2023 01:37:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233303AbjFFFhG (ORCPT ); Tue, 6 Jun 2023 01:37:06 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2094F1B5 for ; Mon, 5 Jun 2023 22:37:06 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1b18474cbb6so33324525ad.1 for ; Mon, 05 Jun 2023 22:37:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=slowstart.org; s=google; t=1686029825; x=1688621825; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=3pu9II8vmC6Ef9qV99x8bdSbLd/lbSjj9YoeDNcqmv8=; b=fKxk2EqmuqLWIAvIGCNAfEKnYDtbqPDpQ7OZ2c7SvymN878q/p4Bc0rMe7V/3vNOzj JjduZbUVVzTOcRPJEUtS1AXRCLv+5EVw7Wr8hYCm8FXfQ5PlfADwtcFIJ1pPHuEGd4qq uZMnmTciYM8KCQI/1HD/nHsRpQox8/6KxqKTtg/gb7qVWRvhySnLOEB6GjTyWWvrUjfX VofsO43uTcf6yG1BVo64xwSFczpC8K5yv2YEWjPl44gELzUQrCgwawmM1F1h9NYb4VIE 0DfHGQQwYJ0OcQ4X1lEzbE6tr6x/77dftt7NZAWIr/esOvyoVPcyZzEJ1fiIJZL+lU2S Nhbg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=elisp-net.20221208.gappssmtp.com; s=20221208; t=1686029825; x=1688621825; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=3pu9II8vmC6Ef9qV99x8bdSbLd/lbSjj9YoeDNcqmv8=; b=iuExxXQ/mnLbP/od1j33FedtT/QhZiw6siQYkL0qHv5gFJtddzuSWgxwtBVqiTvjtP egpKjQDMWZotZNGrKAnRyKbZ+nlUyosOGnnQ+iS1QgAu+yJSmo5gH2ifVCKMMBpdBcXx /gOug0MR1KgqcqciI3zAmWgBn1JmJyc8+WDHFHS+u3i/lqEWKvUiRWDLEFkdrFvHKqPa RnqDlK0AnpEEjg3dmpgHrDFHWcZCHmJ/GI74pVR+BZBw7454ErCr6mIE9vmb2mwLBz0K KUe62yoFboEvv1o/HqyuPBViW9e4Ld78b1ka594tPthp9OgXD9B7q+bFp0XB7hpWwaU6 8bJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686029825; x=1688621825; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=3pu9II8vmC6Ef9qV99x8bdSbLd/lbSjj9YoeDNcqmv8=; b=LgtiIGZwjTh4M8+NkmM4HWOWMBC5nD4hDvqnIBbAlyEG1Z/alhms88hr7f7xoETUkX Yrfy4A6YXrLVI5yqmzQdhWzZPlzl54kYLeSx9hSgMqgA1s0Py+nJR/XwrbzJBRmLqKzi fGwtGH97xDN4z6IZyiyA95n71+V9qjWOmaTQYuHPW+MRmiASb1+VYMH7kKRCmsbLs3nr m2bat7vsKRjazAnT0bH8eNymQFqWicisw6ysx9KWSeNE4Ugooo7gCJ4/zYyrJcCSmrs+ U2tbMqpxMrIu5JVyAnpvL1I4uo2Fc667l0qC7ngLKdC/VAh4Pp8d+Am32WRwVE/Dn2iM qe0A== X-Gm-Message-State: AC+VfDxiMvMZcL2b8xlFa0XJKBUNB5gu0pp/JVUGUvlzhdxFPZU8Motl OZzCaD38OedywHWub1LKOarBCxAfFQUYJpAV0xrLpDBSr9EhvC7rvtGV8gA3IgI7mQQykfKqD1Y telcHcDd8LPXIo0oByGh7lw6ViUxaKSxgoiI+sl9Rwv09kSuwqp4csJdFEQXUsvGoT2oG6Fg3c8 Qc8sXnz3fAzA4E X-Google-Smtp-Source: ACHHUZ5BF1YIXY1yPdovXQWu19voQyH8DdFq4Ylk/LFOgcLoIGTxo+Pchpi1InmQcgX4vpYSHJ6KjA== X-Received: by 2002:a17:902:8693:b0:1ae:62ed:9630 with SMTP id g19-20020a170902869300b001ae62ed9630mr801811plo.15.1686029824896; Mon, 05 Jun 2023 22:37:04 -0700 (PDT) Received: from naota-xeon.wdc.com (fp96936df3.ap.nuro.jp. [150.147.109.243]) by smtp.gmail.com with ESMTPSA id d9-20020a170902cec900b001b06f7f5333sm7521853plg.1.2023.06.05.22.37.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jun 2023 22:37:04 -0700 (PDT) Sender: Naohiro Aota From: Naohiro Aota X-Google-Original-From: Naohiro Aota To: linux-btrfs@vger.kernel.org Cc: Naohiro Aota Subject: [PATCH 4/4] btrfs: reinsert BGs failed to reclaim Date: Tue, 6 Jun 2023 14:36:36 +0900 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The reclaim process can temporally fail. For example, if the space is getting tight, it fails to make the block group read-only. If there are no further writes on that block group, the block group will never get back to the reclaim list, and the BG never get reclaimed. In a certain workload, we can leave many such block groups never reclaimed. So, let's get it back to the list and give it a chance to be reclaimed. Fixes: 18bb8bbf13c1 ("btrfs: zoned: automatically reclaim zones") CC: stable@vger.kernel.org # 5.15+ Signed-off-by: Naohiro Aota --- fs/btrfs/block-group.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index db9bee071434..36e0d9b5d824 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -1833,7 +1833,18 @@ void btrfs_reclaim_bgs_work(struct work_struct *work) } next: - btrfs_put_block_group(bg); + if (!ret) { + btrfs_put_block_group(bg); + } else { + spin_lock(&bg->lock); + spin_lock(&fs_info->unused_bgs_lock); + if (list_empty(&bg->bg_list)) + list_add_tail(&bg->bg_list, &fs_info->reclaim_bgs); + else + btrfs_put_block_group(bg); + spin_unlock(&fs_info->unused_bgs_lock); + spin_unlock(&bg->lock); + } mutex_unlock(&fs_info->reclaim_bgs_lock); /*