From patchwork Wed Aug 21 15:47:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13771837 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 818A014E2DE for ; Wed, 21 Aug 2024 15:47:54 +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=1724255274; cv=none; b=JM1YHSgDFkNIjF/iRxhOTySTTWUkO5gq4QtvwB73twmvi5FoQZI4YYsMM2GS5vwb4X6gjUea0pIMEoCg7/CesvMOB4+4zqNOzF5h6XWL3TJIk+PEkg3D2XK4HocOP0912Tvb7Yf0oMkUZDFkRddygjxKD2EH/X1E9TJsbY80e9s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724255274; c=relaxed/simple; bh=XF9SEBq1qMuC+NzeqEU27oTFpHcRw695qJXpLUMxlVQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tINCr3bYQTwAuvHWZ+M5PL5OOG1Uqb/B8gTGUFoCPjvwpHqoZSzDho5EZbt8jPkWqokJzDzK2QuFNufyaqYxiwLFIxJkQub0Gi9wnv6js838r2UUVy+GA906ELJEgwai/Qa4kjax6J5qPrLrVEf+msbztppRNxs/xOkMTTEpINA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lYy42BsQ; 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="lYy42BsQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C93CC4AF0E; Wed, 21 Aug 2024 15:47:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724255274; bh=XF9SEBq1qMuC+NzeqEU27oTFpHcRw695qJXpLUMxlVQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=lYy42BsQ+msJi3j1D1SAl20L+VHNHIZUwqprOVxxa3R7O4PdJbZgzaP7O85JJTfaP 1tcSd2C+ZMncoNaHZvDDnpAWIaLdTRiWGSkdhLrzc1Sga0RAZQ/55HfApBYdnX1j7k o1GOpCGy5Q0VQBksnB982Mc0G3Qo21rYxIyqmjLmwrWTeMWsVpeq/gKupQaZpODzci mg5iWdikxIeBOnOtvlou2MHDIQv+wQ5R6Hp6rxFlynNBGpLbn6iM6qcvxqwXwD9Uzt pvlsywoxmhyUoo/w+LnzaHIH8AuAqT9oE8+NtW9Fj5nqOCii6CiiCeta0Bk7tW+wht uL3m0IANzlXhw== From: Christian Brauner Date: Wed, 21 Aug 2024 17:47:31 +0200 Subject: [PATCH RFC v2 1/6] fs: add i_state helpers Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240821-work-i_state-v2-1-67244769f102@kernel.org> References: <20240821-work-i_state-v2-0-67244769f102@kernel.org> In-Reply-To: <20240821-work-i_state-v2-0-67244769f102@kernel.org> To: Linus Torvalds Cc: NeilBrown , Peter Zijlstra , Ingo Molnar , Jeff Layton , Jan Kara , Christian Brauner , linux-fsdevel@vger.kernel.org X-Mailer: b4 0.15-dev-37811 X-Developer-Signature: v=1; a=openpgp-sha256; l=2079; i=brauner@kernel.org; h=from:subject:message-id; bh=XF9SEBq1qMuC+NzeqEU27oTFpHcRw695qJXpLUMxlVQ=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaQd41ERmPS1/4Wqk5ZXxYkZQscVNrG8XsOwYXWM2Ipfy 7wE/esEO0pZGMS4GGTFFFkc2k3C5ZbzVGw2ytSAmcPKBDKEgYtTACYSdJSRYa3D4UaBaydlkiaF +c/cvpvxxwGmjBCtCzP6qtbtVroSX8vw37ni/mzW1Hs7uGderGqMerbnlaOJ0uTy/dMYzpx4+U3 clAMA 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 | 10 ++++++++++ include/linux/fs.h | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/fs/inode.c b/fs/inode.c index 154f8689457f..f2a2f6351ec3 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -472,6 +472,16 @@ 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, u32 bit) +{ + void *bit_address; + + bit_address = inode_state_wait_address(inode, bit); + 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..a5b036714d74 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, u32 bit); + +static inline void inode_wake_up_bit(struct inode *inode, u32 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 Wed Aug 21 15:47:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13771838 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 2681B1B2EC2 for ; Wed, 21 Aug 2024 15:47:56 +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=1724255277; cv=none; b=CkMzSTYFk0Flh6lf88m3aQmaMbpDj9wEcTIIr63woOyiYHnVBGRYrWGhGD3vzZH6tXPBQZLUC24h4RskLPuf/3qLpdeEFaeV/JQCL97gtOJ478OfMENxUHhTIZ7WRVAHQLLCZClgEwHAQYU5lI3AD/7igdT25p2P7lxu3ZcVa8A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724255277; c=relaxed/simple; bh=/3yj47Hfp+aYIGBiKeBK2KYt5E2v876vvMCX+8FWM1w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nwbiQfJDG/3qwGmmNdRmEB2a088iVBuBJbY2CIV1XrEDa5XgYi3P6HbImCGetU83c7DSyAaE+zOjNIm6v8OzLZ08R1uYVFp5oJOuTSTqJOI+ryjERbbpvA4u+BKAUY/WqjHyEKuuHxrxjI5tGKdePQsZ2lz5kUbzCaz8wrC/iEA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=l0tBarSm; 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="l0tBarSm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC840C32786; Wed, 21 Aug 2024 15:47:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724255276; bh=/3yj47Hfp+aYIGBiKeBK2KYt5E2v876vvMCX+8FWM1w=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=l0tBarSm9QbWx/vWUbQkYAgiXSzo1cxUcBKBxCFCdAYnTV3Dn4Hk1LlvQmEi5ckaa Kk2Kcmckux/k/TlI00NgHyFvAoV4ZdmXOwHqbBFNTvgc9P7w20Qn22L9VbqdU3ldAm ODOpm8N/28K/C1ax7AGcLvVreEeazoHhSdthyESoukKLLpTwHaDTmX0JLz8l95iGaF Zi55VpbWHeNQ3vO+Ie1mkeDwhCgB6uwdmJNv8aeyq+TUqJUy/0S/6vNT+647T5yF6g 41joKWkviTYBvZjWQhO7dtzKwnDh0dGP6pR4rcWhfwoTF4jCm0l5zpUTR/bMf3GswH hRQoq2hDRKjag== From: Christian Brauner Date: Wed, 21 Aug 2024 17:47:32 +0200 Subject: [PATCH RFC v2 2/6] fs: reorder i_state bits Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240821-work-i_state-v2-2-67244769f102@kernel.org> References: <20240821-work-i_state-v2-0-67244769f102@kernel.org> In-Reply-To: <20240821-work-i_state-v2-0-67244769f102@kernel.org> To: Linus Torvalds Cc: NeilBrown , Peter Zijlstra , Ingo Molnar , Jeff Layton , Jan Kara , Christian Brauner , linux-fsdevel@vger.kernel.org X-Mailer: b4 0.15-dev-37811 X-Developer-Signature: v=1; a=openpgp-sha256; l=2105; i=brauner@kernel.org; h=from:subject:message-id; bh=/3yj47Hfp+aYIGBiKeBK2KYt5E2v876vvMCX+8FWM1w=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaQd41GZ+lmG80Uza8X8KzdbM1pN/cKrnSpdnMrSjDzXL H8tVvGvo5SFQYyLQVZMkcWh3SRcbjlPxWajTA2YOaxMIEMYuDgFYCIl3owMRz5ePzqJO+LG5Z3F C5gXtc0Rij/2afIJi+qNFoaBXPl59Qz/062sNl5iqHt4yqN6kf4jt8NTNXe9jc18e/LWVfuqotj /XAA= X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 so that we can use the first bits to derive unique addresses from i_state. Signed-off-by: Christian Brauner --- include/linux/fs.h | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index a5b036714d74..8525f8bfd7b9 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2418,28 +2418,32 @@ static inline void kiocb_clone(struct kiocb *kiocb, struct kiocb *kiocb_src, * i_count. * * Q: What is the difference between I_WILL_FREE and I_FREEING? + * + * __I_{SYNC,NEW,LRU_ISOLATING} are used to derive unique addresses to wait + * upon. There's one free address left. */ -#define I_DIRTY_SYNC (1 << 0) -#define I_DIRTY_DATASYNC (1 << 1) -#define I_DIRTY_PAGES (1 << 2) -#define __I_NEW 3 +#define __I_NEW 0 #define I_NEW (1 << __I_NEW) -#define I_WILL_FREE (1 << 4) -#define I_FREEING (1 << 5) -#define I_CLEAR (1 << 6) -#define __I_SYNC 7 +#define __I_SYNC 1 #define I_SYNC (1 << __I_SYNC) -#define I_REFERENCED (1 << 8) +#define __I_LRU_ISOLATING 2 +#define I_LRU_ISOLATING (1 << __I_LRU_ISOLATING) + +#define I_DIRTY_SYNC (1 << 3) +#define I_DIRTY_DATASYNC (1 << 4) +#define I_DIRTY_PAGES (1 << 5) +#define I_WILL_FREE (1 << 6) +#define I_FREEING (1 << 7) +#define I_CLEAR (1 << 8) +#define I_REFERENCED (1 << 9) #define I_LINKABLE (1 << 10) #define I_DIRTY_TIME (1 << 11) -#define I_WB_SWITCH (1 << 13) -#define I_OVL_INUSE (1 << 14) -#define I_CREATING (1 << 15) -#define I_DONTCACHE (1 << 16) -#define I_SYNC_QUEUED (1 << 17) -#define I_PINNING_NETFS_WB (1 << 18) -#define __I_LRU_ISOLATING 19 -#define I_LRU_ISOLATING (1 << __I_LRU_ISOLATING) +#define I_WB_SWITCH (1 << 12) +#define I_OVL_INUSE (1 << 13) +#define I_CREATING (1 << 14) +#define I_DONTCACHE (1 << 15) +#define I_SYNC_QUEUED (1 << 16) +#define I_PINNING_NETFS_WB (1 << 17) #define I_DIRTY_INODE (I_DIRTY_SYNC | I_DIRTY_DATASYNC) #define I_DIRTY (I_DIRTY_INODE | I_DIRTY_PAGES) From patchwork Wed Aug 21 15:47:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13771839 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 71B9981727 for ; Wed, 21 Aug 2024 15:47:59 +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=1724255280; cv=none; b=rbmKvejh+Xi6fWbvhEKI4GD53vnEjhLnNMNtKonHx3zlXMCOpWJ09NUYF8AoJOVZ/UTBmTUNKQyEmI0vHGmo3lhVa26ZpN4sN9AEpp1aUzxueDbGncAPGGst2Eag1zEbpGd/Y5ve6JUMk2xRAdYT5+Q1FB37M98xgY5lnNaOYv4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724255280; c=relaxed/simple; bh=VCSkbbH6FAb5Kc1A8Ex+KDjB6tcNSXukDqw5rZQc1lI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=euzVg75NSsOI5OTQNUJdrsqB3XRCiu9TwwsRLcsRVn90tRCjqoQt6KhQKclWRGLmvY1zCB4v6pDQxGf0DStRd4KMgxA4Sd2hOwC7BHEm/Nw/NI2qfOFoiRJO/AcQNOjoBPKZ2an0l3Xoh2TV775EZ0Sb2U+h2biWEkYcySLlDvs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mttaVOPU; 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="mttaVOPU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41528C4AF09; Wed, 21 Aug 2024 15:47:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724255279; bh=VCSkbbH6FAb5Kc1A8Ex+KDjB6tcNSXukDqw5rZQc1lI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=mttaVOPUnxRls3B++od4RR+NmunDIKemfrcGWlFL6/R0PpbemIhtg+FDs1pm8GSJj RJk1CQENI21RYlgdY7HCvHjF6hLwIj5jYj7wNRJRtDIrSCURHFO6ces5OIZQsydmRo 1WB9wWcRHQthM+Fiiff4LD6Ty0RnE7ZFZxfyCENmojhZNY1TIjWTWv3FbuNsq/Ce5K iPTRt2bFra7u+1O//QIIVxYeqPki7lLVzQVEORiLiswOVOrcUEWFSMZurCVK3rltre YHnYCDZswqzZ9n5zvwJrgbwi9i5V9eIgREnfAY9S4DUcNCpLgytZdwV9Ju56jj2WVe Yq5BQtCAX5V4Q== From: Christian Brauner Date: Wed, 21 Aug 2024 17:47:33 +0200 Subject: [PATCH RFC v2 3/6] writeback: port __I_SYNC to var event Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240821-work-i_state-v2-3-67244769f102@kernel.org> References: <20240821-work-i_state-v2-0-67244769f102@kernel.org> In-Reply-To: <20240821-work-i_state-v2-0-67244769f102@kernel.org> To: Linus Torvalds Cc: NeilBrown , Peter Zijlstra , Ingo Molnar , Jeff Layton , Jan Kara , Christian Brauner , linux-fsdevel@vger.kernel.org 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=owGbwMvMwCU28Zj0gdSKO4sYT6slMaQd41EV0F9Zq+PCf/EO/zcPi9PLY3mW5nF+93O4x1ibn lQQJGbdUcrCIMbFICumyOLQbhIut5ynYrNRpgbMHFYmkCEMXJwCMBH7fwz/fT64+WbG2i7dqpTo vjfd2qEtecmt206zQ2pKliz+4xj8g5FhD2vWmdRm2WIdvYfCegaaL18sK7ue6Lso5PGtG1Mffp3 PAAA= 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 Wed Aug 21 15:47:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13771840 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 A79A281727 for ; Wed, 21 Aug 2024 15:48:01 +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=1724255281; cv=none; b=cas5QhqCOO6+Lr0NgezXwdrwUSCbBy89AF7KhQLcSabAKDvlKN8JlunF86mkn1hr+9bmvka+uMMZjeSZYGtyMYg0CgUXDPHSm9kEDdgDdvgerIwpt9SX6HCQ971zFUikluHachAmDhgx71LGVG0njz2vOHpunhk368UkhWhv+2A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724255281; c=relaxed/simple; bh=zaVb2d/NmW+GsWauUDjGcih6jIFjTkVW71FFkM9B/Tg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lQfdYCFFYs7XS3od2Dh6ApU7AWgVjHkn6u1aoLg+ucKb1mMqD9Fc5ljzu1ORDy/qplbXXC93kZBozjoIU5+/lCH0VkjjpEBHE08Km2gBd15SQGDe/jDEgFqGc8Bxy5IApPE4GafE8OYFVmT4pb0oIPDQqFfPw3xy6g0eVTtKnic= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HU0BKMlz; 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="HU0BKMlz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B8F0C32781; Wed, 21 Aug 2024 15:47:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724255281; bh=zaVb2d/NmW+GsWauUDjGcih6jIFjTkVW71FFkM9B/Tg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=HU0BKMlzBfhLDy5Hupr7Rt7NYBfjQUi5z7OJ30R4PEUPHR6JQzbw2I7Q2WKVpi2eI OGIU8WWgXEMVkGPbK5CPQy15RzUcFM8CAapjucffZMSk7fUuwOJbZV52PdjZvTSLVo McwisU7lLSZN1nS4rvHMgGTFt7D7Ga5vmXx0tA0msxzC/RZYBC/KgZxZZoZKI51rsn 72Gz6GNL4Bf8u7v+3jaVXU/rvKYltPqdUbZRbMz2r+a7BzslCy0o8HtEyoI29hOj/P NSL9dTywEKFhc0X56UTM0/5MmGKpJkOFHpqhmwJfiZpuXwhdUa0YPeYVdDcdniacPR uAg6ExWefjS3Q== From: Christian Brauner Date: Wed, 21 Aug 2024 17:47:34 +0200 Subject: [PATCH RFC v2 4/6] inode: port __I_NEW to var event Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240821-work-i_state-v2-4-67244769f102@kernel.org> References: <20240821-work-i_state-v2-0-67244769f102@kernel.org> In-Reply-To: <20240821-work-i_state-v2-0-67244769f102@kernel.org> To: Linus Torvalds Cc: NeilBrown , Peter Zijlstra , Ingo Molnar , Jeff Layton , Jan Kara , Christian Brauner , linux-fsdevel@vger.kernel.org X-Mailer: b4 0.15-dev-37811 X-Developer-Signature: v=1; a=openpgp-sha256; l=4451; i=brauner@kernel.org; h=from:subject:message-id; bh=zaVb2d/NmW+GsWauUDjGcih6jIFjTkVW71FFkM9B/Tg=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaQd41GdYH2J79f+rzNm3nf6nMop8OZ1x6s5E0tl//osK D4hOTNCsKOUhUGMi0FWTJHFod0kXG45T8Vmo0wNmDmsTCBDGLg4BWAiKZkMv1lXiE63aTXffO1x jKzcv/z3eREy9yxjL5zXe7Ha/oebwA2G/9WrLm8MZOaV8849ZOz6ZtNcywUZ/T2LPWOdY51OpV3 k4gcA 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..c0900c0c0f8a 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->v, __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 f2a2f6351ec3..d18e1567c487 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -733,7 +733,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); @@ -1141,8 +1141,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); @@ -1153,8 +1152,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); } @@ -2343,8 +2341,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. @@ -2355,14 +2353,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_NEW); + 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 Wed Aug 21 15:47:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13771841 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 58BBF1BAED5 for ; Wed, 21 Aug 2024 15:48:03 +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=1724255284; cv=none; b=WuAVfVGOfrqUe2p7tyJfUs/FfVeiB5HrgUA9MzwiMQr1SnDzSFa3PFWjuwltR/Tv2cslgftSnuZRdAxaMo3bQlonAR58vKdGe9ezzvoFaRar8tMcdBea6G4dzecEsrCQp5zILyPyjtvU5KNC6xdA8HHJmWPf+NxiwIu2Fj804lY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724255284; c=relaxed/simple; bh=DS5/a6JJFN2bMggpCIXfeUIF6WxzMYj2BLKMWGxSV04=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eo5Im9Lbbh4q+Op6bVxPGE3TzCE54OxMZkpmfhJNbeNxjYii2o4e2Svl3KqC4m2VQn2YTjSQzXHLz12WuUbJHKqHYcW3GF+Vtd0DjFqUCfQTyMCovNvKQ4/6XtXDBwbbDH/ve2H8D4Hr0GiqBmofhYnAfmq79ZuMiDw7HMisyec= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NU+wjdmi; 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="NU+wjdmi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13424C32786; Wed, 21 Aug 2024 15:48:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724255283; bh=DS5/a6JJFN2bMggpCIXfeUIF6WxzMYj2BLKMWGxSV04=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=NU+wjdmiJ6tia1sCp3gP8tK7V1roxtApcLvyGReL7jz/wf19ofND0M4lMlPYlpPBd h2XqxiPX5VVR3VcGZCp9AHtzwPRnmL4VJuFQme0xL2GVBAf+sHgJJtmqwJodR/6PrI 7netSY/+OZx9BHLAiBncHYCgjlC6ujEbGylNyx/9R0uuHXAzXsVk4uuz3zGQe2xT7X sGleSodpnbqhVEIrhBjIRuvzEo94gLKpZVPhccySyWZHp0XmJL3jO9fTkcmEGw6jSU jqBX+jTErHbTTj4YLCbH18CdG175Zy29RBBMjnyzbYwxBgFjbHDYqJE35BNBHwJSiB D6a6bRr8O6WBA== From: Christian Brauner Date: Wed, 21 Aug 2024 17:47:35 +0200 Subject: [PATCH RFC v2 5/6] inode: port __I_LRU_ISOLATING to var event Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240821-work-i_state-v2-5-67244769f102@kernel.org> References: <20240821-work-i_state-v2-0-67244769f102@kernel.org> In-Reply-To: <20240821-work-i_state-v2-0-67244769f102@kernel.org> To: Linus Torvalds Cc: NeilBrown , Peter Zijlstra , Ingo Molnar , Jeff Layton , Jan Kara , Christian Brauner , linux-fsdevel@vger.kernel.org X-Mailer: b4 0.15-dev-37811 X-Developer-Signature: v=1; a=openpgp-sha256; l=1679; i=brauner@kernel.org; h=from:subject:message-id; bh=DS5/a6JJFN2bMggpCIXfeUIF6WxzMYj2BLKMWGxSV04=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaQd41FViMqPUv0gcDH9w5OJP1ryF0Q0K3p85v94aeWSu H3tjT39HaUsDGJcDLJiiiwO7Sbhcst5KjYbZWrAzGFlAhnCwMUpABPZE8nwT2f/Sibbqo1ar7QP r0qfY863rnL1zRtKmx3y3glJ8xt7HmT4X/Td37X2j9cz/jbOXx5esnt3H1mmItZxSmPh2RMb9Br z+QA= 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 d18e1567c487..c8a5c63dc980 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -510,8 +510,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); } @@ -519,13 +518,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_LRU_ISOLATING); + 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 Wed Aug 21 15:47:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 13771842 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 B458C1BAED5 for ; Wed, 21 Aug 2024 15:48:06 +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=1724255286; cv=none; b=ukCdxwKGVHBdfdhOfLstmK25K3oYHQX72D+Yopu3XX3l9kfwcqLKwj4ORVkvXaPrp1LRk8cLgiipMAPLEPu7ZAZGCKuhyo+NxGwsGbk0ZbVEqgjBR3HcuJon2hectV0FR6CEsJTpomGAhnLu2/0X7I/2qyblgLhNbPxVrCv7PiI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724255286; c=relaxed/simple; bh=/MxpcQxK7vm+zOfGllmfyxOEpsgsb6y/adQKarv93bU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qYvvlF2Tk8yX0PxMqu+pUlKg4VgzQISFNpmX/sR4rtX4aVO0mgVdaOs2Q2ut8mbp2kzohDP7xZejoWRnRlBWjaUBhbrHQv9YPp/u5draX1gnoB4RVQ+++xY9guB5Qro/epIuMzYIn+khY4Jm51z/jJNwmwQkt8mfrUiLNSv4cCg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mz87APxu; 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="mz87APxu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62016C4AF0E; Wed, 21 Aug 2024 15:48:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724255286; bh=/MxpcQxK7vm+zOfGllmfyxOEpsgsb6y/adQKarv93bU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=mz87APxuZ73OhhWgRRaI2ugaB3kxEvqXD5VIwb3ItdQ4aic5gWMVaJ1d290L+BhzO WCzzZypz+Q4hTp/3PgYvhGYUvaD6+jLGN9FGmMQC1roDw0CpBY/mtrxuhGsgNXPg/k kc4Sz3ByTe7ohtX5qE8AChqzUSFA8Q8xfR1nkRFRgS80uLGlnwTlWfCWn8PF5mbXEN UCTPvTqhwefBNCLAc9N7ljglM1eJ0hFQ2RBGLHkggGdyonniW3U48nv1iuM1gQTDHt 8HFvUhrPoOc84KWHDSSTOHNlagj0rQOs/XlfDSJ/toCGRUgeqFEUql1v/E5IGMdOEG BWWMLf/gQIwOw== From: Christian Brauner Date: Wed, 21 Aug 2024 17:47:36 +0200 Subject: [PATCH RFC v2 6/6] inode: make i_state a u32 Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240821-work-i_state-v2-6-67244769f102@kernel.org> References: <20240821-work-i_state-v2-0-67244769f102@kernel.org> In-Reply-To: <20240821-work-i_state-v2-0-67244769f102@kernel.org> To: Linus Torvalds Cc: NeilBrown , Peter Zijlstra , Ingo Molnar , Jeff Layton , Jan Kara , Christian Brauner , linux-fsdevel@vger.kernel.org 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=/MxpcQxK7vm+zOfGllmfyxOEpsgsb6y/adQKarv93bU=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMaQd41HVXlcj1R66MzFYT+S19ydvlUuiUq/qT3jcfyJ33 2aK5K9dHaUsDGJcDLJiiiwO7Sbhcst5KjYbZWrAzGFlAhnCwMUpABN5LcPIsIVt5RPmp6yfeXaf a2S8IbtLaPaTnG0NhyW2rTjnut61byHDL6bEGSJ7RNS3MJS/5fi7mn1djtDiq7Jfq3rO8jvFmEx NZAYA 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 8525f8bfd7b9..a673173b6896 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 */