[rhel6-branch] [PATCH] Limit the maximum swap size to 10 % of disk space
Vratislav Podzimek
vpodzime at redhat.com
Fri Jan 4 15:20:02 UTC 2013
On e.g. virtual machines with smalls disks and high amount of
memory it doesn't make sense to create large swap space leaving
only a little for the system and user data.
Also change comment to a docstring and document parameters.
Related: rhbz#878907
Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
---
iutil.py | 28 ++++++++++++++++++++++++----
kickstart.py | 20 +++++++++++++++++---
storage/__init__.py | 15 +++++++++++++++
3 files changed, 56 insertions(+), 7 deletions(-)
diff --git a/iutil.py b/iutil.py
index 3e3f903..3a9a583 100644
--- a/iutil.py
+++ b/iutil.py
@@ -40,6 +40,9 @@ import logging
log = logging.getLogger("anaconda")
program_log = logging.getLogger("program")
+# maximum ratio of swap size to disk size (10%)
+MAX_SWAP_DISK_RATIO = 0.1
+
#Python reimplementation of the shell tee process, so we can
#feed the pipe output into two places at the same time
class tee(threading.Thread):
@@ -450,10 +453,17 @@ def memInstalled():
return long(mem)
-## Suggest the size of the swap partition that will be created.
-# @param quiet Should size information be logged?
-# @return A tuple of the minimum and maximum swap size, in megabytes.
-def swapSuggestion(quiet=0, hibernation=False):
+def swapSuggestion(quiet=0, hibernation=False, disk_space=None):
+ """
+ Suggest the size of the swap partition that will be created.
+
+ @param quiet: Should size information be logged?
+ @param hibernation: Suggest size of the swap partition to support hibernation?
+ @param disk_space: Total disk space available
+ @return: A tuple of the minimum and maximum swap size, in megabytes.
+
+ """
+
mem = memInstalled()/1024
mem = ((mem/16)+1)*16
if not quiet:
@@ -479,6 +489,16 @@ def swapSuggestion(quiet=0, hibernation=False):
else:
log.info("Ignoring --hibernation option on systems with 64 GB of RAM or more")
+ if disk_space is not None:
+ max_swap = int(disk_space * MAX_SWAP_DISK_RATIO)
+ if swap > max_swap:
+ log.info("Suggested swap size (%(swap)d M) exceeds %(percent)d %% of "
+ "disk space, using %(percent)d %% of disk space (%(size)d M) "
+ "instead." % {"percent": MAX_SWAP_DISK_RATIO*100,
+ "swap": swap,
+ "size": max_swap})
+ swap = max_swap
+
if not quiet:
log.info("Swap attempt of %sM", swap)
diff --git a/kickstart.py b/kickstart.py
index e4b960a..4a4ce43 100644
--- a/kickstart.py
+++ b/kickstart.py
@@ -481,11 +481,18 @@ class LogVolData(commands.logvol.RHEL6_LogVolData):
# we might have truncated or otherwise changed the specified vg name
vgname = anaconda.id.ksdata.onPart.get(self.vgname, self.vgname)
+ disk_space = 0
+ for disk in storage.disks:
+ if not storage.clearPartDisks \
+ or disk.name in storage.clearPartDisks:
+ disk_space += disk.size
+
if self.mountpoint == "swap":
type = "swap"
self.mountpoint = ""
if self.recommended or self.hibernation:
- (self.size, self.maxSizeMB) = iutil.swapSuggestion(hibernation=self.hibernation)
+ (self.size, self.maxSizeMB) = \
+ iutil.swapSuggestion(hibernation=self.hibernation, disk_space=disk_space)
self.grow = True
else:
if self.fstype != "":
@@ -498,7 +505,7 @@ class LogVolData(commands.logvol.RHEL6_LogVolData):
raise KickstartValueError, formatErrorMsg(self.lineno, msg="The mount point \"%s\" is not valid." % (self.mountpoint,))
# Check that the VG this LV is a member of has already been specified.
- vg = devicetree.getDeviceByName(vgname)
+ vg = devicetree.getDeviceByName(self.vgname)
if not vg:
raise KickstartValueError, formatErrorMsg(self.lineno, msg="No volume group exists with the name \"%s\". Specify volume groups before logical volumes." % self.vgname)
@@ -752,11 +759,18 @@ class PartitionData(commands.partition.RHEL6_PartData):
if self.disk == "":
raise KickstartValueError, formatErrorMsg(self.lineno, msg="Specified BIOS disk %s cannot be determined" % self.onbiosdisk)
+ disk_space = 0
+ for disk in storage.disks:
+ if not storage.clearPartDisks \
+ or disk.name in storage.clearPartDisks:
+ disk_space += disk.size
+
if self.mountpoint == "swap":
type = "swap"
self.mountpoint = ""
if self.recommended or self.hibernation:
- (self.size, self.maxSizeMB) = iutil.swapSuggestion(hibernation=self.hibernation)
+ (self.size, self.maxSizeMB) = \
+ iutil.swapSuggestion(hibernation=self.hibernation, disk_space=disk_space)
self.grow = True
# if people want to specify no mountpoint for some reason, let them
diff --git a/storage/__init__.py b/storage/__init__.py
index 1e32d9d..f9efb83 100644
--- a/storage/__init__.py
+++ b/storage/__init__.py
@@ -121,6 +121,21 @@ def storageInitialize(anaconda, examine_all=True):
else:
return storageInitialize(anaconda)
sys.exit(1)
+ else:
+ # otherwise get new swap suggestion now that we know the total
+ # disk space
+ disk_space = 0
+ for disk in storage.disks:
+ if not storage.clearPartDisks \
+ or disk.name in storage.clearPartDisks:
+ disk_space += disk.size
+
+ (min_size, max_size) = iutil.swapSuggestion(disk_space=disk_space)
+ for request in storage.autoPartitionRequests:
+ if request.fstype == "swap":
+ request.size = min_size
+ request.maxSize= max_size
+
# dispatch.py helper function
def storageComplete(anaconda):
--
1.7.11.7
More information about the anaconda-patches
mailing list