Skip to content

Commit 7431620

Browse files
neilbrownIngo Molnar
authored andcommitted
sched: Remove proliferation of wait_on_bit() action functions
The current "wait_on_bit" interface requires an 'action' function to be provided which does the actual waiting. There are over 20 such functions, many of them identical. Most cases can be satisfied by one of just two functions, one which uses io_schedule() and one which just uses schedule(). So: Rename wait_on_bit and wait_on_bit_lock to wait_on_bit_action and wait_on_bit_lock_action to make it explicit that they need an action function. Introduce new wait_on_bit{,_lock} and wait_on_bit{,_lock}_io which are *not* given an action function but implicitly use a standard one. The decision to error-out if a signal is pending is now made based on the 'mode' argument rather than being encoded in the action function. All instances of the old wait_on_bit and wait_on_bit_lock which can use the new version have been changed accordingly and their action functions have been discarded. wait_on_bit{_lock} does not return any specific error code in the event of a signal so the caller must check for non-zero and interpolate their own error code as appropriate. The wait_on_bit() call in __fscache_wait_on_invalidate() was ambiguous as it specified TASK_UNINTERRUPTIBLE but used fscache_wait_bit_interruptible as an action function. David Howells confirms this should be uniformly "uninterruptible" The main remaining user of wait_on_bit{,_lock}_action is NFS which needs to use a freezer-aware schedule() call. A comment in fs/gfs2/glock.c notes that having multiple 'action' functions is useful as they display differently in the 'wchan' field of 'ps'. (and /proc/$PID/wchan). As the new bit_wait{,_io} functions are tagged "__sched", they will not show up at all, but something higher in the stack. So the distinction will still be visible, only with different function names (gds2_glock_wait versus gfs2_glock_dq_wait in the gfs2/glock.c case). Since first version of this patch (against 3.15) two new action functions appeared, on in NFS and one in CIFS. CIFS also now uses an action function that makes the same freezer aware schedule call as NFS. Signed-off-by: NeilBrown <neilb@suse.de> Acked-by: David Howells <dhowells@redhat.com> (fscache, keys) Acked-by: Steven Whitehouse <swhiteho@redhat.com> (gfs2) Acked-by: Peter Zijlstra <peterz@infradead.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Steve French <sfrench@samba.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Link: http://lkml.kernel.org/r/20140707051603.28027.72349.stgit@notabene.brown Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent d26fad5 commit 7431620

File tree

38 files changed

+195
-275
lines changed

38 files changed

+195
-275
lines changed

Documentation/filesystems/caching/operations.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ operations:
9090
to be cleared before proceeding:
9191

9292
wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
93-
fscache_wait_bit, TASK_UNINTERRUPTIBLE);
93+
TASK_UNINTERRUPTIBLE);
9494

9595

9696
(2) The operation may be fast asynchronous (FSCACHE_OP_FAST), in which case it

drivers/md/dm-bufio.c

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -614,16 +614,6 @@ static void write_endio(struct bio *bio, int error)
614614
wake_up_bit(&b->state, B_WRITING);
615615
}
616616

617-
/*
618-
* This function is called when wait_on_bit is actually waiting.
619-
*/
620-
static int do_io_schedule(void *word)
621-
{
622-
io_schedule();
623-
624-
return 0;
625-
}
626-
627617
/*
628618
* Initiate a write on a dirty buffer, but don't wait for it.
629619
*
@@ -640,8 +630,7 @@ static void __write_dirty_buffer(struct dm_buffer *b,
640630
return;
641631

642632
clear_bit(B_DIRTY, &b->state);
643-
wait_on_bit_lock(&b->state, B_WRITING,
644-
do_io_schedule, TASK_UNINTERRUPTIBLE);
633+
wait_on_bit_lock_io(&b->state, B_WRITING, TASK_UNINTERRUPTIBLE);
645634

646635
if (!write_list)
647636
submit_io(b, WRITE, b->block, write_endio);
@@ -675,9 +664,9 @@ static void __make_buffer_clean(struct dm_buffer *b)
675664
if (!b->state) /* fast case */
676665
return;
677666

678-
wait_on_bit(&b->state, B_READING, do_io_schedule, TASK_UNINTERRUPTIBLE);
667+
wait_on_bit_io(&b->state, B_READING, TASK_UNINTERRUPTIBLE);
679668
__write_dirty_buffer(b, NULL);
680-
wait_on_bit(&b->state, B_WRITING, do_io_schedule, TASK_UNINTERRUPTIBLE);
669+
wait_on_bit_io(&b->state, B_WRITING, TASK_UNINTERRUPTIBLE);
681670
}
682671

683672
/*
@@ -1030,7 +1019,7 @@ static void *new_read(struct dm_bufio_client *c, sector_t block,
10301019
if (need_submit)
10311020
submit_io(b, READ, b->block, read_endio);
10321021

1033-
wait_on_bit(&b->state, B_READING, do_io_schedule, TASK_UNINTERRUPTIBLE);
1022+
wait_on_bit_io(&b->state, B_READING, TASK_UNINTERRUPTIBLE);
10341023

10351024
if (b->read_error) {
10361025
int error = b->read_error;
@@ -1209,15 +1198,13 @@ int dm_bufio_write_dirty_buffers(struct dm_bufio_client *c)
12091198
dropped_lock = 1;
12101199
b->hold_count++;
12111200
dm_bufio_unlock(c);
1212-
wait_on_bit(&b->state, B_WRITING,
1213-
do_io_schedule,
1214-
TASK_UNINTERRUPTIBLE);
1201+
wait_on_bit_io(&b->state, B_WRITING,
1202+
TASK_UNINTERRUPTIBLE);
12151203
dm_bufio_lock(c);
12161204
b->hold_count--;
12171205
} else
1218-
wait_on_bit(&b->state, B_WRITING,
1219-
do_io_schedule,
1220-
TASK_UNINTERRUPTIBLE);
1206+
wait_on_bit_io(&b->state, B_WRITING,
1207+
TASK_UNINTERRUPTIBLE);
12211208
}
12221209

12231210
if (!test_bit(B_DIRTY, &b->state) &&
@@ -1321,15 +1308,15 @@ void dm_bufio_release_move(struct dm_buffer *b, sector_t new_block)
13211308

13221309
__write_dirty_buffer(b, NULL);
13231310
if (b->hold_count == 1) {
1324-
wait_on_bit(&b->state, B_WRITING,
1325-
do_io_schedule, TASK_UNINTERRUPTIBLE);
1311+
wait_on_bit_io(&b->state, B_WRITING,
1312+
TASK_UNINTERRUPTIBLE);
13261313
set_bit(B_DIRTY, &b->state);
13271314
__unlink_buffer(b);
13281315
__link_buffer(b, new_block, LIST_DIRTY);
13291316
} else {
13301317
sector_t old_block;
1331-
wait_on_bit_lock(&b->state, B_WRITING,
1332-
do_io_schedule, TASK_UNINTERRUPTIBLE);
1318+
wait_on_bit_lock_io(&b->state, B_WRITING,
1319+
TASK_UNINTERRUPTIBLE);
13331320
/*
13341321
* Relink buffer to "new_block" so that write_callback
13351322
* sees "new_block" as a block number.
@@ -1341,8 +1328,8 @@ void dm_bufio_release_move(struct dm_buffer *b, sector_t new_block)
13411328
__unlink_buffer(b);
13421329
__link_buffer(b, new_block, b->list_mode);
13431330
submit_io(b, WRITE, new_block, write_endio);
1344-
wait_on_bit(&b->state, B_WRITING,
1345-
do_io_schedule, TASK_UNINTERRUPTIBLE);
1331+
wait_on_bit_io(&b->state, B_WRITING,
1332+
TASK_UNINTERRUPTIBLE);
13461333
__unlink_buffer(b);
13471334
__link_buffer(b, old_block, b->list_mode);
13481335
}

drivers/md/dm-snap.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,21 +1032,13 @@ static void start_merge(struct dm_snapshot *s)
10321032
snapshot_merge_next_chunks(s);
10331033
}
10341034

1035-
static int wait_schedule(void *ptr)
1036-
{
1037-
schedule();
1038-
1039-
return 0;
1040-
}
1041-
10421035
/*
10431036
* Stop the merging process and wait until it finishes.
10441037
*/
10451038
static void stop_merge(struct dm_snapshot *s)
10461039
{
10471040
set_bit(SHUTDOWN_MERGE, &s->state_bits);
1048-
wait_on_bit(&s->state_bits, RUNNING_MERGE, wait_schedule,
1049-
TASK_UNINTERRUPTIBLE);
1041+
wait_on_bit(&s->state_bits, RUNNING_MERGE, TASK_UNINTERRUPTIBLE);
10501042
clear_bit(SHUTDOWN_MERGE, &s->state_bits);
10511043
}
10521044

