diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-10-13 16:51:53 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2021-10-13 16:51:53 +0100 |
commit | 943a36c4a6f3ce6f3e37ddd52422094d1e47d23b (patch) | |
tree | bc11e1162b7361398f6923c157e7b4d00fe3d270 /src | |
parent | cee232b61c1e868e41e08392d9752283ab1a5853 (diff) | |
download | rspamd-943a36c4a6f3ce6f3e37ddd52422094d1e47d23b.tar.gz rspamd-943a36c4a6f3ce6f3e37ddd52422094d1e47d23b.zip |
[Minor] Readahead cdb file if possible
Diffstat (limited to 'src')
-rw-r--r-- | src/lua/lua_cdb.c | 15 |
1 files changed, 15 insertions, 0 deletions
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); |