Skip to contentSkip to conversation

fix swap cluster offset

PATCH In review Akinobu Mita 2 participants 2 messages Mar 12, 2006 – Mar 13, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix swap cluster offset

When we've allocated SWAPFILE_CLUSTER pages, ->cluster_next should be the first index of swap cluster. But current code probably sets it wrong offset.

mm/swapfile.c +1 -1
Index: work/mm/swapfile.c
===================================================================
@@ -116,7 +116,7 @@ static inline unsigned long scan_swap_ma
 				last_in_cluster = offset + SWAPFILE_CLUSTER;
 			else if (offset == last_in_cluster) {
 				spin_lock(&swap_lock);
-				si->cluster_next = offset-SWAPFILE_CLUSTER-1;
+				si->cluster_next = offset-SWAPFILE_CLUSTER+1;
 				goto cluster;
 			}
 			if (unlikely(--latency_ration < 0)) {
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Akinobu Mita

When we've allocated SWAPFILE_CLUSTER pages, ->cluster_next should be the first index of swap cluster. But current code probably sets it wrong offset.

Very good eye! My shame.
No need to say "probably" above, it was simply wrong.

By a stroke of luck, it's no worse than a slight inefficiency in an algorithm only used when we're already going slow; but (if offset had been signed, or not checked against highest_bit for unrelated reasons) it could very easily have tried to access and modify swap_map[-1].

Anyway, thanks for catching that:
Andrew, please apply (but not desperate for 2.6.16).

Hugh

Quoted 13 lines

Index: work/mm/swapfile.c
===================================================================

mm/swapfile.c +1 -1
@@ -116,7 +116,7 @@ static inline unsigned long scan_swap_ma
 				last_in_cluster = offset + SWAPFILE_CLUSTER;
 			else if (offset == last_in_cluster) {
 				spin_lock(&swap_lock);
-				si->cluster_next = offset-SWAPFILE_CLUSTER-1;
+				si->cluster_next = offset-SWAPFILE_CLUSTER+1;
 				goto cluster;
 			}
 			if (unlikely(--latency_ration < 0)) {