drivers/media/usb/dvb-usb-v2/dvb_usb_core.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,6 @@ static int dvb_usbv2_adapter_stream_exit(struct dvb_usb_adapter *adap)
253253
return usb_urb_exitv2(&adap->stream);
254254
}
255255

256-
static int wait_schedule(void *ptr)
257-
{
258-
schedule();
259-
260-
return 0;
261-
}
262-
263256
static int dvb_usb_start_feed(struct dvb_demux_feed *dvbdmxfeed)
264257
{
265258
struct dvb_usb_adapter *adap = dvbdmxfeed->demux->priv;
@@ -273,8 +266,7 @@ static int dvb_usb_start_feed(struct dvb_demux_feed *dvbdmxfeed)
273266
dvbdmxfeed->pid, dvbdmxfeed->index);
274267

275268
/* wait init is done */
276-
wait_on_bit(&adap->state_bits, ADAP_INIT, wait_schedule,
277-
TASK_UNINTERRUPTIBLE);
269+
wait_on_bit(&adap->state_bits, ADAP_INIT, TASK_UNINTERRUPTIBLE);
278270

279271
if (adap->active_fe == -1)
280272
return -EINVAL;
@@ -568,7 +560,7 @@ static int dvb_usb_fe_sleep(struct dvb_frontend *fe)
568560

569561
if (!adap->suspend_resume_active) {
570562
set_bit(ADAP_SLEEP, &adap->state_bits);
571-
wait_on_bit(&adap->state_bits, ADAP_STREAMING, wait_schedule,
563+
wait_on_bit(&adap->state_bits, ADAP_STREAMING,
572564
TASK_UNINTERRUPTIBLE);
573565
}
574566

fs/btrfs/extent_io.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3437,16 +3437,10 @@ static int __extent_writepage(struct page *page, struct writeback_control *wbc,
34373437
return 0;
34383438
}
34393439

3440-
static int eb_wait(void *word)
3441-
{
3442-
io_schedule();
3443-
return 0;
3444-
}
3445-
34463440
void wait_on_extent_buffer_writeback(struct extent_buffer *eb)
34473441
{
3448-
wait_on_bit(&eb->bflags, EXTENT_BUFFER_WRITEBACK, eb_wait,
3449-
TASK_UNINTERRUPTIBLE);
3442+
wait_on_bit_io(&eb->bflags, EXTENT_BUFFER_WRITEBACK,
3443+
TASK_UNINTERRUPTIBLE);
34503444
}
34513445

34523446
static noinline_for_stack int

fs/buffer.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,9 @@ inline void touch_buffer(struct buffer_head *bh)
6161
}
6262
EXPORT_SYMBOL(touch_buffer);
6363

64-
static int sleep_on_buffer(void *word)
65-
{
66-
io_schedule();
67-
return 0;
68-
}
69-
7064
void __lock_buffer(struct buffer_head *bh)
7165
{
72-
wait_on_bit_lock(&bh->b_state, BH_Lock, sleep_on_buffer,
73-
TASK_UNINTERRUPTIBLE);
66+
wait_on_bit_lock_io(&bh->b_state, BH_Lock, TASK_UNINTERRUPTIBLE);
7467
}
7568
EXPORT_SYMBOL(__lock_buffer);
7669

@@ -123,7 +116,7 @@ EXPORT_SYMBOL(buffer_check_dirty_writeback);
123116
*/
124117
void __wait_on_buffer(struct buffer_head * bh)
125118
{
126-
wait_on_bit(&bh->b_state, BH_Lock, sleep_on_buffer, TASK_UNINTERRUPTIBLE);
119+
wait_on_bit_io(&bh->b_state, BH_Lock, TASK_UNINTERRUPTIBLE);
127120
}
128121
EXPORT_SYMBOL(__wait_on_buffer);
129122

fs/cifs/connect.c

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3934,13 +3934,6 @@ cifs_sb_master_tcon(struct cifs_sb_info *cifs_sb)
39343934
return tlink_tcon(cifs_sb_master_tlink(cifs_sb));
39353935
}
39363936

3937-
static int
3938-
cifs_sb_tcon_pending_wait(void *unused)
3939-
{
3940-
schedule();
3941-
return signal_pending(current) ? -ERESTARTSYS : 0;
3942-
}
3943-
39443937
/* find and return a tlink with given uid */
39453938
static struct tcon_link *
39463939
tlink_rb_search(struct rb_root *root, kuid_t uid)
@@ -4039,11 +4032,10 @@ cifs_sb_tlink(struct cifs_sb_info *cifs_sb)
40394032
} else {
40404033
wait_for_construction:
40414034
ret = wait_on_bit(&tlink->tl_flags, TCON_LINK_PENDING,
4042-
cifs_sb_tcon_pending_wait,
40434035
TASK_INTERRUPTIBLE);
40444036
if (ret) {
40454037
cifs_put_tlink(tlink);
4046-
return ERR_PTR(ret);
4038+
return ERR_PTR(-ERESTARTSYS);
40474039
}
40484040

40494041
/* if it's good, return it */

fs/cifs/file.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3618,13 +3618,6 @@ static int cifs_launder_page(struct page *page)
36183618
return rc;
36193619
}
36203620

3621-
static int
3622-
cifs_pending_writers_wait(void *unused)
3623-
{
3624-
schedule();
3625-
return 0;
3626-
}
3627-
36283621
void cifs_oplock_break(struct work_struct *work)
36293622
{
36303623
struct cifsFileInfo *cfile = container_of(work, struct cifsFileInfo,
@@ -3636,7 +3629,7 @@ void cifs_oplock_break(struct work_struct *work)
36363629
int rc = 0;
36373630

36383631
wait_on_bit(&cinode->flags, CIFS_INODE_PENDING_WRITERS,
3639-
cifs_pending_writers_wait, TASK_UNINTERRUPTIBLE);
3632+
TASK_UNINTERRUPTIBLE);
36403633

36413634
server->ops->downgrade_oplock(server, cinode,
36423635
test_bit(CIFS_INODE_DOWNGRADE_OPLOCK_TO_L2, &cinode->flags));

fs/cifs/inode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,8 +1794,8 @@ cifs_revalidate_mapping(struct inode *inode)
17941794
int rc;
17951795
unsigned long *flags = &CIFS_I(inode)->flags;
17961796

1797-
rc = wait_on_bit_lock(flags, CIFS_INO_LOCK, cifs_wait_bit_killable,
1798-
TASK_KILLABLE);
1797+
rc = wait_on_bit_lock_action(flags, CIFS_INO_LOCK, cifs_wait_bit_killable,
1798+
TASK_KILLABLE);
17991799
if (rc)
18001800
return rc;
18011801

fs/cifs/misc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ int cifs_get_writer(struct cifsInodeInfo *cinode)
582582

583583
start:
584584
rc = wait_on_bit(&cinode->flags, CIFS_INODE_PENDING_OPLOCK_BREAK,
585-
cifs_oplock_break_wait, TASK_KILLABLE);
585+
TASK_KILLABLE);
586586
if (rc)
587587
return rc;
588588

fs/fs-writeback.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,8 @@ static void __inode_wait_for_writeback(struct inode *inode)
342342
wqh = bit_waitqueue(&inode->i_state, __I_SYNC);
343343
while (inode->i_state & I_SYNC) {
344344
spin_unlock(&inode->i_lock);
345-
__wait_on_bit(wqh, &wq, inode_wait, TASK_UNINTERRUPTIBLE);
345+
__wait_on_bit(wqh, &wq, bit_wait,
346+
TASK_UNINTERRUPTIBLE);
346347
spin_lock(&inode->i_lock);
347348
}
348349
}

fs/fscache/cookie.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void __fscache_enable_cookie(struct fscache_cookie *cookie,
160160
_enter("%p", cookie);
161161

162162
wait_on_bit_lock(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK,
163-
fscache_wait_bit, TASK_UNINTERRUPTIBLE);
163+
TASK_UNINTERRUPTIBLE);
164164

165165
if (test_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags))
166166
goto out_unlock;
@@ -255,7 +255,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
255255
if (!fscache_defer_lookup) {
256256
_debug("non-deferred lookup %p", &cookie->flags);
257257
wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
258-
fscache_wait_bit, TASK_UNINTERRUPTIBLE);
258+
TASK_UNINTERRUPTIBLE);
259259
_debug("complete");
260260
if (test_bit(FSCACHE_COOKIE_UNAVAILABLE, &cookie->flags))
261261
goto unavailable;
@@ -463,7 +463,6 @@ void __fscache_wait_on_invalidate(struct fscache_cookie *cookie)
463463
_enter("%p", cookie);
464464

465465
wait_on_bit(&cookie->flags, FSCACHE_COOKIE_INVALIDATING,
466-
fscache_wait_bit_interruptible,
467466
TASK_UNINTERRUPTIBLE);
468467

469468
_leave("");
@@ -525,7 +524,7 @@ void __fscache_disable_cookie(struct fscache_cookie *cookie, bool invalidate)
525524
}
526525

527526
wait_on_bit_lock(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK,
528-
fscache_wait_bit, TASK_UNINTERRUPTIBLE);
527+
TASK_UNINTERRUPTIBLE);
529528
if (!test_and_clear_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags))
530529
goto out_unlock_enable;
531530

fs/fscache/internal.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ static inline bool fscache_object_congested(void)
9797
return workqueue_congested(WORK_CPU_UNBOUND, fscache_object_wq);
9898
}
9999

100-
extern int fscache_wait_bit(void *);
101-
extern int fscache_wait_bit_interruptible(void *);
102100
extern int fscache_wait_atomic_t(atomic_t *);
103101

104102
/*

fs/fscache/main.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -196,24 +196,6 @@ static void __exit fscache_exit(void)
196196

197197
module_exit(fscache_exit);
198198

199-
/*
200-
* wait_on_bit() sleep function for uninterruptible waiting
201-
*/
202-
int fscache_wait_bit(void *flags)
203-
{
204-
schedule();
205-
return 0;
206-
}
207-
208-
/*
209-
* wait_on_bit() sleep function for interruptible waiting
210-
*/
211-
int fscache_wait_bit_interruptible(void *flags)
212-
{
213-
schedule();
214-
return signal_pending(current);
215-
}
216-
217199
/*
218200
* wait_on_atomic_t() sleep function for uninterruptible waiting
219201
*/

fs/fscache/page.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
298298

299299
jif = jiffies;
300300
if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
301-
fscache_wait_bit_interruptible,
302301
TASK_INTERRUPTIBLE) != 0) {
303302
fscache_stat(&fscache_n_retrievals_intr);
304303
_leave(" = -ERESTARTSYS");
@@ -342,7 +341,6 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
342341
if (stat_op_waits)
343342
fscache_stat(stat_op_waits);
344343
if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
345-
fscache_wait_bit_interruptible,
346344
TASK_INTERRUPTIBLE) != 0) {
347345
ret = fscache_cancel_op(op, do_cancel);
348346
if (ret == 0)
@@ -351,7 +349,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
351349
/* it's been removed from the pending queue by another party,
352350
* so we should get to run shortly */
353351
wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
354-
fscache_wait_bit, TASK_UNINTERRUPTIBLE);
352+
TASK_UNINTERRUPTIBLE);
355353
}
356354
_debug("<<< GO");
357355

0 commit comments

Comments
 (0)