Skip to content

Commit 9518e5b

Browse files
umgwanakikbutiaxboe
authored andcommitted
zram: Replace bit spinlocks with a spinlock_t.
The bit spinlock disables preemption. The spinlock_t lock becomes a sleeping lock on PREEMPT_RT and it can not be acquired in this context. In this locked section, zs_free() acquires a zs_pool::lock, and there is access to zram::wb_limit_lock. Add a spinlock_t for locking. Keep the set/ clear ZRAM_LOCK bit after the lock has been acquired/ dropped. The size of struct zram_table_entry increases by 4 bytes due to lock and additional 4 bytes padding with CONFIG_ZRAM_TRACK_ENTRY_ACTIME enabled. Signed-off-by: Mike Galbraith <[email protected]> Reviewed-by: Sergey Senozhatsky <[email protected]> Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Reviewed-by: Jens Axboe <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 296dbc7 commit 9518e5b

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

drivers/block/zram/zram_drv.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,24 @@ static int zram_read_page(struct zram *zram, struct page *page, u32 index,
5959

6060
static int zram_slot_trylock(struct zram *zram, u32 index)
6161
{
62-
return bit_spin_trylock(ZRAM_LOCK, &zram->table[index].flags);
62+
int ret;
63+
64+
ret = spin_trylock(&zram->table[index].lock);
65+
if (ret)
66+
__set_bit(ZRAM_LOCK, &zram->table[index].flags);
67+
return ret;
6368
}
6469

6570
static void zram_slot_lock(struct zram *zram, u32 index)
6671
{
67-
bit_spin_lock(ZRAM_LOCK, &zram->table[index].flags);
72+
spin_lock(&zram->table[index].lock);
73+
__set_bit(ZRAM_LOCK, &zram->table[index].flags);
6874
}
6975

7076
static void zram_slot_unlock(struct zram *zram, u32 index)
7177
{
72-
bit_spin_unlock(ZRAM_LOCK, &zram->table[index].flags);
78+
__clear_bit(ZRAM_LOCK, &zram->table[index].flags);
79+
spin_unlock(&zram->table[index].lock);
7380
}
7481

7582
static inline bool init_done(struct zram *zram)
@@ -1211,7 +1218,7 @@ static void zram_meta_free(struct zram *zram, u64 disksize)
12111218

12121219
static bool zram_meta_alloc(struct zram *zram, u64 disksize)
12131220
{
1214-
size_t num_pages;
1221+
size_t num_pages, index;
12151222

12161223
num_pages = disksize >> PAGE_SHIFT;
12171224
zram->table = vzalloc(array_size(num_pages, sizeof(*zram->table)));
@@ -1226,6 +1233,9 @@ static bool zram_meta_alloc(struct zram *zram, u64 disksize)
12261233

12271234
if (!huge_class_size)
12281235
huge_class_size = zs_huge_class_size(zram->mem_pool);
1236+
1237+
for (index = 0; index < num_pages; index++)
1238+
spin_lock_init(&zram->table[index].lock);
12291239
return true;
12301240
}
12311241

drivers/block/zram/zram_drv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ struct zram_table_entry {
6969
unsigned long element;
7070
};
7171
unsigned long flags;
72+
spinlock_t lock;
7273
#ifdef CONFIG_ZRAM_TRACK_ENTRY_ACTIME
7374
ktime_t ac_time;
7475
#endif

0 commit comments

Comments
 (0)