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

Fixes #799: Split the pooled type declarations into weak-reffed and the non-weak-reffed #564

Conversation

jiridanek
Copy link
Contributor

@jiridanek jiridanek commented Jun 10, 2022

There are three reasons why use memory pool for a type. First, because it makes allocation/deallocation faster, second because it prevents memory fragmentation, and third it allows holding weak references to the type.

The pool is constrained by having to support these use cases. Namely, a pool that supports weak references may never free any memory to the operating system, because it must be always able to dereference any previously obtained weak pointer.

This PR creates a separate API to declare weak-reffed types, so it is now obvious what types need weak references. There are no changes to functionality.

Note the functions mentioned in the second commit, which bypass the usual weak pointer API and mess with weak pointers under the table. This approach makes it look like the types don't get used with weak pointers, but they actually do get weak-pointed. (This only becomes visible when you (for testing purposes) replace pooled allocation for the non-weak types with malloc/free; the way the PR does things, the underhanded approach can still be used to create weak references even though type was not declared to support it.)

@jiridanek jiridanek changed the title [experiment] Split the pooled type declaration into weak-reffed and the rest [experiment] Split the pooled type declarations into weak-reffed and the non-weak-reffed Jun 10, 2022
@jiridanek jiridanek requested review from kgiusti and ganeshmurthy and removed request for kgiusti June 10, 2022 18:28
@codecov-commenter
Copy link

codecov-commenter commented Jun 10, 2022

Codecov Report

Merging #564 (3f084bc) into main (76dc9b2) will decrease coverage by 49.99%.
The diff coverage is 22.22%.

❗ Current head 3f084bc differs from pull request most recent head f356ffd. Consider uploading reports for the commit f356ffd to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #564       +/-   ##
===========================================
- Coverage   77.89%   27.90%   -49.99%     
===========================================
  Files         238      133      -105     
  Lines       60704    31816    -28888     
  Branches     5580     5091      -489     
===========================================
- Hits        47286     8879    -38407     
- Misses      10795    21807    +11012     
+ Partials     2623     1130     -1493     
Flag Coverage Δ
pysystemtests ?
pyunittests ?
systemtests ?
unittests 27.90% <22.22%> (+0.70%) ⬆️

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

Components Coverage Δ
calculator 27.90% <22.22%> (+0.70%) ⬆️
systemtests 27.90% <22.22%> (-49.99%) ⬇️

@jiridanek
Copy link
Contributor Author

/me trying git-absorb, https://github.com/tummychow/git-absorb

rename _WEAK to _SAFE, then run

git add -u
git-absorb

and...

@jiridanek jiridanek force-pushed the jd_2022_06_10_split_pooled_types_into_weakrefed_and_the_rest branch from b7e77dc to f0c5a11 Compare July 20, 2022 16:45
@jiridanek
Copy link
Contributor Author

... one more command is needed to process the generated fixup! commits

git rebase -i --autosquash origin/main

@jiridanek jiridanek changed the title [experiment] Split the pooled type declarations into weak-reffed and the non-weak-reffed Split the pooled type declarations into weak-reffed and the non-weak-reffed Oct 22, 2022
@jiridanek jiridanek self-assigned this Oct 22, 2022
@jiridanek jiridanek changed the title Split the pooled type declarations into weak-reffed and the non-weak-reffed Fixes #799: Split the pooled type declarations into weak-reffed and the non-weak-reffed Oct 22, 2022
@jiridanek jiridanek force-pushed the jd_2022_06_10_split_pooled_types_into_weakrefed_and_the_rest branch 2 times, most recently from 58bb119 to 70eeae6 Compare October 22, 2022 12:06
@jiridanek
Copy link
Contributor Author

AFAIK we do want to do this,

image

@jiridanek jiridanek force-pushed the jd_2022_06_10_split_pooled_types_into_weakrefed_and_the_rest branch from a3e403d to 3f084bc Compare October 26, 2022 10:07
@jiridanek jiridanek force-pushed the jd_2022_06_10_split_pooled_types_into_weakrefed_and_the_rest branch 2 times, most recently from ca277ce to a7bc783 Compare April 5, 2023 18:13
jiridanek added 2 commits June 8, 2023 17:08
see qdr_link_set_context (the context may be qd_link_t, qdr_tcp_connection_t, qdr_http2_stream_data_t or qdr_http1_connection_t)

see qd_link_set_incoming_msg which uses qd_alloc_set_safe_ptr directly for qd_message_t
@jiridanek jiridanek force-pushed the jd_2022_06_10_split_pooled_types_into_weakrefed_and_the_rest branch from a7bc783 to 6628d6b Compare June 8, 2023 15:09
@ganeshmurthy
Copy link
Contributor

@jiridanek Looks like your new rebase fixed the issue and all tests have passed. Please feel free to merge.

@jiridanek jiridanek merged commit 8fdaaf2 into skupperproject:main Jun 9, 2023
@jiridanek jiridanek deleted the jd_2022_06_10_split_pooled_types_into_weakrefed_and_the_rest branch June 9, 2023 10:09
jiridanek added a commit to jiridanek/skupper-router that referenced this pull request Sep 19, 2023
…e-pointed and the non-safe-pointed ones (skupperproject#564)

* Split out the types that do need to have safe pointers

* Add _SAFE for types that nonobviously need it;

see `qdr_link_set_context` (the `context` may be `qd_link_t`, `qdr_tcp_connection_t`, `qdr_http2_stream_data_t` or `qdr_http1_connection_t`)

see `qd_link_set_incoming_msg` which uses `qd_alloc_set_safe_ptr` directly for `qd_message_t`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Split the pooled type declarations into weak-reffed and the non-weak-reffed
3 participants