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.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham 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 91596C43603 for ; Mon, 9 Dec 2019 19:46:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6481C206E0 for ; Mon, 9 Dec 2019 19:46:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575920795; bh=GQ+BjxC7/CuBpQyiHRH/lmJqHlt35eEBEropietOcn8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References:List-ID:From; b=I2v9TTSM0PdeRSn68MaqxxqdIk+akXFd1iMX+S/1+/7KVlVNOYza/LXeYBjtjGl2o OLXGrhBHvhheDfApFgBxz7VIjPMXRYglHWm9pwreO2WEOnDlASIXm061ehEqb4j0e5 3hg/LxEHh7lVUDVzXfkh4Gho3L/RikMna4jnkEWY= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726930AbfLITqe (ORCPT ); Mon, 9 Dec 2019 14:46:34 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:34113 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726923AbfLITqc (ORCPT ); Mon, 9 Dec 2019 14:46:32 -0500 Received: by mail-pl1-f193.google.com with SMTP id x17so964213pln.1 for ; Mon, 09 Dec 2019 11:46:32 -0800 (PST) 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:in-reply-to:references; bh=WPnCaWIqSBt/bL2qzdu5zpp7M7qofjjmTjvo3UUStYc=; b=a65+3f7Ffcu9dgcVbjCGx/uYar03DESyPmzH1jMSbMOZAiCSCBhfOUtjuMTzTs76nc 4LM3GKxFYuYYA9ThNKkUMAxldEiaadQ6vtn34FCO1Y1sVB34p94ykAUHQUUo60HFSDRt tix3DgxS/lerH2VZhg6IvC14aEEubt7GAnOb+59weMx3MsveEqb0MymY1svMnqMYpkFS ZsWK80Y6X2WiK311gLSzSRuEMsPhZp6bYdC9Wm/aZybMLzV8eO9atNsdQpnjsIehk9u8 gxFNhgezQ8Pva4VAMOj1q38KuUIWzzDS85wzMDRjmtvd1oFOllk24tyYxBdswD2JKbtp JNbg== X-Gm-Message-State: APjAAAVv0IHgLW1xkXF3TwCPzjrCa0linKE+iBu9pcGKsddWGXj+MECc kBRAnXv5PXkMVboMnuUKaFM= X-Google-Smtp-Source: APXvYqxD3nr7YMBF9iNcILLwZJmVens1sqLBfGT9UW+ILZDnr6hmT9ix6KMU0KgQz1lfl0VpxQeOaQ== X-Received: by 2002:a17:902:a9c7:: with SMTP id b7mr10074105plr.23.1575920791921; Mon, 09 Dec 2019 11:46:31 -0800 (PST) Received: from dennisz-mbp.thefacebook.com ([199.201.64.138]) by smtp.gmail.com with ESMTPSA id b190sm282956pfg.66.2019.12.09.11.46.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 09 Dec 2019 11:46:31 -0800 (PST) From: Dennis Zhou To: David Sterba , Chris Mason , Josef Bacik , Omar Sandoval Cc: kernel-team@fb.com, linux-btrfs@vger.kernel.org, Dennis Zhou Subject: [PATCH 20/22] btrfs: add async discard header Date: Mon, 9 Dec 2019 11:46:05 -0800 Message-Id: <4010415d184b5a5e47ec5ab4fc215d3ef9532488.1575919746.git.dennis@kernel.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Give a brief overview for how async discard is implemented. Signed-off-by: Dennis Zhou Reviewed-by: Josef Bacik --- fs/btrfs/discard.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/fs/btrfs/discard.c b/fs/btrfs/discard.c index fe73814526ef..fe5719797eee 100644 --- a/fs/btrfs/discard.c +++ b/fs/btrfs/discard.c @@ -1,4 +1,39 @@ // SPDX-License-Identifier: GPL-2.0 +/* + * This contains the logic to handle async discard. + * + * Async discard manages trimming of free space outside of transaction commit. + * Discarding is done by managing the block_groups on a LRU list based on free + * space recency. Two passes are used to first prioritize discarding extents + * and then allow for trimming in the bitmap the best opportunity to coalesce. + * The block_groups are maintained on multiple lists to allow for multiple + * passes with different discard filter requirements. A delayed work item is + * used to manage discarding with timeout determined by a max of the delay + * incurred by the iops rate limit, byte rate limit, and the timeout of max + * delay of BTRFS_DISCARD_MAX_DELAY. + * + * The first list is special to manage discarding of fully free block groups. + * This is necessary because we issue a final trim for a full free block group + * after forgetting it. When a block group becomes unused, instead of directly + * being added to the unused_bgs list, we add it to this first list. Then + * from there, if it becomes fully discarded, we place it onto the unused_bgs + * list. + * + * The in-memory free space cache serves as the backing state for discard. + * Consequently this means there is no persistence. We opt to load all the + * block groups in as not discarded, so the mount case degenerates to the + * crashing case. + * + * As the free space cache uses bitmaps, there exists a tradeoff between + * ease/efficiency for find_free_extent() and the accuracy of discard state. + * Here we opt to let untrimmed regions merge with everything while only letting + * trimmed regions merge with other trimmed regions. This can cause + * overtrimming, but the coalescing benefit seems to be worth it. Additionally, + * bitmap state is tracked as a whole. If we're able to fully trim a bitmap, + * the trimmed flag is set on the bitmap. Otherwise, if an allocation comes in, + * this resets the state and we will retry trimming the whole bitmap. This is a + * tradeoff between discard state accuracy and the cost of accounting. + */ #include #include -- 2.17.1