Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFE: please propagate documented error codes from /usr/bin/swapoff in swapoff failed due to OOM #1050

Closed
poettering opened this issue May 26, 2020 · 5 comments

Comments

@poettering
Copy link
Contributor

IIUC the kernel swapoff() syscall returns ENOMEM if there's not enough RAM to place the swapped out data into. It would be great if the swapoff binary would propagate that error code in some documented way through its exit status, so that systemd and similar systems can react to that condition in some way.

karelzak added a commit that referenced this issue May 27, 2020
The current code hides details about reason why swapoff(8) and swapoff(2) failed. For example
ENOMEM from swapoff(2) is important as it indicates OOM.

The patch also clean ups --all return codes to be more compatible for
example with [u]mount --all, etc.

Addresses: #1050
Signed-off-by: Karel Zak <kzak@redhat.com>
@karelzak
Copy link
Collaborator

Implemented. The magic exit status you look for is "2" (for ENOMEM). The rest is (copy & past from man page):

       0      success
       1      system has insufficient memory to stop swapping (OOM)
       2      swapoff syscall failed for another reason
       4      non-swapoff syscall system error (out of memory, ...)
       16     usage or syntax error
       32     all swapoff failed on --all
       64     some swapoff succeeded on --all

 The command swapoff --all returns 0 (all succeeded), 32 (all failed), or 64 (some failed, some succeeded).

We need also clean up swapon(8) to keep it consistent, but tomorrow ;-)

@poettering
Copy link
Contributor Author

What did the tool return previously on failure? always 1? if so, for compat reasons, wouldn't it make sense to change the table above, and map OOM to 2 and "failed for another reason" to 1? That way, systemd could check for error code 2, and on new swapoff it's a clear indication for OOM, and on old OOM it would never happen. But with your current work we couldn't distuingish the case "old swapoff" from "new swapoff and oom", if you follow what i mean?

@karelzak
Copy link
Collaborator

The old version returns 255 on all swapoff(2) errors and 1 for non-swaoff() and for EPERM errors. Maybe avoid 1 at all would be the best thing. It means use 0, 2, 4, 8, 16, 32, and 64.

@poettering
Copy link
Contributor Author

Yes, that would make sense!

For the systemd case we are primarily interested in having a recognizable error for the OOM case that wasn't previously used otherwise.

karelzak added a commit that referenced this issue May 28, 2020
The make sure we are not in collision with old versions.

Addresses: #1050
Signed-off-by: Karel Zak <kzak@redhat.com>
@karelzak
Copy link
Collaborator

karelzak commented Nov 3, 2020

Released in util-linux v2.36.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants