public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fix swap cluster offset
@ 2006-03-12  4:34 Akinobu Mita
  2006-03-13 16:52 ` Hugh Dickins
  0 siblings, 1 reply; 2+ messages in thread
From: Akinobu Mita @ 2006-03-12  4:34 UTC (permalink / raw)
  To: linux-kernel, akpm

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.

Signed-off-by: Akinobu Mita <mita@miraclelinux.com>

Index: work/mm/swapfile.c
===================================================================
--- work.orig/mm/swapfile.c
+++ 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)) {

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] fix swap cluster offset
  2006-03-12  4:34 [PATCH] fix swap cluster offset Akinobu Mita
@ 2006-03-13 16:52 ` Hugh Dickins
  0 siblings, 0 replies; 2+ messages in thread
From: Hugh Dickins @ 2006-03-13 16:52 UTC (permalink / raw)
  To: Akinobu Mita; +Cc: linux-kernel, akpm

On Sun, 12 Mar 2006, Akinobu Mita wrote:

> 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.
> 
> Signed-off-by: Akinobu Mita <mita@miraclelinux.com>

Acked-by: Hugh Dickins <hugh@veritas.com>

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

> Index: work/mm/swapfile.c
> ===================================================================
> --- work.orig/mm/swapfile.c
> +++ 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)) {

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-03-13 16:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-12  4:34 [PATCH] fix swap cluster offset Akinobu Mita
2006-03-13 16:52 ` Hugh Dickins

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox