nfs/sunrpc: allow freezing of tasks with NFS calls in flight
Subsystems (6)
cover nfs/sunrpc: allow freezing of tasks with NFS calls in flight
This patchset is a second (third?) attempt at fixing the issues with suspending a machine that has an active NFS mount.
The bug reported against Fedora is here:
https://bugzilla.redhat.com/show_bug.cgi?id=717735
This patchset is a bit different from the original one. Instead of attempting to make TASK_KILLABLE sleeps wake up when the freezer runs, this one makes the freezer skip those processes when it runs.
This is the method that Tejun, Rafael, and Oleg have recommended for now. Long term, it might make more sense to add a new TASK_WAKEFREEZE flag or something and awake tasks based on that, and have them then call try_to_freeze() when awoken. For now though this seems to work as expected.
So far, results with this patchset have been good, but it seems like it's a bit late for 3.2. I'd like to see this go in early for 3.3, probably via Rafael's tree.
Jeff Layton (2):
sunrpc: make rpc_wait_bit_killable handle freeze events
nfs: make TASK_KILLABLE sleeps attempt to freeze
fs/nfs/inode.c | 3 ++- fs/nfs/nfs3proc.c | 3 ++- fs/nfs/nfs4proc.c | 5 +++-- fs/nfs/proc.c | 3 ++- include/linux/freezer.h | 22 ++++++++++++++++++++++ net/sunrpc/sched.c | 3 ++- 6 files changed, 33 insertions(+), 6 deletions(-)
Signature · 1 line
1.7.6.4
PATCH 1/2 sunrpc: make rpc_wait_bit_killable handle freeze events
Allow the freezer to skip wait_on_bit_killable sleeps in the sunrpc layer. This should allow suspend and hibernate events to proceed, even when there are RPC's pending on the wire.
--- include/linux/freezer.h | 12 ++++++++++++ net/sunrpc/sched.c | 3 ++- 2 files changed, 14 insertions(+), 1 deletions(-)
include/linux/freezer.h +12 -0
@@ -135,6 +135,16 @@ static inline void set_freezable_with_signal(void) }/* +* Freezer-friendly macro around schedule() in the kernel. +*/ +#define freezable_schedule () \ +({ \ + freezer_do_not_count(); \ + schedule(); \ + freezer_count(); \ +}) + +/* * Freezer-friendly wrappers around wait_event_interruptible(), * wait_event_killable() and wait_event_interruptible_timeout(), originally * defined in <linux/wait.h>
@@ -194,6 +204,8 @@ static inline int freezer_should_skip(struct task_struct *p) { return 0; }static inline void set_freezable (void ) {}static inline void set_freezable_with_signal (void ) {} +#define freezable_schedule () schedule() +#define wait_event_freezable (wq, condition) \ wait_event_interruptible(wq, condition)
net/sunrpc/sched.c +2 -1
@@ -18,6 +18,7 @@#include <linux/smp.h> #include <linux/spinlock.h> #include <linux/mutex.h> +#include <linux/freezer.h> #include <linux/sunrpc/clnt.h>
@@ -231,7 +232,7 @@ static int rpc_wait_bit_killable(void *word) {if (fatal_signal_pending (current))return -ERESTARTSYS ; -schedule (); +freezable_schedule ();return 0 ; }
Signature · 1 line
1.7.6.4
PATCH 2/2 nfs: make TASK_KILLABLE sleeps attempt to freeze
In reply to Jeff LaytonWrap the TASK_KILLABLE sleeps in NFS layer in freezer_do_not_count and freezer_count calls. This allows the freezer to skip these processes when they are sleeping while looping on EJUKEBOX or NFS4ERR_DELAY sorts of errors.
--- fs/nfs/inode.c | 3 ++- fs/nfs/nfs3proc.c | 3 ++- fs/nfs/nfs4proc.c | 5 +++-- fs/nfs/proc.c | 3 ++- include/linux/freezer.h | 12 +++++++++++- 5 files changed, 20 insertions(+), 6 deletions(-)
fs/nfs/inode.c +2 -1
@@ -38,6 +38,7 @@#include <linux/nfs_xdr.h> #include <linux/slab.h> #include <linux/compat.h> +#include <linux/freezer.h> #include <asm/system.h> #include <asm/uaccess.h>
@@ -77,7 +78,7 @@ int nfs_wait_bit_killable(void *word) {if (fatal_signal_pending (current))return -ERESTARTSYS ; -schedule (); +freezable_schedule ();return 0 ; }
fs/nfs/nfs3proc.c +2 -1
@@ -17,6 +17,7 @@#include <linux/nfs_page.h> #include <linux/lockd/bind.h> #include <linux/nfs_mount.h> +#include <linux/freezer.h> #include "iostat.h" #include "internal.h"
@@ -32,7 +33,7 @@ nfs3_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags) res =rpc_call_sync (clnt, msg, flags);if (res != -EJUKEBOX && res != -EKEYEXPIRED )break ; -schedule_timeout_killable (NFS_JUKEBOX_RETRY_TIME ); +freezable_schedule_timeout_killable (NFS_JUKEBOX_RETRY_TIME ); res = -ERESTARTSYS ; }while (!fatal_signal_pending (current));return res;
fs/nfs/nfs4proc.c +3 -2
@@ -53,6 +53,7 @@#include <linux/sunrpc/bc_xprt.h> #include <linux/xattr.h> #include <linux/utsname.h> +#include <linux/freezer.h> #include "nfs4_fs.h" #include "delegation.h"
@@ -241,7 +242,7 @@ static int nfs4_delay(struct rpc_clnt *clnt, long *timeout) *timeout =NFS4_POLL_RETRY_MIN ;if (*timeout >NFS4_POLL_RETRY_MAX ) *timeout =NFS4_POLL_RETRY_MAX ; -schedule_timeout_killable (*timeout); +freezable_schedule_timeout_killable (*timeout);if (fatal_signal_pending (current)) res = -ERESTARTSYS ; *timeout <<=1 ;
@@ -3951,7 +3952,7 @@ int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4static unsigned long nfs4_set_lock_task_retry (unsigned long timeout) { -schedule_timeout_killable (timeout); +freezable_schedule_timeout_killable (timeout); timeout <<=1 ;if (timeout >NFS4_LOCK_MAXTIMEOUT )return NFS4_LOCK_MAXTIMEOUT ;
fs/nfs/proc.c +2 -1
@@ -41,6 +41,7 @@#include <linux/nfs_fs.h> #include <linux/nfs_page.h> #include <linux/lockd/bind.h> +#include <linux/freezer.h> #include "internal.h" #define NFSDBG_FACILITY NFSDBG_PROC
@@ -59,7 +60,7 @@ nfs_rpc_wrapper(struct rpc_clnt *clnt, struct rpc_message *msg, int flags) res =rpc_call_sync (clnt, msg, flags);if (res != -EKEYEXPIRED )break ; -schedule_timeout_killable (NFS_JUKEBOX_RETRY_TIME ); +freezable_schedule_timeout_killable (NFS_JUKEBOX_RETRY_TIME ); res = -ERESTARTSYS ; }while (!fatal_signal_pending (current));return res;
include/linux/freezer.h +11 -1
@@ -135,7 +135,7 @@ static inline void set_freezable_with_signal(void) }/* -* Freezer-friendly macro around schedule() in the kernel. +* Freezer-friendly macros around some sleeping functions. */ #define freezable_schedule () \ ({ \
@@ -144,6 +144,13 @@ static inline void set_freezable_with_signal(void)freezer_count (); \ }) +#define freezable_schedule_timeout_killable (timeout) \ +({ \ + freezer_do_not_count(); \ + schedule_timeout_killable(timeout); \ + freezer_count(); \ +}) +/* * Freezer-friendly wrappers around wait_event_interruptible(), * wait_event_killable() and wait_event_interruptible_timeout(), originally
@@ -206,6 +213,9 @@ static inline void set_freezable_with_signal(void) {}#define freezable_schedule () schedule() +#define freezable_schedule_timeout_killable (timeout) \ + schedule_timeout_killable(timeout) +#define wait_event_freezable (wq, condition) \ wait_event_interruptible(wq, condition)
Signature · 1 line
1.7.6.4
Re: [PATCH 1/2] sunrpc: make rpc_wait_bit_killable handle freeze events
In reply to Jeff LaytonQuoted 15 lines · Jeff Layton
Allow the freezer to skip
wait_on_bit_killablesleeps in the sunrpc layer. This should allow suspend and hibernate events to proceed, even when there are RPC's pending on the wire.Signed-off-by Jeff Layton <[email protected]>--- include/linux/freezer.h | 12 ++++++++++++ net/sunrpc/sched.c | 3 ++- 2 files changed, 14 insertions(+), 1 deletions(-)include/linux/freezer.h +0
-0
include/linux/freezer.h static inline void set_freezable_with_signal(void) · line 144
Quoted 10 lines
include/linux/freezer.h +7
-0@@ -135,6 +135,16 @@ static inline void set_freezable_with_signal(void) }/* +* Freezer-friendly macro around schedule() in the kernel. +*/ +#define freezable_schedule () \ +({ \ + freezer_do_not_count(); \ + schedule(); \ + freezer_count(); \
Don't we want try_to_freeze() here? If the freezer thought the task was safe to skip, it better stay inside freezer until the freezing condition is lifted.
Thanks.
Signature · 1 line
tejun
Re: [PATCH 1/2] sunrpc: make rpc_wait_bit_killable handle freeze events
Quoted 31 lines · On Mon, 21 Nov 2011 09:56:44 -0800 Tejun Heo <[email protected]> wrote:
Quoted 15 lines · Jeff Layton
Allow the freezer to skip
wait_on_bit_killablesleeps in the sunrpc layer. This should allow suspend and hibernate events to proceed, even when there are RPC's pending on the wire.Signed-off-by Jeff Layton <[email protected]>--- include/linux/freezer.h | 12 ++++++++++++ net/sunrpc/sched.c | 3 ++- 2 files changed, 14 insertions(+), 1 deletions(-)include/linux/freezer.h +0
-0include/linux/freezer.h static inline void set_freezable_with_signal(void) · line 144
Quoted 10 lines
include/linux/freezer.h +7
-0@@ -135,6 +135,16 @@ static inline void set_freezable_with_signal(void) }/* +* Freezer-friendly macro around schedule() in the kernel. +*/ +#define freezable_schedule () \ +({ \ + freezer_do_not_count(); \ + schedule(); \ + freezer_count(); \Don't we want
try_to_freeze()here? If the freezer thought the task was safe to skip, it better stay inside freezer until the freezing condition is lifted.
Quoted 2 lines
Thanks.
I suppose you're suggesting something like this?
freezer_do_not_count(); if (!try_to_freeze()) schedule(); freezer_count();
Hmm, so I guess the concern is that we'd race in such a way that freezer_count() ends up running after the freezer has already skipped the task?
If so, that seems just as racy...nothing guarantees that the freeze event occurs before the try_to_freeze call...
The freezer is not really my forte', but I have to say that the whole do_not_count scheme seems "sketchy". Would we not be better off with something closer to the original method that I proposed, along with a new TASK_WAKEFREEZE state bit? Processes that are sleeping in uninterruptible sleep that are able to deal with freezer events could set that bit and fake_signal_wake_up could be changed to also wake processes with that bit set.
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH 1/2] sunrpc: make rpc_wait_bit_killable handle freeze events
Hello, Jeff.
Quoted 6 lines · Jeff Layton
I suppose you're suggesting something like this?
freezer_do_not_count(); if (!try_to_freeze()) schedule(); freezer_count();
No,
freezer_do_not_count(); schedule(); freezer_count(); try_to_freeze();
freezer_count() may make %current eligible for freezing again, so it has to check whether freezing condition is pending afterwards.
Quoted 7 lines
The freezer is not really my forte', but I have to say that the whole
do_not_countscheme seems "sketchy". Would we not be better off with something closer to the original method that I proposed, along with a newTASK_WAKEFREEZEstate bit? Processes that are sleeping in uninterruptible sleep that are able to deal with freezer events could set that bit andfake_signal_wake_upcould be changed to also wake processes with that bit set.
AFAICS, the above should be race-free w/ the pending freezer update.
http://git.kernel.org/?p=linux/kernel/git/tj/misc.git;a=shortlog;h=refs/heads/pm-freezer
Thank you.
Signature · 1 line
tejun
Re: [PATCH 1/2] sunrpc: make rpc_wait_bit_killable handle freeze events
Quoted 12 lines · Tejun Heo
Hello, Jeff.
Quoted 6 lines · Jeff Layton
I suppose you're suggesting something like this?
freezer_do_not_count(); if (!try_to_freeze()) schedule(); freezer_count();No,
Quoted 7 lines
freezer_do_not_count(); schedule(); freezer_count(); try_to_freeze();
freezer_count()may make %current eligible for freezing again, so it has to check whether freezing condition is pending afterwards.
Ooh, freezer_count() already has that. Heh, call me an idiot. The proposed code seems correct then.
Thanks.
Signature · 1 line
tejun
Re: [PATCH 1/2] sunrpc: make rpc_wait_bit_killable handle freeze events
In reply to Jeff Laytoninclude/linux/freezer.h static inline void set_freezable_with_signal(void) · line 145
Quoted 9 lines · Jeff Layton
/*
+ * Freezer-friendly macro aroundschedule()in the kernel.
+ */include/linux/freezer.h +6
-0+#define freezable_schedule () \ +({ \ + freezer_do_not_count(); \ + schedule(); \ + freezer_count(); \ +})
So, yes, this seems correct to me but I'm not really sure about the naming. Given what freezable means for other interfaces, this is a bit confusing to me but that could be because I know how each is implemented. Anyone with a better name?
Also, this definitely can use a lot more detailed comment. What it's supposed to do, how it's supposed to be used and so on.
Thank you.
Signature · 1 line
tejun
Re: [PATCH 1/2] sunrpc: make rpc_wait_bit_killable handle freeze events
Quoted 16 lines · On Mon, 21 Nov 2011 12:46:20 -0800 Tejun Heo <[email protected]> wrote:
include/linux/freezer.h static inline void set_freezable_with_signal(void) · line 145
Quoted 9 lines · Jeff Layton
/*
+ * Freezer-friendly macro aroundschedule()in the kernel.
+ */include/linux/freezer.h +6
-0+#define freezable_schedule () \ +({ \ + freezer_do_not_count(); \ + schedule(); \ + freezer_count(); \ +})So, yes, this seems correct to me but I'm not really sure about the naming. Given what freezable means for other interfaces, this is a bit confusing to me but that could be because I know how each is implemented. Anyone with a better name?
Quoted 5 lines
Also, this definitely can use a lot more detailed comment. What it's supposed to do, how it's supposed to be used and so on.
Thank you.
That makes sense. I'll plan to flesh out the comments in a respin.
Yeah, naming these things is rather difficult -- too many "*able" adjectives. I'm quite open to better suggestions for the name (and for wait_event_freezekillable too).
Signature · 1 line
Jeff Layton <[email protected]>