Coder Social home page Coder Social logo

memcr's Introduction

memory checkpoint and restore

Build status Build status Build status Build status Build status

memcr was written as a PoC to demonstrate that it is possible to temporarily reduce RSS of a target process without killing it. This is achieved by freezing the process, checkpointing its memory to a file and restoring it later when needed.

The idea is based on concepts seen in ptrace-parasite and early CRIU versions. The key difference is that the target process is kept alive and memcr manipulates its memory with madvise() MADV_DONTNEED syscall to reduce RSS. VM mappings are not changed.

building

make
compilation options

You can enable support for compression and checksumming of memory dump file:

  • COMPRESS_LZ4=1 - requires liblz4
  • CHECKSUM_MD5=1 - requires libcrypto and openssl headers

There is also ENCRYPT option for building libencrypt.so that provides sample implementation of encryption layer based on libcrypto API. memcr is not linked with libencrypt.so, but it can be preloaded with LD_PRELOAD.

  • ENCRYPT=1 - requires libcrypto and openssl headers

Ubuntu 22.04:

sudo apt-get install liblz4-dev liblz4-1
sudo apt-get install libssl-dev libssl3
make COMPRESS_LZ4=1 CHECKSUM_MD5=1 ENCRYPT=1
cross compilation

Currently, supported architectures are x86_64, arm, arm64 and riscv64. You can cross compile memcr by providing CROSS_COMPILE prefix. i.e.:

make CROSS_COMPILE=arm-linux-gnueabihf-
make CROSS_COMPILE=aarch64-linux-gnu-
yocto

There is a generic memcr.bb file provided that you can copy into your yocto layer and build memcr as any other packet with bitbake.

bitbake memcr

how to use memcr

Basic usage to tinker with memcr is:

memcr -p <target pid>

For the list of available options, check memcr help:

memcr [-h] [-p PID] [-d DIR] [-S DIR] [-l PORT|PATH] [-n] [-m] [-f] [-z] [-c] [-e]
options:
  -h --help             help
  -p --pid              target processs pid
  -d --dir              dir where memory dump is stored (defaults to /tmp)
  -S --parasite-socket-dir dir where socket to communicate with parasite is created
        (abstract socket will be used if no path specified)
  -l --listen           work as a service waiting for requests on a socket
        -l PORT: TCP port number to listen for requests on
        -l PATH: filesystem path for UNIX domain socket file (will be created)
  -n --no-wait          no wait for key press
  -m --proc-mem         get pages from /proc/pid/mem
  -f --rss-file         include file mapped memory
  -z --compress         compress memory dump
  -c --checksum         enable md5 checksum for memory dump
  -e --encrypt          enable encryption of memory dump

memcr also supports client / server scenario where memcr runs as a deamon and listens for commands from a client process. The main reason for supporting this is that memcr needs rather high privileges to hijack target process and it's a good idea to keep it separate from memcr-client that can run in a container with low privileges.

memcr daemon:

sudo memcr -l 9000 -zc

memcr client:

memcr-client -l 9000 -p 1234567 --checkpoint
memcr-client -l 9000 -p 1234567 --restore

memcr's People

Contributors

adrianm27 avatar bgray-sky avatar mkozlowski avatar poopi avatar szymon-mulczynski-red avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

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.