Skip to content

Commit 6973519

Browse files
KAGA-KOKOrostedt
authored andcommitted
buffer_head: Replace bh_uptodate_lock for -rt
Wrap the bit_spin_lock calls into a separate inline and add the RT replacements with a real spinlock. Signed-off-by: Thomas Gleixner <[email protected]>
1 parent ebb738b commit 6973519

File tree

5 files changed

+48
-29
lines changed

5 files changed

+48
-29
lines changed

fs/buffer.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,7 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate)
302302
* decide that the page is now completely done.
303303
*/
304304
first = page_buffers(page);
305-
local_irq_save(flags);
306-
bit_spin_lock(BH_Uptodate_Lock, &first->b_state);
305+
flags = bh_uptodate_lock_irqsave(first);
307306
clear_buffer_async_read(bh);
308307
unlock_buffer(bh);
309308
tmp = bh;
@@ -316,8 +315,7 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate)
316315
}
317316
tmp = tmp->b_this_page;
318317
} while (tmp != bh);
319-
bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
320-
local_irq_restore(flags);
318+
bh_uptodate_unlock_irqrestore(first, flags);
321319

322320
/*
323321
* If none of the buffers had errors and they are all
@@ -329,9 +327,7 @@ static void end_buffer_async_read(struct buffer_head *bh, int uptodate)
329327
return;
330328

331329
still_busy:
332-
bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
333-
local_irq_restore(flags);
334-
return;
330+
bh_uptodate_unlock_irqrestore(first, flags);
335331
}
336332

337333
/*
@@ -358,8 +354,7 @@ void end_buffer_async_write(struct buffer_head *bh, int uptodate)
358354
}
359355

360356
first = page_buffers(page);
361-
local_irq_save(flags);
362-
bit_spin_lock(BH_Uptodate_Lock, &first->b_state);
357+
flags = bh_uptodate_lock_irqsave(first);
363358

364359
clear_buffer_async_write(bh);
365360
unlock_buffer(bh);
@@ -371,15 +366,12 @@ void end_buffer_async_write(struct buffer_head *bh, int uptodate)
371366
}
372367
tmp = tmp->b_this_page;
373368
}
374-
bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
375-
local_irq_restore(flags);
369+
bh_uptodate_unlock_irqrestore(first, flags);
376370
end_page_writeback(page);
377371
return;
378372

379373
still_busy:
380-
bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
381-
local_irq_restore(flags);
382-
return;
374+
bh_uptodate_unlock_irqrestore(first, flags);
383375
}
384376
EXPORT_SYMBOL(end_buffer_async_write);
385377

@@ -3417,6 +3409,7 @@ struct buffer_head *alloc_buffer_head(gfp_t gfp_flags)
34173409
struct buffer_head *ret = kmem_cache_zalloc(bh_cachep, gfp_flags);
34183410
if (ret) {
34193411
INIT_LIST_HEAD(&ret->b_assoc_buffers);
3412+
buffer_head_init_locks(ret);
34203413
preempt_disable();
34213414
__this_cpu_inc(bh_accounting.nr);
34223415
recalc_bh_state();

fs/ext4/page-io.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ static void ext4_finish_bio(struct bio *bio)
9595
* We check all buffers in the page under BH_Uptodate_Lock
9696
* to avoid races with other end io clearing async_write flags
9797
*/
98-
local_irq_save(flags);
99-
bit_spin_lock(BH_Uptodate_Lock, &head->b_state);
98+
flags = bh_uptodate_lock_irqsave(head);
10099
do {
101100
if (bh_offset(bh) < bio_start ||
102101
bh_offset(bh) + bh->b_size > bio_end) {
@@ -108,8 +107,7 @@ static void ext4_finish_bio(struct bio *bio)
108107
if (bio->bi_status)
109108
buffer_io_error(bh);
110109
} while ((bh = bh->b_this_page) != head);
111-
bit_spin_unlock(BH_Uptodate_Lock, &head->b_state);
112-
local_irq_restore(flags);
110+
bh_uptodate_unlock_irqrestore(head, flags);
113111
if (!under_io) {
114112
#ifdef CONFIG_EXT4_FS_ENCRYPTION
115113
if (data_page)

fs/ntfs/aops.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ static void ntfs_end_buffer_async_read(struct buffer_head *bh, int uptodate)
108108
"0x%llx.", (unsigned long long)bh->b_blocknr);
109109
}
110110
first = page_buffers(page);
111-
local_irq_save(flags);
112-
bit_spin_lock(BH_Uptodate_Lock, &first->b_state);
111+
flags = bh_uptodate_lock_irqsave(first);
113112
clear_buffer_async_read(bh);
114113
unlock_buffer(bh);
115114
tmp = bh;
@@ -124,8 +123,7 @@ static void ntfs_end_buffer_async_read(struct buffer_head *bh, int uptodate)
124123
}
125124
tmp = tmp->b_this_page;
126125
} while (tmp != bh);
127-
bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
128-
local_irq_restore(flags);
126+
bh_uptodate_unlock_irqrestore(first, flags);
129127
/*
130128
* If none of the buffers had errors then we can set the page uptodate,
131129
* but we first have to perform the post read mst fixups, if the
@@ -160,9 +158,7 @@ static void ntfs_end_buffer_async_read(struct buffer_head *bh, int uptodate)
160158
unlock_page(page);
161159
return;
162160
still_busy:
163-
bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
164-
local_irq_restore(flags);
165-
return;
161+
bh_uptodate_unlock_irqrestore(first, flags);
166162
}
167163

168164
/**

fs/xfs/xfs_aops.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,7 @@ xfs_finish_page_writeback(
120120
ASSERT(bvec->bv_offset + bvec->bv_len <= PAGE_SIZE);
121121
ASSERT((bvec->bv_len & (i_blocksize(inode) - 1)) == 0);
122122

123-
local_irq_save(flags);
124-
bit_spin_lock(BH_Uptodate_Lock, &head->b_state);
123+
flags = bh_uptodate_lock_irqsave(head);
125124
do {
126125
if (off >= bvec->bv_offset &&
127126
off < bvec->bv_offset + bvec->bv_len) {
@@ -143,8 +142,7 @@ xfs_finish_page_writeback(
143142
}
144143
off += bh->b_size;
145144
} while ((bh = bh->b_this_page) != head);
146-
bit_spin_unlock(BH_Uptodate_Lock, &head->b_state);
147-
local_irq_restore(flags);
145+
bh_uptodate_unlock_irqrestore(head, flags);
148146

149147
if (!busy)
150148
end_page_writeback(bvec->bv_page);

include/linux/buffer_head.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,42 @@ struct buffer_head {
7676
struct address_space *b_assoc_map; /* mapping this buffer is
7777
associated with */
7878
atomic_t b_count; /* users using this buffer_head */
79+
#ifdef CONFIG_PREEMPT_RT_BASE
80+
spinlock_t b_uptodate_lock;
81+
#endif
7982
};
8083

