From patchwork Wed Apr 17 14:35:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13633461 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC6A853801 for ; Wed, 17 Apr 2024 14:36:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364570; cv=none; b=pT/LfcsrUglkWZVWpXWkgepEYRTuSDGvrO37AH1x6vCc8mugTaqm5NQwpE3iHPjupJ9G2nSu5uW/UPujRmua2ectepBSYg31pWHf9NjGeKlTilI9bO5LS0M00J1rMyMfg/c+etSdu9sqUk+77M2sJZEATJ3wdSxXc/f2/lH2JDs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364570; c=relaxed/simple; bh=KuDGSK6cEDUEFM8xPYyaEziu9aBv5wsFA+cFbTRKVmc=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FXE7nzRjC9ppTy1C37C8fI3t37l6jF3TwidZaHSSu/tC15kC1MKTXVsVSerSxTBxC7kOkNfQHwvFDt2sAu0lhd9qzbxCzea03inuCzpBesqpmOY8Hc3WurIS2iS6laLADMM6ElkgMsJ/00Ec+CEevxfPXc2cr7CFOaWFUtGLQCE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=Q8+dpn5k; arc=none smtp.client-ip=209.85.222.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="Q8+dpn5k" Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-78f05e56cb3so18651185a.1 for ; Wed, 17 Apr 2024 07:36:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713364567; x=1713969367; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=F3LNDYaPKTgHmjH2Yl1+sKVlSw3InI9Wgw4nB5RHABI=; b=Q8+dpn5kmL7qUIIc7X0rBtfFIsarbI+OLX6nyzjGR6fQTkgMO3olKBdjIb/wzZU8Ws XpeOStnzyoOjE4YIIHXf7gMYdgrX6lzidd2Y5VvQESl3Sd6JVyVz2kI1ophRa+gPfpVA MZ4cSQOzTFQrPDgyDcw31o3F2geBBTkwB02+J2n6fy4Hg5oaRTHDkKMAB0s+37bAfxD/ 1iu8Fav6isnLB00OHL2svizL54J8dZxifQhmKNdU2w4bxLH7E35TjsByLPq1f4ypMnMd EONuDwSE1HYzJBhk7mTrHM47wEYuXvJeaLad4JwT3KyaGvHf22U1/H1zDGGTGsh6WyFa WOCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713364567; x=1713969367; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=F3LNDYaPKTgHmjH2Yl1+sKVlSw3InI9Wgw4nB5RHABI=; b=f5dXmaOZBB9ABRsIZ0ilsoEyCc4lXse957qeZ7yXyCroGOmn1V+9NyCpW+3JLUs1Pp mJVkazlHYeZZEbAvtnqVHurnz6FKSrKtqGimlKg+2tIqMw9jtlXKCNbMTZk6yuaRtP6r FyV6KDGgaZoGcidb1F6hK1O1evIp5i/9gBH3+/Q70sguAh02HtAtD1kq4/6lo91JYKqL 9Zri0YtSVUB7NjnpfgUqCE+v4RiML0nNGVMfyXlRw2CWd2/B1S7AHdnNNmoCFoX4W7Yh RpIasI4i5JgODnKGSdd8UBN/pfxNlYC/dv/0oySsCIMS7KUugHb0Fzx8s1qFOrV66aoV OrgA== X-Gm-Message-State: AOJu0Yzi4pC9cB1YxodXh37HVxI0XM/Ec5hglHwa0VhXpnYimJTw94pc J2cLJgFJUQJm9VNh1qMG1OAUwVE5xoSIkwsRGM7p5gS/LJIAjBvQn+ifIZtpBLNN1h5KfnH1Yic P X-Google-Smtp-Source: AGHT+IHPoxXo+qvihcu2A0PpfD7rNxDeZkZJQ2LryaolrX6T+qeb63gkedEw6LC2IOVydmWMR1ncgg== X-Received: by 2002:a0c:f512:0:b0:699:162a:b8e8 with SMTP id j18-20020a0cf512000000b00699162ab8e8mr18699743qvm.61.1713364567528; Wed, 17 Apr 2024 07:36:07 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id pm11-20020ad446cb000000b0069b432df140sm8384183qvb.121.2024.04.17.07.36.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 07:36:07 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 01/17] btrfs: handle errors in btrfs_reloc_clone_csums properly Date: Wed, 17 Apr 2024 10:35:45 -0400 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In the cow path we will clone the reloc csums for relocated data extents, and if there's an error we already have an ordered extent and rely on the ordered extent finishing to clean everything up. There's a problem however, we don't mark the ordered extent with an error, we pretend like everything was just fine. If we were at the end of our range we won't actually bubble up this error anywhere, and we could end up inserting an extent that doesn't have csums where it should have them. Fix this by adding a helper to mark the ordered extent with an error, and then use this when we fail to lookup the csums in btrfs_reloc_clone_csums. Use this helper in the other place where we use the same pattern while we're here. This will prevent us from erroneously inserting the extent that doesn't have the required checksums. Signed-off-by: Josef Bacik Reviewed-by: Johannes Thumshirn --- fs/btrfs/inode.c | 5 ++--- fs/btrfs/ordered-data.c | 6 ++++++ fs/btrfs/ordered-data.h | 1 + fs/btrfs/relocation.c | 4 +++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 1dde8085271e..94d9a74a912c 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -3183,9 +3183,8 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent) * set the mapping error, so we need to set it if we're the ones * marking this ordered extent as failed. */ - if (ret && !test_and_set_bit(BTRFS_ORDERED_IOERR, - &ordered_extent->flags)) - mapping_set_error(ordered_extent->inode->i_mapping, -EIO); + if (ret) + btrfs_mark_ordered_extent_error(ordered_extent); if (truncated) unwritten_start += logical_len; diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c index 03b2f646b2f9..1fe64625d006 100644 --- a/fs/btrfs/ordered-data.c +++ b/fs/btrfs/ordered-data.c @@ -294,6 +294,12 @@ void btrfs_add_ordered_sum(struct btrfs_ordered_extent *entry, spin_unlock_irq(&inode->ordered_tree_lock); } +void btrfs_mark_ordered_extent_error(struct btrfs_ordered_extent *ordered) +{ + if (!test_and_set_bit(BTRFS_ORDERED_IOERR, &ordered->flags)) + mapping_set_error(ordered->inode->i_mapping, -EIO); +} + static void finish_ordered_fn(struct btrfs_work *work) { struct btrfs_ordered_extent *ordered_extent; diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h index 34413fc5b4bd..b6f6c6b91732 100644 --- a/fs/btrfs/ordered-data.h +++ b/fs/btrfs/ordered-data.h @@ -203,6 +203,7 @@ bool btrfs_try_lock_ordered_range(struct btrfs_inode *inode, u64 start, u64 end, struct extent_state **cached_state); struct btrfs_ordered_extent *btrfs_split_ordered_extent( struct btrfs_ordered_extent *ordered, u64 len); +void btrfs_mark_ordered_extent_error(struct btrfs_ordered_extent *ordered); int __init ordered_data_init(void); void __cold ordered_data_exit(void); diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 7e7799b4560b..0ef84dd5762e 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -4411,8 +4411,10 @@ int btrfs_reloc_clone_csums(struct btrfs_ordered_extent *ordered) ret = btrfs_lookup_csums_list(csum_root, disk_bytenr, disk_bytenr + ordered->num_bytes - 1, &list, false); - if (ret < 0) + if (ret < 0) { + btrfs_mark_ordered_extent_error(ordered); return ret; + } while (!list_empty(&list)) { struct btrfs_ordered_sum *sums = From patchwork Wed Apr 17 14:35:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13633462 Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 136DA141995 for ; Wed, 17 Apr 2024 14:36:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364572; cv=none; b=jAh8UsaBOCtUGqbWvaxyC/PoPLx3K1ojFBqXsYC6/n+9FxSULD85o/5aPr+VipnHPO8+QmZTSN5TJjWRZ3hfhNR2uWitpifwQnENstcafr/ch1uZn5xGQ6hWb5bHrXZ4NyQ+8lQZEwwStTDzAtxo/6pxkW9kvXhAWa3F9aEr/Ek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364572; c=relaxed/simple; bh=aNcZdPxo8u/pCayIkB5q7CYhN4+vt6ALpPLNXTIm0v0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nW7NUuHMenvLdV9TIRFP9CeWmZkIkd9JgaUdrNbLw1gDYtSSpcVIwVfh6ZiJv9CG1hPJl42qNSzFj3L3773AHFaJcisrfOe79LFKgc2aZrSdAD2fEYHoWeqSrv0Dy9Pjkkto5YjPUf7SWRbnSUWYmNeMgYDJ6xn/HSqAI6oUHl0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=RHASYPZU; arc=none smtp.client-ip=209.85.219.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="RHASYPZU" Received: by mail-qv1-f43.google.com with SMTP id 6a1803df08f44-69b7d2de292so10981026d6.2 for ; Wed, 17 Apr 2024 07:36:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713364569; x=1713969369; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Ok6H1BKlMw4Nai5Jk/eY9RxUhrfqn1qPYvewp5xF6EM=; b=RHASYPZU7dtjT5r8++l01yhmdf8AKNgno9sy+JCnjs4k+aoaHwoWXA4XuJwec8rKEK NRc9t9wkQMqZ629IvRyhxu+KMa3YRZ1bj4l2J8aL8sk+KTS42Qe/6afvkTqganYgfABV r/WP62NlULbc3mzKIlA/25+a2TbKWDhglSMnFkELINPkBAY947eTeuZwHh0BWAWR8nWM B3ZKa1c0kWAfi70kRGbNyB8I/oqQNBO36PJK/8YsvpvhUPes67U/Lrjllo0yHz8sgLIJ mcxfdf7GICLq9bQ+FHLzOZFiTwngokD77ts4R6QKQ9A12+jN83EPHplyJIcMJtjBaj08 +FOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713364569; x=1713969369; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ok6H1BKlMw4Nai5Jk/eY9RxUhrfqn1qPYvewp5xF6EM=; b=HHtKQgKPNWSejmFBwEX20cAs9jU/V67LPdNJw5VqQnhaSW/u6KppF226DqDY4Sp1Gi VHC6/6LsG5BzNdA6OJbLjtmAd8AyZOOtRTg3jC24eIudXKU0l/j4NtEWUI99frwEa7RA Kz/rIeYAKX5CP9dfY6WvhTTv+BTyBF7oaPzMJESa65ntsID/PYTQs8kQ0RYOMmwFCVB4 KavYFoM5d2lvXsnoLZHLU4qRCfG+kygqmFXnwWTskiZdykLI9yqblrwfelUFR5b8w6db yQc9G8icnBSZ0PZl5CsR632Rf6db4a5Ea8g2nC/ltOHSrOw5GX/6d3h+iI194D2xuzqu hu4Q== X-Gm-Message-State: AOJu0Yxay/scsRmsgAbq6MOeDdDoduROEXtq9ciDWBtjnSnlNfHt5biC b75Xmro1LxhRdAwsXNpN1yglBxr+Wcqrlu/HH/Fi3LnJeUUmvZA4HxAiraN/acfrGqnWsz0T37O s X-Google-Smtp-Source: AGHT+IGXiSQuSRcVRFoYL88BoM4Wy5FxebE74/yoaqZwZDMeT85WBrjKAHb4B+bJ5bYBiKBp6CUUTg== X-Received: by 2002:a05:6214:c67:b0:69b:da6:b9d3 with SMTP id t7-20020a0562140c6700b0069b0da6b9d3mr18363319qvj.65.1713364568610; Wed, 17 Apr 2024 07:36:08 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id jh17-20020a0562141fd100b006990b44228dsm8374699qvb.125.2024.04.17.07.36.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 07:36:08 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 02/17] btrfs: push all inline logic into cow_file_range Date: Wed, 17 Apr 2024 10:35:46 -0400 Message-ID: <2796fb5d2b04c3ff87c2ab5b285fd7e072a8e4a2.1713363472.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently we have a lot of duplicated checks of if (start == 0 && fs_info->sectorsize == PAGE_SIZE) cow_file_range_inline(); Instead of duplicating this check everywhere, consolidate all of the inline extent logic into a helper which documents all of the checks and then use that helper inside of cow_file_range_inline(). With this we can clean up all of the calls to either unconditionally call cow_file_range_inline(), or at least reduce the checks we're doing before we call cow_file_range_inline(); Signed-off-by: Josef Bacik Reviewed-by: Goldwyn Rodrigues --- fs/btrfs/inode.c | 143 +++++++++++++++++++++++++++-------------------- 1 file changed, 81 insertions(+), 62 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 94d9a74a912c..925a53d886b4 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -614,14 +614,56 @@ static int insert_inline_extent(struct btrfs_trans_handle *trans, return ret; } +static bool can_cow_file_range_inline(struct btrfs_inode *inode, + u64 offset, u64 size, + size_t compressed_size) +{ + struct btrfs_fs_info *fs_info = inode->root->fs_info; + u64 data_len = (compressed_size ?: size); + + /* Inline extents must start at offset 0. */ + if (offset != 0) + return false; + + /* + * Due to the page size limit, for subpage we can only trigger the + * writeback for the dirty sectors of page, that means data writeback + * is doing more writeback than what we want. + * + * This is especially unexpected for some call sites like fallocate, + * where we only increase i_size after everything is done. + * This means we can trigger inline extent even if we didn't want to. + * So here we skip inline extent creation completely. + */ + if (fs_info->sectorsize != PAGE_SIZE) + return false; + + /* Inline extents are limited to sectorsize. */ + if (size > fs_info->sectorsize) + return false; + + /* We cannot exceed the maximum inline data size. */ + if (data_len > BTRFS_MAX_INLINE_DATA_SIZE(fs_info)) + return false; + + /* We cannot exceed the user specified max_inline size. */ + if (data_len > fs_info->max_inline) + return false; + + /* Inline extents must be the entirety of the file. */ + if (size < i_size_read(&inode->vfs_inode)) + return false; + + return true; +} /* * conditionally insert an inline extent into the file. This * does the checks required to make sure the data is small enough * to fit as an inline extent. */ -static noinline int cow_file_range_inline(struct btrfs_inode *inode, u64 size, - size_t compressed_size, +static noinline int cow_file_range_inline(struct btrfs_inode *inode, u64 offset, + u64 size, size_t compressed_size, int compress_type, struct folio *compressed_folio, bool update_i_size) @@ -634,16 +676,7 @@ static noinline int cow_file_range_inline(struct btrfs_inode *inode, u64 size, int ret; struct btrfs_path *path; - /* - * We can create an inline extent if it ends at or beyond the current - * i_size, is no larger than a sector (decompressed), and the (possibly - * compressed) data fits in a leaf and the configured maximum inline - * size. - */ - if (size < i_size_read(&inode->vfs_inode) || - size > fs_info->sectorsize || - data_len > BTRFS_MAX_INLINE_DATA_SIZE(fs_info) || - data_len > fs_info->max_inline) + if (!can_cow_file_range_inline(inode, offset, size, compressed_size)) return 1; path = btrfs_alloc_path(); @@ -971,43 +1004,38 @@ static void compress_file_range(struct btrfs_work *work) * Check cow_file_range() for why we don't even try to create inline * extent for the subpage case. */ - if (start == 0 && fs_info->sectorsize == PAGE_SIZE) { - if (total_in < actual_end) { - ret = cow_file_range_inline(inode, actual_end, 0, - BTRFS_COMPRESS_NONE, NULL, - false); - } else { - ret = cow_file_range_inline(inode, actual_end, - total_compressed, - compress_type, folios[0], - false); - } - if (ret <= 0) { - unsigned long clear_flags = EXTENT_DELALLOC | - EXTENT_DELALLOC_NEW | EXTENT_DEFRAG | - EXTENT_DO_ACCOUNTING; + if (total_in < actual_end) + ret = cow_file_range_inline(inode, start, actual_end, 0, + BTRFS_COMPRESS_NONE, NULL, false); + else + ret = cow_file_range_inline(inode, start, actual_end, + total_compressed, compress_type, + folios[0], false); + if (ret <= 0) { + unsigned long clear_flags = EXTENT_DELALLOC | + EXTENT_DELALLOC_NEW | EXTENT_DEFRAG | + EXTENT_DO_ACCOUNTING; - if (ret < 0) - mapping_set_error(mapping, -EIO); + if (ret < 0) + mapping_set_error(mapping, -EIO); - /* - * inline extent creation worked or returned error, - * we don't need to create any more async work items. - * Unlock and free up our temp pages. - * - * We use DO_ACCOUNTING here because we need the - * delalloc_release_metadata to be done _after_ we drop - * our outstanding extent for clearing delalloc for this - * range. - */ - extent_clear_unlock_delalloc(inode, start, end, - NULL, - clear_flags, - PAGE_UNLOCK | - PAGE_START_WRITEBACK | - PAGE_END_WRITEBACK); - goto free_pages; - } + /* + * inline extent creation worked or returned error, + * we don't need to create any more async work items. + * Unlock and free up our temp pages. + * + * We use DO_ACCOUNTING here because we need the + * delalloc_release_metadata to be done _after_ we drop + * our outstanding extent for clearing delalloc for this + * range. + */ + extent_clear_unlock_delalloc(inode, start, end, + NULL, + clear_flags, + PAGE_UNLOCK | + PAGE_START_WRITEBACK | + PAGE_END_WRITEBACK); + goto free_pages; } /* @@ -1315,22 +1343,12 @@ static noinline int cow_file_range(struct btrfs_inode *inode, inode_should_defrag(inode, start, end, num_bytes, SZ_64K); - /* - * Due to the page size limit, for subpage we can only trigger the - * writeback for the dirty sectors of page, that means data writeback - * is doing more writeback than what we want. - * - * This is especially unexpected for some call sites like fallocate, - * where we only increase i_size after everything is done. - * This means we can trigger inline extent even if we didn't want to. - * So here we skip inline extent creation completely. - */ - if (start == 0 && fs_info->sectorsize == PAGE_SIZE && !no_inline) { + if (!no_inline) { u64 actual_end = min_t(u64, i_size_read(&inode->vfs_inode), end + 1); /* lets try to make an inline extent */ - ret = cow_file_range_inline(inode, actual_end, 0, + ret = cow_file_range_inline(inode, start, actual_end, 0, BTRFS_COMPRESS_NONE, NULL, false); if (ret == 0) { /* @@ -10229,10 +10247,11 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from, goto out_qgroup_free_data; /* Try an inline extent first. */ - if (start == 0 && encoded->unencoded_len == encoded->len && + if (encoded->unencoded_len == encoded->len && encoded->unencoded_offset == 0) { - ret = cow_file_range_inline(inode, encoded->len, orig_count, - compression, folios[0], true); + ret = cow_file_range_inline(inode, start, encoded->len, + orig_count, compression, folios[0], + true); if (ret <= 0) { if (ret == 0) ret = orig_count; From patchwork Wed Apr 17 14:35:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13633463 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BB321420B3 for ; Wed, 17 Apr 2024 14:36:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364572; cv=none; b=IH4tXZSDMtruo3E5Dq1KLvtTmxApBrMUtfQG7tYLdDVt/3UnXafew4Q9DGwXJK4pH7PmUw6XuFk01PQs0qHVVGzZUn55FnBpgduSamXzgrO1dlQlkbd5PH13cvu5YNQu/fk6UQN/PosX9vMFcbm2b5NG9DL4etGDx1yQE5WJGWw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364572; c=relaxed/simple; bh=kADrSuK3KOAe9vqySv7uetLB0WjLYDzfPLO8t5XnLaM=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YZFminV3N5m24UCXQoUJGdBlGq+c6upyoYfoXOW/nhEpa2nooIRvzg5EX2aOVaan4x9L6naFGSa/LMnb7kxZGqxLwN9lC+8EWmxmbza2J0lHUje3iWT9jyxXJdg485M+xeH4EWw1j4BDF4mpa/iKrjByq3QNOaswgE8oSSqyqPs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=ARWrT6/0; arc=none smtp.client-ip=209.85.222.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="ARWrT6/0" Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-78f0440656eso27935085a.1 for ; Wed, 17 Apr 2024 07:36:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713364570; x=1713969370; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=H5aaVz3YWLTiKomu2ZivMqMrNbeCk1IfwFqtaiGmw4Y=; b=ARWrT6/0El2Kal0NEWXgPz/thSc9W9pJy2WX1ONNRdm8o1d2G+JJP0k+pJdZYNKmwn 7XaEx1yeBhjFPSAnqoImpbquZEjdMwtKhFhW90dqd3uV5SEEseVC749TDhdqVCtINmf3 YH2fP8Ocmr0KuVbYAQYJi91CJwAH+U4PSqrXnUociL2HzHjEczVemAR09kl0mxGl3tHa AnF90xU6vAhKOjKHdD5EL86TWi+49VfHV/FOx9tvC5V17MYLbeX4jIRujlughFQ5M8tg W1RLVJqN252Gc1kdPwZPPZED49q2Qk6+YzGJaKvoHTLH5vlVca4Mr8YLfKdzNWfHi4RC D9Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713364570; x=1713969370; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H5aaVz3YWLTiKomu2ZivMqMrNbeCk1IfwFqtaiGmw4Y=; b=Gqo557NwMXpEpGOL+sw1KIXgL9xYyn6FAPgM+RGjI5UCJI9XApBYoXBzkYNVWQVGuj Z+5gzBbNbpXahjU1A3QRGIKBGHyXyZuQlfZhuQRi5gO2Q8/RYy0DcRDWtM0dTGhdq4ax TsJAsL5gPSAas3np7SrPRpjdeUKl/OvINk4WGNKhlXBUYrl8LW2ze4fCinpEi+5Pm5r8 K+nkUiTnXgkMiJch3ldlAVf/5vfz8kC5zWZyBtdhQfXOPfw1B3s+OFgi2uXwX2WHH6IT NoxOsiVBuaXhlalSm60dKNqOqNnYUwtE2HFkGeCg5dlfnWUJ7oMEi7rtr+eNGT4pghEU vszA== X-Gm-Message-State: AOJu0YxpaT5qMbsvh291XShIwv35/VAD9loU+2QtGSoLgqtC0HOoltzq WJ1/3KL/AFPb2TQUDAWUiaFJ/+4mQnj9vka7BBYutnveN296NlJ3yhFg/CGxOGM/DVHS0QNTWUC b X-Google-Smtp-Source: AGHT+IE8LAwvjNXgV8kbXutxSs3dJaa6CoG9MEvxo97/IxnbV4fB3ag4YgaeRdLThPFbUPqJXk60BQ== X-Received: by 2002:ad4:5502:0:b0:6a0:40f0:7968 with SMTP id pz2-20020ad45502000000b006a040f07968mr3301010qvb.46.1713364570194; Wed, 17 Apr 2024 07:36:10 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id fe1-20020a0562140b8100b0069b497fccaesm8291798qvb.124.2024.04.17.07.36.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 07:36:09 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 03/17] btrfs: unlock all the pages with successful inline extent creation Date: Wed, 17 Apr 2024 10:35:47 -0400 Message-ID: <7e58618dfcb81c8035c30b814b881fd957f134ae.1713363472.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since 4750af3bbe5d ("btrfs: prevent extent_clear_unlock_delalloc() to unlock page not locked by __process_pages_contig()") we have been unlocking the locked page manually instead of via extent_clear_unlock_delalloc() because of subpage blocksize support. However we actually disable inline extent creation for subpage blocksize support, so this behavior isn't necessary. Remove this code and comment, if at some point the subpage blocksize code grows support for inline extents this can be re-evaluated. Signed-off-by: Josef Bacik Reviewed-by: Johannes Thumshirn --- fs/btrfs/inode.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 925a53d886b4..19579439f7f6 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1358,24 +1358,11 @@ static noinline int cow_file_range(struct btrfs_inode *inode, * range. */ extent_clear_unlock_delalloc(inode, start, end, - locked_page, + NULL, EXTENT_LOCKED | EXTENT_DELALLOC | EXTENT_DELALLOC_NEW | EXTENT_DEFRAG | EXTENT_DO_ACCOUNTING, PAGE_UNLOCK | PAGE_START_WRITEBACK | PAGE_END_WRITEBACK); - /* - * locked_page is locked by the caller of - * writepage_delalloc(), not locked by - * __process_pages_contig(). - * - * We can't let __process_pages_contig() to unlock it, - * as it doesn't have any subpage::writers recorded. - * - * Here we manually unlock the page, since the caller - * can't determine if it's an inline extent or a - * compressed extent. - */ - unlock_page(locked_page); ret = 1; goto done; } else if (ret < 0) { From patchwork Wed Apr 17 14:35:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13633464 Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7AF0013A265 for ; Wed, 17 Apr 2024 14:36:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364574; cv=none; b=p/tP+DjIY6rp7UKv3ZAoeVyfOqdyhB1dA0rwRoaom1RKfgTGH848TUCietyYLRTCYWCISS6zSRP7hcfBacnpmTraA8CizolXHpJBtNLrNBemH3sfIV8DIkA/fARdV9oTT7QPu0568UT+xNwXaqEjS03gC4VPpLDm5zUUMcymQtw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364574; c=relaxed/simple; bh=I1xVg9V0xkJ521mQAQsZ3RUBKq0wbHpWGCZpKnkczcg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LXp7Yok4i2jdTnJQSD9TN9LziR1D8yFA455GV4Db5JOY8rcKoeNN1fP/2dR0AvcuuUUFtofvVhslNtoSyv7vaYrexc9jeqP1obQXZyKuc68PnB1XbIxSL7T2IUr2Ky+5GY4s7VlnplIDVkXwtG7SHnDCNFwcubJ+C65u2AKQzsQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=VjBScrWD; arc=none smtp.client-ip=209.85.167.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="VjBScrWD" Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-3c6f785208dso1155056b6e.1 for ; Wed, 17 Apr 2024 07:36:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713364571; x=1713969371; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=bA84v0pPcuZ2Frux1fDIjQ1ZzIwYtepSYbiQ4b6xNkQ=; b=VjBScrWDo+erTf7t37BzXY4sQXz+NW5FEHsOWeVP/Hc7/vGOu0l/PnLJPaVh1VfQzV +4qjtGwkVZRHe4HqylZrBh8BZYZUEFMERt7pE9K4HRi9TjwuEfZeB0FrNquWve0XC+sG ySj33f8l6/FGU9Es4f8tlP6cX9AvRxMS/9fPGRqOd9owL8B2LeWmkUWUq4jL9Wm8uhcf oIMsc/OWf2zkw5VViug85BCYKN+5P5nS0LKmzYMkWMJgTxAf9p0APiNKLeCms15yBipG RhKeBOxmTQttezb6QrZ/iip80To5TDrPXntxF7o0UR/g4FKgpCrkdATf29t9BAiqFeJC HalA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713364571; x=1713969371; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bA84v0pPcuZ2Frux1fDIjQ1ZzIwYtepSYbiQ4b6xNkQ=; b=YX330J5qezMNh7THuDwvU0M/4tIGZllOGGw/piNjuGG3IIRJUl72YN/bRS1E4UL7WZ ji+Tqf/sOwQyorjLYZ3EbypoN2C7d9DeHyPnzQSDMpDzqQAAhhxv4TA3VJRBFZUmb1xe 9vq2J0V4VhzDUnNLeUrOdUr5p+uYpoVyIF9CPyaI1nxFzkQk//kemddCUGUpzDrBcuPL 8Dpu4J5x6BRzYLqipwq5PuWxzrbpj7cfTQB7pyy9AHd3FonX5zJ44RjSjYHHuhWMrpa5 yZYFuqVWXK0d2tIllVYvLNx+9ryxSROFfI2BEvjnl0ErXAD4N4NubtNcNZO5zOzFisdz VEbA== X-Gm-Message-State: AOJu0YwxhhiJG0LB1pZeTUTjU8p7pohEfES4xnPtUe2+FmjnGKnZic+a WBtua1TwcOKGrD44CLmXVbjHJf/iNoYnI3Z18P5dKfATnOg6jCCEj0OcdoTGbsmsM4LXnDFyPWQ f X-Google-Smtp-Source: AGHT+IFTdMWri6fRspQOnzf17KkkIAGrVPKae4UieuZfLRY5coeRUXGHcbQlNXfONDLHUfV6bU/bCA== X-Received: by 2002:a05:6808:6284:b0:3c6:7b8:62e9 with SMTP id du4-20020a056808628400b003c607b862e9mr17676744oib.25.1713364571391; Wed, 17 Apr 2024 07:36:11 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id c13-20020ac86e8d000000b00434a041d310sm8101305qtv.16.2024.04.17.07.36.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 07:36:11 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 04/17] btrfs: move extent bit and page cleanup into cow_file_range_inline Date: Wed, 17 Apr 2024 10:35:48 -0400 Message-ID: <2d2d537ce3d1843f344ebb88d55f6e830c7fdb28.1713363472.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We duplicate the extent cleanup for cow_file_range_inline() in the cow and compressed case. The encoded case doesn't need to do cleanup the same way, so rename cow_file_range_inline to __cow_file_range_inline and then make cow_file_range_inline handle the extent cleanup appropriately, and update the callers. Signed-off-by: Josef Bacik Reviewed-by: Johannes Thumshirn --- fs/btrfs/inode.c | 104 +++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 53 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 19579439f7f6..6fd866a793bb 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -662,11 +662,11 @@ static bool can_cow_file_range_inline(struct btrfs_inode *inode, * does the checks required to make sure the data is small enough * to fit as an inline extent. */ -static noinline int cow_file_range_inline(struct btrfs_inode *inode, u64 offset, - u64 size, size_t compressed_size, - int compress_type, - struct folio *compressed_folio, - bool update_i_size) +static noinline int __cow_file_range_inline(struct btrfs_inode *inode, u64 offset, + u64 size, size_t compressed_size, + int compress_type, + struct folio *compressed_folio, + bool update_i_size) { struct btrfs_drop_extents_args drop_args = { 0 }; struct btrfs_root *root = inode->root; @@ -737,6 +737,33 @@ static noinline int cow_file_range_inline(struct btrfs_inode *inode, u64 offset, return ret; } +static noinline int cow_file_range_inline(struct btrfs_inode *inode, u64 offset, + u64 end, + size_t compressed_size, + int compress_type, + struct folio *compressed_folio, + bool update_i_size, bool locked) +{ + unsigned long clear_flags = EXTENT_DELALLOC | EXTENT_DELALLOC_NEW | + EXTENT_DEFRAG | EXTENT_DO_ACCOUNTING; + u64 size = min_t(u64, i_size_read(&inode->vfs_inode), end + 1); + int ret; + + ret = __cow_file_range_inline(inode, offset, size, compressed_size, + compress_type, compressed_folio, + update_i_size); + if (ret > 0) + return ret; + + if (locked) + clear_flags |= EXTENT_LOCKED; + + extent_clear_unlock_delalloc(inode, offset, end, NULL, clear_flags, + PAGE_UNLOCK | PAGE_START_WRITEBACK | + PAGE_END_WRITEBACK); + return ret; +} + struct async_extent { u64 start; u64 ram_size; @@ -1005,36 +1032,15 @@ static void compress_file_range(struct btrfs_work *work) * extent for the subpage case. */ if (total_in < actual_end) - ret = cow_file_range_inline(inode, start, actual_end, 0, - BTRFS_COMPRESS_NONE, NULL, false); + ret = cow_file_range_inline(inode, start, end, 0, + BTRFS_COMPRESS_NONE, NULL, false, + false); else - ret = cow_file_range_inline(inode, start, actual_end, - total_compressed, compress_type, - folios[0], false); + ret = cow_file_range_inline(inode, start, end, total_compressed, + compress_type, folios[0], false, false); if (ret <= 0) { - unsigned long clear_flags = EXTENT_DELALLOC | - EXTENT_DELALLOC_NEW | EXTENT_DEFRAG | - EXTENT_DO_ACCOUNTING; - if (ret < 0) mapping_set_error(mapping, -EIO); - - /* - * inline extent creation worked or returned error, - * we don't need to create any more async work items. - * Unlock and free up our temp pages. - * - * We use DO_ACCOUNTING here because we need the - * delalloc_release_metadata to be done _after_ we drop - * our outstanding extent for clearing delalloc for this - * range. - */ - extent_clear_unlock_delalloc(inode, start, end, - NULL, - clear_flags, - PAGE_UNLOCK | - PAGE_START_WRITEBACK | - PAGE_END_WRITEBACK); goto free_pages; } @@ -1344,29 +1350,21 @@ static noinline int cow_file_range(struct btrfs_inode *inode, inode_should_defrag(inode, start, end, num_bytes, SZ_64K); if (!no_inline) { - u64 actual_end = min_t(u64, i_size_read(&inode->vfs_inode), - end + 1); - /* lets try to make an inline extent */ - ret = cow_file_range_inline(inode, start, actual_end, 0, - BTRFS_COMPRESS_NONE, NULL, false); - if (ret == 0) { + ret = cow_file_range_inline(inode, start, end, 0, + BTRFS_COMPRESS_NONE, NULL, false, + true); + if (ret <= 0) { /* - * We use DO_ACCOUNTING here because we need the - * delalloc_release_metadata to be run _after_ we drop - * our outstanding extent for clearing delalloc for this - * range. + * We succeeded, return 1 so the caller knows we're done + * with this page and already handled the IO. + * + * If there was an error then cow_file_range_inline() has + * already done the cleanup. */ - extent_clear_unlock_delalloc(inode, start, end, - NULL, - EXTENT_LOCKED | EXTENT_DELALLOC | - EXTENT_DELALLOC_NEW | EXTENT_DEFRAG | - EXTENT_DO_ACCOUNTING, PAGE_UNLOCK | - PAGE_START_WRITEBACK | PAGE_END_WRITEBACK); - ret = 1; + if (ret == 0) + ret = 1; goto done; - } else if (ret < 0) { - goto out_unlock; } } @@ -10236,9 +10234,9 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from, /* Try an inline extent first. */ if (encoded->unencoded_len == encoded->len && encoded->unencoded_offset == 0) { - ret = cow_file_range_inline(inode, start, encoded->len, - orig_count, compression, folios[0], - true); + ret = __cow_file_range_inline(inode, start, encoded->len, + orig_count, compression, folios[0], + true); if (ret <= 0) { if (ret == 0) ret = orig_count; From patchwork Wed Apr 17 14:35:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13633465 Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D68451422AB for ; Wed, 17 Apr 2024 14:36:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364575; cv=none; b=mR5GQ4LkgIkZcUbFtvbr3NFRp4S3MIek7El/dLnpSSnTlkNz9XOPFuBNvMQ/t78YrbscYQW9DlzdNFm+8IrvXWcbDDZ57IjC4POKrqPhg7lx7xLczSwEbpqHwED2nK4eIdhNvHkIAd2Je9Ui+vzQXY2rAhmyVmWSNkFR6dH5F8w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364575; c=relaxed/simple; bh=QXlnfj7KDQpyGNoJS+FwefXlm27btOTcqxy70TUZ+Fo=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J59gqCJoxN7qs1vSNZ4LzjJ9d6KXZeaqiNUB1wZ69rtkCOkippizeklSzsucfSKt+J7//HiRa9gHK605fK7Rdxva10SKM6fL9we/x6n1C7O/TU2v5gjrcTZKxjNzY9HcYlyfmjExYy7YY6v6gM6XNb676wDIdw7wKRNy7LgCjfQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=OkjzH1Z8; arc=none smtp.client-ip=209.85.219.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="OkjzH1Z8" Received: by mail-qv1-f50.google.com with SMTP id 6a1803df08f44-69b24162dd6so25277436d6.2 for ; Wed, 17 Apr 2024 07:36:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713364572; x=1713969372; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=4EHxmW3m3DWN7fzZ1oF9jWMjtNhrvXB9gqGHTf88rEA=; b=OkjzH1Z8zvfjOLfVL3DkVFWVNfn8XqpEKRcPpPRvhTDGBuEfo5svoaW3b/K5fz/QN5 Mh/WhqpgJ0P4+zGvASUAn4JkFN7Czbb3gZqiidaYkk4CtIdOB8C2B2oX5INj8/YtyJMj zOm55OVjh+Kb0pfWLsoLrJa2KA25tgdGsVVi2SoU5ZxMwAYzqgZV4UuhoCG3Mk2GR5RV Ppe18vbRYIc4CbxHQ4ysYNvRo9LqsmJZPqACr6kA72eVP/ffYf3jqDEZHTi4ECleKbGe FqLGCN8D0Fs6Sxp94MCfhdDVtSmeapn5hz4FYgex+7hb8RgjGWLeMXMq6MuZOOe9xpnj tk9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713364572; x=1713969372; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4EHxmW3m3DWN7fzZ1oF9jWMjtNhrvXB9gqGHTf88rEA=; b=QLd6KtUbafqnNM2lntPomyeHAnBaNQdKkecm8+JQRSW4KBi26uobTmcwiUXSSu8+uH YTf8G8PKs5TT0uGGdLg2gyfpI39kiUYQnP9bnNEXodanDVp1MFN45S0XVTCAtA8The8a Q6iQygcTx8FizXGCD9Ol7vp4iWMaXYvGpz2AM+W9H/9PtyQ32elJVhRzOnNZFoEfbvLK +ntHJ4iwCkb9b0R2vOjHdURarTp9yQGDBVqKLyBzHGtlvigCMInek+1S3+vzu6dXn8OJ ud7NYsK31QHE+1rz7YcaZzyKu8/lLd+aa0Mdh5rxYVK2Z7iTje1+Hyq19Om/CBecuAAG 1i9g== X-Gm-Message-State: AOJu0YyB6d2443JZ7nMTvXr5Y6rerRNPI3gnbLMmWL/w7IO8ZLm4Sabs IZiQnvGEk5m26IYOBJmN8ZBIoFEVe07TIxszUlmQC+0brG4phOeJO0DLDGISH9g4cvJffrsZdIS a X-Google-Smtp-Source: AGHT+IGdhO2z1n6SHg7aQObIJe8Wj5A+4p5Rm5LFvhYYe7zPfXmQgMBWPl3K6yOlEbKVVfGWMdHjzA== X-Received: by 2002:ad4:4f8f:0:b0:699:2293:92ba with SMTP id em15-20020ad44f8f000000b00699229392bamr14184925qvb.61.1713364572603; Wed, 17 Apr 2024 07:36:12 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id j15-20020a0ceb0f000000b00698fd83ac04sm8345943qvp.135.2024.04.17.07.36.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 07:36:12 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 05/17] btrfs: lock extent when doing inline extent in compression Date: Wed, 17 Apr 2024 10:35:49 -0400 Message-ID: <99be1657b5273f3a9d24e53f6be9303b381a51eb.1713363472.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We currently don't lock the extent when we're doing a cow_file_range_inline() for a compressed extent. This isn't a problem necessarily, but it's inconsistent with the rest of our usage of cow_file_range_inline(). This also leads to some extra weird logic around whether the extent is locked or not. Fix this to lock the extent before calling cow_file_range_inline() in compression to make it consistent with the rest of the inline users. In future patches this will be pushed down into the cow_file_range_inline() helper, so we're fine with the quick and dirty locking here. This patch exists to make the behavior change obvious. Signed-off-by: Josef Bacik --- fs/btrfs/inode.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 6fd866a793bb..ba74476ac423 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -742,10 +742,10 @@ static noinline int cow_file_range_inline(struct btrfs_inode *inode, u64 offset, size_t compressed_size, int compress_type, struct folio *compressed_folio, - bool update_i_size, bool locked) + bool update_i_size) { unsigned long clear_flags = EXTENT_DELALLOC | EXTENT_DELALLOC_NEW | - EXTENT_DEFRAG | EXTENT_DO_ACCOUNTING; + EXTENT_DEFRAG | EXTENT_DO_ACCOUNTING | EXTENT_LOCKED; u64 size = min_t(u64, i_size_read(&inode->vfs_inode), end + 1); int ret; @@ -755,9 +755,6 @@ static noinline int cow_file_range_inline(struct btrfs_inode *inode, u64 offset, if (ret > 0) return ret; - if (locked) - clear_flags |= EXTENT_LOCKED; - extent_clear_unlock_delalloc(inode, offset, end, NULL, clear_flags, PAGE_UNLOCK | PAGE_START_WRITEBACK | PAGE_END_WRITEBACK); @@ -1031,18 +1028,19 @@ static void compress_file_range(struct btrfs_work *work) * Check cow_file_range() for why we don't even try to create inline * extent for the subpage case. */ + lock_extent(&inode->io_tree, start, end, NULL); if (total_in < actual_end) ret = cow_file_range_inline(inode, start, end, 0, - BTRFS_COMPRESS_NONE, NULL, false, - false); + BTRFS_COMPRESS_NONE, NULL, false); else ret = cow_file_range_inline(inode, start, end, total_compressed, - compress_type, folios[0], false, false); + compress_type, folios[0], false); if (ret <= 0) { if (ret < 0) mapping_set_error(mapping, -EIO); goto free_pages; } + unlock_extent(&inode->io_tree, start, end, NULL); /* * We aren't doing an inline extent. Round the compressed size up to a @@ -1352,8 +1350,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode, if (!no_inline) { /* lets try to make an inline extent */ ret = cow_file_range_inline(inode, start, end, 0, - BTRFS_COMPRESS_NONE, NULL, false, - true); + BTRFS_COMPRESS_NONE, NULL, false); if (ret <= 0) { /* * We succeeded, return 1 so the caller knows we're done From patchwork Wed Apr 17 14:35:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13633466 Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2104413A265 for ; Wed, 17 Apr 2024 14:36:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364576; cv=none; b=cs8qCH48eCKwG+nSgudSQSvK2isdjdOH6TkEiCaeBorrYA7oAFyln3cEzdifaKnMAB78+n3Br0JWbHA8QYlzPquEQ8pw+5a59iBWz0JgsNoZkNKFpFbG9+kRIvOj4HVfu2fu+EsEYndeoIbxZRGAvcJQlQFJdBc7yH8H5cDZ6Dc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364576; c=relaxed/simple; bh=lIJeEDcKILQVjBQnlVNn9tmEJ70mLgziM0k/V/uafN0=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ca/Xps8ceWWA0mpVQeYz2WRh92shY5t+Wou/fqxQ5np7PbcKKm2/Fx5yedCFV0a9NRhZSvRxfCR5KkHNyDx/QQGEpbnl13sbv/Z0OR8eD/dtCioS5m6bJxefRLeL158CS6tzyBmZWtfCUwQ0wuJDmZsfNuvhX3fK4qTVHCntrxs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=d2ZqnFp2; arc=none smtp.client-ip=209.85.160.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="d2ZqnFp2" Received: by mail-qt1-f175.google.com with SMTP id d75a77b69052e-434925427c6so21909631cf.1 for ; Wed, 17 Apr 2024 07:36:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713364574; x=1713969374; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=3VGkqAoXTQ2oHa57gANyYrDf03wmc4JWQxuxHSVnr00=; b=d2ZqnFp2Y7dafzqZzO2GRgzRUeIud+ZpIL/at2ZQ2Z62zgXQzVsCiNfaZN8ITyCP9Y 9qzda8BTxW6wLvKGDgpzSHs00X/9ySlBEuExHmc+Ko6+6oWwI9zqyniuezeSQWsmK6Bj +1vM+938hautXqLkpoxYxPhS/WUee/6UsK78yr9Z9dXt+kmlUFzjeC1w2fCe+hNR/ne7 2L/Ynj5t3TzVNq98RFsq1ZlGqdrCD4M7ke5wjs+h5iQDWx2dVcqmK4cCg+6YBbdcgZAQ cPIeVy0Ksq7QRgzY0xIDOaDgFb4RFI+hDXi/PP3LaPK5w6OtzLs2a6jp7qYkl+w1t+cW KrYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713364574; x=1713969374; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3VGkqAoXTQ2oHa57gANyYrDf03wmc4JWQxuxHSVnr00=; b=Lr0KDnLHWI3e66aapcUfwz0YiUJJeiyiWbLBPbLk+SAbpOhCqC7pTKHxEA/NtWhcO3 PXGnVCe43zgwtI5PZqZxnmYLwOMk6OV6MZMaFzaH+kYZlhJWlUHXQLCW32qNQkQ9cU2S B5wfQuE2LKRS9umjwb4jlSYy3wf7lle4vTuI4bD7iKnIZgGWH1jzimbpGEnYojBRp4ku ms0C9gMYOOEY3gRtUbiwZxf62NSOMrOfoAvyNnsQ/JGjtR6gfkgf/sImZQwOrBcxhPWq B2ovO9WKDC4Qb0qOzzRg86zEhflliVArtOrTLAi4rYFy4/Kh7b+LdRsLHCspn2X+A8wN v+cA== X-Gm-Message-State: AOJu0Ywxyrl6PCBtNAPkqTFtghapTDNoZSRtEbtMriv75ilwSfK5IuaW pMQRRodZmwQORjB6X8kIR4+AzZbY6NH4QL6Hba5bNf6h2LbHkqj6F3TxDUTYPxY9eM9zR0jUJOk Y X-Google-Smtp-Source: AGHT+IHEyfXQNojGXuKSNWnkuhLAWlTirXgln08NhGqlDaqKLmwyxUcJDwRx6MmYbmXD19ZISSgTVw== X-Received: by 2002:a05:622a:1a0d:b0:437:87f9:5ad2 with SMTP id f13-20020a05622a1a0d00b0043787f95ad2mr676066qtb.45.1713364573904; Wed, 17 Apr 2024 07:36:13 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id m25-20020ac84459000000b004377f87147bsm272836qtn.69.2024.04.17.07.36.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 07:36:13 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 06/17] btrfs: push the extent lock into btrfs_run_delalloc_range Date: Wed, 17 Apr 2024 10:35:50 -0400 Message-ID: <1d2952b7fccde719e25867471e61a0126e77e3b6.1713363472.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We want to limit the scope of the extent lock to be around operations that can change in flight. Currently we hold the extent lock through the entire writepage operation, which isn't really necessary. We want to protect to make sure nobody has updated DELALLOC. In find_lock_delalloc_range we must lock the range in order to validate the contents of our io_tree. However once we've done that we're safe to unlock the range and continue, as we have the page lock already held for the range. We are protected from all operations at this point. * mmap() - we're holding the page lock, thus are protected. * buffered writes - again, we're protected because we take the page lock for the first and last page in our range for buffered writes so we won't create new delalloc ranges in this area. * direct IO - we invalidate pagecache before attempting to write a new area, which requires the page lock, so again are protected once we're holding the page lock on this range. Additionally this behavior actually already exists for compressed, we unlock the range as soon as we start to process the async extents, and re-lock it during compression. So this is completely safe, and makes the locking more consistent. Make this simple by just pushing the extent lock into btrfs_run_delalloc_range. From there followup patches will push the lock further down into its users. Signed-off-by: Josef Bacik Reviewed-by: Goldwyn Rodrigues --- fs/btrfs/extent_io.c | 5 ++--- fs/btrfs/inode.c | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 7b10f47d8f83..c09f46f969b1 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -396,15 +396,14 @@ noinline_for_stack bool find_lock_delalloc_range(struct inode *inode, /* then test to make sure it is all still delalloc */ ret = test_range_bit(tree, delalloc_start, delalloc_end, EXTENT_DELALLOC, cached_state); + + unlock_extent(tree, delalloc_start, delalloc_end, &cached_state); if (!ret) { - unlock_extent(tree, delalloc_start, delalloc_end, - &cached_state); __unlock_for_delalloc(inode, locked_page, delalloc_start, delalloc_end); cond_resched(); goto again; } - free_extent_state(cached_state); *start = delalloc_start; *end = delalloc_end; out_failed: diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index ba74476ac423..2083005f2828 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2249,6 +2249,11 @@ int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page const bool zoned = btrfs_is_zoned(inode->root->fs_info); int ret; + /* + * We're unlocked by the different fill functions below. + */ + lock_extent(&inode->io_tree, start, end, NULL); + /* * The range must cover part of the @locked_page, or a return of 1 * can confuse the caller. From patchwork Wed Apr 17 14:35:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13633467 Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37CCE1422BF for ; Wed, 17 Apr 2024 14:36:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364577; cv=none; b=XIS06+8ZFfiTYagCkx7kscAT58vouzAvyydP922+6hzUMT4QJfaSCf8fNz0ZwyoVMkd/iRqRdZ1BQBU7NQ9g4burPfod+SqAPBmF9IUWRF8WY9y4DKqlaaH/Ake0tWyxVr0ByUbt1UvTHNlfUvnCx1aSQyEwW/m8l96ZyWGbkow= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364577; c=relaxed/simple; bh=Y/gwUlYFE7XZUYr6RVyHboVF9XH8QXiMUBqwlD483Mg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V23Swfkq/TGvzRZEkgY4BoSEyqApKbFQYbc7qEaLkZO+xbo1mlUjp3v8PTDihWqimeVptDkNWBHrdgtEN5zCc3BGRJ+2PTgqjVOfalh6w8xl2qByaEZYnL5XwSlOn1sLmQ9gbrYtfOE6MOt+m9BaK59zicaZja7Wtf1BXvdJPSo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=3SDmYmO4; arc=none smtp.client-ip=209.85.167.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="3SDmYmO4" Received: by mail-oi1-f169.google.com with SMTP id 5614622812f47-3c728a8035eso895543b6e.3 for ; Wed, 17 Apr 2024 07:36:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713364575; x=1713969375; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Is08mh5q7jLBmz9q8sss+4lFjRXXFzHZn7k/nmeAvTs=; b=3SDmYmO4h1Mhp+rNcIdUeXNMxhXJq+OaztObOKxRNjaQG1CpFoOagPWs2X2sherGbv 0+U82JwmGWBYQiSibW/81COo26C/cF26qRml3RCzmFNeVGnDkaPO88K+9ltCcy3NTLAr 0AybQXtB1mVXcUbc81XWl/fUJxlANL8iYu9gf1dvTwTUutldd6yNeBkZTBXez7RQcHIx rQaWg6Eu783BKxHEwQDUSEL9f+noBka5WViyYp4PtfvDyXM/iv5r8ZQIwiupjfHIRo/o oMvZXvrZ3cVppeTSQjnKz8Tg3VX/OOzjLCUCXc+/U/0G0u4z4IjchjJJMAi06gi9vxyU Jwew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713364575; x=1713969375; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Is08mh5q7jLBmz9q8sss+4lFjRXXFzHZn7k/nmeAvTs=; b=gP6L/B+wk1AGscn1P2/hMl6bmbMd3k+lA0w2uMyepfMP9VswMlALFwvA/2FsBqEGT7 FxJ9ykQrI1TKx5fGZlddmNrAHozZOTMD8Mmvoe/Pm8cuN+xKhgsGuwyfCGDFYBzVnS// 384HEPgPBI/2gHJvgjbgGDG6LqTDmq09/rXavmS1fc0dFzCP7Op/uLX0fu7+3kRjKuzp 4J89F3yqU8xPRJgeMmo+HTH+fILpTZ0ZaTIj8ExG3eT4bQOPmpLlx6076vZoiB3xTtFL lz20p7AKeONmzsNatuDGlwr3REYQPkYHeWy8/McTCoiSatek9MT9sUOJexF43nxbhi99 jzaA== X-Gm-Message-State: AOJu0YzdFLU1gZBnM3JbbeiwIAXG9ZjDaoIA7aSduG3QeMt8CPs/BO5w ljy/gbsxlamqV1vQAWUyn6LU/JkuyUqPMR0wXtUYatqmap5NvLar5aVYdNlSiHgPwK3zimGufeL f X-Google-Smtp-Source: AGHT+IGfTvNU8p5PUsvclA0VUACF52egFMeXmlxeL0DCYUyZjMCFLZVF/UKwn9f5Dn0q/bREgw39cA== X-Received: by 2002:a05:6808:b27:b0:3c7:79c:72c9 with SMTP id t7-20020a0568080b2700b003c7079c72c9mr13597740oij.54.1713364575105; Wed, 17 Apr 2024 07:36:15 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id f4-20020a05620a20c400b0078d4732d92fsm8421929qka.115.2024.04.17.07.36.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 07:36:14 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 07/17] btrfs: push extent lock into run_delalloc_nocow Date: Wed, 17 Apr 2024 10:35:51 -0400 Message-ID: <60f8e6362e50086d796d8cdd44031d9496398b08.1713363472.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 run_delalloc_nocow is a bit special as it walks through the file extents for the inode and determines what it can nocow and what it can't. This is the more complicated area for extent locking, so start with this function. Signed-off-by: Josef Bacik Reviewed-by: Goldwyn Rodrigues --- fs/btrfs/inode.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 2083005f2828..f14b3cecce47 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1977,6 +1977,8 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode, */ ASSERT(!btrfs_is_zoned(fs_info) || btrfs_is_data_reloc_root(root)); + lock_extent(&inode->io_tree, start, end, NULL); + path = btrfs_alloc_path(); if (!path) { ret = -ENOMEM; @@ -2249,11 +2251,6 @@ int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page const bool zoned = btrfs_is_zoned(inode->root->fs_info); int ret; - /* - * We're unlocked by the different fill functions below. - */ - lock_extent(&inode->io_tree, start, end, NULL); - /* * The range must cover part of the @locked_page, or a return of 1 * can confuse the caller. @@ -2266,6 +2263,11 @@ int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page goto out; } + /* + * We're unlocked by the different fill functions below. + */ + lock_extent(&inode->io_tree, start, end, NULL); + if (btrfs_inode_can_compress(inode) && inode_need_compress(inode, start, end) && run_delalloc_compressed(inode, locked_page, start, end, wbc)) From patchwork Wed Apr 17 14:35:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13633468 Received: from mail-qt1-f173.google.com (mail-qt1-f173.google.com [209.85.160.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4A5881422C9 for ; Wed, 17 Apr 2024 14:36:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364578; cv=none; b=hcRkxtC/7meacxK8dHlHrY0bxwhe/6OiSh2A8QtUpLUorbtdNbk1K7K26gK5T/dxlEJkFQC6jFPp2LzJRyhtnMi8A3qJ3956vtR1m3o1h4arJqtvBcyqRXSZk9yENhDlmQoNBEc1jRJIOHr3FWN0P2JPKSOMl/hIbJXSQN/GEyo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364578; c=relaxed/simple; bh=SI7UBRui4exBVzMmZDqjH6jmbp2M31ZFFyvhb1yWGfY=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hsYsg9zXlemDGK+tA0S7j6qbHQeSShoKpIcAS5knYRxYu2LFeA9/hJeN2GTKaWxrsqqt6mzz/NbwtHc8SV7ZfajWJoKkfPLBFeaVHqYg5BPtPh3bZWh2OOxckkVYFd4wZkuLcU57kJzq3mlWD2mnnYxABY5q/6c8lZ9+T1Sq1oY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=rS+NQDjG; arc=none smtp.client-ip=209.85.160.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="rS+NQDjG" Received: by mail-qt1-f173.google.com with SMTP id d75a77b69052e-437846c4ceaso1766431cf.3 for ; Wed, 17 Apr 2024 07:36:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713364576; x=1713969376; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=SwdBOXbPQKMF58zCnd69akHypCDuvtwD37ItRJVi6jM=; b=rS+NQDjGjgZ+baimg39XfwNwtN7oGQiUqYHrwbqp0S4sOCRjYLtg0LEm+nUDk4xsM1 eyhzvwCeEGMVTDbjtgVNlKMh96GCNlMIueAb5DvzZMUZWOwQVGyhpPriqZtKwjsBl7U7 TdTHX3p9266Ey1SD4/gzOpNXa/dG+qTQqWiZ7wVzSoa/FBBAKQB9ROc0W0WUwWr9pS+H xBEqqPrxKB4ad0HlErCT6U2wBA03RoaDCcwfo/oLPf5nCYtiTbywb9JcOdJVjjBffHq/ YQCrBw9vy9vZftR244TLqWhJp4G5crN/yDZOTocEQVB779DXvBvX1ahUUm++ATGJBYOV JLuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713364576; x=1713969376; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SwdBOXbPQKMF58zCnd69akHypCDuvtwD37ItRJVi6jM=; b=CmfKh3nx+Ovy94Td0ZkdpGsZXrPlUMuBua1UaSn3JCsUGvKW/75kfeDR5uVxie2FDT Z0Opx0QKqPordDx+qx/mLRuP/PmKCzPx2zxHumVgLpYFGypYlVJGNSFXSl3d+tkGgO3i 2qBa/7V68KhWykxaExusi3r2Mo9mSNn08v4/2whhVsEee1VODG6yvmI5JnWVA4WkDs4s vInXF0Leko5EijGBTSblXkSFo1ojfdhEdREXpPng6vnSHGSyc4qJUtuwi/tOOfl0CSyR tBs2IBpBE3PDfXGALA4j/AVh+ruRyrIqj4AHPfqI7dbrgblpq9Nj0rzKo44P9DtPyYRb hDew== X-Gm-Message-State: AOJu0Ywa2krC1Mxc50XG/g1kNxsJBP74h85hxW5zj6uqJgyAnGY7whX4 aY9XhPEk7/1Tz/W56E/jIMjmR3rLrZ5KWNlMYmFhiW/emWlomqydPAU7hZTrUtl8GulU7+rnVdC b X-Google-Smtp-Source: AGHT+IGlaKweZmdH/buzml36qfArRByI0LZeDQAE9CF8AXe+eiGqotthyC34JwP5fE1OSk8iBndA2w== X-Received: by 2002:ac8:7c52:0:b0:437:8bb2:4439 with SMTP id o18-20020ac87c52000000b004378bb24439mr210261qtv.48.1713364576187; Wed, 17 Apr 2024 07:36:16 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id h11-20020ac8514b000000b00432bd953506sm8142566qtn.84.2024.04.17.07.36.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 07:36:15 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 08/17] btrfs: adjust while loop condition in run_delalloc_nocow Date: Wed, 17 Apr 2024 10:35:52 -0400 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We have the following pattern while (1) { if (cur_offset > end) break; } Which is just while (cur_offset <= end) { } so adjust the code to be more clear. Signed-off-by: Josef Bacik Reviewed-by: Goldwyn Rodrigues --- fs/btrfs/inode.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index f14b3cecce47..80e92d37af34 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1988,7 +1988,7 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode, nocow_args.end = end; nocow_args.writeback_path = true; - while (1) { + while (cur_offset <= end) { struct btrfs_block_group *nocow_bg = NULL; struct btrfs_ordered_extent *ordered; struct btrfs_key found_key; @@ -2192,8 +2192,6 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode, */ if (ret) goto error; - if (cur_offset > end) - break; } btrfs_release_path(path); From patchwork Wed Apr 17 14:35:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13633469 Received: from mail-qv1-f45.google.com (mail-qv1-f45.google.com [209.85.219.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 94E6F13D2B5 for ; Wed, 17 Apr 2024 14:36:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364580; cv=none; b=SC4JJhpfSFyWyEFz8rw/77vejHTCkX6B3YzzT0FqgSG+50a1A/oPAIEWXgyhMfLxVMvzZv421ixrBCiNPdfxm6pc6Za4E+0plIbo0wPEEOCdxGTlIc3LgCUTlksFx8fpliKZ9DU3IJNsq9ACWo5lxfE+sZ5dATgzsXs6Rc8HxI0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364580; c=relaxed/simple; bh=CN1fabPY01Y45PR27Ovs+cDoICKXpAkTzB3PxjpziUQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EiWKAvFR1lzHpbmCh1E2Z8nWBCYr+FBPX6U5E6FlaLrQOQwl7sfoVEWcJJ1cyX0QOnyy9Kk5a3JU5F5O6y20N5DA0BB8GfWKkKs9kuxDFFva1sDz+W8/RNP5/rH1DsHiS63kbR70TEOIPwftdIuuKqe0dxYY1B3+aMHIxZWOdPM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=PUrL2VfQ; arc=none smtp.client-ip=209.85.219.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="PUrL2VfQ" Received: by mail-qv1-f45.google.com with SMTP id 6a1803df08f44-69b40061bbeso29968476d6.1 for ; Wed, 17 Apr 2024 07:36:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713364577; x=1713969377; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=AReq9/l6IknEl65HbhwH0wLmQr5fkR4CqQNmIWsSnR4=; b=PUrL2VfQq2F77vOJ2WD8JSQd57MIUSBWHRACnuqbj8TxmUMF11668pshB4x4b5JFuB toSdyv01LqdtKaLbJ5HqoIYjqiOrGQCGEFNrUvDUAfVeiKojf4rhLhvmj7NeEOd0bimx 81g0IiLh/wW4rX0LvaJvABUE5FePJCzacA0TY9bQoMMhvpyh07C5DLpGG92EUz6TA1i1 +1l+SXw1fcCfYpyc5um2ZzvJBiAzKZDuF+6UJbSe+lRrOb+L7GbyqzSdSioPZl5i1IuU XY5srhX+6ID01lK8K89U8IYnSCJtH6JRsy3w4U3A4LZqGtWHkzTXvl5L6ZDUEfNhwt2X F1lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713364577; x=1713969377; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AReq9/l6IknEl65HbhwH0wLmQr5fkR4CqQNmIWsSnR4=; b=Qvj4V89XNwH5PJhN6ADzsEPtr8Vrg33TbQ0xcakhDdVkGjHf4dseXzxv8RLrDLFVVe Lq4sD0l5vEkis9F09qcFHuzbrKrHn7c0fqk0YiO6ZtZFUJ7KlwZsjvQeCkbhgq+Mt00R CJ1s0GvsIeLK3onJxdZOrXri/+Wp4KhnYj6Eq006ZwZVikavwNnmIHWYsWdgkXEunNCU UjsNuusGeGlJXMdnnlOLmf+ttrV6rJO/YjWDGk7pUZDQlNr6Z7Z1zbTNmElEmyWg9mv9 0+WkRxZyqZ8VqMaaQZBLwvH79cSm7CkRg4w3xaRAeDZCC4bBcX+HQoxCjsUkKNssMSKa fDsg== X-Gm-Message-State: AOJu0YyoRhh3AAqpy9j/70Dp/jxhzg6isuhUGucsES6+sl9AiMvDJNp6 vWYacwM0zRGWSHWcE+VwB0MvlPHybZ/PVtmQYvgjIt1Oo0Vf/ODTmsgmKG9MnoZQ72scWMPk/ba 7 X-Google-Smtp-Source: AGHT+IEyA5as89eWCuZNl1oqaboJmvl74u61kUuGRWXKa+TaWQ7trUaxkTXDpGKqFiA7DE6BoPIfeQ== X-Received: by 2002:a05:6214:c67:b0:69b:20a7:5669 with SMTP id t7-20020a0562140c6700b0069b20a75669mr20369462qvj.53.1713364577361; Wed, 17 Apr 2024 07:36:17 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id c12-20020a0ceb4c000000b0069b5672bab8sm7067844qvq.134.2024.04.17.07.36.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 07:36:17 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 09/17] btrfs: push extent lock down in run_delalloc_nocow Date: Wed, 17 Apr 2024 10:35:53 -0400 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 run_delalloc_nocow is a little special because we use the file extents to see if we can nocow a range. We don't actually need the protection of the extent lock to look at the file extents at this point however. We are currently holding the page lock for this range, so we are protected from anybody who would simultaneously be modifying the file extent items for this range. * mmap() - we're holding the page lock. * buffered writes - we're holding the page lock. * direct writes - we're holding the page lock and direct IO has to flush page cache before it's able to continue. * fallocate() - all callers flush the range and wait on ordered extents while holding the inode lock and the mmap lock, so we are again saved by the page lock. We want to use the extent lock to protect 1) The mapping tree for the given range. 2) The ordered extents for the given range. 3) The io_tree for the given range. Push the extent lock down to cover these operations. In the fallback_to_cow() case we simply lock before doing anything and rely on the cow_file_range() helper to handle it's range properly. Signed-off-by: Josef Bacik Reviewed-by: Goldwyn Rodrigues --- fs/btrfs/inode.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 80e92d37af34..ab3d6ebbce6a 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1747,6 +1747,8 @@ static int fallback_to_cow(struct btrfs_inode *inode, struct page *locked_page, u64 count; int ret; + lock_extent(io_tree, start, end, NULL); + /* * If EXTENT_NORESERVE is set it means that when the buffered write was * made we had not enough available data space and therefore we did not @@ -1977,8 +1979,6 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode, */ ASSERT(!btrfs_is_zoned(fs_info) || btrfs_is_data_reloc_root(root)); - lock_extent(&inode->io_tree, start, end, NULL); - path = btrfs_alloc_path(); if (!path) { ret = -ENOMEM; @@ -1994,6 +1994,7 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode, struct btrfs_key found_key; struct btrfs_file_extent_item *fi; struct extent_buffer *leaf; + struct extent_state *cached_state = NULL; u64 extent_end; u64 ram_bytes; u64 nocow_end; @@ -2131,6 +2132,8 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode, } nocow_end = cur_offset + nocow_args.num_bytes - 1; + lock_extent(&inode->io_tree, cur_offset, nocow_end, &cached_state); + is_prealloc = extent_type == BTRFS_FILE_EXTENT_PREALLOC; if (is_prealloc) { u64 orig_start = found_key.offset - nocow_args.extent_offset; @@ -2144,6 +2147,8 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode, ram_bytes, BTRFS_COMPRESS_NONE, BTRFS_ORDERED_PREALLOC); if (IS_ERR(em)) { + unlock_extent(&inode->io_tree, cur_offset, + nocow_end, &cached_state); btrfs_dec_nocow_writers(nocow_bg); ret = PTR_ERR(em); goto error; @@ -2164,6 +2169,8 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode, btrfs_drop_extent_map_range(inode, cur_offset, nocow_end, false); } + unlock_extent(&inode->io_tree, cur_offset, + nocow_end, &cached_state); ret = PTR_ERR(ordered); goto error; } @@ -2182,6 +2189,7 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode, EXTENT_DELALLOC | EXTENT_CLEAR_DATA_RESV, PAGE_UNLOCK | PAGE_SET_ORDERED); + free_extent_state(cached_state); cur_offset = extent_end; @@ -2217,13 +2225,20 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode, */ if (cow_start != (u64)-1) cur_offset = cow_start; - if (cur_offset < end) + + /* + * We need to lock the extent here because we're clearing DELALLOC and + * we're not locked at this point. + */ + if (cur_offset < end) { + lock_extent(&inode->io_tree, cur_offset, end, NULL); extent_clear_unlock_delalloc(inode, cur_offset, end, locked_page, EXTENT_LOCKED | EXTENT_DELALLOC | EXTENT_DEFRAG | EXTENT_DO_ACCOUNTING, PAGE_UNLOCK | PAGE_START_WRITEBACK | PAGE_END_WRITEBACK); + } btrfs_free_path(path); return ret; } From patchwork Wed Apr 17 14:35:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13633470 Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 91085142625 for ; Wed, 17 Apr 2024 14:36:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364580; cv=none; b=BRoRILJPK0AahAPRTH9RFkJvedLwyzo70HrX6L/J94ea2hy72NzxY7A02DxzBqMRloocIcSmXA8O8rSng6qW25+kwD4f04XwBDbctCYD8E19pqaSkW1Mcs/lms/DCCQdKazeVDiSOlfDl4XX0KUD4t9D1WhO85fGKRT4L9lPrfk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364580; c=relaxed/simple; bh=+nq0wtpfH4KER8mBsUbu6J4UUsuSCCFYK0gEt/a5TJg=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=u2Ym2Qs1x+YmqBMbaY1wS0sQqdZccbjrgel9PAP2PjsZ6YbrR6l0H6E+t2aP6eD6E2XaEW19CL8oHAYbWtoAAOSNwI0FuB97luU/D90TMcxGjyBsFtDgQl548PgXIVjD1DhxoRH5aCwEjPmydU3ZN2sabVUMgjFa7e7dl8Ahp6A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=W1QHGBAG; arc=none smtp.client-ip=209.85.219.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="W1QHGBAG" Received: by mail-qv1-f47.google.com with SMTP id 6a1803df08f44-699320fcbc1so30419066d6.3 for ; Wed, 17 Apr 2024 07:36:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713364578; x=1713969378; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=wO9Y9pmUaM331yijLL4Y5jBy/ESfY0EBWXkj0YYSLW0=; b=W1QHGBAG1TA66Ru8mQrWFe+OtoBHTU3bj9/ovRXdQMnXCgqAQ+CW3VJ1ONiwwYn+EE BfuNrUW/t3/iiNFClKzcAquOOCj6ryw/62kjN3pGvtu1rL7pRRj6tNdxviU1i5fOGREk ZKfGzovWfLoKx8yMH2mAdN/052iCA0agDj60mUFmtacYNEQAtkins/O4U4YwCU0IiJh/ dx53JXcdlq/BQgswwpkczFeYXLrGY4lHNL5YshSDiLH/GuRBpg+5RU+pQHRYO3bhrT5B ddMdQOu3y31ldSET/6NhXoiMYh50ygKqw0eEbQ07RBUJuhizPBFZv5J8rvKOJU+Osx62 KEXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713364578; x=1713969378; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wO9Y9pmUaM331yijLL4Y5jBy/ESfY0EBWXkj0YYSLW0=; b=Oud4OeZ6OShv+Y0tuyt9vW1/kvKhQ4R/Cz7GZSFae2nbJuESFwW7ZS0JHnvDKFBjFV w0S0Y53Upzot7jLwRYNpur9T+5VsCqsoDYzhLGP34bm29ZyhWq9O7p7zQxihNWgjBQjB jMpkd0FGCX811hrvU3r4hS1TgyaRQ4vSlBcsD2O5YWug618NDSRoYWvc+PIlI96q3g2v LvdxHoY7RzfbgjEH7enaTR09qejNGhL1CwEsG2jbn7Djj8vcXwd9bUo6a6nDklnX8RPE 18ptRWEtlX2ZmQXd0ev0aShvnUgSojtTrqtNoG3EyxKf8KWPhglMNWgoxyxInkkBGkXJ DIsw== X-Gm-Message-State: AOJu0YwMgIaUz3+tE+dUPMh9Yiak6JS0akBoKU+Wt3OScaIibJ0H6oZ1 xDH1KycXBO70IbuBGJ6leJv873l3pXLG1rvPTpc2s6gulLU6JmpZkcEkW7LY3amygIYXd++WUez m X-Google-Smtp-Source: AGHT+IFyzvcSMfCv6YOMzgFWa7cy7NxzQCP0MNyU7cDfpBlRSjE5GDwKd+PG1jWYK8dmBHjxo7Qqaw== X-Received: by 2002:a0c:f644:0:b0:69b:aca:4a1c with SMTP id s4-20020a0cf644000000b0069b0aca4a1cmr16778889qvm.10.1713364578491; Wed, 17 Apr 2024 07:36:18 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id dw11-20020a0562140a0b00b0069be29e160fsm2505673qvb.141.2024.04.17.07.36.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 07:36:18 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 10/17] btrfs: remove unlock_extent from run_delalloc_compressed Date: Wed, 17 Apr 2024 10:35:54 -0400 Message-ID: <62c3ad839000ac851c813c84f94580fafae16389.1713363472.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Since we immediately unlock the extent range when we enter run_delalloc_compressed() simply move the lock_extent() down to cover cow_file_range() and then remove the unlock_extent() from run_delalloc_compressed. Signed-off-by: Josef Bacik Reviewed-by: Goldwyn Rodrigues --- fs/btrfs/inode.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index ab3d6ebbce6a..9066d248b9aa 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1642,7 +1642,6 @@ static bool run_delalloc_compressed(struct btrfs_inode *inode, if (!ctx) return false; - unlock_extent(&inode->io_tree, start, end, NULL); set_bit(BTRFS_INODE_HAS_ASYNC_EXTENT, &inode->runtime_flags); async_chunk = ctx->chunks; @@ -2276,16 +2275,16 @@ int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page goto out; } - /* - * We're unlocked by the different fill functions below. - */ - lock_extent(&inode->io_tree, start, end, NULL); - if (btrfs_inode_can_compress(inode) && inode_need_compress(inode, start, end) && run_delalloc_compressed(inode, locked_page, start, end, wbc)) return 1; + /* + * We're unlocked by the different fill functions below. + */ + lock_extent(&inode->io_tree, start, end, NULL); + if (zoned) ret = run_delalloc_cow(inode, locked_page, start, end, wbc, true); From patchwork Wed Apr 17 14:35:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13633471 Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4ED914263B for ; Wed, 17 Apr 2024 14:36:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364582; cv=none; b=tNIKyhAqR5+ugmyp9UJGhfxVuuZg4LeSjB8CyQ3Kui1NYjJwd7YeUaV3ERRmPF1xG9cxUE07/LuA9GAvfSN7un7RuBVtzLiilxAVv2IHsjQVIC5jOO0pYITjNCo3geNe1NuZVw98WdxCXpCx3+6mmbSys4dH2HjdAwwZgMEJ7Kg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364582; c=relaxed/simple; bh=00hgfnVhoBcXg8GEywqQ4h/LLh2FYMxEtZlJ3iaidzo=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nZ8KSgiYQwNN+TxCKxUKJ7wA67yq56faoEWxkVnwaDUH52y1j2HsS267pbnSCtdR8v+JDOEysbByMBetnIYdoGl6J6CL4pHYez2FKvwWtJ2u+s++xi0ZSQEDN0BECd44ArgpT5RYANYsGG4GvNYqBF63E7zcKrmkZAjbV+RhfIE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=i4V087Sj; arc=none smtp.client-ip=209.85.222.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="i4V087Sj" Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-78d62c1e82bso377975885a.3 for ; Wed, 17 Apr 2024 07:36:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713364579; x=1713969379; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=3op8i+QWOUfFMTbxcqBbWv42/JXJbDNCJwjyc1OBwNw=; b=i4V087SjH+t3EOCa23HUn415XzdCe6LdOp64E+av66rLdaoc34BxJdo33SXV8uDlnP Mrc1KANZuZY2fiseum2WzJ/3dfFaKDv1ZwcKEf1migxUYIczJLVbbUMGYUt6dFDpw57h gNNxbnD/qPPO9Y6aKYjQiF7SUIdozZupAHwmByxu0C6e6cAMQv3bRZW+25mBI7aRpHTb iL/fk5dqbi4FO/N/fq+NTj4WmIDXvA2rHPyHsghsYIZTG9lcxZGnDXNwCkXWrlfqZvKT dhoct+Y+ykGGms+uYi4aUMg6ANPTkoSlJtkDvciF0aFOr/xYj7j1XiBFZKgLeZSjq7DA amuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713364579; x=1713969379; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3op8i+QWOUfFMTbxcqBbWv42/JXJbDNCJwjyc1OBwNw=; b=jzYiTeuqAEjelVPw0UQ1PlmHZi09IBJEoTcvZHHHYHOjzLBsiSA0DfRzhqQ2VIAHCO TZGycL9pqqG3td++lrAkG/P2x594zGmhnqkIskXPoXaw8Uf1kezP500Drpp7LkcxI/Ws Qf9muMRwaAriwPOQ5hGDrMmLxxVUDd+N/iNa3aHoAfZ/xDdKrDitRxAIkM/CcFZMVWhX IG6glvVMjZ9hhNoyblKXvI0oflAIKUWUjPzaRuFt6C/Kyt/YEKkOHEwr7B4hhbFSX6yD ChAmHajm8alRchF++Ye7dv0h0gXoUW8aVo9m47KgB+Uz0dwBWQ4ghtl2MBtgztwBirxj kghw== X-Gm-Message-State: AOJu0YzGFmO79uCBT6ehczodKILFoT98mkDuWJNgGW+6pVNdFr+vSb0V ytrczF5AB2/mIJOuSPE6rEV1TjzpE7lLt/SqVyH+fDqBRVlMQHcis93qpfCQO8wyBxSjxTZRD3e S X-Google-Smtp-Source: AGHT+IFFuEv9YQqTmPxo+qAtTjw7H+dYLlFfWXGy0/JMezpJ20IeCSN9MzBzDYfgDIRHu1vAseywjA== X-Received: by 2002:a05:620a:521d:b0:78d:4dc2:5f94 with SMTP id dc29-20020a05620a521d00b0078d4dc25f94mr15836667qkb.2.1713364579638; Wed, 17 Apr 2024 07:36:19 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id wa11-20020a05620a4d0b00b0078ef9ad16adsm1175746qkn.130.2024.04.17.07.36.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 07:36:19 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 11/17] btrfs: push extent lock into run_delalloc_cow Date: Wed, 17 Apr 2024 10:35:55 -0400 Message-ID: <139e8e88fb6e8eb6203ae211b0e7056729e6ed81.1713363472.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This is used by zoned but also as the fallback for uncompressed extents when we fail to compress the ranges. Push the extent lock into run_dealloc_cow(), and adjust the compression case to take the extent lock after calling run_delalloc_cow(). Signed-off-by: Josef Bacik Reviewed-by: Goldwyn Rodrigues --- fs/btrfs/inode.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 9066d248b9aa..b1ae3308ecad 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1167,13 +1167,13 @@ static void submit_one_async_extent(struct async_chunk *async_chunk, if (!(start >= locked_page_end || end <= locked_page_start)) locked_page = async_chunk->locked_page; } - lock_extent(io_tree, start, end, NULL); if (async_extent->compress_type == BTRFS_COMPRESS_NONE) { submit_uncompressed_range(inode, async_extent, locked_page); goto done; } + lock_extent(io_tree, start, end, NULL); ret = btrfs_reserve_extent(root, async_extent->ram_size, async_extent->compressed_size, async_extent->compressed_size, @@ -1722,6 +1722,8 @@ static noinline int run_delalloc_cow(struct btrfs_inode *inode, u64 done_offset = end; int ret; + lock_extent(&inode->io_tree, start, end, NULL); + while (start <= end) { ret = cow_file_range(inode, locked_page, start, end, &done_offset, true, false); @@ -2280,17 +2282,14 @@ int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page run_delalloc_compressed(inode, locked_page, start, end, wbc)) return 1; - /* - * We're unlocked by the different fill functions below. - */ - lock_extent(&inode->io_tree, start, end, NULL); - - if (zoned) + if (zoned) { ret = run_delalloc_cow(inode, locked_page, start, end, wbc, true); - else + } else { + lock_extent(&inode->io_tree, start, end, NULL); ret = cow_file_range(inode, locked_page, start, end, NULL, false, false); + } out: if (ret < 0) From patchwork Wed Apr 17 14:35:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13633472 Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3ED2142651 for ; Wed, 17 Apr 2024 14:36:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364583; cv=none; b=krFWMXUvwt646bKDe18gRt312p32pwd0Q15FuLwfghgQ+Ax7rx0BlQhcMY6bixZE5By0Do1dRGK0cSENsUzm5nAFrWJm4DvLMPUQmUTEYlxtqbNIjs016fY+KBJv8ZvLxz+4nboGuO+14N3ppF69wqGOleeI5T1QMCGBXqZFlvI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364583; c=relaxed/simple; bh=MegFHaX8envyvqos52a//gcW7T/q+ySit9A133rRvaA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KOgEARk1nx4HXVYYMe4mvmwYRmp8B7SIBsdsSQYrpa88dTKFeMOn3MoGE8+E0HBhVnKFkB7mMJtYiIlycP7YeR9SoCJ2dcgKxyuhTPtsBprVt963K359FpordOYP145uJrg371ycH1JJOEykloNmmGyZPFelHIrRkrYG1Au/ITE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=0xwVk1as; arc=none smtp.client-ip=209.85.222.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="0xwVk1as" Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-78f043eaee9so30606085a.3 for ; Wed, 17 Apr 2024 07:36:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713364580; x=1713969380; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=3dpkO6N8nqeOoPP2URG7mI4SGd9cbCu/2Bx0uKnmuSM=; b=0xwVk1asq95PHE7fktvhKFw4lK1ie49ml/7KvbIFg4muu+71V3+PuK/n4fhqf0DamZ Ac7iydJb0pMsNVSMkasf1RNLARHh3ZVYxAV040BUyPTltJaffkM4iYxJedxB3+oUlDpv iuRrcURM+9QKmJVdNQ5niwiWEs6lPaIq7UgLKUdVSX3lMirKLEZVVA2mswaElkCbHnBe NRuuPgUw2IANeKAYm188PcGx2ME0rCyACho903pDUP/sAak6dME4DMCgia+oGvuA4cvr rWK/XzDPTsXA2tClvR58zJXs7rB1QC9aeOasBrcaRnqYWOuLFg3+e7SMHAxMLIrz4a21 iSFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713364580; x=1713969380; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3dpkO6N8nqeOoPP2URG7mI4SGd9cbCu/2Bx0uKnmuSM=; b=gw27Y+qri7E+w3yGYy0V7+jGwHHdXZDodVPYtJ3lOXfsV5dwvFziTLkMGvyfLMKqmr RoATvJOaHxa2ZnbHDxQ+o3YVOOOcMICq06p3W2GyLsfu1qMPLSH3pgboiQCQef0Bh5Dt 4VE7emJVNzrlFsCDe44x1CwDRDmAQyS2jBwWwLpD1l+lmvVFjKhi8cM/vZGQW6e7NxHv GJi28msUDPcBFjJfGqEchPKsWu1SY5gE1iE50ZM9jHaucad/uuMAeM1rtYOF+h2+KqR6 jQKPldSrIuB7Bo0Fj/bo//oU3wMAnuFzZ/4Ldd0msteSjaeVctZwoAhuzmCoHBylgO0U uUnA== X-Gm-Message-State: AOJu0YxXxUHtq/KbtMGFAMJF5yrGojXG5qKzETlai9tGwpxACcisp4dH uvqscNgw0whiDJT8nZYg7y1tfqdFGBs65f0G+hKBZ08zYFXawHey9EqGTNxjGXkHOfN3MoQsqdS W X-Google-Smtp-Source: AGHT+IGk+JSxTwD0wkkw/YjlbOZhL+7gj1eS9NWnZfzmXohr6GPeOLCu1q3LhYaucorWUQczymHw5A== X-Received: by 2002:a05:620a:55a9:b0:78b:bef6:4066 with SMTP id vr9-20020a05620a55a900b0078bbef64066mr18634331qkn.14.1713364580696; Wed, 17 Apr 2024 07:36:20 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id n9-20020ae9c309000000b0078eebee6a49sm2922315qkg.85.2024.04.17.07.36.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 07:36:20 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 12/17] btrfs: push extent lock into cow_file_range Date: Wed, 17 Apr 2024 10:35:56 -0400 Message-ID: <2b350d711be80e83e961082d1e119813e2c7bde0.1713363472.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that cow_file_range is the only function that is called with the range locked, push this call into cow_file_range so we can further narrow the scope. Signed-off-by: Josef Bacik Reviewed-by: Goldwyn Rodrigues --- fs/btrfs/inode.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index b1ae3308ecad..e076b91376a9 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1336,6 +1336,8 @@ static noinline int cow_file_range(struct btrfs_inode *inode, bool extent_reserved = false; int ret = 0; + lock_extent(&inode->io_tree, start, end, NULL); + if (btrfs_is_free_space_inode(inode)) { ret = -EINVAL; goto out_unlock; @@ -1722,8 +1724,6 @@ static noinline int run_delalloc_cow(struct btrfs_inode *inode, u64 done_offset = end; int ret; - lock_extent(&inode->io_tree, start, end, NULL); - while (start <= end) { ret = cow_file_range(inode, locked_page, start, end, &done_offset, true, false); @@ -1744,12 +1744,11 @@ static int fallback_to_cow(struct btrfs_inode *inode, struct page *locked_page, const bool is_reloc_ino = btrfs_is_data_reloc_root(inode->root); const u64 range_bytes = end + 1 - start; struct extent_io_tree *io_tree = &inode->io_tree; + struct extent_state *cached_state = NULL; u64 range_start = start; u64 count; int ret; - lock_extent(io_tree, start, end, NULL); - /* * If EXTENT_NORESERVE is set it means that when the buffered write was * made we had not enough available data space and therefore we did not @@ -1782,6 +1781,7 @@ static int fallback_to_cow(struct btrfs_inode *inode, struct page *locked_page, * group that contains that extent to RO mode and therefore force COW * when starting writeback. */ + lock_extent(io_tree, start, end, &cached_state); count = count_range_bits(io_tree, &range_start, end, range_bytes, EXTENT_NORESERVE, 0, NULL); if (count > 0 || is_space_ino || is_reloc_ino) { @@ -1800,6 +1800,7 @@ static int fallback_to_cow(struct btrfs_inode *inode, struct page *locked_page, clear_extent_bit(io_tree, start, end, EXTENT_NORESERVE, NULL); } + unlock_extent(io_tree, start, end, &cached_state); /* * Don't try to create inline extents, as a mix of inline extent that @@ -2282,14 +2283,12 @@ int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page run_delalloc_compressed(inode, locked_page, start, end, wbc)) return 1; - if (zoned) { + if (zoned) ret = run_delalloc_cow(inode, locked_page, start, end, wbc, true); - } else { - lock_extent(&inode->io_tree, start, end, NULL); + else ret = cow_file_range(inode, locked_page, start, end, NULL, false, false); - } out: if (ret < 0) From patchwork Wed Apr 17 14:35:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13633473 Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFB6514265A for ; Wed, 17 Apr 2024 14:36:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364584; cv=none; b=RDdw24kZz45y29YTAf2b/8chCJCg8X2hYvCsJUu1cJvz4nMwkZVsGnd2Dx/PM42mZrj3sXV1jN7uplfj4NezA63rJFFaV27xLLWGWyAnu0CIL9EnbdlWlumYIxl76qlxEa/+WMCUZao01VoavXv7erYGj3R1ir9Zi9+Ru4MCTxE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364584; c=relaxed/simple; bh=C2pHpaOwxF4Uy/2iPX/OMPprNTSJ5v7TXP/vU49rI3c=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jELncPENreFyKjwIYrq/7Q3dEOuHvEzCV7z8zv1bo9MRzNcdeVoRwoMKkMFQk9P12WSjgIX/+L1f7JsSChdjQPuoVqBecz/KFvA/vW01yX2WO1ipKU4WMGw5/jyHNHr1KlG3YYYMaIbJ8TiiP+g/gi3gUjeLFlfTlbJQxhKaRR8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=2IEm6qCr; arc=none smtp.client-ip=209.85.222.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="2IEm6qCr" Received: by mail-qk1-f176.google.com with SMTP id af79cd13be357-78f0628da1eso17932785a.3 for ; Wed, 17 Apr 2024 07:36:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713364582; x=1713969382; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=/cD7WSdCurTVd5Mm/482ElKQHrN3Ade6v1tp7omUgaQ=; b=2IEm6qCrP2NDkGgoSWtef4xv8DulC5dXKJ8ON60/RKJzO3mIR+uXAJo82nlKOmvhoD wdECbi+RB59fDLY2GABUSS7K3a1Y49SauyNZo23dl+Uw4jp9PTHn+3BLfB+QqCymyxd7 JtMBu24E0ssDuHHAHGb+SAulQvT6mml/b/Zell6/2reSEbqlZVHRpwZ93u/Kd7nIIzep eL1YUvSrrnLrkyNFQs3a5kun6MZVlZzdcqbWy8C3C+1wi+w3ABACOqUg8xrHuhlA7iNY fDmR76TJEvOm/t24ixq84/chaH77ZT99ZpcIbjapeeuhn9Gk8j5cLApZiJvykcASScAm bAiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713364582; x=1713969382; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/cD7WSdCurTVd5Mm/482ElKQHrN3Ade6v1tp7omUgaQ=; b=fsKRy2yaIaMXaqBFUmwuQjea/odLwbjArIVcDVLn5EWlA84t8FACIfxqIjMHZoKPSL WLOg9lgSfv0/WS1d4EdAsoOIdMXXVhhK/xv9AK3eDzZwiu+Jl4IoQymJO8+1z7xsgMK5 MrQvUS3Zq5A2cKy4zrYO3gsJKiz3i/XHGsgGObWUjTFbjUOXVqtpj0ZvZHkPHwPo7ZAf mUcKZBi/FwsJW38M2+6rctgxaXKXVy0LNYh4eoMChtUo1XfDLm82g0FhJf7wufU6UJFu iOddt4RfX4s5TjNkydsqNpFPNradka31kV26oJgoLW9z+d9WP0w7wZGuP/s7LjPo3iUi 5Omg== X-Gm-Message-State: AOJu0YyXzDuM7S8BfVKf8L7YUVkP5+xnQwc3VzYyFmvEAf2QQ96NzuiD 75bepksjRSs7eWfXAMfvwz9VSPug9loNgrYCIUp6B4wGt+yvDlXejp5xTt9BgHNCzR/+fexPWTM I X-Google-Smtp-Source: AGHT+IG+GWnupM/XbrQKHAJcdBtoWlOQT37cEldb32+GdnYoBUqZ9W/5C9WF0qAc3224f299SmHP0g== X-Received: by 2002:a37:e116:0:b0:78d:5f25:ef66 with SMTP id c22-20020a37e116000000b0078d5f25ef66mr18384638qkm.50.1713364581773; Wed, 17 Apr 2024 07:36:21 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id ou5-20020a05620a620500b0078d5b3b5b4asm8473528qkn.125.2024.04.17.07.36.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 07:36:21 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 13/17] btrfs: push lock_extent into cow_file_range_inline Date: Wed, 17 Apr 2024 10:35:57 -0400 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that we've pushed the lock_extent() into cow_file_range() we can push the extent locking into cow_file_range_inline() and move the lock_extent in cow_file_range() to after we call cow_file_range_inline(). Signed-off-by: Josef Bacik Reviewed-by: Goldwyn Rodrigues --- fs/btrfs/inode.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index e076b91376a9..fcad740b1e28 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -744,17 +744,22 @@ static noinline int cow_file_range_inline(struct btrfs_inode *inode, u64 offset, struct folio *compressed_folio, bool update_i_size) { + struct extent_state *cached = NULL; unsigned long clear_flags = EXTENT_DELALLOC | EXTENT_DELALLOC_NEW | EXTENT_DEFRAG | EXTENT_DO_ACCOUNTING | EXTENT_LOCKED; u64 size = min_t(u64, i_size_read(&inode->vfs_inode), end + 1); int ret; + lock_extent(&inode->io_tree, offset, end, &cached); ret = __cow_file_range_inline(inode, offset, size, compressed_size, compress_type, compressed_folio, update_i_size); - if (ret > 0) + if (ret > 0) { + unlock_extent(&inode->io_tree, offset, end, &cached); return ret; + } + free_extent_state(cached); extent_clear_unlock_delalloc(inode, offset, end, NULL, clear_flags, PAGE_UNLOCK | PAGE_START_WRITEBACK | PAGE_END_WRITEBACK); @@ -1028,7 +1033,6 @@ static void compress_file_range(struct btrfs_work *work) * Check cow_file_range() for why we don't even try to create inline * extent for the subpage case. */ - lock_extent(&inode->io_tree, start, end, NULL); if (total_in < actual_end) ret = cow_file_range_inline(inode, start, end, 0, BTRFS_COMPRESS_NONE, NULL, false); @@ -1040,7 +1044,6 @@ static void compress_file_range(struct btrfs_work *work) mapping_set_error(mapping, -EIO); goto free_pages; } - unlock_extent(&inode->io_tree, start, end, NULL); /* * We aren't doing an inline extent. Round the compressed size up to a @@ -1336,8 +1339,6 @@ static noinline int cow_file_range(struct btrfs_inode *inode, bool extent_reserved = false; int ret = 0; - lock_extent(&inode->io_tree, start, end, NULL); - if (btrfs_is_free_space_inode(inode)) { ret = -EINVAL; goto out_unlock; @@ -1367,6 +1368,8 @@ static noinline int cow_file_range(struct btrfs_inode *inode, } } + lock_extent(&inode->io_tree, start, end, NULL); + alloc_hint = get_extent_allocation_hint(inode, start, num_bytes); /* From patchwork Wed Apr 17 14:35:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13633474 Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A95F1428E9 for ; Wed, 17 Apr 2024 14:36:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364585; cv=none; b=FFqly3j4/klRm5UngtbjRF06EP3jErdsMCTYOzzJfAXg71HKQKppG2oE/IWdPiq9m30omq3wRGRjUSCQ648TT05aRliLwgIL65+PqHtc2fhsx5ThFkGuQtBlXaPQTHQt5MzNT9J6lfDgZ67fBMRlMuJk4NNfAGk0Mk7L4ehgaMQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364585; c=relaxed/simple; bh=S4DB2KyL24PDQ3QrHKRE6kBeakEA6gyS7cGLqSjFUfA=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P6uugy2SlF47gBJMD07pw8TqHWn43wUhJKK5Eock/lAi5WZSYge8gWx2Q0apsaGV1q8R5sRbey7h4LknhkgymOaGGbO1LvGxqQMoJIJSyhka70YYimeC/+C9QnVyZvwV/K1gRU+8tX0g8Q2YTrgAuWsZTu7AynjdrA2i4Uf7t2M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=nFEy1zF4; arc=none smtp.client-ip=209.85.219.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="nFEy1zF4" Received: by mail-qv1-f50.google.com with SMTP id 6a1803df08f44-6969388c36fso26104966d6.1 for ; Wed, 17 Apr 2024 07:36:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713364583; x=1713969383; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=ltGptI0NULH55aKTgcoIDOFsYFDmCyE/kf+mo9mKdyQ=; b=nFEy1zF4mGuwBnW806713IDBEWubhEO7hd2zauWN7tOrb2Uf6Fog2QpEbECriwIHe8 VzMfYymt7roj3TOVkl30svYf0WJNRetR+6N94TVypD5F6MB/T6hFOknKw9Pk/W/YLzZz DX1eZo+cuXMG+qv5EgGVYSsdlpSd7/hRfzEOVSv0LAAWsyWD8QXHcB3DSCgvokZv8maI LVH++Sf9OrlUkBksHaie/RZ/R/7VZnwDVsE+/XyAivVTOr0WU5spoK6PpaVwZDWtnYZa jeQJc/UHbr7ziwp9x0tD1MCMnIMsEKowOvWIHhKeqfa+7hPQpn5k8Gjo5HAXENgQttgi 3ZJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713364583; x=1713969383; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ltGptI0NULH55aKTgcoIDOFsYFDmCyE/kf+mo9mKdyQ=; b=TjbcDhyr744NkuOV2amjWpO9ISqeOx6rmQVrf7O1+eLb8I/bCpdgpsYdreGQoIQLxs pOhmqzf+rSjLWl4Ydrwx3149+HpumeIQw9ESEDvu2IbrnWHOSWD/T95sLSRrubEABD1u 73crpDbipc3vJTFlI0qXt46rUbMRTWMkbc2s2g6G/El0B2bmXrXJIXjwhBHvvQEv8sic vZ/vCoIdrrtmcjRPwZXikhthgAxdHn1CDjqO9ntBQT/FDGIulHC+Jgi3+Cl0TQz0iDEq uzxZcmOxYm5m7H+y4sDEjYGnBp5aExNeCXHiWMw45X0okV5SCD9x2qnZCB+uv7QCgQdX pXSQ== X-Gm-Message-State: AOJu0Yx6MJ/DXrEf4FyrY6JtXgtAyPeCWjdZfqB3WEiB3+qcdG/15G7h zoLzQolzUcAn8/89IAkj6COwYpiTfbLLwzt4DocFKA1YnTHF9wS5lePd2HQHHLTDQJqxzzoOyNh / X-Google-Smtp-Source: AGHT+IHBHon1uARnY0WEspELQjNgDm3pAnrT/gZeJD3EYDnM2rPA4l7D5eGgllPhqJeoyzaXz39HHQ== X-Received: by 2002:a0c:f64e:0:b0:699:2754:2e8b with SMTP id s14-20020a0cf64e000000b0069927542e8bmr17580063qvm.39.1713364582917; Wed, 17 Apr 2024 07:36:22 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id e19-20020a056214163300b00691873a7748sm8396643qvw.128.2024.04.17.07.36.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 07:36:22 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 14/17] btrfs: move can_cow_file_range_inline() outside of the extent lock Date: Wed, 17 Apr 2024 10:35:58 -0400 Message-ID: <258a6eaf5c9b672fdadea6264e3fb9b795e1a179.1713363472.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 These checks aren't reliant on the extent lock. Move this up into cow_file_range_inline(), and then update encoded writes to call this check before calling __cow_file_range_inline(). This will allow us to skip the extent lock if we're not able to inline the given extent. Signed-off-by: Josef Bacik Reviewed-by: Goldwyn Rodrigues --- fs/btrfs/inode.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index fcad740b1e28..07bdad6f1be0 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -661,6 +661,9 @@ static bool can_cow_file_range_inline(struct btrfs_inode *inode, * conditionally insert an inline extent into the file. This * does the checks required to make sure the data is small enough * to fit as an inline extent. + * + * If being used directly, you must have already checked we're allowed to cow + * the range by getting true from can_cow_file_range_inline(). */ static noinline int __cow_file_range_inline(struct btrfs_inode *inode, u64 offset, u64 size, size_t compressed_size, @@ -676,9 +679,6 @@ static noinline int __cow_file_range_inline(struct btrfs_inode *inode, u64 offse int ret; struct btrfs_path *path; - if (!can_cow_file_range_inline(inode, offset, size, compressed_size)) - return 1; - path = btrfs_alloc_path(); if (!path) return -ENOMEM; @@ -750,6 +750,9 @@ static noinline int cow_file_range_inline(struct btrfs_inode *inode, u64 offset, u64 size = min_t(u64, i_size_read(&inode->vfs_inode), end + 1); int ret; + if (!can_cow_file_range_inline(inode, offset, size, compressed_size)) + return 1; + lock_extent(&inode->io_tree, offset, end, &cached); ret = __cow_file_range_inline(inode, offset, size, compressed_size, compress_type, compressed_folio, @@ -10250,7 +10253,8 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from, /* Try an inline extent first. */ if (encoded->unencoded_len == encoded->len && - encoded->unencoded_offset == 0) { + encoded->unencoded_offset == 0 && + can_cow_file_range_inline(inode, start, encoded->len, orig_count)) { ret = __cow_file_range_inline(inode, start, encoded->len, orig_count, compression, folios[0], true); From patchwork Wed Apr 17 14:35:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13633475 Received: from mail-qk1-f170.google.com (mail-qk1-f170.google.com [209.85.222.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6AA9714265A for ; Wed, 17 Apr 2024 14:36:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364586; cv=none; b=NyCGNK6xsOSYh0H8GuoKVK5IowKoK6lF54tsjOE6hqOgxEO2ZqxiywNqNMXUDr65QTw3Iiih2PR72Xc7WWQ8oMiQl+ADIpH0nHTDDgXVeM+FZCOfgsDLd+PpkuV7D0C46mIm34bUVAPf/g8paLlTmMcN10xekqpfsshUPamO+EI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364586; c=relaxed/simple; bh=MGTATfq0PPuX1WHLcU2cuFlCB4SjIhuYg5gcTDpSSsw=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uy7GM2zyLSR0BH/Q8B+tekqxazwfOwwPUfYYzWHunCE+ZqmepsEbvwMaiGdWFODaGyfoo5su9w/h2MmzF3188zmq+LnDNWhjeZ3Vjt+FFgkHihEWUJ/6aytjIGUCoi10rR5WAUdtwUDbIT/NaJV8qsVuK1TYfylcvU8vnfDwj1U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=1zjt0FGw; arc=none smtp.client-ip=209.85.222.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="1zjt0FGw" Received: by mail-qk1-f170.google.com with SMTP id af79cd13be357-78f05341128so27524985a.0 for ; Wed, 17 Apr 2024 07:36:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713364584; x=1713969384; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=LMzRYIyEoeGd2D2KPyCGUgzPh7V3w4v3izx882BOpoo=; b=1zjt0FGwrQUgW4dEAsnXGTDtRYPUDe4aOr59pyF9CI+NCymGB8TjRjOtkQjZkxP2wE FjcXegf/iRakFYDYPQDsI/h5KyEvYJQgzEFS5mCoqaPl2lUvly3kbq3THkk6+snIyKRO QCsJPPq25bs9dFk8bUWIIn9TJflpLO4NAHCFatcHkGW6afB4X5sohYSRX/SHq4SbABOd AuK2SSe/e4nXksXJi/C2j4KUn6qUFeB4PaVeOWWtHwxDTVBpBXoJdClNXLJZQrLgPR9h 21iqiqJsEq6DZL3Djz5NPqbmDoId8PUfhz+4NAI6wQOVXlnREvAkEHU3RMegp1k//aIW xY0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713364584; x=1713969384; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LMzRYIyEoeGd2D2KPyCGUgzPh7V3w4v3izx882BOpoo=; b=BW4ChL7+dIGhfFYXvHMNwdzzW9yKy5wqupiDLM2T20uv9zjSMQoUI/4jSpPvvb4cBB o0PyLqYO+m36/zqVk4bUfk8anJT6Y9RQ/WjD5X3RX9Qp3g4rbUtgKgcrMYX9MltmCI/N toQzdGFh7c8p9Vyk7gC138nevtWC1Ir3nwS/gel4G5sWc1Z3i6WoobjrIrZWspBn7ygp 1ZqmukMVva/XP0DamqmwNLpqJdqZzyYDibP0fbWcgaB9n96nfDdvoFLfYpww1/lXXVXw pnBRjEYFw3nEtmxuFF3RmiL++97uEeCGuo9MxC6I2Dyxk54YyU1CXmWmvQj2LRIvROWa hNXw== X-Gm-Message-State: AOJu0YwyWeKRXNGMO5jeN7RaFMhXxOCZiV10X4fmdb/5h2VoGN5rQLcJ ttMjGjq9IaAfysYRscZ2N9NFdxSTxD8UT/xaaSAjy6z6Czcrlf6Ckyc363fAmey0phov8UdevcO V X-Google-Smtp-Source: AGHT+IH4FbYC2bppPjGjTYZ4MWlSIKV9loXpqP5mbqJcM/RW78mVURNReFHKTnxmgUe5ivtj5hL5sA== X-Received: by 2002:a05:620a:471f:b0:78d:777e:c11f with SMTP id bs31-20020a05620a471f00b0078d777ec11fmr22568339qkb.57.1713364584097; Wed, 17 Apr 2024 07:36:24 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id v23-20020a05620a0a9700b0078ebb13a03csm8415405qkg.67.2024.04.17.07.36.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 07:36:23 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 15/17] btrfs: push lock_extent down in cow_file_range() Date: Wed, 17 Apr 2024 10:35:59 -0400 Message-ID: <88e255b855e917caa3ca7c2ffca2f3d974a6cce6.1713363472.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that we've got the extent lock pushed into cow_file_range() we can push it further down into the allocation loop. This allows us to only hold the extent lock during the dropping of the extent map range and inserting the ordered extent. This makes the error case a little trickier as we'll now have to lock the range before clearing any of the other extent bits for the range, but this is the error path so is less performance critical. Signed-off-by: Josef Bacik Reviewed-by: Goldwyn Rodrigues --- fs/btrfs/inode.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 07bdad6f1be0..3cd092fab31d 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1371,8 +1371,6 @@ static noinline int cow_file_range(struct btrfs_inode *inode, } } - lock_extent(&inode->io_tree, start, end, NULL); - alloc_hint = get_extent_allocation_hint(inode, start, num_bytes); /* @@ -1429,6 +1427,9 @@ static noinline int cow_file_range(struct btrfs_inode *inode, extent_reserved = true; ram_size = ins.offset; + + lock_extent(&inode->io_tree, start, start + ram_size - 1, NULL); + em = create_io_em(inode, start, ins.offset, /* len */ start, /* orig_start */ ins.objectid, /* block_start */ @@ -1438,6 +1439,8 @@ static noinline int cow_file_range(struct btrfs_inode *inode, BTRFS_COMPRESS_NONE, /* compress_type */ BTRFS_ORDERED_REGULAR /* type */); if (IS_ERR(em)) { + unlock_extent(&inode->io_tree, start, + start + ram_size - 1, NULL); ret = PTR_ERR(em); goto out_reserve; } @@ -1448,6 +1451,8 @@ static noinline int cow_file_range(struct btrfs_inode *inode, 0, 1 << BTRFS_ORDERED_REGULAR, BTRFS_COMPRESS_NONE); if (IS_ERR(ordered)) { + unlock_extent(&inode->io_tree, start, + start + ram_size - 1, NULL); ret = PTR_ERR(ordered); goto out_drop_extent_cache; } @@ -1549,6 +1554,13 @@ static noinline int cow_file_range(struct btrfs_inode *inode, locked_page, 0, page_ops); } + /* + * At this point we're unlocked, we want to make sure we're only + * clearing these flags under the extent lock, so lock the rest of the + * range and clear everything up. + */ + lock_extent(&inode->io_tree, start, end, NULL); + /* * For the range (2). If we reserved an extent for our delalloc range * (or a subrange) and failed to create the respective ordered extent, From patchwork Wed Apr 17 14:36:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13633476 Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76B031428F3 for ; Wed, 17 Apr 2024 14:36:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364588; cv=none; b=u6m9jaCoLkzRYBOA/lSYE2NFtYx95S3qoUeZwSUJV7RDwIG7HYPqq81OezIUEi/ro/sNT00hQkDl5R+AOT6mRmg5pyTKOZFpQ0SJfxS/Mxdw9jWjHyoL4H2csMTshZTyBpO7RKUZPfko8mCQkY/RAAICc3YiKAyFJjlzVB8u8U4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364588; c=relaxed/simple; bh=KyZvOu16ZqWs/702Es+YMpkmRwVArNyAohDZlUTzrjM=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QurJDLddITGph2QpbjJsuziX/nZyGeefOuYHTQy+3RaUNtXhIU+os8/kTKNuLyMDA1fxZjgRGCw04eS167NDti6cW2Q17gmZf4qFqtnYNjyONGS9kguuE4JPJ88+csapKfWHiMMMPxEzSOBMT2KWG/96DnL1sc6LowHAUYxV4Vw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=IoncvJNJ; arc=none smtp.client-ip=209.85.160.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="IoncvJNJ" Received: by mail-qt1-f174.google.com with SMTP id d75a77b69052e-436ee76c3b8so26997951cf.1 for ; Wed, 17 Apr 2024 07:36:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713364586; x=1713969386; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=4u0YJ37MSHkIvUt2B4ttfLT6tgeoVpo4/XTY5Z/Ue6Q=; b=IoncvJNJmTQ1isyRvZmIrcnP798GtIJuviOWYl5L6PGubEz/qhigsgI0CiQoro0Kv8 O4JDf1y/wvItLYNOARZJ3w2JSb3cMLVq+pAmtqrbGz+3sWA+z3+8UreENTKuddy6CqOK WDjSNWNPxSkWeoZWlORA3q3+IiQx6FJCV2xTiP24VTSV47D4zpHOy361pNyf90LpUI04 aIrIV8rEz4g4ImsFiR9JywHO0Pc3DsTcffZ0W30wTLJX98PdBS/LNkpE9gjGngW/U2YG 53cGXvLkLtG4nurEd4q04FI810ahaaaxCXM/WYS4BPxlo2LcEh5x0RdY4Iwpk/FaslMm C9/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713364586; x=1713969386; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4u0YJ37MSHkIvUt2B4ttfLT6tgeoVpo4/XTY5Z/Ue6Q=; b=dAybvnDyvIda20VCf6IwBGrY/BtASJfpsaJybKCtPrKWHGD3IJ/CdgQWiYw8RF9s/1 kFZ2ikogn79k6rzfJP4gZ1507KnYATRtgNPPBVfGhTkDK0nEa3v7gUefHRi8Vn4DpLUo nezWqdiqHX778/RqNgpNymZU7SP41/s8avbhOZE2Q8IfA1M1fbidz1rK7kBN1OQLiKGi lW407gSmeK5ovn1l/lG4qPvGVNSQQVpJ3FXt8mbyhzGdCz6lkB8mrJCbmeZ+Bi7bctIw UJNCoBb5737kI9TokS3SzsJY0sdRTMZlfkdPueBWfYjyPjV/dtp+MhugVuHpzzb+30jy QMSw== X-Gm-Message-State: AOJu0YxVcoTZx7eLVmMbBx1jUcaR08Gmb3A5MnG/DxLtM9r/1hWgu3/m PoT4iZqmak6P1kXBtMdxNcXBeYFtfBw9uPE3xAqRdLr4uuqnP96TjDxanZrVtoai/dVe2ojs6tD R X-Google-Smtp-Source: AGHT+IH4iD+JkFUn3LRQ+wjVlMxa9OGSGGJJEVM0kV2LgxTK9EXcylH6/vIZocWY9Wb1kyXA9wU7og== X-Received: by 2002:a05:622a:254:b0:437:45b1:a3b0 with SMTP id c20-20020a05622a025400b0043745b1a3b0mr5140216qtx.66.1713364586315; Wed, 17 Apr 2024 07:36:26 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id f16-20020ac86ed0000000b004348d54a873sm8138648qtv.57.2024.04.17.07.36.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 07:36:25 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 16/17] btrfs: push extent lock down in submit_one_async_extent Date: Wed, 17 Apr 2024 10:36:00 -0400 Message-ID: <24251ec51aaea6cd39b22e3969d4e8e2a878808d.1713363472.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We don't need to include the time we spend in the allocator under our extent lock protection, move it after the allocator and make sure we lock the extent in the error case to ensure we're not clearing these bits without the extent lock held. Signed-off-by: Josef Bacik Reviewed-by: Goldwyn Rodrigues --- fs/btrfs/inode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 3cd092fab31d..a96f68f61495 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -1179,7 +1179,6 @@ static void submit_one_async_extent(struct async_chunk *async_chunk, goto done; } - lock_extent(io_tree, start, end, NULL); ret = btrfs_reserve_extent(root, async_extent->ram_size, async_extent->compressed_size, async_extent->compressed_size, @@ -1195,6 +1194,8 @@ static void submit_one_async_extent(struct async_chunk *async_chunk, goto done; } + lock_extent(io_tree, start, end, NULL); + /* Here we're doing allocation and writeback of the compressed pages */ em = create_io_em(inode, start, async_extent->ram_size, /* len */ From patchwork Wed Apr 17 14:36:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13633477 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E91D1420A0 for ; Wed, 17 Apr 2024 14:36:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364590; cv=none; b=e3IWb7yDlCrtsXaOJwrBxRDbEQqQbloLYARTZBqxand332WB4xC7KH7mEzg/VZMNrHb6R1A8LzqtWgM8IBHZjp8tP8db9wr577wHDfbOCERoBWvLU8n99/a/4KzZlK5OVQw0VtcTF/x3S8vxJRGNibRHCZvzeXft2B8khvBswU0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713364590; c=relaxed/simple; bh=Om2AfipYw7ru6GSgAMqWPEQO8Y3gFFZag0Py3INjPoM=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EMJZPGBqAmuzbRjQEUsMeU0ZKWG0LlqgakSAUc/oWyKne7EQ8wXE2Rk8FMrH54XYEjzCkcyvd0iC9r/vNmMO2wiPZBKdZc7+rF+1ieUiDzT7swHdnQBcygM8r1qZDe9j3/SRRqbpqrH0IbyY/DMioljoim52IGn7v577Z0stk3U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com; spf=none smtp.mailfrom=toxicpanda.com; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b=iWRU/aj0; arc=none smtp.client-ip=209.85.222.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=toxicpanda.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toxicpanda-com.20230601.gappssmtp.com header.i=@toxicpanda-com.20230601.gappssmtp.com header.b="iWRU/aj0" Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-78f05afc8d6so22477485a.3 for ; Wed, 17 Apr 2024 07:36:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1713364587; x=1713969387; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=LPTGjQs9Rh0XgjJ58BcQlKVgIL04uXdsncQ+roVpz9Q=; b=iWRU/aj02zN/NyBGVRXUlIu3W9J5SeG4lHqdIfv0VyR+7/SsvDVEbc5Au8LOiBGc0N jlkmLm90cOcAOUNBeT+/X3ziHyCUTlUMunZCcPxnjRPREkaAImyLY5YjVGbN4E3RaseW znpkhr7aKw3u1Qzm7Oicph2eCzmECUs5bijKYBnbwxLCNX/GYwjQJv7DsZwebnzFwJ3a 10ALrOk9ZF+Ss0Nekh2qd94fDm7u4Y4x1FgZIkNJcx0/tHO3hGFDYqtqMc2OFoNgJGyT zO1JUPSteoDxZa5ySPik1i1FRBQc3r8HzfPULlEMNVcQnY1NNs+bj3ydJqH9Daas7WV5 VYBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713364587; x=1713969387; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LPTGjQs9Rh0XgjJ58BcQlKVgIL04uXdsncQ+roVpz9Q=; b=clFNzui0JAqgtPPsGreYlSYSJ78HnH+hP5PgjL2j4SAL6bDiumWMQMlRKPhtxTf+2s UeuwCpoj95HU6vjMVk7LAZENgH8wY2OUtkhuWz5TnxKN81fdPtL4bZ4xDM+wxmgib1SZ hS8skytonIZreepLlwocwlzyV6YXRDf9W0zdY0w7FX8NLqQeE5JR+UVw+VL7T3ZO7Gu9 +D+M+PSo9QV929hvO5vTp6UO/ue0IOGh4eeiYIkHJEZjmbPOiuUCCXSNP5AfqEdGWeBb HJC73Yn3mL2X+wI7kOBrUs21WQ0M3Wd4FMOtYBvJyCgF5zudHpXtKAbecVC1M1Xi4Xo+ iTDw== X-Gm-Message-State: AOJu0YwKG0a7AiV3IXyChS3ObvPKx0/0rKcvRXuXFNMERPlKLxxG0xp3 Z7E16AzB+TqXPPVqXNm4UIpeFBMPOHMWFKQoyBTAheDRnWcNauUj7aGSsyBZWOj6xVfloDZ0Ixo S X-Google-Smtp-Source: AGHT+IELaL6fGLSnZZDbBBvLDpYzwf5LDCYRXkflxiw7mCjmQZbY+zOOw+9PO+i1HsCNhVDuxWqCGA== X-Received: by 2002:a05:620a:370f:b0:78d:579a:29ea with SMTP id de15-20020a05620a370f00b0078d579a29eamr21820076qkb.52.1713364587441; Wed, 17 Apr 2024 07:36:27 -0700 (PDT) Received: from localhost ([76.182.20.124]) by smtp.gmail.com with ESMTPSA id d6-20020a05620a240600b0078d735ca917sm8453081qkn.123.2024.04.17.07.36.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 07:36:27 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 17/17] btrfs: add a cached state to extent_clear_unlock_delalloc Date: Wed, 17 Apr 2024 10:36:01 -0400 Message-ID: <62f3c0fa890b9bebc7f2d1871ec4c885c5287ed5.1713363472.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now that we have the lock_extent tightly coupled with extent_clear_unlock_delalloc we can add a cached state to extent_clear_unlock_delalloc and benefit from skipping the extra lookup when we're doing cow. Signed-off-by: Josef Bacik Reviewed-by: Goldwyn Rodrigues Reviewed-by: Goldwyn Rodrigues --- fs/btrfs/extent_io.c | 3 ++- fs/btrfs/extent_io.h | 2 ++ fs/btrfs/inode.c | 42 ++++++++++++++++++++++++------------------ 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index c09f46f969b1..8ec5f5c7bfe1 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -412,9 +412,10 @@ noinline_for_stack bool find_lock_delalloc_range(struct inode *inode, void extent_clear_unlock_delalloc(struct btrfs_inode *inode, u64 start, u64 end, struct page *locked_page, + struct extent_state **cached, u32 clear_bits, unsigned long page_ops) { - clear_extent_bit(&inode->io_tree, start, end, clear_bits, NULL); + clear_extent_bit(&inode->io_tree, start, end, clear_bits, cached); __process_pages_contig(inode->vfs_inode.i_mapping, locked_page, start, end, page_ops); diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index c81a9b546c9f..e62dc720e1d2 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h @@ -27,6 +27,7 @@ struct address_space; struct writeback_control; struct extent_io_tree; struct extent_map_tree; +struct extent_state; struct btrfs_block_group; struct btrfs_fs_info; struct btrfs_inode; @@ -352,6 +353,7 @@ void clear_extent_buffer_uptodate(struct extent_buffer *eb); void extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end); void extent_clear_unlock_delalloc(struct btrfs_inode *inode, u64 start, u64 end, struct page *locked_page, + struct extent_state **cached, u32 bits_to_clear, unsigned long page_ops); int extent_invalidate_folio(struct extent_io_tree *tree, struct folio *folio, size_t offset); diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index a96f68f61495..7a738ec41095 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -762,8 +762,8 @@ static noinline int cow_file_range_inline(struct btrfs_inode *inode, u64 offset, return ret; } - free_extent_state(cached); - extent_clear_unlock_delalloc(inode, offset, end, NULL, clear_flags, + extent_clear_unlock_delalloc(inode, offset, end, NULL, &cached, + clear_flags, PAGE_UNLOCK | PAGE_START_WRITEBACK | PAGE_END_WRITEBACK); return ret; @@ -1154,6 +1154,7 @@ static void submit_one_async_extent(struct async_chunk *async_chunk, struct btrfs_ordered_extent *ordered; struct btrfs_key ins; struct page *locked_page = NULL; + struct extent_state *cached = NULL; struct extent_map *em; int ret = 0; u64 start = async_extent->start; @@ -1194,7 +1195,7 @@ static void submit_one_async_extent(struct async_chunk *async_chunk, goto done; } - lock_extent(io_tree, start, end, NULL); + lock_extent(io_tree, start, end, &cached); /* Here we're doing allocation and writeback of the compressed pages */ em = create_io_em(inode, start, @@ -1229,7 +1230,7 @@ static void submit_one_async_extent(struct async_chunk *async_chunk, /* Clear dirty, set writeback and unlock the pages. */ extent_clear_unlock_delalloc(inode, start, end, - NULL, EXTENT_LOCKED | EXTENT_DELALLOC, + NULL, &cached, EXTENT_LOCKED | EXTENT_DELALLOC, PAGE_UNLOCK | PAGE_START_WRITEBACK); btrfs_submit_compressed_write(ordered, async_extent->folios, /* compressed_folios */ @@ -1247,7 +1248,8 @@ static void submit_one_async_extent(struct async_chunk *async_chunk, btrfs_free_reserved_extent(fs_info, ins.objectid, ins.offset, 1); mapping_set_error(inode->vfs_inode.i_mapping, -EIO); extent_clear_unlock_delalloc(inode, start, end, - NULL, EXTENT_LOCKED | EXTENT_DELALLOC | + NULL, &cached, + EXTENT_LOCKED | EXTENT_DELALLOC | EXTENT_DELALLOC_NEW | EXTENT_DEFRAG | EXTENT_DO_ACCOUNTING, PAGE_UNLOCK | PAGE_START_WRITEBACK | @@ -1329,6 +1331,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode, { struct btrfs_root *root = inode->root; struct btrfs_fs_info *fs_info = root->fs_info; + struct extent_state *cached = NULL; u64 alloc_hint = 0; u64 orig_start = start; u64 num_bytes; @@ -1429,7 +1432,8 @@ static noinline int cow_file_range(struct btrfs_inode *inode, ram_size = ins.offset; - lock_extent(&inode->io_tree, start, start + ram_size - 1, NULL); + lock_extent(&inode->io_tree, start, start + ram_size - 1, + &cached); em = create_io_em(inode, start, ins.offset, /* len */ start, /* orig_start */ @@ -1441,7 +1445,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode, BTRFS_ORDERED_REGULAR /* type */); if (IS_ERR(em)) { unlock_extent(&inode->io_tree, start, - start + ram_size - 1, NULL); + start + ram_size - 1, &cached); ret = PTR_ERR(em); goto out_reserve; } @@ -1453,7 +1457,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode, BTRFS_COMPRESS_NONE); if (IS_ERR(ordered)) { unlock_extent(&inode->io_tree, start, - start + ram_size - 1, NULL); + start + ram_size - 1, &cached); ret = PTR_ERR(ordered); goto out_drop_extent_cache; } @@ -1493,7 +1497,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode, page_ops |= PAGE_SET_ORDERED; extent_clear_unlock_delalloc(inode, start, start + ram_size - 1, - locked_page, + locked_page, &cached, EXTENT_LOCKED | EXTENT_DELALLOC, page_ops); if (num_bytes < cur_alloc_size) @@ -1552,7 +1556,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode, if (!locked_page) mapping_set_error(inode->vfs_inode.i_mapping, ret); extent_clear_unlock_delalloc(inode, orig_start, start - 1, - locked_page, 0, page_ops); + locked_page, NULL, 0, page_ops); } /* @@ -1575,7 +1579,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode, if (extent_reserved) { extent_clear_unlock_delalloc(inode, start, start + cur_alloc_size - 1, - locked_page, + locked_page, &cached, clear_bits, page_ops); start += cur_alloc_size; @@ -1590,7 +1594,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode, if (start < end) { clear_bits |= EXTENT_CLEAR_DATA_RESV; extent_clear_unlock_delalloc(inode, start, end, locked_page, - clear_bits, page_ops); + &cached, clear_bits, page_ops); } return ret; } @@ -2206,11 +2210,10 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode, btrfs_put_ordered_extent(ordered); extent_clear_unlock_delalloc(inode, cur_offset, nocow_end, - locked_page, EXTENT_LOCKED | - EXTENT_DELALLOC | + locked_page, &cached_state, + EXTENT_LOCKED | EXTENT_DELALLOC | EXTENT_CLEAR_DATA_RESV, PAGE_UNLOCK | PAGE_SET_ORDERED); - free_extent_state(cached_state); cur_offset = extent_end; @@ -2252,10 +2255,13 @@ static noinline int run_delalloc_nocow(struct btrfs_inode *inode, * we're not locked at this point. */ if (cur_offset < end) { - lock_extent(&inode->io_tree, cur_offset, end, NULL); + struct extent_state *cached = NULL; + + lock_extent(&inode->io_tree, cur_offset, end, &cached); extent_clear_unlock_delalloc(inode, cur_offset, end, - locked_page, EXTENT_LOCKED | - EXTENT_DELALLOC | EXTENT_DEFRAG | + locked_page, &cached, + EXTENT_LOCKED | EXTENT_DELALLOC | + EXTENT_DEFRAG | EXTENT_DO_ACCOUNTING, PAGE_UNLOCK | PAGE_START_WRITEBACK | PAGE_END_WRITEBACK);