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,URIBL_BLOCKED,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 3E677CA9EB9 for ; Wed, 23 Oct 2019 22:53:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 10CF820663 for ; Wed, 23 Oct 2019 22:53:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1571871223; bh=FdH+xCBBuP+V9qHFj5VDM2KkAytFDtMjpsaAgWvlDA8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References:List-ID:From; b=KwF04sa/rGV1l2vW6K2P3Zj1kxXJG/nDuop2vfyLj+MZuWJ0GGOMrxGGEFq+UtnMh tD9rBnH/EzagglKBAcc7HpPFymWyVP91+LRlj5c6waTWLaK0Qo3wh6gIc9+yFAI9EC VlJhQfEmOYHjBt5LRHsLl1FFe54RPIwlCuQcPCWc= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436944AbfJWWxl (ORCPT ); Wed, 23 Oct 2019 18:53:41 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:33596 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436935AbfJWWxj (ORCPT ); Wed, 23 Oct 2019 18:53:39 -0400 Received: by mail-qk1-f195.google.com with SMTP id 71so17639801qkl.0 for ; Wed, 23 Oct 2019 15:53:37 -0700 (PDT) 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=PYOKZ/1QajvnP3fueqt/XcahZsRMffUtiJV5/Gx2ziM=; b=mZ05iX3zYsc4XggjNeA9pvriaZt7fZe7UXV1fwyBKGce7qmhAOsrKI2TcpsmRnH5LV 1wQZt7O1r3KRjQgBup6GBpw3XAFZlTjXxFiGuve9s5hD5oQXP3TrYvMUTzD0CtuCElZ6 8hR8aCbA2t5fs7Dn1IhZPcFE8eG07hz9ebVVNaBaVngMUseaPG79cRsS7bX1J1zEd2yi 4W1Om1yxUN5VhwrS+uDuA/Ya0ulSSwwsbV+RrA8chTjvJ0SeKTi9/lAceEsEG1Khhzai SQVM604NNmILp+IxJuYf6WDhatIpW852bhYdsV6F9OJeWlFR1pHe1Z3FzYL0mEifuJsB F6pg== X-Gm-Message-State: APjAAAUoGc1419glSH5Ff21YLCPV1N8vAuW6a0agZZmIrFB8f+AuXArO M+Zq8dKrdNtgMjQF9urpVN8= X-Google-Smtp-Source: APXvYqzsGVi6PBnL4Y8oZsVIiibB8fXUZlp1Aim99CGXp95OBRXBNtRWwENkQcfrZlU3uniFOhlInw== X-Received: by 2002:a37:4793:: with SMTP id u141mr7480720qka.402.1571871216692; Wed, 23 Oct 2019 15:53:36 -0700 (PDT) Received: from dennisz-mbp.thefacebook.com ([163.114.130.128]) by smtp.gmail.com with ESMTPSA id j4sm11767542qkf.116.2019.10.23.15.53.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Oct 2019 15:53:35 -0700 (PDT) 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 15/22] btrfs: limit max discard size for async discard Date: Wed, 23 Oct 2019 18:53:09 -0400 Message-Id: <633cde192d549559b675e1182bcf61c4f2dc58ca.1571865774.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 Throttle the maximum size of a discard so that we can provide an upper bound for the rate of async discard. While the block layer is able to split discards into the appropriate sized discards, we want to be able to account more accurately the rate at which we are consuming ncq slots as well as limit the upper bound of work for a discard. Signed-off-by: Dennis Zhou Reviewed-by: Josef Bacik --- fs/btrfs/discard.h | 5 ++++ fs/btrfs/free-space-cache.c | 48 +++++++++++++++++++++++++++---------- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/fs/btrfs/discard.h b/fs/btrfs/discard.h index 2d933b44abd9..c1e745196b6c 100644 --- a/fs/btrfs/discard.h +++ b/fs/btrfs/discard.h @@ -5,10 +5,15 @@ #ifndef BTRFS_DISCARD_H #define BTRFS_DISCARD_H +#include + struct btrfs_fs_info; struct btrfs_discard_ctl; struct btrfs_block_group_cache; +/* Discard size limits. */ +#define BTRFS_ASYNC_DISCARD_MAX_SIZE (SZ_64M) + /* List operations. */ void btrfs_add_to_discard_list(struct btrfs_discard_ctl *discard_ctl, struct btrfs_block_group_cache *cache); diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index 8d4ffd50aee6..186a4243fb7f 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -3440,19 +3440,40 @@ static int trim_no_bitmap(struct btrfs_block_group_cache *block_group, if (entry->offset >= end) goto out_unlock; - extent_start = entry->offset; - extent_bytes = entry->bytes; - extent_trim_state = entry->trim_state; - start = max(start, extent_start); - bytes = min(extent_start + extent_bytes, end) - start; - if (bytes < minlen) { - spin_unlock(&ctl->tree_lock); - mutex_unlock(&ctl->cache_writeout_mutex); - goto next; - } + if (async) { + start = extent_start = entry->offset; + bytes = extent_bytes = entry->bytes; + extent_trim_state = entry->trim_state; + if (bytes < minlen) { + spin_unlock(&ctl->tree_lock); + mutex_unlock(&ctl->cache_writeout_mutex); + goto next; + } + unlink_free_space(ctl, entry); + if (bytes > BTRFS_ASYNC_DISCARD_MAX_SIZE) { + bytes = extent_bytes = + BTRFS_ASYNC_DISCARD_MAX_SIZE; + entry->offset += BTRFS_ASYNC_DISCARD_MAX_SIZE; + entry->bytes -= BTRFS_ASYNC_DISCARD_MAX_SIZE; + link_free_space(ctl, entry); + } else { + kmem_cache_free(btrfs_free_space_cachep, entry); + } + } else { + extent_start = entry->offset; + extent_bytes = entry->bytes; + extent_trim_state = entry->trim_state; + start = max(start, extent_start); + bytes = min(extent_start + extent_bytes, end) - start; + if (bytes < minlen) { + spin_unlock(&ctl->tree_lock); + mutex_unlock(&ctl->cache_writeout_mutex); + goto next; + } - unlink_free_space(ctl, entry); - kmem_cache_free(btrfs_free_space_cachep, entry); + unlink_free_space(ctl, entry); + kmem_cache_free(btrfs_free_space_cachep, entry); + } spin_unlock(&ctl->tree_lock); trim_entry.start = extent_start; @@ -3617,6 +3638,9 @@ static int trim_bitmaps(struct btrfs_block_group_cache *block_group, goto next; } + if (async && bytes > BTRFS_ASYNC_DISCARD_MAX_SIZE) + bytes = BTRFS_ASYNC_DISCARD_MAX_SIZE; + bitmap_clear_bits(ctl, entry, start, bytes); if (entry->bytes == 0) free_bitmap(ctl, entry); -- 2.17.1