Skip to content

Commit a0acae0

Browse files
committed
freezer: unexport refrigerator() and update try_to_freeze() slightly
There is no reason to export two functions for entering the refrigerator. Calling refrigerator() instead of try_to_freeze() doesn't save anything noticeable or removes any race condition. * Rename refrigerator() to __refrigerator() and make it return bool indicating whether it scheduled out for freezing. * Update try_to_freeze() to return bool and relay the return value of __refrigerator() if freezing(). * Convert all refrigerator() users to try_to_freeze(). * Update documentation accordingly. * While at it, add might_sleep() to try_to_freeze(). Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Samuel Ortiz <samuel@sortiz.org> Cc: Chris Mason <chris.mason@oracle.com> Cc: "Theodore Ts'o" <tytso@mit.edu> Cc: Steven Whitehouse <swhiteho@redhat.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Jan Kara <jack@suse.cz> Cc: KONISHI Ryusuke <konishi.ryusuke@lab.ntt.co.jp> Cc: Christoph Hellwig <hch@infradead.org>
1 parent 3a7cbd5 commit a0acae0

15 files changed

Lines changed: 37 additions & 39 deletions

File tree

‎Documentation/power/freezing-of-tasks.txt‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ freeze_processes() (defined in kernel/power/process.c) is called. It executes
2121
try_to_freeze_tasks() that sets TIF_FREEZE for all of the freezable tasks and
2222
either wakes them up, if they are kernel threads, or sends fake signals to them,
2323
if they are user space processes. A task that has TIF_FREEZE set, should react
24-
to it by calling the function called refrigerator() (defined in
24+
to it by calling the function called __refrigerator() (defined in
2525
kernel/freezer.c), which sets the task's PF_FROZEN flag, changes its state
2626
to TASK_UNINTERRUPTIBLE and makes it loop until PF_FROZEN is cleared for it.
2727
Then, we say that the task is 'frozen' and therefore the set of functions
2828
handling this mechanism is referred to as 'the freezer' (these functions are
2929
defined in kernel/power/process.c, kernel/freezer.c & include/linux/freezer.h).
3030
User space processes are generally frozen before kernel threads.
3131

32-
It is not recommended to call refrigerator() directly. Instead, it is
33-
recommended to use the try_to_freeze() function (defined in
34-
include/linux/freezer.h), that checks the task's TIF_FREEZE flag and makes the
35-
task enter refrigerator() if the flag is set.
32+
__refrigerator() must not be called directly. Instead, use the
33+
try_to_freeze() function (defined in include/linux/freezer.h), that checks
34+
the task's TIF_FREEZE flag and makes the task enter __refrigerator() if the
35+
flag is set.
3636

3737
For user space processes try_to_freeze() is called automatically from the
3838
signal-handling code, but the freezable kernel threads need to call it
@@ -61,7 +61,7 @@ wait_event_freezable() and wait_event_freezable_timeout() macros.
6161
After the system memory state has been restored from a hibernation image and
6262
devices have been reinitialized, the function thaw_processes() is called in
6363
order to clear the PF_FROZEN flag for each frozen task. Then, the tasks that
64-
have been frozen leave refrigerator() and continue running.
64+
have been frozen leave __refrigerator() and continue running.
6565

6666
III. Which kernel threads are freezable?
6767

‎drivers/net/irda/stir4200.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ static int stir_transmit_thread(void *arg)
750750

751751
write_reg(stir, REG_CTRL1, CTRL1_TXPWD|CTRL1_RXPWD);
752752

753-
refrigerator();
753+
try_to_freeze();
754754

755755
if (change_speed(stir, stir->speed))
756756
break;

‎fs/btrfs/async-thread.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ static int worker_loop(void *arg)
340340
if (freezing(current)) {
341341
worker->working = 0;
342342
spin_unlock_irq(&worker->lock);
343-
refrigerator();
343+
try_to_freeze();
344344
} else {
345345
spin_unlock_irq(&worker->lock);
346346
if (!kthread_should_stop()) {

‎fs/btrfs/disk-io.c‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,9 +1579,7 @@ static int cleaner_kthread(void *arg)
15791579
btrfs_run_defrag_inodes(root->fs_info);
15801580
}
15811581

1582-
if (freezing(current)) {
1583-
refrigerator();
1584-
} else {
1582+
if (!try_to_freeze()) {
15851583
set_current_state(TASK_INTERRUPTIBLE);
15861584
if (!kthread_should_stop())
15871585
schedule();
@@ -1635,9 +1633,7 @@ static int transaction_kthread(void *arg)
16351633
wake_up_process(root->fs_info->cleaner_kthread);
16361634
mutex_unlock(&root->fs_info->transaction_kthread_mutex);
16371635

1638-
if (freezing(current)) {
1639-
refrigerator();
1640-
} else {
1636+
if (!try_to_freeze()) {
16411637
set_current_state(TASK_INTERRUPTIBLE);
16421638
if (!kthread_should_stop() &&
16431639
!btrfs_transaction_blocked(root->fs_info))

‎fs/ext4/super.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2882,8 +2882,7 @@ static int ext4_lazyinit_thread(void *arg)
28822882
}
28832883
mutex_unlock(&eli->li_list_mtx);
28842884

2885-
if (freezing(current))
2886-
refrigerator();
2885+
try_to_freeze();
28872886

28882887
cur = jiffies;
28892888
if ((time_after_eq(cur, next_wakeup)) ||

‎fs/gfs2/log.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,8 @@ int gfs2_logd(void *data)
951951
wake_up(&sdp->sd_log_waitq);
952952

953953
t = gfs2_tune_get(sdp, gt_logd_secs) * HZ;
954-
if (freezing(current))
955-
refrigerator();
954+
955+
try_to_freeze();
956956

957957
do {
958958
prepare_to_wait(&sdp->sd_logd_waitq, &wait,

‎fs/gfs2/quota.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,8 +1427,8 @@ int gfs2_quotad(void *data)
14271427
/* Check for & recover partially truncated inodes */
14281428
quotad_check_trunc_list(sdp);
14291429

1430-
if (freezing(current))
1431-
refrigerator();
1430+
try_to_freeze();
1431+
14321432
t = min(quotad_timeo, statfs_timeo);
14331433

14341434
prepare_to_wait(&sdp->sd_quota_wait, &wait, TASK_INTERRUPTIBLE);

‎fs/jbd/journal.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ static int kjournald(void *arg)
166166
*/
167167
jbd_debug(1, "Now suspending kjournald\n");
168168
spin_unlock(&journal->j_state_lock);
169-
refrigerator();
169+
try_to_freeze();
170170
spin_lock(&journal->j_state_lock);
171171
} else {
172172
/*

‎fs/jbd2/journal.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ static int kjournald2(void *arg)
173173
*/
174174
jbd_debug(1, "Now suspending kjournald2\n");
175175
write_unlock(&journal->j_state_lock);
176-
refrigerator();
176+
try_to_freeze();
177177
write_lock(&journal->j_state_lock);
178178
} else {
179179
/*

‎fs/jfs/jfs_logmgr.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2349,7 +2349,7 @@ int jfsIOWait(void *arg)
23492349

23502350
if (freezing(current)) {
23512351
spin_unlock_irq(&log_redrive_lock);
2352-
refrigerator();
2352+
try_to_freeze();
23532353
} else {
23542354
set_current_state(TASK_INTERRUPTIBLE);
23552355
spin_unlock_irq(&log_redrive_lock);

0 commit comments

Comments
 (0)