blob: 225bdb7daec749ba85e93c35aceb39fac8be53b5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_BLOCKGROUP_LOCK_H
2#define _LINUX_BLOCKGROUP_LOCK_H
3/*
4 * Per-blockgroup locking for ext2 and ext3.
5 *
6 * Simple hashed spinlocking.
7 */
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/spinlock.h>
10#include <linux/cache.h>
11
12#ifdef CONFIG_SMP
Eric Biggers7c5f6b32016-09-15 18:29:06 -040013#define NR_BG_LOCKS (4 << ilog2(NR_CPUS < 32 ? NR_CPUS : 32))
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#else
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#define NR_BG_LOCKS 1
Eric Biggers7c5f6b32016-09-15 18:29:06 -040016#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18struct bgl_lock {
19 spinlock_t lock;
20} ____cacheline_aligned_in_smp;
21
22struct blockgroup_lock {
23 struct bgl_lock locks[NR_BG_LOCKS];
24};
25
26static inline void bgl_lock_init(struct blockgroup_lock *bgl)
27{
28 int i;
29
30 for (i = 0; i < NR_BG_LOCKS; i++)
31 spin_lock_init(&bgl->locks[i].lock);
32}
33
Pekka Enbergc644f0e2009-01-04 12:00:48 -080034static inline spinlock_t *
35bgl_lock_ptr(struct blockgroup_lock *bgl, unsigned int block_group)
36{
Eric Biggers9e5ab852016-09-15 18:25:07 -040037 return &bgl->locks[block_group & (NR_BG_LOCKS-1)].lock;
Pekka Enbergc644f0e2009-01-04 12:00:48 -080038}
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40#endif