From patchwork Tue Aug 20 16:06:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13770438 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD1481AD9D9 for ; Tue, 20 Aug 2024 16:07:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724170047; cv=none; b=EXMXg6244CJEFh7rnlOu89fm35AhhEzxpMAhtZGoJPY8Ya8raZ5BkB/gD/0wrMu8OZlQ4t1V9Q83gFFwVl02wfUQQK9mn8zmdAkpq7cOzkRlefnj6YwC5WS723StE2m63mtJHJWKlnm6LBcBTJGtFe01x8kPXG8h0Dx3TASFjZ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724170047; c=relaxed/simple; bh=wfrOhSbGNbWhAZAXg1FilaXtrweZe6ZJJcqAlAoMrMo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YaW8wsrgqaDUQ/SOfcVQ3F261O2RNrFQFzzyiM2CqZ051YzOAXmzln9AZmB9uY8QP5XScYNQ4zu217vzseE/jEDu+aiqzQGG8fxVc0l/XvEMW58NvLdjwgZDK6ReRC6ST8PEq3cdnXJnqJQ6xI1+RKXloWN8WqS80zhVYCquU7g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eIb3T/oC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eIb3T/oC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 448A9C4AF0F; Tue, 20 Aug 2024 16:07:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724170046; bh=wfrOhSbGNbWhAZAXg1FilaXtrweZe6ZJJcqAlAoMrMo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eIb3T/oCyaM4iwAcyDp9gelOVRTlpMZ/6y9K5W3hQ6uLN1mNaSx7U/DDgBPQMDY0q fmZ390PRYCDN8ZqsaPUoP8MXTHi+rDb51Bkhpw2VJmh/EFwGFfwA2oTFmH4628UXls qccWtTflq18yqyClbUy/B1+woEUhU6XAyTSWMQLLFa2bDEf22TbAF2cn+xoy9cW0ew 4EMiNUDkpP3V7gFrRIy57jfAsVQu9hZZ3JAZNGzY0m7nxBLibHaDLDbv4kccGKFTZg LM8K9Bx023aFdRHyLhKQg/xask7TD5Jm0DnLcNdRfra5zWRgtHBQNtriaIyughQWJJ poSYtd9/TeFXg== From: Christian Brauner To: Linus Torvalds Cc: Christian Brauner , NeilBrown , Peter Zijlstra , Ingo Molnar , Jeff Layton , Jan Kara , linux-fsdevel@vger.kernel.org Subject: [PATCH RFC 1/5] fs: add i_state helpers Date: Tue, 20 Aug 2024 18:06:54 +0200 Message-ID: <20240820-work-i_state-v1-1-794360714829@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240820-work-i_state-v1-0-794360714829@kernel.org> References: <20240820-work-i_state-v1-0-794360714829@kernel.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.15-dev-37811 X-Developer-Signature: v=1; a=openpgp-sha256; l=2138; i=brauner@kernel.org; h=from:subject:message-id; bh=wfrOhSbGNbWhAZAXg1FilaXtrweZe6ZJJcqAlAoMrMo=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaQd2a+gVbq9IU2aj9OH85GDX+eUZXsO3m3q1NvXYloTy WNi4H2qo5SFQYyLQVZMkcWh3SRcbjlPxWajTA2YOaxMIEMYuDgFYCIK/xj+SrBPbGSo1OAR2FHn 06RTYlVocWemycr48w8W+FQFv3PbzPBPpfj9Fp8ww8TNnfcEOjyXv3mtNPF/vNXR8ssLD+wwD1z DCwA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 The i_state member is an unsigned long so that it can be used with the wait bit infrastructure which expects unsigned long. This wastes 4 bytes which we're unlikely to ever use. Switch to using the var event wait mechanism using the address of the bit. Thanks to Linus for the address idea. Signed-off-by: Christian Brauner --- fs/inode.c | 11 +++++++++++ include/linux/fs.h | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/fs/inode.c b/fs/inode.c index 154f8689457f..d0f614677798 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -472,6 +472,17 @@ static void __inode_add_lru(struct inode *inode, bool rotate) inode->i_state |= I_REFERENCED; } +struct wait_queue_head *inode_bit_waitqueue(struct wait_bit_queue_entry *wqe, + struct inode *inode, int bit); +{ + struct wait_queue_head *wq_head; + void *bit_address; + + bit_address = inode_state_wait_address(inode, __I_SYNC); + init_wait_var_entry(wqe, bit_address, 0); + return __var_waitqueue(bit_address); +} + /* * Add inode to LRU if needed (inode is unused and clean). * diff --git a/include/linux/fs.h b/include/linux/fs.h index 23e7d46b818a..f854f83e91af 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -744,6 +744,22 @@ struct inode { void *i_private; /* fs or device private pointer */ } __randomize_layout; +/* + * Get bit address from inode->i_state to use with wait_var_event() + * infrastructre. + */ +#define inode_state_wait_address(inode, bit) ((char *)&(inode)->i_state + (bit)) + +struct wait_queue_head *inode_bit_waitqueue(struct wait_bit_queue_entry *wqe, + struct inode *inode, int bit); + +static inline void inode_wake_up_bit(struct inode *inode, unsigned int bit) +{ + /* Ensure @bit will be seen cleared/set when caller is woken up. */ + smp_mb(); + wake_up_var(inode_state_wait_address(inode, bit)); +} + struct timespec64 timestamp_truncate(struct timespec64 t, struct inode *inode); static inline unsigned int i_blocksize(const struct inode *node) From patchwork Tue Aug 20 16:06:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13770439 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1DB161B8E9E for ; Tue, 20 Aug 2024 16:07:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724170049; cv=none; b=TRxu4KYtsqlZxx4672AbQNRcy0YJCcyrLvd70iq7foAMWr18nHz1l32I6e0Z3pgN+4Icpi6oBlt15RxvhnmuK4TAr1lIkxbtDVm7cGxzxK1UfCLTfnoQ2QS5ZTEfbuUYUxXNRMfV/FuxcvDMtRcaNEBiNwQ2NbExlve0tmkXQqo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724170049; c=relaxed/simple; bh=VCSkbbH6FAb5Kc1A8Ex+KDjB6tcNSXukDqw5rZQc1lI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=svx42b3oEnFmNqnlEOp81hUCNCh7/4r4313O/D/aWIo6CvJ9Gza/GeVIE0TsGeg5dc7pHRQY0ZVMqcY9kKfUiWlOnUsGZkN6S7UY7501m1Jqul725X28UPEcYmWcNXcjGhU8IdnyWiXGgwugrtC4gcOq1sFTZUiO3fdonEcOJoo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QGrQb7E2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QGrQb7E2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AEDEDC4AF14; Tue, 20 Aug 2024 16:07:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724170048; bh=VCSkbbH6FAb5Kc1A8Ex+KDjB6tcNSXukDqw5rZQc1lI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QGrQb7E2o6+xqA2BKGDMlRmvHY814PiRwTd8Ht0BdvkF6HawVZ5j9mIQ5u7aDHAV8 qm04rio5Jj2xmr6uuj5GPelNNeCOYxqm1CLq9zsLGcFK7PI4SLs8G6P1i2QhC44ihe iKCqdIyyp1WYzzV1gvvQn4JIsZdPxVdBsbSLIO2MmE0ZIj4+zkY5lCo9izmpBvPuw+ dpy8l5PhcAiug46cX831wbLJNaycTxjkEtotzES+oTfaYM3+wPjovbwh3QvfMHy8c3 vmslFv0Iky9+yMiAEToZD5bgcEj/qby0e5a29G6IDaoK0posGg4bdC+TgvN0m3vjKd wYSWslz7ElmPw== From: Christian Brauner To: Linus Torvalds Cc: Christian Brauner , NeilBrown , Peter Zijlstra , Ingo Molnar , Jeff Layton , Jan Kara , linux-fsdevel@vger.kernel.org Subject: [PATCH RFC 2/5] writeback: port __I_SYNC to var event Date: Tue, 20 Aug 2024 18:06:55 +0200 Message-ID: <20240820-work-i_state-v1-2-794360714829@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240820-work-i_state-v1-0-794360714829@kernel.org> References: <20240820-work-i_state-v1-0-794360714829@kernel.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.15-dev-37811 X-Developer-Signature: v=1; a=openpgp-sha256; l=2530; i=brauner@kernel.org; h=from:subject:message-id; bh=VCSkbbH6FAb5Kc1A8Ex+KDjB6tcNSXukDqw5rZQc1lI=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaQd2a9wwUVZeNJOszqRPsHbZV3/X3Qcn+G7c5crT6dBw WRVo+nzOkpZGMS4GGTFFFkc2k3C5ZbzVGw2ytSAmcPKBDKEgYtTACYSYcvIMKnwqV5F/qvWI61S opNmNnx4aHFvydY9bbwM13bv/155souR4VXF3p77ley1CbGrzeIu1vS+Fd/R47XGZMEOt9tL/i3 8yQwA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Port the __I_SYNC mechanism to use the new var event mechanism. Signed-off-by: Christian Brauner --- fs/fs-writeback.c | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index 1a5006329f6f..3619c86273a4 100644 --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c @@ -1389,9 +1389,7 @@ static void inode_sync_complete(struct inode *inode) inode->i_state &= ~I_SYNC; /* If inode is clean an unused, put it into LRU now... */ inode_add_lru(inode); - /* Waiters must see I_SYNC cleared before being woken up */ - smp_mb(); - wake_up_bit(&inode->i_state, __I_SYNC); + inode_wake_up_bit(inode, __I_SYNC); } static bool inode_dirtied_after(struct inode *inode, unsigned long t) @@ -1512,17 +1510,21 @@ static int write_inode(struct inode *inode, struct writeback_control *wbc) */ void inode_wait_for_writeback(struct inode *inode) { - DEFINE_WAIT_BIT(wq, &inode->i_state, __I_SYNC); - wait_queue_head_t *wqh; + struct wait_bit_queue_entry wqe; + struct wait_queue_head *wq_head; - lockdep_assert_held(&inode->i_lock); - wqh = bit_waitqueue(&inode->i_state, __I_SYNC); - while (inode->i_state & I_SYNC) { - spin_unlock(&inode->i_lock); - __wait_on_bit(wqh, &wq, bit_wait, - TASK_UNINTERRUPTIBLE); - spin_lock(&inode->i_lock); + wq_head = inode_bit_waitqueue(&wqe, inode, __I_SYNC); + for (;;) { + prepare_to_wait_event(wq_head, &wqe.wq_entry, TASK_UNINTERRUPTIBLE); + if (inode->i_state & I_SYNC) { + spin_unlock(&inode->i_lock); + schedule(); + spin_lock(&inode->i_lock); + continue; + } + break; } + finish_wait(wq_head, &wqe.wq_entry); } /* @@ -1533,16 +1535,17 @@ void inode_wait_for_writeback(struct inode *inode) static void inode_sleep_on_writeback(struct inode *inode) __releases(inode->i_lock) { - DEFINE_WAIT(wait); - wait_queue_head_t *wqh = bit_waitqueue(&inode->i_state, __I_SYNC); - int sleep; + struct wait_bit_queue_entry wqe; + struct wait_queue_head *wq_head; + bool sleep; - prepare_to_wait(wqh, &wait, TASK_UNINTERRUPTIBLE); - sleep = inode->i_state & I_SYNC; + wq_head = inode_bit_waitqueue(&wqe, inode, __I_SYNC); + prepare_to_wait_event(wq_head, &wqe.wq_entry, TASK_UNINTERRUPTIBLE); + sleep = !!(inode->i_state & I_SYNC); spin_unlock(&inode->i_lock); if (sleep) schedule(); - finish_wait(wqh, &wait); + finish_wait(wq_head, &wqe.wq_entry); } /* From patchwork Tue Aug 20 16:06:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13770440 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92A70192B83 for ; Tue, 20 Aug 2024 16:07:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724170052; cv=none; b=muRDkmI6+uWYmq+/6gde2OnGtdhF43tqTB6gZ44kg/Fqm8y+XozD7FIEMWuQ1/aR/nn/kSPKsle0jJCIBSMS2xmJNGZyqikMAirPNtzjXaoO7AJiC6NNHvuxctd1w5+MCX7YyBBHkold+LmfiTapDfxYhSchsZY8NPOctiLtE/I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724170052; c=relaxed/simple; bh=eguI6DtuiOl8/KnPYK2EPLl82uVmWoDPvYHtdJIgj2M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IwHFOJISDRkI2AOus240ETLOi8ekTbsZZ3xD0EDYiBAe6ZpUWsr1WK+oUqG902LDbfb45giwNmWp5HkOJGsTqYEEpt06Y2ihkkH25SHcTyNV7a2XhMbB6N8JBCOmfdNmVGsH58tx12vC65oTYiREYo7kM5GQaEFlXZghTF2MB9U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BDPtKdSI; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BDPtKdSI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1AF4BC4AF11; Tue, 20 Aug 2024 16:07:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724170051; bh=eguI6DtuiOl8/KnPYK2EPLl82uVmWoDPvYHtdJIgj2M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BDPtKdSITkfegjz4j3TxlB59xWKjgqHkoDparhjI8RYGNDUZfPy8hGuiCCewjk9sq NYcylWZ/I5sj7wQpuIz3c1HHJlcsuWIrWfggbdnJSOSv7brgiOrL8bouQOsCS5zYCj RBH3U28NY36wtaPn7M9NTvs41iATWIwmLP/W9lAWLLmGrfT1ImSF/6wSYrc/GYqT+9 UDcGlNhg4xv8bWgRf94IRMfZkyXDv5iybRK9A7/SeMbvJus99ll+OcoADC9F9YkYpx n8XJi+BPHrmLgKiJUTgIMU7UQsyT+AHf0dwlgDnTQaZbhWKjKr02/JQUg99IJZU47Z t8+8D9xbi3sCA== From: Christian Brauner To: Linus Torvalds Cc: Christian Brauner , NeilBrown , Peter Zijlstra , Ingo Molnar , Jeff Layton , Jan Kara , linux-fsdevel@vger.kernel.org Subject: [PATCH RFC 3/5] inode: port __I_NEW to var event Date: Tue, 20 Aug 2024 18:06:56 +0200 Message-ID: <20240820-work-i_state-v1-3-794360714829@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240820-work-i_state-v1-0-794360714829@kernel.org> References: <20240820-work-i_state-v1-0-794360714829@kernel.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.15-dev-37811 X-Developer-Signature: v=1; a=openpgp-sha256; l=4448; i=brauner@kernel.org; h=from:subject:message-id; bh=eguI6DtuiOl8/KnPYK2EPLl82uVmWoDPvYHtdJIgj2M=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaQd2a/YmKQz6+YW+wb13tN6z8Ql9VcffLLHh+ef0tH5c vkvnSff7ChlYRDjYpAVU2RxaDcJl1vOU7HZKFMDZg4rE8gQBi5OAZjIrwCGvxIsxskNzUpvdBeV TxVYvvTU299CJ04yxzEfZevf6PVm9SNGhjsZLOf7eLZGCsyY4rD08az1XMc6DRnv+9oyzkycs1h WjRsA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Port the __I_NEW mechanism to use the new var event mechanism. Signed-off-by: Christian Brauner --- fs/bcachefs/fs.c | 10 ++++++---- fs/dcache.c | 3 +-- fs/inode.c | 18 ++++++++---------- include/linux/writeback.h | 3 ++- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/fs/bcachefs/fs.c b/fs/bcachefs/fs.c index 94c392abef65..8575aedb9fde 100644 --- a/fs/bcachefs/fs.c +++ b/fs/bcachefs/fs.c @@ -1644,14 +1644,16 @@ void bch2_evict_subvolume_inodes(struct bch_fs *c, snapshot_id_list *s) break; } } else if (clean_pass && this_pass_clean) { - wait_queue_head_t *wq = bit_waitqueue(&inode->v.i_state, __I_NEW); - DEFINE_WAIT_BIT(wait, &inode->v.i_state, __I_NEW); + struct wait_bit_queue_entry wqe; + struct wait_queue_head *wq_head; - prepare_to_wait(wq, &wait.wq_entry, TASK_UNINTERRUPTIBLE); + wq_head = inode_bit_waitqueue(&wqe, inode, __I_NEW); + prepare_to_wait_event(wq_head, &wqe.wq_entry, + TASK_UNINTERRUPTIBLE); mutex_unlock(&c->vfs_inodes_lock); schedule(); - finish_wait(wq, &wait.wq_entry); + finish_wait(wq_head, &wqe.wq_entry); goto again; } } diff --git a/fs/dcache.c b/fs/dcache.c index 1af75fa68638..7037f9312ed4 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -1908,8 +1908,7 @@ void d_instantiate_new(struct dentry *entry, struct inode *inode) __d_instantiate(entry, inode); WARN_ON(!(inode->i_state & I_NEW)); inode->i_state &= ~I_NEW & ~I_CREATING; - smp_mb(); - wake_up_bit(&inode->i_state, __I_NEW); + inode_wake_up_bit(inode, __I_NEW); spin_unlock(&inode->i_lock); } EXPORT_SYMBOL(d_instantiate_new); diff --git a/fs/inode.c b/fs/inode.c index d0f614677798..d9e119b5eeef 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -734,7 +734,7 @@ static void evict(struct inode *inode) * used as an indicator whether blocking on it is safe. */ spin_lock(&inode->i_lock); - wake_up_bit(&inode->i_state, __I_NEW); + inode_wake_up_bit(inode, __I_NEW); BUG_ON(inode->i_state != (I_FREEING | I_CLEAR)); spin_unlock(&inode->i_lock); @@ -1142,8 +1142,7 @@ void unlock_new_inode(struct inode *inode) spin_lock(&inode->i_lock); WARN_ON(!(inode->i_state & I_NEW)); inode->i_state &= ~I_NEW & ~I_CREATING; - smp_mb(); - wake_up_bit(&inode->i_state, __I_NEW); + inode_wake_up_bit(inode, __I_NEW); spin_unlock(&inode->i_lock); } EXPORT_SYMBOL(unlock_new_inode); @@ -1154,8 +1153,7 @@ void discard_new_inode(struct inode *inode) spin_lock(&inode->i_lock); WARN_ON(!(inode->i_state & I_NEW)); inode->i_state &= ~I_NEW; - smp_mb(); - wake_up_bit(&inode->i_state, __I_NEW); + inode_wake_up_bit(inode, __I_NEW); spin_unlock(&inode->i_lock); iput(inode); } @@ -2344,8 +2342,8 @@ EXPORT_SYMBOL(inode_needs_sync); */ static void __wait_on_freeing_inode(struct inode *inode, bool is_inode_hash_locked) { - wait_queue_head_t *wq; - DEFINE_WAIT_BIT(wait, &inode->i_state, __I_NEW); + struct wait_bit_queue_entry wqe; + struct wait_queue_head *wq_head; /* * Handle racing against evict(), see that routine for more details. @@ -2356,14 +2354,14 @@ static void __wait_on_freeing_inode(struct inode *inode, bool is_inode_hash_lock return; } - wq = bit_waitqueue(&inode->i_state, __I_NEW); - prepare_to_wait(wq, &wait.wq_entry, TASK_UNINTERRUPTIBLE); + wq_head = inode_bit_waitqueue(&wqe, inode, __I_SYNC); + prepare_to_wait_event(wq_head, &wqe.wq_entry, TASK_UNINTERRUPTIBLE); spin_unlock(&inode->i_lock); rcu_read_unlock(); if (is_inode_hash_locked) spin_unlock(&inode_hash_lock); schedule(); - finish_wait(wq, &wait.wq_entry); + finish_wait(wq_head, &wqe.wq_entry); if (is_inode_hash_locked) spin_lock(&inode_hash_lock); rcu_read_lock(); diff --git a/include/linux/writeback.h b/include/linux/writeback.h index 56b85841ae4c..bed795b8340b 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -200,7 +200,8 @@ void inode_io_list_del(struct inode *inode); /* writeback.h requires fs.h; it, too, is not included from here. */ static inline void wait_on_inode(struct inode *inode) { - wait_on_bit(&inode->i_state, __I_NEW, TASK_UNINTERRUPTIBLE); + wait_var_event(inode_state_wait_address(inode, __I_NEW), + !(inode->i_state & I_NEW)); } #ifdef CONFIG_CGROUP_WRITEBACK From patchwork Tue Aug 20 16:06:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13770441 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22E24192B83 for ; Tue, 20 Aug 2024 16:07:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724170054; cv=none; b=U+sZkxkTP671ctqdAO4UAF/DrJW/zvDdTy+uFV9paoldJZ+UaxwC9XtNpo2VMhnhkNiFoC5a0rQEnapcO8bfvx9tcexvTDYpcP2tTkHc8oQ3gD6SPskUbrZaQCVl3PKibMb+2XbKweALk6BnlxCF1YeRchN4CHOAgNWl3nETxz4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724170054; c=relaxed/simple; bh=cgTUGY9nCB2XXnhteA5TnY+XSftnWg0S3KrFGXJg4qU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tK74csk+Kxi8oycIK4TTf5m8EKxy7EXB/M1GDQt98imOrDJIf/rtswCUdxacwWbNNl7sGzmXGM7C20THH9WB0a3EL+12hSaJVyxqhhIEtZ40qms7/2q3OtfK4OL76jr6BkrwzSsNNpWK8lLcx812SO3Gq+3a1xSb6eQ2se49w6A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CTmQ34ns; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CTmQ34ns" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 89E2DC4AF13; Tue, 20 Aug 2024 16:07:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724170053; bh=cgTUGY9nCB2XXnhteA5TnY+XSftnWg0S3KrFGXJg4qU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CTmQ34nskKtetveDymW+jLg53G5Z+FvS4KHdQHDEuq6E3K9PaWTO8pojy7DXjhfmV fScjZL/1TYaSFmKRzaJzzNVQPDJlh1spCjgLn+f6jW6u9wJ4DWvHLzW9iSBC7f4Ey1 0iU/7JkrXWsetGCtqQnqmsrq2OudPgIiX4nnYrvatFKVPJsFTHl4pa4WvRb1QYragc AFErQNPPjWWdNXskSZYp3cJOCgWtp2MA8pGjRQ6sQIwl/pyevkpzzzUr4RUPYO1Khz kAyncRavBkqp1kYGpdrZunED0JUEiFoP589IgCMpOXGXSS8jxN9DKlHl1eDIWsGtx9 CsOM12+u8kDpA== From: Christian Brauner To: Linus Torvalds Cc: Christian Brauner , NeilBrown , Peter Zijlstra , Ingo Molnar , Jeff Layton , Jan Kara , linux-fsdevel@vger.kernel.org Subject: [PATCH RFC 4/5] inode: port __I_LRU_ISOLATING to var event Date: Tue, 20 Aug 2024 18:06:57 +0200 Message-ID: <20240820-work-i_state-v1-4-794360714829@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240820-work-i_state-v1-0-794360714829@kernel.org> References: <20240820-work-i_state-v1-0-794360714829@kernel.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.15-dev-37811 X-Developer-Signature: v=1; a=openpgp-sha256; l=1669; i=brauner@kernel.org; h=from:subject:message-id; bh=cgTUGY9nCB2XXnhteA5TnY+XSftnWg0S3KrFGXJg4qU=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaQd2a+oV+Ui0n/zy71J2wIdJZKXfpjj+N9qe2Ptp9lz4 x56nO1x6yhlYRDjYpAVU2RxaDcJl1vOU7HZKFMDZg4rE8gQBi5OAZhIxSWG/xFROVN/z+z7M/X4 7L0LmXfssWjR1ixVKfHSOf3+9KlopjuMDE3VJcycBv9f9ApvPcs4+9+VF5tCDBMk+6f0XZt4l2e /Ey8A X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Port the __I_LRU_ISOLATING mechanism to use the new var event mechanism. Signed-off-by: Christian Brauner --- fs/inode.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index d9e119b5eeef..a48b6df05139 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -511,8 +511,7 @@ static void inode_unpin_lru_isolating(struct inode *inode) spin_lock(&inode->i_lock); WARN_ON(!(inode->i_state & I_LRU_ISOLATING)); inode->i_state &= ~I_LRU_ISOLATING; - smp_mb(); - wake_up_bit(&inode->i_state, __I_LRU_ISOLATING); + inode_wake_up_bit(inode, __I_LRU_ISOLATING); spin_unlock(&inode->i_lock); } @@ -520,13 +519,22 @@ static void inode_wait_for_lru_isolating(struct inode *inode) { lockdep_assert_held(&inode->i_lock); if (inode->i_state & I_LRU_ISOLATING) { - DEFINE_WAIT_BIT(wq, &inode->i_state, __I_LRU_ISOLATING); - wait_queue_head_t *wqh; - - wqh = bit_waitqueue(&inode->i_state, __I_LRU_ISOLATING); - spin_unlock(&inode->i_lock); - __wait_on_bit(wqh, &wq, bit_wait, TASK_UNINTERRUPTIBLE); - spin_lock(&inode->i_lock); + struct wait_bit_queue_entry wqe; + struct wait_queue_head *wq_head; + + wq_head = inode_bit_waitqueue(&wqe, inode, __I_NEW); + for (;;) { + prepare_to_wait_event(wq_head, &wqe.wq_entry, + TASK_UNINTERRUPTIBLE); + if (inode->i_state & I_LRU_ISOLATING) { + spin_unlock(&inode->i_lock); + schedule(); + spin_lock(&inode->i_lock); + continue; + } + break; + } + finish_wait(wq_head, &wqe.wq_entry); WARN_ON(inode->i_state & I_LRU_ISOLATING); } } From patchwork Tue Aug 20 16:06:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13770442 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4602192B83 for ; Tue, 20 Aug 2024 16:07:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724170056; cv=none; b=WT9hHQ8J2Ns6ib9XKcGfNAiB/I2VuJfQIXT5xM7AyL+sJnVdYhSV189lE6JrfpMwKwdQPOMjrsfn8y2x2rIdy+OHYb70C5VdB70GDQo+Hwx9DoIEOszDmdNf4oxWgOjDPBqRO3ygK1upqRkrItNVq5c2k+uh6FeFrV+gSSdslUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724170056; c=relaxed/simple; bh=vQaqAitSD8zjQ4WrCi/snDMGSRzMp5NkTpK7rN760cM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ha/NvA5G8FbasTcMHGqlfjUy0awGd85yvXjKYto0BpeK5DA//riFd5IxLIsgatpfF0wy6mPUzZxrAj8djvkErYdVkW9MZsutXBCtrYcJyIXwQydTHjj4oh/JJj9Ack0J46QImbBBvCXB5/A6v5gVcEoHr/81l+GtYfGrANaElbI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SL4ZQlS9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SL4ZQlS9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2FCA2C4AF10; Tue, 20 Aug 2024 16:07:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724170056; bh=vQaqAitSD8zjQ4WrCi/snDMGSRzMp5NkTpK7rN760cM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SL4ZQlS9+VHyJktxi4MIQKwUBrPTWCCtWRa3FkrYKggLoe9YJevrcH5S3Tka3Rbz3 t5erCNq/KFqbzLEoiq5XR2RqS5v7KLz00Z1VxkRYeYyj9ko3SPBoXk13ccGqhe7XS2 mcNhzJR+emLSazKQjECSEqdwMvUtnBreG7pf5NkUIP+GkzDpsGMnQf38Tlv5ms4Qim lh1gndWKU18fEt0B0JFduSua24JyksGngllIbw9n3RaqRom7goNPPWp04ZNXsza87k ivs3rHw9Kfu/ExxNrrVjVkhgGEFV69SdYVaiI5oskYaGRiGE0coIDiLhuDR5Luv8W+ ThQZdGsNhIQhg== From: Christian Brauner To: Linus Torvalds Cc: Christian Brauner , NeilBrown , Peter Zijlstra , Ingo Molnar , Jeff Layton , Jan Kara , linux-fsdevel@vger.kernel.org Subject: [PATCH RFC 5/5] inode: make i_state a u32 Date: Tue, 20 Aug 2024 18:06:58 +0200 Message-ID: <20240820-work-i_state-v1-5-794360714829@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240820-work-i_state-v1-0-794360714829@kernel.org> References: <20240820-work-i_state-v1-0-794360714829@kernel.org> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.15-dev-37811 X-Developer-Signature: v=1; a=openpgp-sha256; l=677; i=brauner@kernel.org; h=from:subject:message-id; bh=vQaqAitSD8zjQ4WrCi/snDMGSRzMp5NkTpK7rN760cM=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaQd2a/Uc+vR5TtFtY9Kr2+1+npucsZjLmU9//NSpryPl lasvLMyv6OUhUGMi0FWTJHFod0kXG45T8Vmo0wNmDmsTCBDGLg4BWAiIeaMDLPYLvxewmWafsD0 /ta/6383bvi2yTXzA7fOns990lHcN1IYGS7qe1W8SXlUa64WzXjpksU8s9rsS3M2h6710OKdOOW BGDcA X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 Now that we use the wait var event mechanism make i_state a u32 and free up 4 bytes. This means we currently have two 4 byte holes in struct inode which we can pack. Signed-off-by: Christian Brauner --- include/linux/fs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index f854f83e91af..54cfb75b6a28 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -681,7 +681,7 @@ struct inode { #endif /* Misc */ - unsigned long i_state; + u32 i_state; struct rw_semaphore i_rwsem; unsigned long dirtied_when; /* jiffies of first dirtying */