PM: suspend: Add sysfs attribute to control the "sync on suspend" behavior
The sysfs attribute `/sys/power/sync_on_suspend` controls, whether or not filesystems are synced by the kernel before system suspend. Congruously, the behaviour of build-time switch CONFIG_SUSPEND_SKIP_SYNC is slightly changed: It now defines the run-tim default for the new sysfs attribute `/sys/power/sync_on_suspend`. The run-time attribute is added because the existing corresponding build-time Kconfig flag for (`CONFIG_SUSPEND_SKIP_SYNC`) is not flexible enough. E.g. Linux distributions that provide pre-compiled kernels usually want to stick with the default (sync filesystems before suspend) but under special conditions this needs to be changed. One example for such a special condition is user-space handling of suspending block devices (e.g. using `cryptsetup luksSuspend` or `dmsetup suspend`) before system suspend. The Kernel trying to sync filesystems after the underlying block device already got suspended obviously leads to dead-locks. Be aware that you have to take care of the filesystem sync yourself before suspending the system in those scenarios. Signed-off-by: Jonas Meurer <jonas@freesources.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
committed by
Rafael J. Wysocki
parent
5c0e9de065
commit
c052bf82c6
@@ -27,7 +27,10 @@ config SUSPEND_SKIP_SYNC
|
||||
Skip the kernel sys_sync() before freezing user processes.
|
||||
Some systems prefer not to pay this cost on every invocation
|
||||
of suspend, or they are content with invoking sync() from
|
||||
user-space before invoking suspend. Say Y if that's your case.
|
||||
user-space before invoking suspend. There's a run-time switch
|
||||
at '/sys/power/sync_on_suspend' to configure this behaviour.
|
||||
This setting changes the default for the run-tim switch. Say Y
|
||||
to change the default to disable the kernel sys_sync().
|
||||
|
||||
config HIBERNATE_CALLBACKS
|
||||
bool
|
||||
|
||||
@@ -190,6 +190,38 @@ static ssize_t mem_sleep_store(struct kobject *kobj, struct kobj_attribute *attr
|
||||
}
|
||||
|
||||
power_attr(mem_sleep);
|
||||
|
||||
/*
|
||||
* sync_on_suspend: invoke ksys_sync_helper() before suspend.
|
||||
*
|
||||
* show() returns whether ksys_sync_helper() is invoked before suspend.
|
||||
* store() accepts 0 or 1. 0 disables ksys_sync_helper() and 1 enables it.
|
||||
*/
|
||||
bool sync_on_suspend_enabled = !IS_ENABLED(CONFIG_SUSPEND_SKIP_SYNC);
|
||||
|
||||
static ssize_t sync_on_suspend_show(struct kobject *kobj,
|
||||
struct kobj_attribute *attr, char *buf)
|
||||
{
|
||||
return sprintf(buf, "%d\n", sync_on_suspend_enabled);
|
||||
}
|
||||
|
||||
static ssize_t sync_on_suspend_store(struct kobject *kobj,
|
||||
struct kobj_attribute *attr,
|
||||
const char *buf, size_t n)
|
||||
{
|
||||
unsigned long val;
|
||||
|
||||
if (kstrtoul(buf, 10, &val))
|
||||
return -EINVAL;
|
||||
|
||||
if (val > 1)
|
||||
return -EINVAL;
|
||||
|
||||
sync_on_suspend_enabled = !!val;
|
||||
return n;
|
||||
}
|
||||
|
||||
power_attr(sync_on_suspend);
|
||||
#endif /* CONFIG_SUSPEND */
|
||||
|
||||
#ifdef CONFIG_PM_SLEEP_DEBUG
|
||||
@@ -855,6 +887,7 @@ static struct attribute * g[] = {
|
||||
&wakeup_count_attr.attr,
|
||||
#ifdef CONFIG_SUSPEND
|
||||
&mem_sleep_attr.attr,
|
||||
&sync_on_suspend_attr.attr,
|
||||
#endif
|
||||
#ifdef CONFIG_PM_AUTOSLEEP
|
||||
&autosleep_attr.attr,
|
||||
|
||||
@@ -564,7 +564,7 @@ static int enter_state(suspend_state_t state)
|
||||
if (state == PM_SUSPEND_TO_IDLE)
|
||||
s2idle_begin();
|
||||
|
||||
if (!IS_ENABLED(CONFIG_SUSPEND_SKIP_SYNC)) {
|
||||
if (sync_on_suspend_enabled) {
|
||||
trace_suspend_resume(TPS("sync_filesystems"), 0, true);
|
||||
ksys_sync_helper();
|
||||
trace_suspend_resume(TPS("sync_filesystems"), 0, false);
|
||||
|
||||
Reference in New Issue
Block a user