diff --git a/{{project-name}}/Cargo.toml b/{{project-name}}/Cargo.toml index d06a00f..a869e6e 100644 --- a/{{project-name}}/Cargo.toml +++ b/{{project-name}}/Cargo.toml @@ -13,9 +13,7 @@ clap = { version = "4.1", features = ["derive"] } {{project-name}}-common = { path = "../{{project-name}}-common", features = ["user"] } anyhow = "1" env_logger = "0.10" -{%- if program_type == "uprobe" %} libc = "0.2" -{%- endif %} log = "0.4" tokio = { version = "1.25", features = ["macros", "rt", "rt-multi-thread", "net", "signal"] } diff --git a/{{project-name}}/src/main.rs b/{{project-name}}/src/main.rs index 5ef5328..ab87e39 100644 --- a/{{project-name}}/src/main.rs +++ b/{{project-name}}/src/main.rs @@ -45,7 +45,7 @@ use aya_log::BpfLogger; {% if program_types_with_opts contains program_type -%} use clap::Parser; {% endif -%} -use log::{info, warn}; +use log::{info, warn, debug}; use tokio::signal; {% if program_types_with_opts contains program_type -%} @@ -71,6 +71,17 @@ async fn main() -> Result<(), anyhow::Error> { {% endif %} env_logger::init(); + // Bump the memlock rlimit. This is needed for older kernels that don't use the + // new memcg based accounting, see https://lwn.net/Articles/837122/ + let rlim = libc::rlimit { + rlim_cur: libc::RLIM_INFINITY, + rlim_max: libc::RLIM_INFINITY, + }; + let ret = unsafe { libc::setrlimit(libc::RLIMIT_MEMLOCK, &rlim) }; + if ret != 0 { + debug!("remove limit on locked memory failed, ret is: {}", ret); + } + // This will include your eBPF object file as raw bytes at compile-time and load it at // runtime. This approach is recommended for most real-world use cases. If you would // like to specify the eBPF program at runtime rather than at compile-time, you can