nerdexam
CompTIA

XK0-004 · Question #500

A system shows high utilization of swap space but low utilization of physical memory. Which of the following commands should an administrator run to free up usable swap space?

The correct answer is C. swapoff -a && swapon -a. When swap is heavily used but physical RAM is underutilized, cycling swap off and back on forces the kernel to move swap data back into available RAM and resets the swap space to a clean state.

Troubleshooting and Diagnostics

Question

A system shows high utilization of swap space but low utilization of physical memory. Which of the following commands should an administrator run to free up usable swap space?

Options

  • Amkswap ; swapon -a
  • Bfree && swapon -a
  • Cswapoff -a && swapon -a
  • Dswapon -a ; swapoff -a

How the community answered

(29 responses)
  • A
    10% (3)
  • B
    3% (1)
  • C
    83% (24)
  • D
    3% (1)

Why each option

When swap is heavily used but physical RAM is underutilized, cycling swap off and back on forces the kernel to move swap data back into available RAM and resets the swap space to a clean state.

Amkswap ; swapon -a

mkswap reformats a device as swap space, which is a destructive operation used during initial setup - it does not free existing swap data or move it back to RAM.

Bfree && swapon -a

'free' is a read-only display command that shows memory statistics and takes no action; running swapon -a afterward would only attempt to enable swap again without clearing it.

Cswapoff -a && swapon -aCorrect

Running 'swapoff -a' disables all swap partitions and forces the kernel to move all swapped-out pages back into physical memory, which is currently available. Running 'swapon -a' immediately after re-enables all swap partitions in a clean, empty state. The '&&' operator ensures swapon only runs if swapoff succeeds, preventing swap from being re-enabled before data is fully migrated.

Dswapon -a ; swapoff -a

The order is reversed - enabling swap before disabling it would not free the existing swap contents, and the semicolon means swapoff would run after swapon regardless of success, potentially corrupting state.

Concept tested: Linux swap space management and recycling

Source: https://man7.org/linux/man-pages/man8/swapoff.8.html

Topics

#swap space#swapoff#swapon#memory management

Community Discussion

No community discussion yet for this question.

Full XK0-004 Practice