From bffbb98fbbb089a17b752450efbda39d2624ca45 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Sat, 17 Feb 2024 15:11:31 -0500 Subject: [PATCH 1/3] add m1 macos ci target Signed-off-by: Dan Cline <6798349+Rjected@users.noreply.github.com> --- .github/workflows/main.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 58ea088d0..231d01504 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,13 +2,14 @@ name: CI on: pull_request: - branches: + branches: - 'master' - 'main' push: branches: - 'master' - 'main' + - 'dan/add-m1-target' jobs: test: @@ -21,6 +22,11 @@ jobs: nobgt: 0 no_tests: 1 tag: arm64 + - name: aarch64-apple-darwin + target: aarch64-apple-darwin + nobgt: 0 + no_tests: 1 + tag: macos-14 - name: x86_64-unknown-linux-gnu (nightly) target: x86_64-unknown-linux-gnu nobgt: 0 From 6dde9d0afc9fd6327d2be1b7eb6a116aaca6f58c Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Sat, 17 Feb 2024 15:27:04 -0500 Subject: [PATCH 2/3] feat: add profiling options Signed-off-by: Dan Cline <6798349+Rjected@users.noreply.github.com> --- .github/workflows/main.yml | 1 - jemalloc-ctl/Cargo.toml | 1 + jemalloc-ctl/src/lib.rs | 2 + jemalloc-ctl/src/profiling.rs | 156 ++++++++++++++++++++++++++++++++++ 4 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 jemalloc-ctl/src/profiling.rs diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 231d01504..673506365 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,7 +9,6 @@ on: branches: - 'master' - 'main' - - 'dan/add-m1-target' jobs: test: diff --git a/jemalloc-ctl/Cargo.toml b/jemalloc-ctl/Cargo.toml index 0375ef526..f477ce754 100644 --- a/jemalloc-ctl/Cargo.toml +++ b/jemalloc-ctl/Cargo.toml @@ -35,6 +35,7 @@ tikv-jemallocator = { path = "../jemallocator", version = "0.5.0" } [features] default = [] +profiling = ["tikv-jemalloc-sys/profiling"] use_std = [ "libc/use_std" ] disable_initial_exec_tls = ["tikv-jemalloc-sys/disable_initial_exec_tls"] diff --git a/jemalloc-ctl/src/lib.rs b/jemalloc-ctl/src/lib.rs index a5aef998a..c5aea8ad7 100644 --- a/jemalloc-ctl/src/lib.rs +++ b/jemalloc-ctl/src/lib.rs @@ -88,6 +88,8 @@ pub mod config; mod error; mod keys; pub mod opt; +#[cfg(feature = "profiling")] +pub mod profiling; pub mod raw; pub mod stats; #[cfg(feature = "use_std")] diff --git a/jemalloc-ctl/src/profiling.rs b/jemalloc-ctl/src/profiling.rs new file mode 100644 index 000000000..c4c4a062d --- /dev/null +++ b/jemalloc-ctl/src/profiling.rs @@ -0,0 +1,156 @@ +//! `jemalloc`'s run-time configuration for profiling-specific settings. +//! +//! These settings are controlled by the `MALLOC_CONF` environment variable. +#![cfg(feature = "profiling")] + +option! { + lg_prof_interval[ str: b"opt.lg_prof_interval\0", non_str: 2 ] => libc::ssize_t | + ops: r | + docs: + /// Average interval (log base 2) between memory profile dumps, as measured in bytes of + /// allocation activity. + /// + /// The actual interval between dumps may be sporadic because + /// decentralized allocation counters are used to avoid synchronization bottlenecks. + /// + /// Profiles are dumped to files named according to the pattern + /// \.\.\.i\.heap, where \ is controlled by the + /// opt.prof_prefix and prof.prefix options. By default, interval-triggered profile dumping is + /// disabled (encoded as -1). + /// + /// # Examples + /// + /// ``` + /// # #[global_allocator] + /// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; + /// # + /// # fn main() { + /// use tikv_jemalloc_ctl::profiling; + /// let lg_prof_interval = profiling::lg_prof_interval::read().unwrap(); + /// println!("average interval between memory profile dumps: {}", lg_prof_interval); + /// # } + /// ``` + mib_docs: /// See [`lg_prof_interval`]. +} + +option! { + lg_prof_sample[ str: b"opt.lg_prof_sample\0", non_str: 2 ] => libc::size_t | + ops: r | + docs: + /// Average interval (log base 2) between allocation samples, as measured in bytes of + /// allocation activity. Increasing the sampling interval decreases profile fidelity, but also + /// decreases the computational overhead. + /// + /// The default sample interval is 512 KiB (2^19 B). + /// + /// # Examples + /// + /// ``` + /// # #[global_allocator] + /// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; + /// # + /// # fn main() { + /// use tikv_jemalloc_ctl::profiling; + /// let lg_prof_sample = profiling::lg_prof_sample::read().unwrap(); + /// println!("average interval between allocation samples: {}", lg_prof_sample); + /// # } + /// ``` + mib_docs: /// See [`lg_prof_sample`]. +} + +option! { + prof_final[ str: b"opt.prof_final\0", non_str: 2 ] => bool | + ops: r | + docs: + /// Use an atexit(3) function to dump final memory usage to a file named according to the + /// pattern \.\.\.f.heap, where \ is controlled by the opt.prof_prefix + /// and prof.prefix options. + /// + /// Note that atexit() may allocate memory during application initialization and then deadlock + /// internally when jemalloc in turn calls `atexit()`, so this option is not universally usable + /// (though the application can register its own `atexit()` function with equivalent + /// functionality). + /// + /// This option is disabled by default. + /// + /// # Examples + /// + /// ``` + /// # #[global_allocator] + /// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; + /// # + /// # fn main() { + /// use tikv_jemalloc_ctl::profiling; + /// let prof_final = profiling::prof_final::read().unwrap(); + /// println!("dump final memory usage to file: {}", prof_final); + /// # } + /// ``` + mib_docs: /// See [`prof_final`]. +} + +option! { + prof[ str: b"opt.prof\0", non_str: 2 ] => bool | + ops: r | + docs: + /// Memory profiling enabled/disabled. + /// + /// If enabled, profile memory allocation activity. + /// + /// See the `opt.prof_active` option for on-the-fly activation/deactivation. + /// + /// See the `opt.lg_prof_sample` option for probabilistic sampling control. + /// + /// See the `opt.prof_accum` option for control of cumulative sample reporting. + /// + /// See the `opt.lg_prof_interval` option for information on interval-triggered profile + /// dumping, the `opt.prof_gdump` option for information on high-water-triggered profile + /// dumping, and the `opt.prof_final` option for final profile dumping. + /// + /// Profile output is compatible with the jeprof command, which is based on the pprof that is + /// developed as part of the gperftools package. See `HEAP PROFILE FORMAT` for heap profile + /// format documentation. + /// + /// # Examples + /// + /// ``` + /// # #[global_allocator] + /// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; + /// # + /// # fn main() { + /// use tikv_jemalloc_ctl::profiling; + /// let prof = profiling::prof::read().unwrap(); + /// println!("is memory profiling enabled: {}", prof); + /// # } + /// ``` + mib_docs: /// See [`prof`]. +} + +option! { + prof_leak[ str: b"opt.prof_leak\0", non_str: 2 ] => bool | + ops: r | + docs: + /// Leak reporting enabled/disabled. + /// + /// If enabled, use an `atexit(3)` function to report memory leaks detected by allocation + /// sampling. + /// + /// See the opt.prof option for information on analyzing heap profile output. + /// + /// Works only when combined with `opt.prof_final`, otherwise does nothing. + /// + /// This option is disabled by default. + /// + /// # Examples + /// + /// ``` + /// # #[global_allocator] + /// # static ALLOC: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; + /// # + /// # fn main() { + /// use tikv_jemalloc_ctl::profiling; + /// let prof_leak = profiling::prof_leak::read().unwrap(); + /// println!("is leak reporting enabled: {}", prof_leak); + /// # } + /// ``` + mib_docs: /// See [`prof_leak`]. +} From 299ecd04d9920c3f70885f80ea7e4b924b117953 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Fri, 22 Mar 2024 13:03:39 -0400 Subject: [PATCH 3/3] remove redundant profiling cfg Signed-off-by: Dan Cline <6798349+Rjected@users.noreply.github.com> --- jemalloc-ctl/src/profiling.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/jemalloc-ctl/src/profiling.rs b/jemalloc-ctl/src/profiling.rs index c4c4a062d..306ab1a8e 100644 --- a/jemalloc-ctl/src/profiling.rs +++ b/jemalloc-ctl/src/profiling.rs @@ -1,7 +1,6 @@ //! `jemalloc`'s run-time configuration for profiling-specific settings. //! //! These settings are controlled by the `MALLOC_CONF` environment variable. -#![cfg(feature = "profiling")] option! { lg_prof_interval[ str: b"opt.lg_prof_interval\0", non_str: 2 ] => libc::ssize_t |