Commit d6bbbd29b1de2da807753be8a3a992a72aef42de
Committed by
Linus Torvalds
1 parent
ec9bed9d38
Exists in
master
and in
20 other branches
swap: warn when a swap area overflows the maximum size
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 64G # 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 [akpm@linux-foundation.org: fix warning] Signed-off-by: Raymond Jennings <shentino@gmail.com> Acked-by: Valdis Kletnieks <valdis.kletnieks@vt.edu> Reviewed-by: Rik van Riel <riel@redhat.com> Cc: Hugh Dickins <hughd@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 10 additions and 2 deletions Side-by-side Diff
mm/swapfile.c
... | ... | @@ -1926,6 +1926,7 @@ |
1926 | 1926 | int i; |
1927 | 1927 | unsigned long maxpages; |
1928 | 1928 | unsigned long swapfilepages; |
1929 | + unsigned long last_page; | |
1929 | 1930 | |
1930 | 1931 | if (memcmp("SWAPSPACE2", swap_header->magic.magic, 10)) { |
1931 | 1932 | printk(KERN_ERR "Unable to find swap-space signature\n"); |
... | ... | @@ -1968,8 +1969,15 @@ |
1968 | 1969 | */ |
1969 | 1970 | maxpages = swp_offset(pte_to_swp_entry( |
1970 | 1971 | swp_entry_to_pte(swp_entry(0, ~0UL)))) + 1; |
1971 | - if (maxpages > swap_header->info.last_page) { | |
1972 | - maxpages = swap_header->info.last_page + 1; | |
1972 | + last_page = swap_header->info.last_page; | |
1973 | + if (last_page > maxpages) { | |
1974 | + printk(KERN_WARNING | |
1975 | + "Truncating oversized swap area, only using %luk out of %luk\n", | |
1976 | + maxpages << (PAGE_SHIFT - 10), | |
1977 | + last_page << (PAGE_SHIFT - 10)); | |
1978 | + } | |
1979 | + if (maxpages > last_page) { | |
1980 | + maxpages = last_page + 1; | |
1973 | 1981 | /* p->max is an unsigned int: don't overflow it */ |
1974 | 1982 | if ((unsigned int)maxpages == 0) |
1975 | 1983 | maxpages = UINT_MAX; |