commit 943a36c: [Minor] Readahead cdb file if possible
Vsevolod Stakhov
vsevolod at highsecure.ru
Wed Oct 13 15:56:05 UTC 2021
Author: Vsevolod Stakhov
Date: 2021-10-13 16:51:53 +0100
URL: https://github.com/rspamd/rspamd/commit/943a36c4a6f3ce6f3e37ddd52422094d1e47d23b (HEAD -> master)
[Minor] Readahead cdb file if possible
---
src/lua/lua_cdb.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/src/lua/lua_cdb.c b/src/lua/lua_cdb.c
index 0762c8d35..8f13f6ccf 100644
--- a/src/lua/lua_cdb.c
+++ b/src/lua/lua_cdb.c
@@ -72,6 +72,21 @@ lua_cdb_create (lua_State *L)
lua_pushnil (L);
}
else {
+#ifdef HAVE_READAHEAD
+ struct stat st;
+ /*
+ * Do not readahead more than 100mb,
+ * which is enough for the vast majority of the use cases
+ */
+ static const size_t max_readahead = 100 * 0x100000;
+
+ if (fstat(cdb_fileno(cdb), &st) != 1) {
+ /* Must always be true because cdb_init calls it as well */
+ if (readahead(cdb_fileno(cdb), 0, MIN(max_readahead, st.st_size)) == -1) {
+ msg_warn ("cannot readahead cdb: %s, %s", filename, strerror (errno));
+ }
+ }
+#endif
cdb_add_timer (cdb, ev_base, CDB_REFRESH_TIME);
pcdb = lua_newuserdata (L, sizeof (struct cdb *));
rspamd_lua_setclass (L, "rspamd{cdb}", -1);
More information about the Commits
mailing list