Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Optimize freeMemorySpace() to not loop in vain #200
base: master
Are you sure you want to change the base?
Optimize freeMemorySpace() to not loop in vain #200
Changes from 12 commits
8cd8de0
03e1af3
2bc801d
ac3cf7c
33a2c2c
919a6df
df95793
b9d2033
4843b19
2340315
ec5917e
7820d21
6423c13
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
IMO, yes: Buggy code (elsewhere) may forget to decrease the total (in some cases) or may increase the total by more than the number of pages in mem_hdr.
We could assert that there are no overflows, but that requires approximately the same effort AFAICT.
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.
Did the IncreaseSum() address your concern?
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.
Agreed. We are essentially asserting that there is no underflow, and I missed that fact.
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.
Let's simplify/streamline this as well:
Please also move this code right after the lock is incremented, to clarify the intent/precondition/cause.
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.
Ok.
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.
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.
Ok.
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.
Can we keep this assertion? It feels like it was correct or, at the very least, should not be removed in this PR.
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.
Restored: this was first moved to isLocalWriter(), but then I forgot to undo after removing isLocalWriter().
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.
If this method survives, to simplify, reduce maintenance costs, and provide more info:
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.
I removed writeData() method.
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.
This is a new assertion (i.e. official code does not check this), right? It seems misplaced because it checks data_hdr-specific logic. Should not it go inside the mem_hdr::write() method instead? It is also rather weak and awkwardly phrased. I wonder whether this PR is the right place to add this assertion... In fact, should this PR add this method at all?? I suspect this method is no longer needed in this PR. If so, please remove instead of polishing.
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.
This assertion was moved here from (removed) MemObject::write()). After our recent changes, I decided to remove writeData() at all and restore MemObject::write(). If we decide to refactor/eliminate the number off these write() methods scattered across several objects, let's do it separately.
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.
If this method survives, please respect NDEBUG builds, even though Squid has a few other bugs like this already.
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.
I removed writeData() method.
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.
I suggest using allowedToFreeWithReplPolicy() "OK to call twice with the same value" convenience/safety feature and avoiding questions about the
else
case:Alternatively, we should document what is going on in that (somewhat expected or should-be-common)
else
case:I prefer the simplicity and clarity of the first variant, despite the extra function calls it causes. If those extra function calls are a concern, we should refactor allowedToFreeWithReplPolicy() declaration/implementation a little, to allow the compiler to inline the no-changes check into callers.
I applied the same logic in another allowedToFreeWithReplPolicy(true) change request, without an explanation.
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.
I applied the first suggestion.
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.
Why?
I assume that if this (used to be
IN_MEMORY
!) entry is not in mem_policy for some reason, then its removableByReplPolicy flag is already false and calling allowedToFreeWithReplPolicy(false) is harmless. In all other cases, that call will (also) do what it is supposed to do -- decrease the total counter because we are removing the entry from the replacement policy. What am I missing?In other words, this particular "removal from policy" event alone is sufficient to make removableByReplPolicy false, and our code should express that idea. It is also good to show asymmetry with the
true
case above it: It takes several events to make removableByReplPolicy true but only one event to make it false.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.
The intention was that if we do something with policy, we need to check that the policy exists (i.e., is configured). However you are right that we can call this allowedToFreeWithReplPolicy() even if the policy has been never configured - it will do nothing in this case.
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.
Undo as no longer necessary?
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.
Undone.
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.
Remove as unused?
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.
Removed.