Skip to content

[WIP] psutil.disk_swaps() (swap partitions) - #1694

Open
giampaolo wants to merge 24 commits into
masterfrom
disk-swaps
Open

[WIP] psutil.disk_swaps() (swap partitions)#1694
giampaolo wants to merge 24 commits into
masterfrom
disk-swaps

Conversation

@giampaolo

@giampaolo giampaolo commented Feb 14, 2020

Copy link
Copy Markdown
Owner

This implements #1681, by adding a new psutil.disk_swaps() which lists swap partitions (and swap files).

# Linux
>>> import psutil
>>> psutil.disk_swaps()
[sdiskswaps(path='/dev/nvme0n1p3', total=11718652, used=2724, fstype='partition', priority=-2)]
# Windows
>>> import psutil
>>> psutil.disk_swaps()
[sdiskswaps(path='C:\\pagefile.sys', total=1118652, used=5721, peak=3453)]

Linux and Windows only for now, but at least macOS and/or FreeBSD would also be nice to have.
I'm still not 100% sure about the name.

UPDATE - added support for:

  • Linux
  • Windows
  • FreeBSD
  • OpenBSD

@giampaolo

giampaolo commented Feb 14, 2020

Copy link
Copy Markdown
Owner Author

And here's some bikeshedding.
Current name:

  • disk_swaps()
    • +1 because it's neutral about swap partitions vs. swap files (Linux can have both, Windows only has files (called pagefiles))
    • +1 /proc/swaps suggests someone already did the bikeshedding =)

Other possible names:

  • swap_partitions():
    • +1 because of the swap prefix
    • -1 because we can also list swap files
  • swap_disks():
    • +1 because we already have the "swap_" prefix of swap_memory()
    • -1 because it sounds like entries refer to an entire disk
  • swap_locations():
    • +1 (reuse "swap_" prefix)

Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
@giampaolo giampaolo added the windows platform : Windows specific label Aug 4, 2026
@giampaolo giampaolo added linux platform : Linux specific freebsd platform : FreeBSD specific openbsd platform : OpenBSD specific new-api the public API grows: a new function, argument, or returned value and removed enhancement labels Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

freebsd platform : FreeBSD specific linux platform : Linux specific new-api the public API grows: a new function, argument, or returned value openbsd platform : OpenBSD specific windows platform : Windows specific

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant