Skip to content

clean(libsinsp): do not abuse std::shared_ptr for creating table entries #2747

Merged
poiana merged 1 commit intofalcosecurity:masterfrom
irozzo-1A:clean-up-table-entry-creation
Dec 15, 2025
Merged

clean(libsinsp): do not abuse std::shared_ptr for creating table entries #2747
poiana merged 1 commit intofalcosecurity:masterfrom
irozzo-1A:clean-up-table-entry-creation

Conversation

@irozzo-1A
Copy link
Copy Markdown
Contributor

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind bug

/kind cleanup

/kind design

/kind documentation

/kind failing-test

/kind test

/kind feature

/kind sync

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area API-version

/area build

/area CI

/area driver-kmod

/area driver-bpf

/area driver-modern-bpf

/area libscap-engine-bpf

/area libscap-engine-gvisor

/area libscap-engine-kmod

/area libscap-engine-modern-bpf

/area libscap-engine-nodriver

/area libscap-engine-noop

/area libscap-engine-source-plugin

/area libscap-engine-savefile

/area libscap

/area libpman

/area libsinsp

/area tests

/area proposals

Does this PR require a change in the driver versions?

/version driver-API-version-major

/version driver-API-version-minor

/version driver-API-version-patch

/version driver-SCHEMA-version-major

/version driver-SCHEMA-version-minor

/version driver-SCHEMA-version-patch

What this PR does / why we need it:

Add a separate container for created table entries using std::unique_ptr to make the ownership semantic clearer. This removes the hacky usage of no-op deleter with std::shared_ptr.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

@github-actions
Copy link
Copy Markdown

github-actions bot commented Dec 11, 2025

Perf diff from master - unit tests

     4.45%    +12.02%  [.] std::__shared_ptr<sinsp_threadinfo, (__gnu_cxx::_Lock_policy)2>::__shared_ptr(std::__weak_ptr<sinsp_threadinfo, (__gnu_cxx::_Lock_policy)2> const&, std::nothrow_t)
     3.49%    +11.35%  [.] std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_add_ref_lock_nothrow()
     3.56%     +9.19%  [.] std::__shared_count<(__gnu_cxx::_Lock_policy)2>::_M_get_use_count() const
     4.16%     +8.12%  [.] sinsp_threadinfo::get_main_thread()
     3.33%     +7.23%  [.] sinsp_threadinfo::update_main_fdtable()
     3.13%     +6.84%  [.] sinsp_threadinfo::get_fd_table()
     5.97%     +6.76%  [.] std::_Sp_counted_base<(__gnu_cxx::_Lock_policy)2>::_M_release()
     2.08%     +5.53%  [.] std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count(std::__weak_count<(__gnu_cxx::_Lock_policy)2> const&, std::nothrow_t)
    11.38%     -5.39%  [.] sinsp::next(sinsp_evt**)
     1.82%     +3.91%  [.] thread_group_info::get_first_thread() const

Heap diff from master - unit tests

peak heap memory consumption: 27.64K
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B

Heap diff from master - scap file

peak heap memory consumption: -24B
peak RSS (including heaptrack overhead): 0B
total memory leaked: 0B

Benchmarks diff from master

