Skip to content

Commit c1955ce

Browse files
Christoph HellwigJens Axboe
authored andcommitted
writeback: remove wb_list
The wb_list member of struct backing_device_info always has exactly one element. Just use the direct bdi->wb pointer instead and simplify some code. Also remove bdi_task_init which is now trivial to prepare for the next patch. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
1 parent 4c4762d commit c1955ce

3 files changed

Lines changed: 32 additions & 60 deletions

File tree

‎fs/fs-writeback.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ static void bdi_queue_work(struct backing_dev_info *bdi,
7373
* If the default thread isn't there, make sure we add it. When
7474
* it gets created and wakes up, we'll run this work.
7575
*/
76-
if (unlikely(list_empty_careful(&bdi->wb_list)))
76+
if (unlikely(!bdi->wb.task)) {
7777
wake_up_process(default_backing_dev_info.wb.task);
78-
else {
78+
} else {
7979
struct bdi_writeback *wb = &bdi->wb;
8080

8181
if (wb->task)

‎include/linux/backing-dev.h‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ enum bdi_stat_item {
4545
#define BDI_STAT_BATCH (8*(1+ilog2(nr_cpu_ids)))
4646

4747
struct bdi_writeback {
48-
struct list_head list; /* hangs off the bdi */
49-
5048
struct backing_dev_info *bdi; /* our parent bdi */
5149
unsigned int nr;
5250

@@ -80,8 +78,7 @@ struct backing_dev_info {
8078
unsigned int max_ratio, max_prop_frac;
8179

8280
struct bdi_writeback wb; /* default writeback info for this bdi */
83-
spinlock_t wb_lock; /* protects update side of wb_list */
84-
struct list_head wb_list; /* the flusher threads hanging off this bdi */
81+
spinlock_t wb_lock; /* protects work_list */
8582

8683
struct list_head work_list;
8784

‎mm/backing-dev.c‎

Lines changed: 29 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,21 @@ static void bdi_debug_init(void)
6565
static int bdi_debug_stats_show(struct seq_file *m, void *v)
6666
{
6767
struct backing_dev_info *bdi = m->private;
68-
struct bdi_writeback *wb;
68+
struct bdi_writeback *wb = &bdi->wb;
6969
unsigned long background_thresh;
7070
unsigned long dirty_thresh;
7171
unsigned long bdi_thresh;
7272
unsigned long nr_dirty, nr_io, nr_more_io, nr_wb;
7373
struct inode *inode;
7474

75-
/*
76-
* inode lock is enough here, the bdi->wb_list is protected by
77-
* RCU on the reader side
78-
*/
7975
nr_wb = nr_dirty = nr_io = nr_more_io = 0;
8076
spin_lock(&inode_lock);
81-
list_for_each_entry(wb, &bdi->wb_list, list) {
82-
nr_wb++;
83-
list_for_each_entry(inode, &wb->b_dirty, i_list)
84-
nr_dirty++;
85-
list_for_each_entry(inode, &wb->b_io, i_list)
86-
nr_io++;
87-
list_for_each_entry(inode, &wb->b_more_io, i_list)
88-
nr_more_io++;
89-
}
77+
list_for_each_entry(inode, &wb->b_dirty, i_list)
78+
nr_dirty++;
79+
list_for_each_entry(inode, &wb->b_io, i_list)
80+
nr_io++;
81+
list_for_each_entry(inode, &wb->b_more_io, i_list)
82+
nr_more_io++;
9083
spin_unlock(&inode_lock);
9184

9285
get_dirty_limits(&background_thresh, &dirty_thresh, &bdi_thresh, bdi);
@@ -98,19 +91,16 @@ static int bdi_debug_stats_show(struct seq_file *m, void *v)
9891
"BdiDirtyThresh: %8lu kB\n"
9992
"DirtyThresh: %8lu kB\n"
10093
"BackgroundThresh: %8lu kB\n"
101-
"WritebackThreads: %8lu\n"
10294
"b_dirty: %8lu\n"
10395
"b_io: %8lu\n"
10496
"b_more_io: %8lu\n"
10597
"bdi_list: %8u\n"
106-
"state: %8lx\n"
107-
"wb_list: %8u\n",
98+
"state: %8lx\n",
10899
(unsigned long) K(bdi_stat(bdi, BDI_WRITEBACK)),
109100
(unsigned long) K(bdi_stat(bdi, BDI_RECLAIMABLE)),
110101
K(bdi_thresh), K(dirty_thresh),
111-
K(background_thresh), nr_wb, nr_dirty, nr_io, nr_more_io,
112-
!list_empty(&bdi->bdi_list), bdi->state,
113-
!list_empty(&bdi->wb_list));
102+
K(background_thresh), nr_dirty, nr_io, nr_more_io,
103+
!list_empty(&bdi->bdi_list), bdi->state);
114104
#undef K
115105

116106
return 0;
@@ -270,24 +260,6 @@ static void bdi_wb_init(struct bdi_writeback *wb, struct backing_dev_info *bdi)
270260
INIT_LIST_HEAD(&wb->b_more_io);
271261
}
272262

273-
static void bdi_task_init(struct backing_dev_info *bdi,
274-
struct bdi_writeback *wb)
275-
{
276-
struct task_struct *tsk = current;
277-
278-
spin_lock(&bdi->wb_lock);
279-
list_add_tail_rcu(&wb->list, &bdi->wb_list);
280-
spin_unlock(&bdi->wb_lock);
281-
282-
tsk->flags |= PF_FLUSHER | PF_SWAPWRITE;
283-
set_freezable();
284-
285-
/*
286-
* Our parent may run at a different priority, just set us to normal
287-
*/
288-
set_user_nice(tsk, 0);
289-
}
290-
291263
static int bdi_start_fn(void *ptr)
292264
{
293265
struct bdi_writeback *wb = ptr;
@@ -301,7 +273,13 @@ static int bdi_start_fn(void *ptr)
301273
list_add_rcu(&bdi->bdi_list, &bdi_list);
302274
spin_unlock_bh(&bdi_lock);
303275

304-
bdi_task_init(bdi, wb);
276+
current->flags |= PF_FLUSHER | PF_SWAPWRITE;
277+
set_freezable();
278+
279+
/*
280+
* Our parent may run at a different priority, just set us to normal
281+
*/
282+
set_user_nice(current, 0);
305283

306284
/*
307285
* Clear pending bit and wakeup anybody waiting to tear us down
@@ -312,12 +290,7 @@ static int bdi_start_fn(void *ptr)
312290

313291
ret = bdi_writeback_task(wb);
314292

315-
/*
316-
* Remove us from the list
317-
*/
318-
spin_lock(&bdi->wb_lock);
319-
list_del_rcu(&wb->list);
320-
spin_unlock(&bdi->wb_lock);
293+
wb->task = NULL;
321294

322295
/*
323296
* Flush any work that raced with us exiting. No new work
@@ -326,7 +299,6 @@ static int bdi_start_fn(void *ptr)
326299
if (!list_empty(&bdi->work_list))
327300
wb_do_writeback(wb, 1);
328301

329-
wb->task = NULL;
330302
return ret;
331303
}
332304

@@ -391,7 +363,13 @@ static int bdi_forker_task(void *ptr)
391363
{
392364
struct bdi_writeback *me = ptr;
393365

394-
bdi_task_init(me->bdi, me);
366+
current->flags |= PF_FLUSHER | PF_SWAPWRITE;
367+
set_freezable();
368+
369+
/*
370+
* Our parent may run at a different priority, just set us to normal
371+
*/
372+
set_user_nice(current, 0);
395373

396374
for (;;) {
397375
struct backing_dev_info *bdi, *tmp;
@@ -598,8 +576,6 @@ EXPORT_SYMBOL(bdi_register_dev);
598576
*/
599577
static void bdi_wb_shutdown(struct backing_dev_info *bdi)
600578
{
601-
struct bdi_writeback *wb;
602-
603579
if (!bdi_cap_writeback_dirty(bdi))
604580
return;
605581

@@ -615,14 +591,14 @@ static void bdi_wb_shutdown(struct backing_dev_info *bdi)
615591
bdi_remove_from_list(bdi);
616592

617593
/*
618-
* Finally, kill the kernel threads. We don't need to be RCU
594+
* Finally, kill the kernel thread. We don't need to be RCU
619595
* safe anymore, since the bdi is gone from visibility. Force
620596
* unfreeze of the thread before calling kthread_stop(), otherwise
621597
* it would never exet if it is currently stuck in the refrigerator.
622598
*/
623-
list_for_each_entry(wb, &bdi->wb_list, list) {
624-
thaw_process(wb->task);
625-
kthread_stop(wb->task);
599+
if (bdi->wb.task) {
600+
thaw_process(bdi->wb.task);
601+
kthread_stop(bdi->wb.task);
626602
}
627603
}
628604

@@ -667,7 +643,6 @@ int bdi_init(struct backing_dev_info *bdi)
667643
spin_lock_init(&bdi->wb_lock);
668644
INIT_RCU_HEAD(&bdi->rcu_head);
669645
INIT_LIST_HEAD(&bdi->bdi_list);
670-
INIT_LIST_HEAD(&bdi->wb_list);
671646
INIT_LIST_HEAD(&bdi->work_list);
672647

673648
bdi_wb_init(&bdi->wb, bdi);

0 commit comments

Comments
 (0)