-
Notifications
You must be signed in to change notification settings - Fork 36.5k
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
Accurately account for mempool index memory #18086
Conversation
1c4deb5
to
6b79662
Compare
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
@sipa can you take a look at JeremyRubin#7? It looks like when we get rid of mapTxLinks we'd then want to use an accounting allocator on the new child sets and get some DynamicMemoryUsage added to the cached inner usage? At some point I also want to better break down the cachedInnerUsage tracking into buckets as it makes it easier to trace bugs. |
6b79662
to
9e1de7a
Compare
I'm happy to rebase this on top of a removal of mapLinks, if that'd go in first. It looks pretty like I'd just need to remove mapLinks from this as well. I don't know if breaking down cachedInnerUsage is all that meaningful, as the Check() function can verify its correctness in aggregate. There are plenty more options of shuffling things with AccountingAllocators... I don't have any particular preference apart from minimizing code changes. |
Don't you need to make TxLinks sets use accounting allocators in this patch too? |
@JeremyRubin Ah, that seems reasonable. My priority was the things that use a boost multiindex as guessing memory usage there is very hard, but no reason why it can't be extended to also the sets there. |
Do you know if we were over or underestimating before? |
In mapTx we were overestimating slightly for realistic mempool size, but underestimating for near-empty ones. |
Ok the near empty case doesn't really matter... w.r.t. the realistic size one, here's a question just to be detailed/pedantic with what this change does: Given that we were previously overestimating, if I set my mempool to 100MB then I actually was getting (let's say) 99 MB, if the "slightly" was by 1%. If after this change, I am now actually using a little bit more memory is this enough to be concerned? E.g., are we going to see a bunch of raspberry pi users complaining of OOMs? |
Our memory accounting has never been more accurate than in the orders of 10s of MBs. A tiny change like this shouldn't matter. And probably on the long term, it helps: it's likely the case that in some scenarios we were off more than others (e.g. many tiny transactions vs a few big ones) - better estimations means that experimentally-determined max memory limits need less margin. |
The mempool tests happen to be very fragile -- I've noticed that sometimes when I made the mempool more memory efficient (e.g., in removing mapLinks) there are a bunch of failures because the tests depend on evictions happening because it's out of space. I'm not positive that's why your tests are failing, but it could be related. |
Yes, they're failing because the mempool limits now work slightly differently. The test makes rather silly assumptions on the menory usage of transaction entries. |
9e1de7a
to
ea454c2
Compare
Concept ACK, I think this is an elegant way to track accurate usage. |
Concept ACK. |
As unit tests are based on "near-empty" containers the difference of estimations seems broke them. Testing ed1c5b1 with |
explicit AccountingAllocator(size_t& allocated) noexcept : m_allocated(&allocated) {} | ||
|
||
//! A copy-constructed container will be non-accounting. | ||
static AccountingAllocator select_on_container_copy_construction() { return AccountingAllocator(); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Includes thread safety annotations added by Hennadii Stepanov.
67f1516
to
6ad6e54
Compare
🐙 This pull request conflicts with the target branch and needs rebase. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK, light pre-rebase ACK.
Feel free to ignore: commit message eace374 s/inherent/inherit/; the 2 test commits both do essentially the same thing in under 4 lines, could be squashed.
It looks like this will need a rebase anyway, but I'm having issues compiling eace374, which looks consistent with the CI. Error
|
@sipa @adamjonas That branch is rebased and:
CI CentOS build fails due to the old GCC 4.8 which, I think, just lacks support of the |
I'll get back to this after the 0.21 branching. |
There hasn't been much activity lately and the patch still needs rebase. What is the status here?
|
1 similar comment
There hasn't been much activity lately and the patch still needs rebase. What is the status here?
|
|
This introduces a C++ allocator class (
memusage::AccountingAllocator
) which enables containers that accurately account for all their memory allocations in a tracker variable.This is then used to replace the heuristics in the mempool to guess memory usage.