rust-extensions/crates/runc
zhang yu 10307750 3a7b9ce173 feat: set THP_DISABLE=true in shim, and restore it before starting runc
If /sys/kernel/mm/transparent_hugepage/enabled=always, the shim process
will use huge pages, which will consume a lot of memory.

Just like this:
ps -efo pid,rss,comm | grep shim
    PID   RSS COMMAND
   2614  7464 containerd-shim

I don't think shim needs to use huge pages, and if we turn off the huge
pages option, we can save a lot of memory resources.

After we set THP_DISABLE=true:
ps -efo pid,comm,rss
    PID COMMAND           RSS
1629841 containerd-shim  5648

containerd
    |
    |--shim1   --start
        |
        |--shim2    (this shim will on host)
            |
            |--runc create (when containerd send create request by ttrpc)
                |
                |--runc init (this is the pid 1 in container)

    we should set thp_disabled=1 in shim1 --start, because if we set this
    in shim 2, the huge page has been setted while func main() running,
    we set thp_disabled cannot change the setted huge pages.
    So We need to set thp_disabled=1 in shim1 so that shim2 inherits the
    settings of the parent process shim1, and shim2 has closed the
    hugepage when it starts.

    For runc processes, we need to set thp_disabled='before' in shim2 after
    fork() and before execve(). So we use cmd.pre_exec to do this.
2024-02-20 02:43:24 +00:00
..
src feat: set THP_DISABLE=true in shim, and restore it before starting runc 2024-02-20 02:43:24 +00:00
Cargo.toml feat: set THP_DISABLE=true in shim, and restore it before starting runc 2024-02-20 02:43:24 +00:00
README.md Make examples compilable 2023-10-03 20:41:38 -07:00

README.md

Rust bindings for runc CLI

Crates.io docs.rs Crates.io CI

A crate for consuming the runc binary in your Rust applications, similar to go-runc for Go. This crate is based on archived rust-runc.

Usage

Both sync/async version is available. You can build runc client with RuncConfig in method chaining style. Call build() or build_async() to get client. Note that async client depends on tokio, then please use it on tokio runtime.

#[tokio::main]
async fn main() {
    let config = runc::GlobalOpts::new()
        .root("./new_root")
        .debug(false)
        .log("/path/to/logfile.json")
        .log_format(runc::LogFormat::Json)
        .rootless(true);

    let client = config.build_async().unwrap();

    let opts = runc::options::CreateOpts::new()
        .pid_file("/path/to/pid/file")
        .no_pivot(true);
    
    client.create("container-id", "path/to/bundle", Some(&opts)).unwrap();
}

Limitations

  • Supported commands are only:
    • create
    • start
    • state
    • kill
    • delete
  • Exec is not available in RuncAsyncClient now.
  • Console utilites are not available