Skip to content

Commit b73aee4

Browse files
KAGA-KOKOSebastian Andrzej Siewior
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 6fa8467 commit b73aee4

File tree

3 files changed

+44
-21
lines changed

3 files changed

+44
-21
lines changed

fs/buffer.c

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

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

330328
still_busy:
331-
bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
332-
local_irq_restore(flags);
333-
return;
329+
bh_uptodate_unlock_irqrestore(first, flags);
334330
}
335331

336332
/*
@@ -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

@@ -3383,6 +3375,7 @@ struct buffer_head *alloc_buffer_head(gfp_t gfp_flags)
33833375
struct buffer_head *ret = kmem_cache_zalloc(bh_cachep, gfp_flags);
33843376
if (ret) {
33853377
INIT_LIST_HEAD(&ret->b_assoc_buffers);
3378+
buffer_head_init_locks(ret);
33863379
preempt_disable();
33873380
__this_cpu_inc(bh_accounting.nr);
33883381
recalc_bh_state();

fs/ntfs/aops.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ static void ntfs_end_buffer_async_read(struct buffer_head *bh, int uptodate)
107107
"0x%llx.", (unsigned long long)bh->b_blocknr);
108108
}
109109
first = page_buffers(page);
110-
local_irq_save(flags);
111-
bit_spin_lock(BH_Uptodate_Lock, &first->b_state);
110+
flags = bh_uptodate_lock_irqsave(first);
112111
clear_buffer_async_read(bh);
113112
unlock_buffer(bh);
114113
tmp = bh;
@@ -123,8 +122,7 @@ static void ntfs_end_buffer_async_read(struct buffer_head *bh, int uptodate)
123122
}
124123
tmp = tmp->b_this_page;
125124
} while (tmp != bh);
126-
bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
127-
local_irq_restore(flags);
125+
bh_uptodate_unlock_irqrestore(first, flags);
128126
/*
129127
* If none of the buffers had errors then we can set the page uptodate,
130128
* but we first have to perform the post read mst fixups, if the
@@ -159,9 +157,7 @@ static void ntfs_end_buffer_async_read(struct buffer_head *bh, int uptodate)
159157
unlock_page(page);
160158
return;
161159
still_busy:
162-
bit_spin_unlock(BH_Uptodate_Lock, &first->b_state);
163-
local_irq_restore(flags);
164-
return;
160+
bh_uptodate_unlock_irqrestore(first, flags);
165161
}
166162

167163
/**

include/linux/buffer_head.h

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

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

0 commit comments

Comments
 (0)