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
thmap_create: Test allocation, not relocation, for null. #14
Merged
rmind
merged 1 commit into
rmind:master
from
riastradh:riastradh-20231017-rootallocfail
Oct 30, 2023
Merged
thmap_create: Test allocation, not relocation, for null. #14
rmind
merged 1 commit into
rmind:master
from
riastradh:riastradh-20231017-rootallocfail
Oct 30, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Adapt test so it never returns zero on success. fix rmind#13
netbsd-srcmastr
pushed a commit
to NetBSD/src
that referenced
this pull request
Oct 17, 2023
THMAP_GETPTR may return nonnull even though alloc returned zero. Note that this failure branch is not actually appropriate; thmap_create should not fail. We really need to pass KM_SLEEP through in this call site even though there are other call sites for which KM_NOSLEEP is appropriate. Adapted from: rmind/thmap#14 PR kern/57666 rmind/thmap#13 XXX pullup-10 XXX pullup-9
rmind
reviewed
Oct 17, 2023
@@ -242,13 +242,13 @@ alloc_test_wrapper(size_t len) | |||
uintptr_t p = space_allocated; | |||
space_allocated += roundup2(len, sizeof(void *)); | |||
assert(space_allocated <= sizeof(space)); | |||
return p; | |||
return p + 4; |
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 you please define something like static const unsigned space_off = 4;
after space_allocated
and use the constant? Thanks.
rmind
reviewed
Oct 17, 2023
@@ -894,11 +894,11 @@ thmap_create(uintptr_t baseptr, const thmap_ops_t *ops, unsigned flags) | |||
if ((thmap->flags & THMAP_SETROOT) == 0) { | |||
/* Allocate the root level. */ | |||
root = thmap->ops->alloc(THMAP_ROOT_LEN); | |||
thmap->root = THMAP_GETPTR(thmap, root); | |||
if (!thmap->root) { | |||
if (!root) { |
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.
Good spot.
netbsd-srcmastr
pushed a commit
to NetBSD/src
that referenced
this pull request
Oct 20, 2023
sys/kern/subr_thmap.c: revision 1.14 sys/kern/subr_thmap.c: revision 1.15 thmap(9): Test alloc failure, not THMAP_GETPTR failure. THMAP_GETPTR may return nonnull even though alloc returned zero. Note that this failure branch is not actually appropriate; thmap_create should not fail. We really need to pass KM_SLEEP through in this call site even though there are other call sites for which KM_NOSLEEP is appropriate. Adapted from: rmind/thmap#14 PR kern/57666 rmind/thmap#13 thmap(9): Preallocate GC list storage for thmap_del. thmap_del can't fail, and it is used in places in npf where sleeping is forbidden, so it can't rely on allocating memory either. Instead of having thmap_del allocate memory on the fly for each object to defer freeing until thmap_gc, arrange to have thmap(9) preallocate the same storage when allocating all the objects in the first place, with a GC header. This is suboptimal for memory usage, especially on insertion- and lookup-heavy but deletion-light workloads, but it's not clear rmind's alternative (https://github.com/rmind/thmap/tree/thmap_del_mem_fail) is ready to use yet, so we'll go with this for correctness. PR kern/57208 rmind/npf#129
netbsd-srcmastr
pushed a commit
to NetBSD/src
that referenced
this pull request
Oct 20, 2023
sys/kern/subr_thmap.c: revision 1.14 sys/kern/subr_thmap.c: revision 1.15 thmap(9): Test alloc failure, not THMAP_GETPTR failure. THMAP_GETPTR may return nonnull even though alloc returned zero. Note that this failure branch is not actually appropriate; thmap_create should not fail. We really need to pass KM_SLEEP through in this call site even though there are other call sites for which KM_NOSLEEP is appropriate. Adapted from: rmind/thmap#14 PR kern/57666 rmind/thmap#13 thmap(9): Preallocate GC list storage for thmap_del. thmap_del can't fail, and it is used in places in npf where sleeping is forbidden, so it can't rely on allocating memory either. Instead of having thmap_del allocate memory on the fly for each object to defer freeing until thmap_gc, arrange to have thmap(9) preallocate the same storage when allocating all the objects in the first place, with a GC header. This is suboptimal for memory usage, especially on insertion- and lookup-heavy but deletion-light workloads, but it's not clear rmind's alternative (https://github.com/rmind/thmap/tree/thmap_del_mem_fail) is ready to use yet, so we'll go with this for correctness. PR kern/57208 rmind/npf#129
rokuyama
pushed a commit
to IIJ-NetBSD/netbsd-src
that referenced
this pull request
Oct 26, 2023
THMAP_GETPTR may return nonnull even though alloc returned zero. Note that this failure branch is not actually appropriate; thmap_create should not fail. We really need to pass KM_SLEEP through in this call site even though there are other call sites for which KM_NOSLEEP is appropriate. Adapted from: rmind/thmap#14 PR kern/57666 rmind/thmap#13 XXX pullup-10 XXX pullup-9
rokuyama
pushed a commit
to IIJ-NetBSD/netbsd-src
that referenced
this pull request
Oct 26, 2023
sys/kern/subr_thmap.c: revision 1.14 sys/kern/subr_thmap.c: revision 1.15 thmap(9): Test alloc failure, not THMAP_GETPTR failure. THMAP_GETPTR may return nonnull even though alloc returned zero. Note that this failure branch is not actually appropriate; thmap_create should not fail. We really need to pass KM_SLEEP through in this call site even though there are other call sites for which KM_NOSLEEP is appropriate. Adapted from: rmind/thmap#14 PR kern/57666 rmind/thmap#13 thmap(9): Preallocate GC list storage for thmap_del. thmap_del can't fail, and it is used in places in npf where sleeping is forbidden, so it can't rely on allocating memory either. Instead of having thmap_del allocate memory on the fly for each object to defer freeing until thmap_gc, arrange to have thmap(9) preallocate the same storage when allocating all the objects in the first place, with a GC header. This is suboptimal for memory usage, especially on insertion- and lookup-heavy but deletion-light workloads, but it's not clear rmind's alternative (https://github.com/rmind/thmap/tree/thmap_del_mem_fail) is ready to use yet, so we'll go with this for correctness. PR kern/57208 rmind/npf#129
rokuyama
pushed a commit
to IIJ-NetBSD/netbsd-src
that referenced
this pull request
Oct 27, 2023
sys/kern/subr_thmap.c: revision 1.14 sys/kern/subr_thmap.c: revision 1.15 thmap(9): Test alloc failure, not THMAP_GETPTR failure. THMAP_GETPTR may return nonnull even though alloc returned zero. Note that this failure branch is not actually appropriate; thmap_create should not fail. We really need to pass KM_SLEEP through in this call site even though there are other call sites for which KM_NOSLEEP is appropriate. Adapted from: rmind/thmap#14 PR kern/57666 rmind/thmap#13 thmap(9): Preallocate GC list storage for thmap_del. thmap_del can't fail, and it is used in places in npf where sleeping is forbidden, so it can't rely on allocating memory either. Instead of having thmap_del allocate memory on the fly for each object to defer freeing until thmap_gc, arrange to have thmap(9) preallocate the same storage when allocating all the objects in the first place, with a GC header. This is suboptimal for memory usage, especially on insertion- and lookup-heavy but deletion-light workloads, but it's not clear rmind's alternative (https://github.com/rmind/thmap/tree/thmap_del_mem_fail) is ready to use yet, so we'll go with this for correctness. PR kern/57208 rmind/npf#129
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adapt test so it never returns zero on success.
fix #13