Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/sensors: reduce stack trace map memory footprint #2546

Merged
merged 1 commit into from
Jun 13, 2024

Conversation

mtardy
Copy link
Member

@mtardy mtardy commented Jun 12, 2024

We stopped on a stack trace map that has a max_entries of 32768, which is 64 bits pointers * PERF_MAX_STACK_DEPTH (which is fixed at 127 for now), so 127*64/8=1016 bytes per entry + it's key_size of 32 bits (4 bytes) so 1020 bytes per entry. So 1020 * 32768 = 33,423,360 bytes. From bpftool, this map has a total bytes_memlock of 34,079,040 bytes. So for each stack trace map we load, we had 34MB of kernel memory, and it happened to be loaded many times when we were loading any tracing policy.

Since the map is used by the generic program, the loader will allocate the memory needed for the map even if we don't create a reference from the agent side and create an anonymous map. So we end up allocating a small map of max_entries 1 by default and resize it when the tracing policy actually specifies a matchAction containing a kernelStackTrace or userStackTrace to true. This should drastically reduce the memory footprint of this feature when it's unused.

Reduce the kernel memory footprint (accounted by the cgroup memory controller) of the stack trace feature when unused.

@mtardy mtardy added the release-note/bug This PR fixes an issue in a previous release of Tetragon. label Jun 12, 2024
@mtardy mtardy requested a review from olsajiri June 12, 2024 14:44
@mtardy mtardy requested a review from a team as a code owner June 12, 2024 14:44
Copy link

netlify bot commented Jun 12, 2024

Deploy Preview for tetragon ready!

Name Link
🔨 Latest commit c6db970
🔍 Latest deploy log https://app.netlify.com/sites/tetragon/deploys/6669b45f48c0350008838bba
😎 Deploy Preview https://deploy-preview-2546--tetragon.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mtardy mtardy marked this pull request as draft June 12, 2024 15:03
@mtardy mtardy force-pushed the pr/mtardy/stack-trace-memory-reduce branch from c6db970 to 3307f93 Compare June 12, 2024 15:30
We stopped on a stack trace map that has a max_entries of 32768, which
is 64 bits pointers * PERF_MAX_STACK_DEPTH (which is fixed at 127 for
now), so 127*64/8=1016 bytes per entry + it's key_size of 32 bits (4
bytes) so 1020 bytes per entry. So 1020 * 32768 = 33,423,360 bytes.
From bpftool, this map has a total bytes_memlock of 34,079,040 bytes.
So for each stack trace map we load, we had 34MB of kernel memory, and
it happened to be loaded many times when we were loading any tracing
policy.

Since the map is used by the generic program, the loader will allocate
the memory needed for the map even if we don't create a reference from
the agent side and create an anonymous map. So we end up allocating a
small map of max_entries 1 by default and resize it when the tracing
policy actually specifies a matchAction containing a kernelStackTrace or
userStackTrace to true. This should drastically reduce the memory
footprint of this feature when it's unused.

Signed-off-by: Mahe Tardy <[email protected]>
@mtardy mtardy force-pushed the pr/mtardy/stack-trace-memory-reduce branch from 3307f93 to 4dbc45d Compare June 12, 2024 15:37
@mtardy mtardy marked this pull request as ready for review June 12, 2024 15:47
@mtardy mtardy merged commit 22510d9 into main Jun 13, 2024
48 checks passed
@mtardy mtardy deleted the pr/mtardy/stack-trace-memory-reduce branch June 13, 2024 08:01
@mtardy mtardy added backport-pending/1.0 backport-done/1.1 The backport of this PR is complete labels Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-done/1.1 The backport of this PR is complete backport-pending/1.0 release-note/bug This PR fixes an issue in a previous release of Tetragon.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants