| From 84f3382e0a349c4ad9f6b277b8bc7f2742d380c2 Mon Sep 17 00:00:00 2001 |
| From: Mike Galbraith <umgwanakikbuti@gmail.com> |
| Date: Thu, 31 Mar 2016 04:08:28 +0200 |
| Subject: [PATCH] drivers/block/zram: Replace bit spinlocks with rtmutex for |
| -rt |
| |
| They're nondeterministic, and lead to ___might_sleep() splats in -rt. |
| OTOH, they're a lot less wasteful than an rtmutex per page. |
| |
| Signed-off-by: Mike Galbraith <umgwanakikbuti@gmail.com> |
| Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> |
| [PG: restructure patch for wrappers added in mainline 86c49814d449] |
| Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com> |
| |
| diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c |
| index debee952dcc1..b758e3db2e30 100644 |
| --- a/drivers/block/zram/zram_drv.c |
| +++ b/drivers/block/zram/zram_drv.c |
| @@ -422,6 +422,7 @@ static DEVICE_ATTR_RO(io_stat); |
| static DEVICE_ATTR_RO(mm_stat); |
| static DEVICE_ATTR_RO(debug_stat); |
| |
| +#ifndef CONFIG_PREEMPT_RT_BASE |
| static void zram_slot_lock(struct zram *zram, u32 index) |
| { |
| bit_spin_lock(ZRAM_ACCESS, &zram->table[index].value); |
| @@ -431,6 +432,19 @@ static void zram_slot_unlock(struct zram *zram, u32 index) |
| { |
| bit_spin_unlock(ZRAM_ACCESS, &zram->table[index].value); |
| } |
| +#else /* CONFIG_PREEMPT_RT_BASE */ |
| +static void zram_slot_lock(struct zram *zram, u32 index) |
| +{ |
| + spin_lock(&zram->table[index].lock); |
| + __set_bit(ZRAM_ACCESS, &zram->table[index].value); |
| +} |
| + |
| +static void zram_slot_unlock(struct zram *zram, u32 index) |
| +{ |
| + __clear_bit(ZRAM_ACCESS, &zram->table[index].value); |
| + spin_unlock(&zram->table[index].lock); |
| +} |
| +#endif /* CONFIG_PREEMPT_RT_BASE */ |
| |
| static bool zram_same_page_read(struct zram *zram, u32 index, |
| struct page *page, |
| @@ -504,6 +518,8 @@ static bool zram_meta_alloc(struct zram *zram, u64 disksize) |
| return false; |
| } |
| |
| + zram_meta_init_table_locks(zram, disksize); |
| + |
| return true; |
| } |
| |
| diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h |
| index e34e44d02e3e..53c74fed2561 100644 |
| --- a/drivers/block/zram/zram_drv.h |
| +++ b/drivers/block/zram/zram_drv.h |
| @@ -76,6 +76,9 @@ struct zram_table_entry { |
| unsigned long element; |
| }; |
| unsigned long value; |
| +#ifdef CONFIG_PREEMPT_RT_BASE |
| + spinlock_t lock; |
| +#endif |
| }; |
| |
| struct zram_stats { |
| @@ -116,4 +119,20 @@ struct zram { |
| */ |
| bool claim; /* Protected by bdev->bd_mutex */ |
| }; |
| + |
| +#ifndef CONFIG_PREEMPT_RT_BASE |
| +static inline void zram_meta_init_table_locks(struct zram *zram, u64 disksize) { } |
| +#else /* CONFIG_PREEMPT_RT_BASE */ |
| +static inline void zram_meta_init_table_locks(struct zram *zram, u64 disksize) |
| +{ |
| + size_t num_pages = disksize >> PAGE_SHIFT; |
| + size_t index; |
| + |
| + for (index = 0; index < num_pages; index++) { |
| + spinlock_t *lock = &zram->table[index].lock; |
| + spin_lock_init(lock); |
| + } |
| +} |
| +#endif /* CONFIG_PREEMPT_RT_BASE */ |
| + |
| #endif |
| -- |
| 2.1.4 |
| |