Skip to content

Commit

Permalink
Merge pull request #31 from deborshi1988/space-optimise
Browse files Browse the repository at this point in the history
Recreating the swap file if the current size is sufficiently larger
  • Loading branch information
deborshi1988 committed Aug 4, 2023
2 parents 5a95689 + 9f146ee commit d2ce783
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion agent/hibinit-agent
Expand Up @@ -41,6 +41,7 @@ HIB_ENABLED_FILE = "hibernation-enabled"
IMDS_BASEURL = 'http://169.254.169.254'
IMDS_API_TOKEN_PATH = 'latest/api/token'
IMDS_SPOT_ACTION_PATH = 'latest/meta-data/hibernation/configured'
MAX_SWAP_SIZE_OFFSET_ALLOWED = 100 * 1024

def log(message):
if log_to_syslog:
Expand Down Expand Up @@ -467,7 +468,11 @@ def main():
cur_swap = os.path.getsize(SWAP_FILE)

bi = None
if cur_swap >= target_swap_size - SWAP_RESERVED_SIZE:
if cur_swap > target_swap_size - SWAP_RESERVED_SIZE + MAX_SWAP_SIZE_OFFSET_ALLOWED:
log("Swap already exists! (have %d, need %d), deleting existing swap file %s since current swap is sufficiently large and wasting memory" %
(cur_swap, target_swap_size, SWAP_FILE))
os.remove(SWAP_FILE)
elif cur_swap >= target_swap_size - SWAP_RESERVED_SIZE:
log("There's sufficient swap available (have %d, need %d)" %
(cur_swap, target_swap_size))
update_kernel_swap_offset(config.swapon, config.swapoff, SWAP_FILE, config.grub_update)
Expand Down

0 comments on commit d2ce783

Please sign in to comment.