-
Notifications
You must be signed in to change notification settings - Fork 12
Increase supported Y-level from 127 to 255 #20
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
Merged
Merged
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
6b3eb12
Increase supported Y-level from 127 to 255
underscore-zi 55fc344
Expand Chunk to store all 24 sections (384 y-levels) of a chunk
underscore-zi aa1d527
Allocate chunks grouped by region
underscore-zi 4fa7de6
Convert "real" y-coords from external sources to internal 0-based value
underscore-zi b9eda56
Revert "Convert "real" y-coords from external sources to internal 0-b…
underscore-zi 5fe3b49
Revert "Allocate chunks grouped by region"
underscore-zi bf2f2a1
Support multiple dimensions for region cache files
underscore-zi bcf3ab3
(wip) new allocator
babbaj 678b710
(untested) separate isFromJava from Chunk
babbaj a891643
this should be false
babbaj a22aed6
delete that
babbaj 4157ce6
fix github actions fail
babbaj a6e519f
more fixes
babbaj e533432
update to use zig 13
babbaj dcc066a
zig 0.12 seems to work?
babbaj 0992d7b
should work for real this time
babbaj 8697633
fix bugs
babbaj edac02e
don't trigger unnecessary page allocations in parseAndInsertChunk als…
babbaj 7f7d27c
add dimension to newContext in java
babbaj 8df8c5c
the allocator shouldn't grow forever now
babbaj 1c8d339
oops
babbaj 3225ab5
placement new to be safe from UB
babbaj 1aa4748
this is important lol
babbaj 7458a15
Move next forward for first allocation from a pool
underscore-zi a1fe9d3
Overallocate so an aligned pool can be used
underscore-zi 4790588
Overwrite any existing pool as it must have been freed for the OS to …
underscore-zi 475af29
decommit on free
babbaj 1e752cf
(untested) emulate overcommiting on windows
babbaj 1d3f4ee
fixes
babbaj 28a3722
xd
babbaj 75d9345
make the custom allocator optional
babbaj cfa10a8
oops
babbaj 9259567
probably needs this
babbaj 2ead44f
Free chunks when destroying Context
underscore-zi 2612730
Free original pointers not aligned pointers
underscore-zi d68bd31
Don't copy from all_pools if it hasn't been allocated yet
underscore-zi a66e5ce
Don't copy from all_pools if it hasn't been allocated yet
underscore-zi 94ff7b0
Only reserve space in new_pools to avoid null entries if any are deleted
underscore-zi c652bef
allocator simplifications/optimizations
babbaj c00beff
fix perms
babbaj 298b0a0
add max height argument
babbaj af3f7d7
fix chunk state not being used in callback
babbaj a7e98bf
fix chunk state not being used in callback and lock mutex in setChunk…
babbaj a09b5d5
api changes, make constant chunks read only
babbaj 50278ed
im retarded and too lazy to try building before pushing
babbaj 1afef4e
don't need to lock the mutex if we're not generating chunks
babbaj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| #include "Allocator.h" | ||
|
|
||
| #ifdef _WIN32 | ||
| #include <windows.h> | ||
| #include <atomic> | ||
| #else | ||
| #include <sys/mman.h> | ||
| #include <unistd.h> | ||
| #endif | ||
|
|
||
| void* alignToPoolSize(void* base) { | ||
| return reinterpret_cast<void*>((reinterpret_cast<uintptr_t>(base) + POOL_SIZE - 1) & ~(POOL_SIZE - 1)); | ||
| } | ||
|
|
||
| size_t getPageSize() { | ||
| #ifdef _WIN32 | ||
| SYSTEM_INFO si; | ||
| GetSystemInfo(&si); | ||
| return si.dwPageSize; | ||
| #else | ||
| return sysconf(_SC_PAGESIZE); | ||
| #endif | ||
| } | ||
|
|
||
| #ifdef _WIN32 | ||
| // in case multiple threads want to change the global pool list at the same time but this does not need to be held to read it | ||
| std::mutex pool_mutate_mutex; | ||
| std::shared_ptr<std::vector<void*>> all_pools = std::make_shared<std::vector<void*>>(); | ||
|
|
||
| bool is_pool_pointer(uintptr_t address) { | ||
| auto pools = all_pools; | ||
| return std::find(pools->rbegin(), pools->rend(), (void*) (address & POOL_PTR_MASK)) != pools->rend(); | ||
| } | ||
|
|
||
| LONG page_handler(PEXCEPTION_POINTERS ptr) { | ||
| PEXCEPTION_RECORD record = ptr->ExceptionRecord; | ||
| if (record->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) { | ||
| uintptr_t fault_address = (uintptr_t) (record->ExceptionInformation[1]); | ||
| if (is_pool_pointer(fault_address)) { | ||
| void* page_aligned = (void*) (fault_address & ~(4096 - 1)); | ||
| if (VirtualAlloc(page_aligned, 4096, MEM_COMMIT, PAGE_READWRITE)) { | ||
| return EXCEPTION_CONTINUE_EXECUTION; | ||
| } | ||
| } | ||
| } | ||
| return EXCEPTION_CONTINUE_SEARCH; | ||
| } | ||
|
|
||
| std::atomic_flag handler_added; | ||
| void init_page_handler() { | ||
| if (!handler_added.test_and_set()) { | ||
| AddVectoredExceptionHandler(0, PVECTORED_EXCEPTION_HANDLER(page_handler)); | ||
| } | ||
| } | ||
|
|
||
| void add_pool_global(void* pool) { | ||
| std::lock_guard lock{pool_mutate_mutex}; | ||
| std::vector<void*> new_pools; | ||
| new_pools.reserve(all_pools->size() + 1); | ||
| std::copy(all_pools->begin(), all_pools->end(), std::back_inserter(new_pools)); | ||
| new_pools.push_back(pool); | ||
| all_pools = std::make_shared<std::vector<void*>>(std::move(new_pools)); | ||
| } | ||
|
|
||
| void remove_pools_global(std::span<void*> pools) { | ||
| std::lock_guard lock{pool_mutate_mutex}; | ||
| auto& old_pools = *all_pools; | ||
| std::vector<void*> new_pools; | ||
| new_pools.reserve(old_pools.size()); | ||
| for (auto p : old_pools) { | ||
| if (std::find(pools.begin(), pools.end(), p) == pools.end()) { | ||
| new_pools.push_back(p); | ||
| } | ||
| } | ||
| all_pools = std::make_shared<std::vector<void*>>(new_pools); | ||
| } | ||
|
|
||
| std::pair<void*, void*> alloc_pool() { | ||
| void* original = VirtualAlloc(nullptr, POOL_SIZE * 2, MEM_RESERVE, PAGE_NOACCESS); | ||
| if (!original) { | ||
| return {nullptr, nullptr}; | ||
| } | ||
|
|
||
| void* aligned = alignToPoolSize(original); | ||
| return {aligned, original}; | ||
| } | ||
|
|
||
| void free_pool(void* ptr) { | ||
| VirtualFree(ptr, 0, MEM_RELEASE); | ||
| } | ||
|
|
||
| void decommit(void* ptr, size_t len) { | ||
| // can probably just MEM_RESET | ||
| VirtualFree(ptr, len, MEM_DECOMMIT); | ||
| } | ||
| #else | ||
| std::pair<void*, void*> alloc_pool() { | ||
| void* original = mmap(nullptr, POOL_SIZE * 2, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | ||
| if (original == MAP_FAILED) { | ||
| return {nullptr, nullptr}; | ||
| } | ||
| void* aligned = alignToPoolSize(original); | ||
| return {aligned, original}; | ||
| } | ||
|
|
||
| void free_pool(void* ptr) { | ||
| munmap(ptr, POOL_SIZE * 2); | ||
| } | ||
|
|
||
| void decommit(void* ptr, size_t len) { | ||
| madvise(ptr, len, MADV_DONTNEED); | ||
| //mmap(ptr, len, PROT_NONE, MAP_FIXED, -1, 0); | ||
| } | ||
|
|
||
| // not needed on linux | ||
| void add_pool_global(void*) {} | ||
| void remove_pools_global(std::span<void*>) {} | ||
| void init_page_handler() {} | ||
| #endif | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.