... | ... | @@ -27,9 +27,9 @@ Measuring real memory usage can be tricky, but fortunately, there are some tools |
|
|
|
|
|
### Measuring Memory Internally
|
|
|
|
|
|
The statistics channel exposes counters for the memory contexts. The important values are 'InUse' and 'Malloced'. The 'InUse' counter shows the memory used "externally" and 'Malloced' includes the management overhead (the more memory contexts the more overhead there is).
|
|
|
The [statistics channel](https://bind9.readthedocs.io/en/latest/reference.html#namedconf-statement-statistics-channels) exposes counters for the memory contexts. The important values are 'InUse' and 'Malloced'. The 'InUse' counter shows the memory used "externally" and 'Malloced' includes the management overhead (the more memory contexts the more overhead there is).
|
|
|
|
|
|
You can use attached [memory-json.py](uploads/e9398e64964bbd68e7715c594dadbd3e/memory-json.py) script to parse the statistics channel output to receive following data (this is from `main` branch):
|
|
|
You can use attached [memory-json.py](uploads/e9398e64964bbd68e7715c594dadbd3e/memory-json.py) script to parse the statistics channel output from URL `/json/v1` to obtain following summary data (this is from `main` branch):
|
|
|
|
|
|
```
|
|
|
OpenSSL: 268.8KiB 277.0KiB
|
... | ... | @@ -85,10 +85,10 @@ $ smem -P named -a |
|
|
|
|
|
There are couple of reasons that the numbers reported by the BIND 9 statistics channel might differ from the memory usage reported by the operating system.
|
|
|
|
|
|
External libraries
|
|
|
#### External libraries
|
|
|
BIND 9 uses several external libraries - OpenSSL, libuv, libxml2, json-c and possibly others. All these also need memory from the operating system to operate. The difference should not be large, but it's also not negligible. If the difference between the used memory reported by the internal statistics channel and USS is large (on a busy server), then congratulations, you've found a leak in an external library. (NOTE: BIND 9.19 - the development version - provides own memory context for OpenSSL, libuv and libxml2 if the library versions are recent enough.)
|
|
|
|
|
|
Memory fragmentation
|
|
|
#### Memory fragmentation
|
|
|
There's quite a lot of churn in the memory allocations and deallocations on a busy server, and memory gets fragmented - the default Linux allocator isn't particularly good with the BIND 9 memory usage patterns. Using jemalloc is strongly recommended as it handles memory fragmentation much better and is also faster.
|
|
|
|
|
|
## Memory Profiling
|
... | ... | |