From patchwork Wed May 22 23:47:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 13671184 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 9D28B7F7D3 for ; Wed, 22 May 2024 23:48:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716421696; cv=none; b=n0ApDjFsSzTusG2BQNYbeqCxZDj2CzixbdID45jpiRMzsJlr102nbPm8dXHM9AMMN4cj4XpKAXZul443WJw6YBxIMHBTtXSngVWXSDvN9WqrNRkuCzw72Kn1eEmgSemP+ZaTNhQGbPU9s/joFw7/AuMfa2L9y8dQSMIrpLjP1p0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716421696; c=relaxed/simple; bh=RURQDYux888r6aWGwcLanPKNl80+tOW41ac6zDQL+pM=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=slv2jnkiKr9oQQQeZB284HeAo7wSLwoQLdO3hbjruw3duAFzGLjQZCeUBy6aZmhCQTQopampa8d7ab9FNxosz/qLhxikAxPXB6welRNNar3vZH4u7m4+BhcK7q4sUKGXJrC+W3YXe6RAS7NN4VS/zUueBgGf3IUihg1r+G4xKYU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=ARN7Uysw; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=ARN7Uysw; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="ARN7Uysw"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="ARN7Uysw" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D2B3121A58 for ; Wed, 22 May 2024 23:48:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1716421691; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6VNVUsmRx6OQhLFTAvizgW16Vujdvv8Hy8uCQ8WMo/E=; b=ARN7Uyswk5B8UTzlE66GExaMRvrXYtW15N/ikNFn/G6sHWCAzYjQsG4RbF1C7ReFZWabQP bPfQEh0hDqUuwbfUs4MoREBMKyLiKe7PaegX+vDd7V6dEO4CCTEQN3ayqt8b+aA2SsH2qg NtIcvuwnK8u6IHQjBa8BLeCSHzcK/4s= Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1716421691; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6VNVUsmRx6OQhLFTAvizgW16Vujdvv8Hy8uCQ8WMo/E=; b=ARN7Uyswk5B8UTzlE66GExaMRvrXYtW15N/ikNFn/G6sHWCAzYjQsG4RbF1C7ReFZWabQP bPfQEh0hDqUuwbfUs4MoREBMKyLiKe7PaegX+vDd7V6dEO4CCTEQN3ayqt8b+aA2SsH2qg NtIcvuwnK8u6IHQjBa8BLeCSHzcK/4s= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id E1F0B13A1E for ; Wed, 22 May 2024 23:48:10 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id MK3dJjqETmb6aQAAD6G6ig (envelope-from ) for ; Wed, 22 May 2024 23:48:10 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 1/3] btrfs: move extent_range_clear_dirty_for_io() into inode.c Date: Thu, 23 May 2024 09:17:45 +0930 Message-ID: <6716c0d1d29bb197a72b59fbbc167571afb4c04d.1716421534.git.wqu@suse.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Flag: NO X-Spam-Score: -2.80 X-Spam-Level: X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[linux-btrfs@vger.kernel.org]; RCVD_TLS_ALL(0.00)[] The function is only utilized inside inode.c by compress_file_range(), so move it to inode.c and unexport it. Signed-off-by: Qu Wenruo --- fs/btrfs/extent_io.c | 15 --------------- fs/btrfs/extent_io.h | 1 - fs/btrfs/inode.c | 15 +++++++++++++++ 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 7275bd919a3e..4af16c09dd88 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -164,21 +164,6 @@ void __cold extent_buffer_free_cachep(void) kmem_cache_destroy(extent_buffer_cache); } -void extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end) -{ - unsigned long index = start >> PAGE_SHIFT; - unsigned long end_index = end >> PAGE_SHIFT; - struct page *page; - - while (index <= end_index) { - page = find_get_page(inode->i_mapping, index); - BUG_ON(!page); /* Pages should be in the extent_io_tree */ - clear_page_dirty_for_io(page); - put_page(page); - index++; - } -} - static void process_one_page(struct btrfs_fs_info *fs_info, struct page *page, struct page *locked_page, unsigned long page_ops, u64 start, u64 end) diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h index dca6b12769ec..7c2f1bbc6b67 100644 --- a/fs/btrfs/extent_io.h +++ b/fs/btrfs/extent_io.h @@ -350,7 +350,6 @@ void extent_buffer_bitmap_clear(const struct extent_buffer *eb, void set_extent_buffer_dirty(struct extent_buffer *eb); void set_extent_buffer_uptodate(struct extent_buffer *eb); 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, diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 000809e16aba..99be256f4f0e 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -890,6 +890,21 @@ static inline void inode_should_defrag(struct btrfs_inode *inode, btrfs_add_inode_defrag(NULL, inode, small_write); } +static void extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end) +{ + unsigned long index = start >> PAGE_SHIFT; + unsigned long end_index = end >> PAGE_SHIFT; + struct page *page; + + while (index <= end_index) { + page = find_get_page(inode->i_mapping, index); + BUG_ON(!page); /* Pages should be in the extent_io_tree */ + clear_page_dirty_for_io(page); + put_page(page); + index++; + } +} + /* * Work queue call back to started compression on a file and pages. * From patchwork Wed May 22 23:47:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 13671185 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 5403D14C59C for ; Wed, 22 May 2024 23:48:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716421697; cv=none; b=kTdsG5Sm76Xf9Rez3quq/APTxt9sGR4Ywdm5Gdqq56CoIcBbUMpJZ2tvWmQuF3qHlRMbKgLaIOVmxV+weziagad5qio+4WNrNH95nYx0PGyG/9bba0kLRlue+UJld3aarHbxD6J9WEY7gm/DGIhE489ma7MZ4TOXHcJR89oU7W0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716421697; c=relaxed/simple; bh=zUahOkCAOb5EtrE5fPSuhJP/sUJvNm6ruMe8apide5U=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IhMEI+/D+of+idpmmX2J9hGMixO9sF7CInoXgVnSTJt7AD9mug4gpTfQDHffGen+M9e7Us01oyFfBcQsq5opvOU5a4NVJRYWMzyKj7X6eo4/48joBEGyHIoFhPwdZMsCM40xpMEDT2M+1eETWYrA+dcXf86G9JAHjGWf+bp2eew= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=qqLG9Y6c; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=qqLG9Y6c; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="qqLG9Y6c"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="qqLG9Y6c" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 6C1211FB9C for ; Wed, 22 May 2024 23:48:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1716421693; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Vf/ab0rZDMvXX51qLkC9PvHoxs4La8lp7AlaCYA/Wb8=; b=qqLG9Y6cLTu5VgCi9KQph/IbGAdt3ft9qNg48mP+ASuJL9+f3ZHdzz1opHkeQmJwJNrfNX ip30U1uF6KKXVoU768Ll9STVKQF3AgFQ2SwQNo23utJqmMavHA7byUF7tEHhTgBcH2B2j+ YfM+hqiyDXL9BEhOxEl4GnSex0qXPWI= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1716421693; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Vf/ab0rZDMvXX51qLkC9PvHoxs4La8lp7AlaCYA/Wb8=; b=qqLG9Y6cLTu5VgCi9KQph/IbGAdt3ft9qNg48mP+ASuJL9+f3ZHdzz1opHkeQmJwJNrfNX ip30U1uF6KKXVoU768Ll9STVKQF3AgFQ2SwQNo23utJqmMavHA7byUF7tEHhTgBcH2B2j+ YfM+hqiyDXL9BEhOxEl4GnSex0qXPWI= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 7F73813A1E for ; Wed, 22 May 2024 23:48:12 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 6LCwCzyETmb6aQAAD6G6ig (envelope-from ) for ; Wed, 22 May 2024 23:48:12 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 2/3] btrfs: make extent_range_clear_dirty_for_io() subpage compatible Date: Thu, 23 May 2024 09:17:46 +0930 Message-ID: <015a4a2c7afb8ed894f4fb734cb886f01b9feb0c.1716421534.git.wqu@suse.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-2.13 / 50.00]; BAYES_HAM(-2.33)[96.88%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[linux-btrfs@vger.kernel.org]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.13 X-Spam-Flag: NO Although the function is never called for subpage ranges, there is no harm to make it subpage compatible for the future sector perfect subpage compression support. And since we're here, also change it to use folio APIs as the subpage helper is already folio based. Signed-off-by: Qu Wenruo --- fs/btrfs/inode.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 99be256f4f0e..dda47a273813 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -892,15 +892,20 @@ static inline void inode_should_defrag(struct btrfs_inode *inode, static void extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end) { + struct btrfs_fs_info *fs_info = inode_to_fs_info(inode); + const u64 len = end + 1 - start; unsigned long index = start >> PAGE_SHIFT; unsigned long end_index = end >> PAGE_SHIFT; - struct page *page; + /* We should not have such large range. */ + ASSERT(len < U32_MAX); while (index <= end_index) { - page = find_get_page(inode->i_mapping, index); - BUG_ON(!page); /* Pages should be in the extent_io_tree */ - clear_page_dirty_for_io(page); - put_page(page); + struct folio *folio; + + folio = filemap_get_folio(inode->i_mapping, index); + BUG_ON(IS_ERR(folio)); /* Pages should have been locked. */ + btrfs_folio_clamp_clear_dirty(fs_info, folio, start, len); + folio_put(folio); index++; } } From patchwork Wed May 22 23:47:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 13671186 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (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 CCD7014C5BF for ; Wed, 22 May 2024 23:48:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716421698; cv=none; b=olpobGvi2MaBUwm4mTFCS6IRnt6HRV7a4iMHkrGjEuo/pjduf4ua7qZYNe5HQ1h+f6q3QjYGBjtXuvu6VR1Fh4lPuTS3aVHznwU586gGgSJpm/gnb2SnSzgc0xfhdFeqbe9fCL/wVCstKJysl1Jc92eqZfSxtQlduPYduHCkL90= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716421698; c=relaxed/simple; bh=HRgYvZg+6n6aYzXHV4jo8tLCY5yWQaJNyTy543B4I7Y=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S71881jxDFUyhHPWzHYu6WEuhaK+jGzqbssAhzsiFFbQo3DmDnPgDlMD6BKHMtCZSwQj5ES6giPkKYUQ5em8bXRhBCh3vaAM4a7FT5Lh4XUY3p6UnkgMvpIi6urMUq+kMefN/zMPzDoSWfQfa9+h/XBRFeVQJy0M8iLA0NbBv30= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=U3n6rpT+; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b=U3n6rpT+; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="U3n6rpT+"; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="U3n6rpT+" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 0128221A2F for ; Wed, 22 May 2024 23:48:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1716421695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KVDf8PK66sR9MaDx73uAjx1lTiyvLJgIc+eHfxXT5CI=; b=U3n6rpT+0yBN5MJe9LVoCkVW++QfnLXzSad++rx3bpEpRKvPn4uEovi/Y796lgE7rd/2XX ZweYUkdeGLXWI14qQNoxlAlOkY9PlUkXcqI3S5E92gl7poUVUB5LAmB5sK1iJejotFU41v AeeOr+PEsuRxbxY+/EjoJo01lvLBvV4= Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=U3n6rpT+ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1716421695; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KVDf8PK66sR9MaDx73uAjx1lTiyvLJgIc+eHfxXT5CI=; b=U3n6rpT+0yBN5MJe9LVoCkVW++QfnLXzSad++rx3bpEpRKvPn4uEovi/Y796lgE7rd/2XX ZweYUkdeGLXWI14qQNoxlAlOkY9PlUkXcqI3S5E92gl7poUVUB5LAmB5sK1iJejotFU41v AeeOr+PEsuRxbxY+/EjoJo01lvLBvV4= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 0E3B913A1E for ; Wed, 22 May 2024 23:48:13 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 2AO5KT2ETmb6aQAAD6G6ig (envelope-from ) for ; Wed, 22 May 2024 23:48:13 +0000 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 3/3] btrfs: remove the BUG_ON() inside extent_range_clear_dirty_for_io() Date: Thu, 23 May 2024 09:17:47 +0930 Message-ID: <167cb36269f6f08bf0e14d8a564ad75a62c102a8.1716421534.git.wqu@suse.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_ONE(0.00)[1]; RCVD_VIA_SMTP_AUTH(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:dkim,suse.com:email]; DNSWL_BLOCKED(0.00)[2a07:de40:b281:104:10:150:64:97:from,2a07:de40:b281:106:10:150:64:167:received]; PREVIOUSLY_DELIVERED(0.00)[linux-btrfs@vger.kernel.org]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RCVD_TLS_ALL(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.com:+] X-Rspamd-Action: no action X-Rspamd-Queue-Id: 0128221A2F X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Flag: NO X-Spam-Score: -3.01 Previously we have BUG_ON() inside extent_range_clear_dirty_for_io(), as we expect all involved folios are still locked, thus no folio should be missing. However for extent_range_clear_dirty_for_io() itself, we can skip the missing folio and handling the remaining ones, and return an error if there is anything wrong. So this patch would remove the BUG_ON() and let the caller to handle the error. In the caller we do not have a quick way to cleanup the error, but all the compression routines would handle the missing folio as an error and properly error out, so we only need to do an ASSERT() for developers, meanwhile for non-debug build the compression routine would handle the error correctly. Signed-off-by: Qu Wenruo --- fs/btrfs/inode.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index dda47a273813..18b833e58d19 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -890,24 +890,29 @@ static inline void inode_should_defrag(struct btrfs_inode *inode, btrfs_add_inode_defrag(NULL, inode, small_write); } -static void extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end) +static int extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end) { struct btrfs_fs_info *fs_info = inode_to_fs_info(inode); const u64 len = end + 1 - start; - unsigned long index = start >> PAGE_SHIFT; unsigned long end_index = end >> PAGE_SHIFT; + int ret = 0; /* We should not have such large range. */ ASSERT(len < U32_MAX); - while (index <= end_index) { + for (unsigned long index = start >> PAGE_SHIFT; + index <= end_index; index++) { struct folio *folio; folio = filemap_get_folio(inode->i_mapping, index); - BUG_ON(IS_ERR(folio)); /* Pages should have been locked. */ + if (IS_ERR(folio)) { + if (!ret) + ret = PTR_ERR(folio); + continue; + } btrfs_folio_clamp_clear_dirty(fs_info, folio, start, len); folio_put(folio); - index++; } + return ret; } /* @@ -951,7 +956,16 @@ static void compress_file_range(struct btrfs_work *work) * Otherwise applications with the file mmap'd can wander in and change * the page contents while we are compressing them. */ - extent_range_clear_dirty_for_io(&inode->vfs_inode, start, end); + ret = extent_range_clear_dirty_for_io(&inode->vfs_inode, start, end); + + /* + * All the folios should have been locked thus no failure. + * + * And even some folios are missing, btrfs_compress_folios() + * would handle them correctly, so here just do an ASSERT() check for + * early logic errors. + */ + ASSERT(ret == 0); /* * We need to save i_size before now because it could change in between