Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.9k
[feature-wip] (memory tracker) (step5) Fix track bthread, fix track vectorized query#9145
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -20,6 +20,7 @@ | ||
| #include <sys/mman.h> | ||
| #include "olap/utils.h" | ||
| #include "runtime/thread_context.h" | ||
| namespace doris { | ||
| @@ -42,6 +43,8 @@ void StorageByteBuffer::BufDeleter::operator()(char* p) { | ||
| if (0 != munmap(p, _mmap_length)) { | ||
| LOG(FATAL) << "fail to munmap: mem=" << p << ", len=" << _mmap_length | ||
| << ", errno=" << Errno::no() << ", errno_str=" << Errno::str(); | ||
| } else { | ||
| RELEASE_THREAD_LOCAL_MEM_TRACKER(_mmap_length); | ||
| } | ||
| } else { | ||
| delete[] p; | ||
| @@ -93,10 +96,12 @@ StorageByteBuffer* StorageByteBuffer::reference_buffer(StorageByteBuffer* refere | ||
| StorageByteBuffer* StorageByteBuffer::mmap(void* start, uint64_t length, int prot, int flags, | ||
| int fd, uint64_t offset) { | ||
| CONSUME_THREAD_LOCAL_MEM_TRACKER(length); | ||
| char* memory = (char*)::mmap(start, length, prot, flags, fd, offset); | ||
| if (MAP_FAILED == memory) { | ||
xinyiZzz marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| OLAP_LOG_WARNING("fail to mmap. [errno='%d' errno_str='%s']", Errno::no(), Errno::str()); | ||
| RELEASE_THREAD_LOCAL_MEM_TRACKER(length); | ||
| return nullptr; | ||
| } | ||
| @@ -108,6 +113,7 @@ StorageByteBuffer* StorageByteBuffer::mmap(void* start, uint64_t length, int pro | ||
| if (nullptr == buf) { | ||
| deleter(memory); | ||
| OLAP_LOG_WARNING("fail to allocate StorageByteBuffer."); | ||
| RELEASE_THREAD_LOCAL_MEM_TRACKER(length); | ||
| return nullptr; | ||
| } | ||
| @@ -128,10 +134,12 @@ StorageByteBuffer* StorageByteBuffer::mmap(FileHandler* handler, uint64_t offset | ||
| size_t length = handler->length(); | ||
| int fd = handler->fd(); | ||
| CONSUME_THREAD_LOCAL_MEM_TRACKER(length); | ||
| char* memory = (char*)::mmap(nullptr, length, prot, flags, fd, offset); | ||
| if (MAP_FAILED == memory) { | ||
xinyiZzz marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| OLAP_LOG_WARNING("fail to mmap. [errno='%d' errno_str='%s']", Errno::no(), Errno::str()); | ||
| RELEASE_THREAD_LOCAL_MEM_TRACKER(length); | ||
| return nullptr; | ||
| } | ||
| @@ -143,6 +151,7 @@ StorageByteBuffer* StorageByteBuffer::mmap(FileHandler* handler, uint64_t offset | ||
| if (nullptr == buf) { | ||
| deleter(memory); | ||
| OLAP_LOG_WARNING("fail to allocate StorageByteBuffer."); | ||
| RELEASE_THREAD_LOCAL_MEM_TRACKER(length); | ||
| return nullptr; | ||
| } | ||
| @@ -173,7 +182,7 @@ Status StorageByteBuffer::put(uint64_t index, char src) { | ||
| } | ||
| Status StorageByteBuffer::put(const char* src, uint64_t src_size, uint64_t offset, | ||
| uint64_t length) { | ||
| uint64_t length) { | ||
| //没有足够的空间可以写 | ||
| if (length > remaining()) { | ||
| return Status::OLAPInternalError(OLAP_ERR_BUFFER_OVERFLOW); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -22,6 +22,7 @@ | ||
| #include "common/config.h" | ||
| #include "gutil/strings/substitute.h" | ||
| #include "runtime/thread_context.h" | ||
| #include "util/bit_util.h" | ||
| #include "util/error_util.h" | ||
| @@ -75,9 +76,11 @@ Status SystemAllocator::AllocateViaMMap(int64_t len, uint8_t** buffer_mem) { | ||
| // Map an extra huge page so we can fix up the alignment if needed. | ||
| map_len += HUGE_PAGE_SIZE; | ||
| } | ||
| CONSUME_THREAD_LOCAL_MEM_TRACKER(map_len); | ||
| uint8_t* mem = reinterpret_cast<uint8_t*>( | ||
| mmap(nullptr, map_len, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0)); | ||
| if (mem == MAP_FAILED) { | ||
xinyiZzz marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| RELEASE_THREAD_LOCAL_MEM_TRACKER(map_len); | ||
| return Status::BufferAllocFailed("mmap failed"); | ||
| } | ||
| @@ -89,10 +92,12 @@ Status SystemAllocator::AllocateViaMMap(int64_t len, uint8_t** buffer_mem) { | ||
| if (misalignment != 0) { | ||
| uintptr_t fixup = HUGE_PAGE_SIZE - misalignment; | ||
| munmap(mem, fixup); | ||
| RELEASE_THREAD_LOCAL_MEM_TRACKER(fixup); | ||
| mem += fixup; | ||
| map_len -= fixup; | ||
| } | ||
| munmap(mem + len, map_len - len); | ||
| RELEASE_THREAD_LOCAL_MEM_TRACKER(map_len - len); | ||
| DCHECK_EQ(reinterpret_cast<uintptr_t>(mem) % HUGE_PAGE_SIZE, 0) << mem; | ||
| // Mark the buffer as a candidate for promotion to huge pages. The Linux Transparent | ||
| // Huge Pages implementation will try to back the memory with a huge page if it is | ||
| @@ -142,6 +147,7 @@ Status SystemAllocator::AllocateViaMalloc(int64_t len, uint8_t** buffer_mem) { | ||
| void SystemAllocator::Free(BufferPool::BufferHandle&& buffer) { | ||
| if (config::mmap_buffers) { | ||
| int rc = munmap(buffer.data(), buffer.len()); | ||
| RELEASE_THREAD_LOCAL_MEM_TRACKER(buffer.len()); | ||
| DCHECK_EQ(rc, 0) << "Unexpected munmap() error: " << errno; | ||
| } else { | ||
| bool use_huge_pages = buffer.len() % HUGE_PAGE_SIZE == 0 && config::madvise_huge_pages; | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.