Giter Site home page Giter Site logo

swapify's Introduction

Swapify - Making things go brrr only when you need them

Swapify is a tool to stop processes and swap their memory onto disk. These programs can then later be swapped in again and will resume normal operation. This is done by injecting a shared object into the process that will spawn a second process living in the same memory space, which will, on request, send a SIGSTOP to the main process and write eligible mappings to ~/.swapify/[PID].swap, which are then unmapped.

Motivation

This software is useful for applications that consume a lot of memory, have a long startup time and are only used semi-regularly. For example, this could be used to host many minecraft servers on a single machine, which are swapped in using socket activation and a proxy.

Usage

To use this, you have to spawn the process with swapify <command>. From then on you can swap the process by using swap --action swap --pid <PID> or swap --action swap --socket <NAME>.<PID>.sock. To unswap, just use --action unswap instead. Heres the output of swap --help for more info:

Usage: swap [options] [pids]
Where options are a combination of:
    -h, --help                print this help and exit
    -a, --action <ACTION>     action to send to specified pids and sockets (required)
    -p, --pid <PID>           act on PID (can be used multiple times)
    -s, --socket <NAME>       act on swapify instance listening at NAME
    -P, --socket-path <PATH>  path that sockets are resolved relative to

At least one PID or NAME is required. ACTION has to be one of swap, unswap
or exit. Only one ACTION may be specified. Additional arguments are
interpreted as additional pids to act on.

The default path that swap looks for sockets in is /run/user/[UID]/swapify,
which is also the default path used by swapify.
This program can only act on pids that have a swapify instance attached, and
it interacts with that instance by looking for sockets at PATH/PID.sock

This software is developed at https://github.com/llenck/swapify

It is highly recommended to use a shell which is compatible with bash-like completion scripts, because make install puts one at /etc/bash_completion.d/swap_completion.bash, which makes using this software much easier by providing tab-completion to all of swap's options, most importantly eligible PIDs and socket names.

Installing

Just run make release && sudo make install. The default make target is a debug build, which will litter ~/.swapify/ with log files, so it is recommended to use a release build, unless you want to file a bug report.

If you want to uninstall swapify, just run make uninstall.

Known Issues

There are currently quite a few issues with this software:

  • Programs use slightly more memory than before after being unmapped, since swapify can't interact with the mechanism that Linux uses to only actually allocate pages when they're being used
  • Swapify doesn't play nicely with 32-bit applications on 64-bit systems (e.g. steam), but should work on systems that are all 32-bit
  • For now, this program will also kill the process on failure to unswap, but this might be fixed in the future
  • Swapify doesn't seem to work on ARM systems, e.g. AArch64 (yet)

Lastly, I don't recommend using this Software for anything too important, as this is quite experimental and might crash a lot (though I personally don't know of any programs that crash unexpectedly).

If you find any application that segfaults when (un-)swapping, please create an issue at https://github.com/llenck/swapify/issues and include things like your processor architecture, kernel, C library implementation, Linux Distribution, log file (~/.swapify/log-[SWAPIFY_PID]-[PID]-[random stuff]) and the program that crashed in the bug report.

swapify's People

Contributors

llenck avatar

Stargazers

 avatar  avatar

Watchers

 avatar

swapify's Issues

code bad

i think procstate.c has a problem (by searching for the first instead of the last closing brace), but I'm too lazy to fix it

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.