-
Notifications
You must be signed in to change notification settings - Fork 129
Fix shrink_in_place #92
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
Conversation
cc #64 |
+cc @interwq for the xmallocx question. |
The xmallocx description looks right to me. Any questions or comments on the behavior / performance there? The only thought I have right now is, we can probably do a much better job at shrinking large allocations (across size classes, but stays large), e.g. shrink from 128k to 64k; does it seem like a common workload for you @gnzlbg?. Small size classes I don't think much can be done really. |
@interwq since you asked if there are any questions about the behavior of The assumption that I believe the client is going to make is that if they get So, my question: is there any potential scenario where:
|
@pnkfelix : in the scenario you had, if |
I don’t think it calls nallocx for the @gnzlbg it sounds to me like you might need to fix that? |
(Maybe the easiest fix is to check |
@interwq Given:
we call Iff
If the answer to both these questions is yes, the current diff should be correct @pnkfelix . If the answer to the first question is yes and the second question is no, then in the branch @pnkfelix mentioned (the first one where we currently check If the answer to both questions is no, then the whole diff is probably wrong. Since we are assuming that |
Yes.
Yes it will shrink to new_size, or not shrink at all. The manual doesn't really "enforce" this, but the current implementation works this way and I don't see us changing this. You can see the implementation detail here: https://github.com/jemalloc/jemalloc/blob/5e23f96dd4e4ff2847a85d44a01b66e4ed2da21f/src/large.c#L96 where we split the existing extent into two; to cut off the excess pages. |
I certainly won’t block it landing. @alexcrichton is the one with review privileges here. 🙂 |
The current
shrink_in_place
implementation is incorrect. It returnsOk
if theusable_size
returned byxmallocx
is>= new_size
.However,
xmallocx
returns theusable_size
of the original allocation, which is>= new_size
, if:new_size
lands in a different size-class - we must return error here sincenew_size
cannot be used to deallocate the allocation butAlloc::shrink_in_place
users are allowed to do that on successnew_size
is in the same size-class as the original allocation - in which the allocation was shrunk appropriately by zero, andnew_size
can be used to deallocate the allocation since it lands in the same size-class