-
-
Notifications
You must be signed in to change notification settings - Fork 706
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
Add SharedAllocatorList #6465
Add SharedAllocatorList #6465
Conversation
Thanks for your pull request and interest in making D better, @jercaianu! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + phobos#6465" |
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.
Some things about it seem a bit odd to me, but they're the same as the existing AllocatorList
so I'll give this a thumbs up.
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.
LGTM
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.
LGTM too.
I would prefer if we could automatically generate all this locking code with static foreach over the public methods of the base type (D shouldn't be about repeating code).
At the moment we can't generate documentation strings (I think someone was working on a DIP for it, but probably that got stalled).
Also most doc strings miss the Returns/Params ddoc parts.
auto allocators() | ||
{ | ||
return impl.allocators; | ||
} |
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.
Do we really need this? Can't you use impl.allocators
directly?
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.
One could, but this allows us to keep our unittests DRY. Many of them test both, the shared and the regular versions. The regular version has a private field named allocators
which is what this accessor functions emulates. Removing this helper function would make our unittests quite WET.
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.
Furthermore, this function is both private
and version (unittest)
. I don’t think there’s any harm done by keeping it in.
lock.lock(); | ||
scope(exit) lock.unlock(); | ||
|
||
return assumeUnshared(impl).allocate(s); |
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.
Could be a one-liner:
synchronized(lock) return assumeUnshared(impl).allocate(s);
The alignment offered. | ||
*/ | ||
enum alignment = impl.alignment; | ||
|
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.
FWIW all the following code could be replaced with a nice static foreach
.
Of course the disadvantage is that it won't be shown in the docs, which actually might not be too important.
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.
That static foreach
got implemented, then reverted later.
https://github.com/dlang/phobos/compare/27fa9abb91cd563075958411c00817245e7b6c15..f91e9e7e77b3f3e023ab96241389636d12cef03d
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.
Given this PR already had an “auto-merge” label after that reverting, I’d say, we keep it as-is for now. In case someone wants to opt for the clever meta programming loop, they are free to send their PR.
creates a new allocator by calling `make(s)` and delegates the request | ||
to it. However, if the allocation fresh off a newly created allocator | ||
fails, subsequent calls to `allocate` will not cause more calls to $(D | ||
make). |
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.
Params need to be documented.
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.
To be fair, nobody felt that need for the regular AllocatorList
from which this comment was copied.
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.
After having a look at similar function in the package, I saw their common denominator was to not have their parameters documented. And this could have almost been on purpose – have a look at the package documentation of “building blocks” that provides a table documentating each of these functions in general.
$(TR $(TDC void[] allocate(size_t s);, $(POST $(RES) is null || $(RES).length == |
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.
Apart from that, the text exactly describes the parameter meaning.
satisfy the request, creates a new allocator by calling `make(s + a - 1)` | ||
and delegates the request to it. However, if the allocation fresh off a | ||
newly created allocator fails, subsequent calls to `alignedAllocate` | ||
will not cause more calls to `make`. |
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.
Params + Returns
turn, in most-recently-used order. If the owner is found, it is moved to | ||
the front of the list as a side effect under the assumption it will be used | ||
soon. | ||
|
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.
Params
/** | ||
Defined only if `Allocator.expand` is defined. Finds the owner of `b` | ||
and calls `expand` for it. The owner is not brought to the head of the | ||
list. |
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.
Params + Returns
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 haven’t been able to find a single expand()
function in Phobos with such documentation. Therefore, I consider this out-of-scope for this PR.
@jercaianu try sth. like this: static foreach (T; __traits(allMembers, typeof(impl)))
{
static if (mixin("isCallable!(impl." ~ T ~ ")") && !T.startsWith("__"))
static if (mixin("__traits(getProtection, impl." ~ T ~ ") == `public`"))
{
mixin(`auto ` ~ T ~ `(Parameters!(impl.`~T~`) params)
{
lock.lock();
scope(exit) lock.unlock();
return assumeUnshared(impl).`~T~`(params);
}
`);
}
} |
Oh and if you use synchronized(mutex) {
return impl.foo();
} (though it needs to be a mutex, e.g. |
1d4dc09
to
27fa9ab
Compare
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.
@RazvanN7 can you please look at the compiler bug exposed by the win32 failure?
*/ | ||
enum alignment = impl.alignment; | ||
|
||
static foreach (T; __traits(allMembers, typeof(impl))) |
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.
Please add a comment before this loop explaining what it does. Cool idea @wilzbach !!
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.
AFAICT this loop got removed. Nothing left to comment.
`); | ||
} | ||
} | ||
} |
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.
Note: this does not work well with rvalues because it copies them once more. Probably not a problem here because all parameters are cheap.
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’ve added this note as a comment. See: d701391
If it really affects someone they can open an issue or send a patch that changes it, I suppose.
27fa9ab
to
f91e9e7
Compare
rebase
f91e9e7
to
b0f461b
Compare
Removing auto merge, this is stalled. |
@thewilsonator this one can be merged with resolutions. |
Rebased as #10594 |
I’m reluctant to change this now. This PR had already got its “auto-merge” label as-is. If someone feels like a mutex is a better fit, they sure can send a follow-up PR. |
Added the shared version of
AllocatorList
.This will be very useful together with
SharedAscendingPageAllocator
. Instead of mapping a huge chunk of virtual memory when constructing the allocator, we can now use it together withSharedAllocatorList
and gradually map smaller chunks of memory on demand.