-
Notifications
You must be signed in to change notification settings - Fork 99
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
Wasm buffer manager support #4523
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
-DATASET CSV empty | ||
-BUFFER_POOL_SIZE 134217728 | ||
|
||
-- | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
-DATASET CSV empty | ||
-BUFFER_POOL_SIZE 268435456 | ||
|
||
-- | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,9 +84,10 @@ BufferManager::BufferManager(const std::string& databasePath, const std::string& | |
: bufferPoolSize{bufferPoolSize}, evictionQueue{bufferPoolSize / KUZU_PAGE_SIZE}, | ||
usedMemory{evictionQueue.getCapacity() * sizeof(EvictionCandidate)}, vfs{vfs} { | ||
verifySizeParams(bufferPoolSize, maxDBSize); | ||
vmRegions.resize(2); | ||
#if !BM_MALLOC | ||
vmRegions[0] = std::make_unique<VMRegion>(REGULAR_PAGE, maxDBSize); | ||
vmRegions[1] = std::make_unique<VMRegion>(TEMP_PAGE, bufferPoolSize); | ||
#endif | ||
|
||
// TODO(bmwinger): It may be better to spill to disk in a different location for remote file | ||
// systems, or even in general. | ||
|
@@ -141,7 +142,12 @@ uint8_t* BufferManager::pin(FileHandle& fileHandle, page_idx_t pageIdx, | |
throw BufferManagerException( | ||
"Eviction queue is full! This should be impossible."); | ||
} | ||
#if BM_MALLOC | ||
KU_ASSERT(pageState->getPage()); | ||
return pageState->getPage(); | ||
#else | ||
return getFrame(fileHandle, pageIdx); | ||
#endif | ||
} | ||
} break; | ||
case PageState::UNLOCKED: | ||
|
@@ -193,12 +199,19 @@ void handleAccessViolation(unsigned int exceptionCode, PEXCEPTION_POINTERS excep | |
|
||
// Returns true if the function completes successfully | ||
inline bool try_func(const std::function<void(uint8_t*)>& func, uint8_t* frame, | ||
const std::vector<std::unique_ptr<VMRegion>>& vmRegions, PageSizeClass pageSizeClass) { | ||
#if defined(_WIN32) | ||
const std::array<std::unique_ptr<VMRegion>, 2>& vmRegions [[maybe_unused]], | ||
PageSizeClass pageSizeClass [[maybe_unused]]) { | ||
#if BM_MALLOC | ||
if (frame == nullptr) { | ||
return false; | ||
} | ||
#endif | ||
|
||
#if defined(_WIN32) && !BM_MALLOC | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The macro here is becoming more a bit hard to follow now. I wonder if we should choose to duplicate the code a bit to separate them more clearly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the second There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep 👍 |
||
try { | ||
#endif | ||
func(frame); | ||
#if defined(_WIN32) | ||
#if defined(_WIN32) && !BM_MALLOC | ||
} catch (AccessViolation& exc) { | ||
// If we encounter an acess violation within the VM region, | ||
// the page was decomitted by another thread | ||
|
@@ -209,9 +222,6 @@ inline bool try_func(const std::function<void(uint8_t*)>& func, uint8_t* frame, | |
throw EXCEPTION_ACCESS_VIOLATION; | ||
} | ||
} | ||
#else | ||
(void)pageSizeClass; | ||
(void)vmRegions; | ||
#endif | ||
return true; | ||
} | ||
|
@@ -309,8 +319,7 @@ bool BufferManager::claimAFrame(FileHandle& fileHandle, page_idx_t pageIdx, | |
if (!reserve(pageSizeToClaim)) { | ||
return false; | ||
} | ||
#ifdef _WIN32 | ||
// We need to commit memory explicitly on Windows. | ||
#if _WIN32 && !BM_MALLOC | ||
// Committing in this context means reserving physical memory/page file space for a segment of | ||
// virtual memory. On Linux/Unix this is automatic when you write to the memory address. | ||
auto result = | ||
|
@@ -408,9 +417,16 @@ void BufferManager::cachePageIntoFrame(FileHandle& fileHandle, page_idx_t pageId | |
PageReadPolicy pageReadPolicy) { | ||
auto pageState = fileHandle.getPageState(pageIdx); | ||
pageState->clearDirty(); | ||
#if BM_MALLOC | ||
pageState->allocatePage(fileHandle.getPageSize()); | ||
if (pageReadPolicy == PageReadPolicy::READ_PAGE) { | ||
fileHandle.readPageFromDisk(pageState->getPage(), pageIdx); | ||
} | ||
#else | ||
if (pageReadPolicy == PageReadPolicy::READ_PAGE) { | ||
fileHandle.readPageFromDisk(getFrame(fileHandle, pageIdx), pageIdx); | ||
} | ||
#endif | ||
} | ||
|
||
void BufferManager::removeFilePagesFromFrames(FileHandle& fileHandle) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
-DATASET CSV empty | ||
-BUFFER_POOL_SIZE 268435456 | ||
-- | ||
|
||
-CASE CopyNodeAfterError | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
-DATASET CSV ldbc-sf01 | ||
-BUFFER_POOL_SIZE 134217728 | ||
|
||
-- | ||
|
||
-CASE CreateLikeComment | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
-DATASET CSV ldbc-sf01 | ||
-BUFFER_POOL_SIZE 134217728 | ||
-- | ||
|
||
-CASE DeleteLikeComment1 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
-DATASET CSV ldbc-sf01 | ||
-BUFFER_POOL_SIZE 134217728 | ||
-- | ||
|
||
-CASE SetLikeComment | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
-DATASET CSV tck | ||
-BUFFER_POOL_SIZE 268435456 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this due to recursive joins? |
||
|
||
-- | ||
|
||
|
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 think we should check allocation failure here to avoid seg faults.
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.
Interestingly in webassembly the tests are compiled with the default ABORTING_MALLOC=1, which aborts the webassembly process if it runs out of memory instead of returning 0, but outside of the tests we're compiling with
ALLOW_MEMORY_GROWTH
, which has the default of having malloc return 0 on failure.So I think we should set
ABORTING_MALLOC=0
for the tests just so it's handled the same (not that we have any tests where we expect this yet).