hc
2023-11-06 e3e12f52b214121840b44c91de5b3e5af5d3eb84
kernel/drivers/block/zram/zram_drv.c
....@@ -56,6 +56,40 @@
5656 u32 index, int offset, struct bio *bio);
5757
5858
59
+#ifdef CONFIG_PREEMPT_RT_BASE
60
+static void zram_meta_init_table_locks(struct zram *zram, size_t num_pages)
61
+{
62
+ size_t index;
63
+
64
+ for (index = 0; index < num_pages; index++)
65
+ spin_lock_init(&zram->table[index].lock);
66
+}
67
+
68
+static int zram_slot_trylock(struct zram *zram, u32 index)
69
+{
70
+ int ret;
71
+
72
+ ret = spin_trylock(&zram->table[index].lock);
73
+ if (ret)
74
+ __set_bit(ZRAM_LOCK, &zram->table[index].value);
75
+ return ret;
76
+}
77
+
78
+static void zram_slot_lock(struct zram *zram, u32 index)
79
+{
80
+ spin_lock(&zram->table[index].lock);
81
+ __set_bit(ZRAM_LOCK, &zram->table[index].value);
82
+}
83
+
84
+static void zram_slot_unlock(struct zram *zram, u32 index)
85
+{
86
+ __clear_bit(ZRAM_LOCK, &zram->table[index].value);
87
+ spin_unlock(&zram->table[index].lock);
88
+}
89
+
90
+#else
91
+static void zram_meta_init_table_locks(struct zram *zram, size_t num_pages) { }
92
+
5993 static int zram_slot_trylock(struct zram *zram, u32 index)
6094 {
6195 return bit_spin_trylock(ZRAM_LOCK, &zram->table[index].flags);
....@@ -70,6 +104,7 @@
70104 {
71105 bit_spin_unlock(ZRAM_LOCK, &zram->table[index].flags);
72106 }
107
+#endif
73108
74109 static inline bool init_done(struct zram *zram)
75110 {
....@@ -1145,6 +1180,8 @@
11451180 #endif
11461181 static DEVICE_ATTR_RO(debug_stat);
11471182
1183
+
1184
+
11481185 static void zram_meta_free(struct zram *zram, u64 disksize)
11491186 {
11501187 size_t num_pages = disksize >> PAGE_SHIFT;
....@@ -1175,6 +1212,7 @@
11751212
11761213 if (!huge_class_size)
11771214 huge_class_size = zs_huge_class_size(zram->mem_pool);
1215
+ zram_meta_init_table_locks(zram, num_pages);
11781216 return true;
11791217 }
11801218
....@@ -1237,6 +1275,7 @@
12371275 unsigned long handle;
12381276 unsigned int size;
12391277 void *src, *dst;
1278
+ struct zcomp_strm *zstrm;
12401279
12411280 zram_slot_lock(zram, index);
12421281 if (zram_test_flag(zram, index, ZRAM_WB)) {
....@@ -1267,6 +1306,7 @@
12671306
12681307 size = zram_get_obj_size(zram, index);
12691308
1309
+ zstrm = zcomp_stream_get(zram->comp);
12701310 src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO);
12711311 if (size == PAGE_SIZE) {
12721312 dst = kmap_atomic(page);
....@@ -1274,14 +1314,13 @@
12741314 kunmap_atomic(dst);
12751315 ret = 0;
12761316 } else {
1277
- struct zcomp_strm *zstrm = zcomp_stream_get(zram->comp);
12781317
12791318 dst = kmap_atomic(page);
12801319 ret = zcomp_decompress(zstrm, src, size, dst);
12811320 kunmap_atomic(dst);
1282
- zcomp_stream_put(zram->comp);
12831321 }
12841322 zs_unmap_object(zram->mem_pool, handle);
1323
+ zcomp_stream_put(zram->comp);
12851324 zram_slot_unlock(zram, index);
12861325
12871326 /* Should NEVER happen. Return bio error if it does. */