File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -1218,6 +1218,19 @@ bool zswap_store(struct folio *folio)
1218
1218
if (!zswap_enabled || !tree )
1219
1219
return false;
1220
1220
1221
+ /*
1222
+ * If this is a duplicate, it must be removed before attempting to store
1223
+ * it, otherwise, if the store fails the old page won't be removed from
1224
+ * the tree, and it might be written back overriding the new data.
1225
+ */
1226
+ spin_lock (& tree -> lock );
1227
+ dupentry = zswap_rb_search (& tree -> rbroot , offset );
1228
+ if (dupentry ) {
1229
+ zswap_duplicate_entry ++ ;
1230
+ zswap_invalidate_entry (tree , dupentry );
1231
+ }
1232
+ spin_unlock (& tree -> lock );
1233
+
1221
1234
/*
1222
1235
* XXX: zswap reclaim does not work with cgroups yet. Without a
1223
1236
* cgroup-aware entry LRU, we will push out entries system-wide based on
@@ -1333,7 +1346,14 @@ bool zswap_store(struct folio *folio)
1333
1346
1334
1347
/* map */
1335
1348
spin_lock (& tree -> lock );
1349
+ /*
1350
+ * A duplicate entry should have been removed at the beginning of this
1351
+ * function. Since the swap entry should be pinned, if a duplicate is
1352
+ * found again here it means that something went wrong in the swap
1353
+ * cache.
1354
+ */
1336
1355
while (zswap_rb_insert (& tree -> rbroot , entry , & dupentry ) == - EEXIST ) {
1356
+ WARN_ON (1 );
1337
1357
zswap_duplicate_entry ++ ;
1338
1358
zswap_invalidate_entry (tree , dupentry );
1339
1359
}
You can’t perform that action at this time.
0 commit comments