Wipe unallocated memory
()
| 300 | |
| 301 | |
| 302 | def wipe_memory(): |
| 303 | """Wipe unallocated memory""" |
| 304 | for cmd in ('swapon', 'swapoff', 'blkid'): |
| 305 | if not FileUtilities.exe_exists(cmd): |
| 306 | raise RuntimeError(f"wipe_memory: Command {cmd} not found") |
| 307 | # cache the file because 'swapoff' changes it |
| 308 | proc_swaps = get_proc_swaps() |
| 309 | devices = disable_swap_linux() |
| 310 | yield True # process GTK+ idle loop |
| 311 | # TRANSLATORS: The variable is a device like /dev/sda2 |
| 312 | logger.debug(_("Detected these swap devices: %s"), str(devices)) |
| 313 | wipe_swap_linux(devices, proc_swaps) |
| 314 | yield True |
| 315 | child_pid = os.fork() |
| 316 | if 0 == child_pid: |
| 317 | make_self_oom_target_linux() |
| 318 | fill_memory_linux() |
| 319 | os._exit(0) |
| 320 | else: |
| 321 | # TRANSLATORS: This is a debugging message that the parent process |
| 322 | # is waiting for the child process. %(parent_pid)d is the parent |
| 323 | # process ID; %(child_pid)d is the child process ID. |
| 324 | logger.debug(_("The function wipe_memory() with process ID %(parent_pid)d is " |
| 325 | "waiting for child process ID %(child_pid)d."), |
| 326 | {'parent_pid': os.getpid(), 'child_pid': child_pid}) |
| 327 | rc = os.waitpid(child_pid, 0)[1] |
| 328 | if rc not in [0, 9]: |
| 329 | logger.warning( |
| 330 | _("The child memory-wiping process returned code %d."), rc) |
| 331 | enable_swap_linux() |
| 332 | yield 0 # how much disk space was recovered |
nothing calls this directly
no test coverage detected