diff options
author | Costa Tsaousis <costa@netdata.cloud> | 2023-01-17 19:35:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-17 19:35:14 +0200 |
commit | 7279dd092c23fbafcd7edb8ef7f3f79e1a0e5ecb (patch) | |
tree | 730e1cc845613b1751ad79f5d8ba6bdce1ad9491 /libnetdata/libnetdata.c | |
parent | 6be264d62788b1b50109dc1f2a0cb6f622cfb804 (diff) |
DBENGINE v2 - improvements part 3 (#14269)
* reduce journal v2 shared memory using madvise() - not integrated yet
* working attempt to minimize dbengine shared memory
* never call willneed - let the kernel decide which parts of each file are really needed
* journal files get MADV_RANDOM
* dont call MADV_DONTNEED too frequently
* madvise() is always called with the journal unlocked but referenced
* call madvise() even less frequently
* added chart for monitoring database events
* turn batch mode on under critical conditions
* max size to evict is 1/4 of the max
* fix max size to evict calculation
* use dbengine_page/extent_alloc/free to pages and extents allocations, tracking also the size of these allocations at free time
* fix calculation for batch evictions
* allow main and open cache to have as many evictors as needed
* control inline evictors for each cache; report different levels of cache pressure on every cache evaluation
* more inline evictors for extent cache
* bypass max inline evictors above critical level
* current cache usage has to be taken
* re-arrange items in journafile
* updated docs - work in progress
* more docs work
* more docs work
* Map / unmap journal file
* draw.io diagram for dbengine operations
* updated dbengine diagram
* updated docs
* journal files v2 now get mapped and unmapped as needed
* unmap journal v2 immediately when getting retention
* mmap and munmap do not block queries evaluating journal files v2
* have only one unmap function
Co-authored-by: Stelios Fragkakis <52996999+stelfrag@users.noreply.github.com>
Diffstat (limited to 'libnetdata/libnetdata.c')
-rw-r--r-- | libnetdata/libnetdata.c | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/libnetdata/libnetdata.c b/libnetdata/libnetdata.c index 210d742ffc..aa7a6d7364 100644 --- a/libnetdata/libnetdata.c +++ b/libnetdata/libnetdata.c @@ -1184,6 +1184,14 @@ inline int madvise_sequential(void *mem, size_t len) { return ret; } +inline int madvise_random(void *mem, size_t len) { + static int logger = 1; + int ret = madvise(mem, len, MADV_RANDOM); + + if (ret != 0 && logger-- > 0) error("madvise(MADV_RANDOM) failed."); + return ret; +} + inline int madvise_dontfork(void *mem, size_t len) { static int logger = 1; int ret = madvise(mem, len, MADV_DONTFORK); @@ -1200,6 +1208,14 @@ inline int madvise_willneed(void *mem, size_t len) { return ret; } +inline int madvise_dontneed(void *mem, size_t len) { + static int logger = 1; + int ret = madvise(mem, len, MADV_DONTNEED); + + if (ret != 0 && logger-- > 0) error("madvise(MADV_DONTNEED) failed."); + return ret; +} + inline int madvise_dontdump(void *mem __maybe_unused, size_t len __maybe_unused) { #if __linux__ static int logger = 1; @@ -1224,7 +1240,7 @@ inline int madvise_mergeable(void *mem __maybe_unused, size_t len __maybe_unused #endif } -void *netdata_mmap(const char *filename, size_t size, int flags, int ksm, bool read_only) +void *netdata_mmap(const char *filename, size_t size, int flags, int ksm, bool read_only, int *open_fd) { // info("netdata_mmap('%s', %zu", filename, size); @@ -1281,15 +1297,20 @@ void *netdata_mmap(const char *filename, size_t size, int flags, int ksm, bool r else info("Cannot seek to beginning of file '%s'.", filename); } - madvise_sequential(mem, size); + // madvise_sequential(mem, size); madvise_dontfork(mem, size); madvise_dontdump(mem, size); - if(flags & MAP_SHARED) madvise_willneed(mem, size); + // if(flags & MAP_SHARED) madvise_willneed(mem, size); if(ksm) madvise_mergeable(mem, size); } cleanup: - if(fd != -1) close(fd); + if(fd != -1) { + if (open_fd) + *open_fd = fd; + else + close(fd); + } if(mem == MAP_FAILED) return NULL; errno = 0; return mem; |