Comparing gbench_data.json to /root/actions-runner/_work/libs/libs/build/gbench_data.json
Benchmark                                                         Time             CPU      Time Old      Time New       CPU Old       CPU New
----------------------------------------------------------------------------------------------------------------------------------------------
BM_sinsp_split_mean                                            -0.0494         -0.0495           248           235           247           235
BM_sinsp_split_median                                          -0.0509         -0.0510           248           235           247           235
BM_sinsp_split_stddev                                          -0.1240         -0.1522             1             1             1             1
BM_sinsp_split_cv                                              -0.0784         -0.1080             0             0             0             0
BM_sinsp_concatenate_paths_relative_path_mean                  +0.0520         +0.0518            70            74            70            74
BM_sinsp_concatenate_paths_relative_path_median                +0.0533         +0.0532            70            73            69            73
BM_sinsp_concatenate_paths_relative_path_stddev                -0.0142         -0.0200             1             1             1             1
BM_sinsp_concatenate_paths_relative_path_cv                    -0.0629         -0.0683             0             0             0             0
BM_sinsp_concatenate_paths_empty_path_mean                     -0.0115         -0.0114            44            43            44            43
BM_sinsp_concatenate_paths_empty_path_median                   -0.0015         -0.0014            44            43            44            43
BM_sinsp_concatenate_paths_empty_path_stddev                   -0.7912         -0.7961             1             0             1             0
BM_sinsp_concatenate_paths_empty_path_cv                       -0.7888         -0.7937             0             0             0             0
BM_sinsp_concatenate_paths_absolute_path_mean                  +0.0370         +0.0370            71            74            71            74
BM_sinsp_concatenate_paths_absolute_path_median                +0.0300         +0.0298            71            73            71            73
BM_sinsp_concatenate_paths_absolute_path_stddev                +5.0687         +5.2676             0             1             0             1
BM_sinsp_concatenate_paths_absolute_path_cv                    +4.8521         +5.0438             0             0             0             0

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 11, 2025

Codecov Report

❌ Patch coverage is 94.59459% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.57%. Comparing base (5baecd8) to head (f1eade0).
⚠️ Report is 20 commits behind head on master.

Files with missing lines Patch % Lines
userspace/libsinsp/state/table.h 92.59% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2747      +/-   ##
==========================================
+ Coverage   74.56%   74.57%   +0.01%     
==========================================
  Files         292      292              
  Lines       29998    30025      +27     
  Branches     4651     4657       +6     
==========================================
+ Hits        22367    22392      +25     
- Misses       7631     7633       +2     
Flag Coverage Δ
libsinsp 74.57% <94.59%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@ekoops ekoops left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@poiana
Copy link
Copy Markdown
Contributor

poiana commented Dec 15, 2025

LGTM label has been added.

DetailsGit tree hash: ebed78d47eaaf76c4647823cb0cbabed5fa8b03b

@poiana
Copy link
Copy Markdown
Contributor

poiana commented Dec 15, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ekoops, irozzo-1A

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ekoops ekoops added this to the 0.23.0 milestone Dec 15, 2025
return static_cast<ss_plugin_table_entry_t*>(owned_ptr);
// Store shared_ptr for lifetime management, return raw pointer
owner->store_accessed_entry(ret);
return static_cast<ss_plugin_table_entry_t*>(ret.get());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just double checking, because I'm a little bit on thin ice here, but is it safe to use ret.get() after doing std:move(ret) in store_accessed_entry() or is something like this needed:

auto raw_ptr = ret.get(); 
owner->store_accessed_entry(ret);
return static_cast<ss_plugin_table_entry_t*>(raw_ptr);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @terror96 . Basically the std::move(entry) you see inside store_accessed_entry() acts on a copy of this shared pointer. So we are moving the copy there, not the original ret.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification @ekoops.

Copy link
Copy Markdown
Contributor Author

@irozzo-1A irozzo-1A Dec 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, if stored_accessed_entry() would have taken a ref we would have a problem here

Add a separate storage for created table entries using std::unique_ptr to
make the ownership semantic clearer. This removes the hacky usage of
no-op deleter with std::shared_ptr.

Signed-off-by: irozzo-1A <iacopo@sysdig.com>
@irozzo-1A irozzo-1A force-pushed the clean-up-table-entry-creation branch from 37468d2 to f1eade0 Compare December 15, 2025 13:21
@github-project-automation github-project-automation bot moved this from Todo to In progress in Falco Roadmap Dec 15, 2025
@poiana poiana merged commit d4fb9de into falcosecurity:master Dec 15, 2025
47 checks passed
@github-project-automation github-project-automation bot moved this from In progress to Done in Falco Roadmap Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants