--------
- systemd: use correct cache location for garbage collector (#543)
+Improvements
+------------
+- cache: add fssize lua function to configure entire free disk space on dedicated cache partition (#524, !932)
+
+
Knot Resolver 5.0.0 (2020-01-27)
================================
-- 90 % of free memory after machine restart
cache.size = 13453 * MB
+It is also possible to set the cache size based on the file system size. This is useful
+if you use a dedicated partition for cache (e.g. non-persistent tmpfs). It is recommended
+to leave some free space for special files, such as locks.:
+
+.. code-block:: lua
+
+ cache.size = cache.fssize() - 10*MB
+
.. note:: The :ref:`garbage-collector` can be used to periodically trim the
cache. It is enabled and configured by default when running kresd with
systemd integration.
multiple systemd units, and a shared tmpfs space could be used up by other
applications, leading to ``SIGBUS`` errors during runtime.
-Mounting the cache directory as tmpfs_ is recommended approach.
-Make sure to use appropriate ``size=`` option and don't forget to adjust the
-size in the config file as well.
+Mounting the cache directory as tmpfs_ is the recommended approach. Make sure
+to use appropriate ``size=`` option and don't forget to adjust the size in the
+config file as well.
.. code-block:: none
.. code-block:: lua
- # /etc/knot-resolver/config
- cache.size = 2 * GB
+ -- /etc/knot-resolver/kresd.conf
+ cache.size = cache.fssize() - 10*MB
.. _tmpfs: https://en.wikipedia.org/wiki/Tmpfs
.. note:: This may or may not clear the cache, depending on the cache backend.
+.. function:: cache.fssize()
+
+ :return: Partition size of cache storage.
+
.. function:: cache.stats()
Return table with low-level statistics for each internal cache operation.
uint64_t kr_now();
const char *kr_strptime_diff(const char *, const char *, const char *, double *);
time_t kr_file_mtime(const char *);
+long long kr_fssize(const char *);
void lru_free_items_impl(struct lru *);
struct lru *lru_create_impl(unsigned int, unsigned int, knot_mm_t *, knot_mm_t *);
void *lru_get_impl(struct lru *, const char *, unsigned int, unsigned int, _Bool, _Bool *);
kr_now
kr_strptime_diff
kr_file_mtime
+ kr_fssize
lru_free_items_impl
lru_create_impl
lru_get_impl
return cb(kr_module)
end
+-- Return filesystem size where the cache resides.
+cache.fssize = function ()
+ local path = cache.current_storage or '.'
+ -- As it is now, `path` may or may not include the lmdb:// prefix.
+ if string.sub(path, 1, 7) == 'lmdb://' then
+ path = string.sub(path, 8)
+ end
+ if #path == 0 then
+ path = '.'
+ end
+ local size = tonumber(ffi.C.kr_fssize(path))
+ if size < 0 then
+ panic('cache.fssize(): %s', ffi.string(ffi.C.knot_strerror(size)))
+ else
+ return size
+ end
+end
+
cache.clear = function (name, exact_name, rr_type, chunk_size, callback, prev_state)
if name == nil or (name == '.' and not exact_name) then
-- keep same output format as for 'standard' clear
#include <string.h>
#include <sys/time.h>
#include <sys/stat.h>
+#include <sys/statvfs.h>
#include <sys/un.h>
/* Always compile-in log symbols, even if disabled. */
return fstat.st_mtime;
}
+long long kr_fssize(const char *path)
+{
+ if (!path)
+ return kr_error(EINVAL);
+
+ struct statvfs buf;
+ if (statvfs(path, &buf) != 0)
+ return kr_error(errno);
+
+ return buf.f_frsize * buf.f_blocks;
+}
+
KR_EXPORT uint32_t kr_rrsig_sig_inception(const knot_rdata_t *rdata);
KR_EXPORT uint32_t kr_rrsig_sig_expiration(const knot_rdata_t *rdata);
KR_EXPORT uint16_t kr_rrsig_type_covered(const knot_rdata_t *rdata);
+
KR_EXPORT time_t kr_file_mtime (const char* fname);
+/** Return filesystem size in bytes. */
+KR_EXPORT long long kr_fssize(const char *path);
+