log_assert(0);
return 0;
}
+
+void
+worker_alloc_cleanup(void* ATTR_UNUSED(arg))
+{
+ log_assert(0);
+}
server_stats_init(&worker->stats);
alloc_init(&worker->alloc, &worker->daemon->superalloc,
worker->thread_num);
+ alloc_set_id_cleanup(&worker->alloc, &worker_alloc_cleanup, worker);
worker->env = *worker->daemon->env;
worker->env.worker = worker;
worker->env.send_packet = &worker_send_packet;
}
return e;
}
+
+void
+worker_alloc_cleanup(void* arg)
+{
+ struct worker* worker = (struct worker*)arg;
+ slabhash_clear(&worker->env.rrset_cache->table);
+ slabhash_clear(worker->env.msg_cache);
+}
int worker_handle_service_reply(struct comm_point* c, void* arg, int error,
struct comm_reply* reply_info);
+/** cleanup the cache to remove all rrset IDs from it, arg is worker */
+void worker_alloc_cleanup(void* arg);
+
#endif /* DAEMON_WORKER_H */
that checking the passwd entry still works.
- minor touch up of clear() hashtable function.
- VERB_DETAIL prints out what chdir, username, chroot is being done.
+ - when id numbers run out, caches are cleared, as in design notes.
+ Tested with a mock setup with very few bits in id, it worked.
31 October 2007: Wouter
- cache-max-ttl config option.
#include "util/alloc.h"
#include "util/regional.h"
#include "util/data/packed_rrset.h"
+#include "util/fptr_wlist.h"
/** custom size of cached regional blocks */
#define ALLOC_REG_SIZE 16384
alloc->max_reg_blocks = 100;
alloc->num_reg_blocks = 0;
alloc->reg_list = NULL;
+ alloc->cleanup = NULL;
+ alloc->cleanup_arg = NULL;
if(alloc->super)
prealloc_blocks(alloc, alloc->max_reg_blocks);
if(!alloc->super) {
{
uint64_t id = alloc->next_id++;
if(id == alloc->last_id) {
- /* TODO: clear the rrset cache */
- log_warn("Out of ids. Clearing cache.");
+ log_warn("rrset alloc: out of 64bit ids. Clearing cache.");
+ fptr_whitelist_alloc_cleanup(alloc->cleanup);
+ (*alloc->cleanup)(alloc->cleanup_arg);
+
/* start back at first number */ /* like in alloc_init*/
alloc->next_id = (uint64_t)alloc->thread_num;
alloc->next_id <<= THRNUM_SHIFT; /* in steps for comp. */
alloc->num_reg_blocks++;
}
+void
+alloc_set_id_cleanup(struct alloc_cache* alloc, void (*cleanup)(void*),
+ void* arg)
+{
+ alloc->cleanup = cleanup;
+ alloc->cleanup_arg = arg;
+}
+
/** global debug value to keep track of total memory mallocs */
size_t unbound_mem_alloc = 0;
/** global debug value to keep track of total memory frees */
uint64_t next_id;
/** last id number possible */
uint64_t last_id;
+ /** what function to call to cleanup when last id is reached */
+ void (*cleanup)(void*);
+ /** user arg for cleanup */
+ void* cleanup_arg;
/** how many regional blocks to keep back max */
size_t max_reg_blocks;
*/
void alloc_reg_release(struct alloc_cache* alloc, struct regional* r);
+/**
+ * Set cleanup on ID overflow callback function. This should remove all
+ * RRset ID references from the program. Clear the caches.
+ * @param alloc: the alloc
+ * @param cleanup: the callback function, called as cleanup(arg).
+ * @param arg: user argument to callback function.
+ */
+void alloc_set_id_cleanup(struct alloc_cache* alloc, void (*cleanup)(void*),
+ void* arg);
+
#endif /* UTIL_ALLOC_H */
else if(fptr == &val_get_mem) return 1;
return 0;
}
+
+int
+fptr_whitelist_alloc_cleanup(void (*fptr)(void*))
+{
+ if(fptr == &worker_alloc_cleanup) return 1;
+ return 0;
+}
*/
int fptr_whitelist_mod_get_mem(size_t (*fptr)(struct module_env* env, int id));
+/**
+ * Check function pointer whitelist for alloc clear on id overflow call values.
+ *
+ * @param fptr: function pointer to check.
+ * @return false if not in whitelist.
+ */
+int fptr_whitelist_alloc_cleanup(void (*fptr)(void*));
+
#endif /* UTIL_FPTR_WLIST_H */