Re: swapon reports wrong swapsize

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Feb 16, 2010 at 11:52:15AM +0100, Peter Breitenlohner wrote:
> On Tue, 16 Feb 2010, Karel Zak wrote:
>
>> The number from /proc/swaps is in KiB. The swapsize= from swapon
>> verbose message is a size calculated from the 'lastpage' field from
>> swap header.
>
> Hi Karel,
>
> I'm not worried by a discrepancy of a few pages, but rather by a factor of
> two.  To be on the safe side I just did this:
>
>   # swapoff -av
>   swapoff on /dev/sda2
>   # mkswap /dev/sda2
>   Setting up swapspace version 1, size = 7823648 KiB
>   no label, UUID=ed23d244-73d6-4c8f-b1a2-25659c15e73b
>   # swapon -av
>   swapon on /dev/sda2
>   swapon: /dev/sda2: found swap v1 signature string for 4 KiB PAGE_SIZE
>
>   swapon: /dev/sda2: pagesize=4096, swapsize=3716452352, devsize=8011422720
>   # cat /proc/swaps
>   Filename                                Type            Size    Used    Priority
>   /dev/sda2                               partition       7823644 0       -1
>
> i.e., 'mkswap' and '/proc/swaps' report a swapsize of about 8GiB whereas
> 'swapon' correctly reports devsize as 8GiB but swapsize as <4GiB. Why?

 ...because there was a bug in swapon. Fixed.
 
    Karel


>From 98e9ff610ed0a3a80a7478336acff99133199375 Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@xxxxxxxxxx>
Date: Tue, 16 Feb 2010 13:48:09 +0100
Subject: [PATCH] swapon: fix swapsize calculation

Reported-by: Peter Breitenlohner <peb@xxxxxxxxxxxx>
Signed-off-by: Karel Zak <kzak@xxxxxxxxxx>
---
 mount/swapon.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/mount/swapon.c b/mount/swapon.c
index 75ba865..5574f7e 100644
--- a/mount/swapon.c
+++ b/mount/swapon.c
@@ -354,7 +354,7 @@ swap_get_size(const char *hdr, const char *devname, unsigned int pagesize)
 			pagesize / 1024,
 			flip ? _("different") : _("same"));
 
-	return (last_page + 1) * pagesize;
+	return ((unsigned long long) last_page + 1) * pagesize;
 }
 
 static int
-- 
1.6.6

--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux