]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
swap: warn when a swap area overflows the maximum size
authorRaymond Jennings <shentino@gmail.com>
Thu, 18 Jul 2013 23:56:41 +0000 (09:56 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Thu, 18 Jul 2013 23:56:41 +0000 (09:56 +1000)
It is possible to swapon a swap area that is too big for the pte width
to handle.

Presently this failure happens silently.

Instead, emit a diagnostic to warn the user.

Testing results, root prompt commands and kernel log messages:

# lvresize /dev/system/swap --size 16G
# mkswap /dev/system/swap
# swapon /dev/system/swap

Jul  7 04:27:22 warfang kernel: Adding 16777212k swap
on /dev/mapper/system-swap.  Priority:-1 extents:1 across:16777212k

# lvresize /dev/system/swap --size 16G
# mkswap /dev/system/swap
# swapon /dev/system/swap

Jul  7 04:27:22 warfang kernel: Truncating oversized swap area, only
using 33554432k out of 67108860k
Jul  7 04:27:22 warfang kernel: Adding 33554428k swap
on /dev/mapper/system-swap.  Priority:-1 extents:1 across:33554428k

Signed-off-by: Raymond Jennings <shentino@gmail.com>
Acked-by: Valdis Kletnieks <valdis.kletnieks@vt.edu>
Cc: Hugh Dickins <hughd@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/swapfile.c

index 36af6eeaa67eaa0532442706e668e9a268596c90..382a7da668d4d3200b5e54d787107fc6107c137e 100644 (file)
@@ -1953,6 +1953,12 @@ static unsigned long read_swap_header(struct swap_info_struct *p,
         */
        maxpages = swp_offset(pte_to_swp_entry(
                        swp_entry_to_pte(swp_entry(0, ~0UL)))) + 1;
+       if (swap_header->info.last_page > maxpages) {
+               printk(KERN_WARNING
+                       "Truncating oversized swap area, only using %luk out of %luk\n",
+                       maxpages << (PAGE_SHIFT - 10),
+                       swap_header->info.last_page << (PAGE_SHIFT - 10));
+       }
        if (maxpages > swap_header->info.last_page) {
                maxpages = swap_header->info.last_page + 1;
                /* p->max is an unsigned int: don't overflow it */