84+
static inline unsigned long bh_uptodate_lock_irqsave(struct buffer_head *bh)
85+
{
86+
unsigned long flags;
87+
88+
#ifndef CONFIG_PREEMPT_RT_BASE
89+
local_irq_save(flags);
90+
bit_spin_lock(BH_Uptodate_Lock, &bh->b_state);
91+
#else
92+
spin_lock_irqsave(&bh->b_uptodate_lock, flags);
93+
#endif
94+
return flags;
95+
}
96+
97+
static inline void
98+
bh_uptodate_unlock_irqrestore(struct buffer_head *bh, unsigned long flags)
99+
{
100+
#ifndef CONFIG_PREEMPT_RT_BASE
101+
bit_spin_unlock(BH_Uptodate_Lock, &bh->b_state);
102+
local_irq_restore(flags);
103+
#else
104+
spin_unlock_irqrestore(&bh->b_uptodate_lock, flags);
105+
#endif
106+
}
107+
108+
static inline void buffer_head_init_locks(struct buffer_head *bh)
109+
{
110+
#ifdef CONFIG_PREEMPT_RT_BASE
111+
spin_lock_init(&bh->b_uptodate_lock);
112+
#endif
113+
}
114+
81115
/*
82116
* macro tricks to expand the set_buffer_foo(), clear_buffer_foo()
83117
* and buffer_foo() functions.

0 commit comments

Comments
 (0)