Skip to content

Allow to obtain memory metrics by PID

Matthias Käppler requested to merge 370079-memory-by-pid into master

What does this MR do and why?

This change supports upcoming changes for #370079 (closed).

In that issue I am looking to extend our memory-watchdog, a background task responsible for monitoring Puma workers, to also stop workers based on private memory expansion (currently it is based only on heap fragmentation).

For that to work, we want to compare worker memory with master memory to measure the degree of private memory expansion. This requires reading the parent process' procfs files, which so far we only did for the current process (the caller).

This is currently unused and safe to deploy since we call it without arguments everywhere, in which case it collapses to the previous semantics of probing self.

How to set up and validate locally

Verify the default behavior is still in place:

  1. Run rails console
  2. Call Gitlab::Metrics::System.memory_usage_rss. It should return RSS in bytes for the console process.
  3. Call Gitlab::Metrics::System.memory_usage_rss(pid: <pid>). It should return RSS in bytes for that process instead.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #370079 (closed)

Edited by Matthias Käppler

Merge request reports