Commit b4ef35ff authored by Lubos Slovak's avatar Lubos Slovak

Merge remote branch 'origin/0xdeadbeef' into ldns-to-dnslib

Conflicts:
	CuteDNS.files
	Makefile
parents 4687bf82 b8382a69
......@@ -44,8 +44,6 @@ src/other/dynamic-array.h
src/other/dynamic-array.c
src/other/skip-list.h
src/other/skip-list.c
src/other/slab.h
src/other/slab.c
tests/querytcp.c
src/server/udp-handler.h
src/server/tcp-handler.h
......@@ -74,8 +72,6 @@ src/stat/gatherer.h
src/stat/gatherer.c
src/stat/stat.h
src/stat/stat.c
src/other/malloc.h
src/other/malloc.c
src/dnslib/zone.h
src/dnslib/zone.c
src/tests/dnslib/dnslib_zone_tests.c
......@@ -85,8 +81,6 @@ src/other/tree.h
src/dnslib/response.h
src/dnslib/packet.h
src/dnslib/response.c
src/other/malloc.h
src/other/malloc.c
src/dnslib/edns.h
src/dnslib/utils.h
src/dnslib/zonedb.h
......@@ -102,3 +96,7 @@ src/dnslib/debug.h
src/dnslib/debug.c
src/dnslib/dnslib.h
src/dnslib/tolower.h
src/alloc/malloc.h
src/alloc/malloc.c
src/alloc/slab.h
src/alloc/slab.c
......@@ -9,7 +9,7 @@ COL_CYAN = \033[01;36m
COL_WHITE = \033[01;37m
COL_END = \033[0m
INC_DIRS = obj/ src/ src/hash/ src/dns/ src/other/ src/server/ src/zone/ src/tests src/tests/libtap src/dnslib/ src/stat
INC_DIRS = obj/ src/ src/hash/ src/dns/ src/other/ src/server/ src/zone/ src/tests src/tests/libtap src/dnslib/ src/stat src/alloc/
SRC_DIRS = src/
TESTS_DIR = src/tests/
ZONEC_DIR = src/zone/
......
#include "debug.h"
/*
* Skip unit if not debugging memory.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/resource.h>
#ifdef MEM_DEBUG
/*
* ((destructor)) attribute executes this function after main().
* \see http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
*/
void __attribute__ ((destructor)) usage_dump()
#else
void usage_dump()
#endif
{
/* Get resource usage. */
struct rusage usage;
if (getrusage(RUSAGE_SELF, &usage) < 0) {
memset(&usage, 0, sizeof(struct rusage));
}
fprintf(stderr, "\nMemory statistics:");
fprintf(stderr, "\n==================\n");
fprintf(stderr, "User time: %.03lf ms\nSystem time: %.03lf ms\n",
usage.ru_utime.tv_sec * (double) 1000.0
+ usage.ru_utime.tv_usec / (double)1000.0,
usage.ru_stime.tv_sec * (double) 1000.0
+ usage.ru_stime.tv_usec / (double)1000.0);
fprintf(stderr, "Major page faults: %lu (required I/O)\nMinor page faults: %lu\n",
usage.ru_majflt, usage.ru_minflt);
fprintf(stderr, "Number of swaps: %lu\n",
usage.ru_nswap);
fprintf(stderr, "Voluntary context switches: %lu\nInvoluntary context switches: %lu\n",
usage.ru_nvcsw,
usage.ru_nivcsw);
fprintf(stderr, "==================\n");
}
/*!
* \file malloc.h
*
* \author Marek Vavrusa <marek.vavrusa@nic.cz>
*
* \brief Memory allocation related functions.
*
* \addtogroup alloc
* @{
*/
#ifndef __CUTEDNS_MALLOC_H__
#define __CUTEDNS_MALLOC_H__
#include <stdlib.h>
#include "debug.h"
/*! \brief Print usage statistics.
*
* \note This function has destructor attribute set if MEM_DEBUG is enabled.
*
* \warning Not all printed statistics are available on every OS,
* consult manual page for getrusage(2).
*/
void usage_dump();
#endif
This diff is collapsed.
This diff is collapsed.
......@@ -14,7 +14,6 @@
#include <signal.h>
#include <stdint.h>
#include "other/malloc.h"
/* Common types and constants.
*/
......@@ -31,6 +30,10 @@ typedef unsigned int uint;
/* Sockets. */
#define TCP_BACKLOG_SIZE 5 // TCP listen backlog size
/* Memory allocator. */
//#define MEM_SLAB_CAP 3 // Cap slab_cache empty slab count (undefined = inf)
#define MEM_COLORING // Slab cache coloring
/* Common includes.
*/
......
#include <stdio.h>
#include <stdlib.h>
#include "common.h"
#include "server.h"
......
#include "debug.h"
/*
* Skip unit if not debugging memory.
*/
#ifdef MEM_DEBUG
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/resource.h>
/*
* ((destructor)) attribute executes this function after main().
* \see http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
*/
void __attribute__ ((destructor (101))) log_malloc_dump()
{
/* Get resource usage. */
struct rusage usage;
if (getrusage(RUSAGE_SELF, &usage) < 0) {
memset(&usage, 0, sizeof(struct rusage));
}
debug_mem("\nMemory statistics:");
debug_mem("\n==================\n");
debug_mem("User time: %.03lf ms\nSystem time: %.03lf ms\n",
usage.ru_utime.tv_sec * (double) 1000.0
+ usage.ru_utime.tv_usec / (double)1000.0,
usage.ru_stime.tv_sec * (double) 1000.0
+ usage.ru_stime.tv_usec / (double)1000.0);
debug_mem("Major page faults: %lu (required I/O)\nMinor page faults: %lu\n",
usage.ru_majflt, usage.ru_minflt);
debug_mem("Number of swaps: %lu\n",
usage.ru_nswap);
debug_mem("Voluntary context switches: %lu\nInvoluntary context switches: %lu\n",
usage.ru_nvcsw,
usage.ru_nivcsw);
debug_mem("==================\n");
}
#endif
/*
#ifndef MEM_NOSLAB
#include "slab.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void *malloc(size_t size)
{
void* mem = slab_alloc_g(size);
fprintf(stderr, "%s(%lu) = %p\n", __func__, size, mem);
return mem;
}
void *calloc(size_t nmemb, size_t size)
{
const size_t nsz = nmemb * size;
void* mem = slab_alloc_g(nsz);
memset(mem, 0, nsz);
fprintf(stderr, "%s(%lu, %lu) = %p\n", __func__, nmemb, size, mem);
return mem;
}
void *realloc(void *ptr, size_t size)
{
void* mem = slab_realloc_g(ptr, size);
fprintf(stderr, "%s(%p, %lu) = %p\n", __func__, ptr, size, mem);
return mem;
}
void free(void *ptr)
{
fprintf(stderr, "%s(%p)\n", __func__, ptr);
slab_free(ptr);
}
#endif
*/
#ifndef __CUTEDNS_MALLOC_H__
#define __CUTEDNS_MALLOC_H__
#include <stdlib.h>
#include "debug.h"
/* If not MEM_NOSLAB is defined, use slab as GP allocator. */
#ifndef MEM_NOSLAB
#include "slab.h"
/*void *malloc(size_t size);
void *calloc(size_t nmemb, size_t size);
void *realloc(void *ptr, size_t size);
void free(void *ptr);*/
#define malloc(x) slab_alloc_g((x))
#define calloc(n, x) memset(slab_alloc_g((n)*(x)), 0, (n)*(x))
#define realloc(x, sz) slab_realloc_g((x), (sz))
#define free(x) slab_free((x))
/* Memory is MEM_NOSLAB. */
#else
#endif
#endif
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include "server.h"
#include "udp-handler.h"
......
......@@ -7,6 +7,7 @@
#include <sys/epoll.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "tcp-handler.h"
#include "name-server.h"
......
#include <malloc.h>
#include <pthread.h>
#include "malloc.h"
#include "gatherer.h"
#include "common.h"
......
#include <malloc.h>
#include <time.h>
#include <pthread.h>
#include <unistd.h>
......@@ -111,7 +110,7 @@ static void stat_sleep_compute()
sleep(SLEEP_TIME);
for (int i = 0; i < FREQ_BUFFER_SIZE; i++) {
if (local_gath->freq_array[i] >
if (local_gath->freq_array[i] >
ACTIVE_FLOW_THRESHOLD) {
debug_st("too much activity at index %d:"
" %d queries adress: %s port %d"
......@@ -125,13 +124,13 @@ static void stat_sleep_compute()
pthread_mutex_lock(&(local_gath->mutex_read));
local_gath->udp_qps = local_gath->udp_queries /
local_gath->udp_qps = local_gath->udp_queries /
(double)SLEEP_TIME;
local_gath->tcp_qps = local_gath->tcp_queries /
local_gath->tcp_qps = local_gath->tcp_queries /
(double)SLEEP_TIME;
local_gath->qps = local_gath->udp_qps + local_gath->tcp_qps;
/* following code needs usage of
/* following code needs usage of
* gettimeofday, which is currently disabled */
/* local_gath->udp_mean_latency=((double)local_gath->udp_latency/
......@@ -159,7 +158,7 @@ static void stat_sleep_compute()
debug_st("qps_tcp: %f\n", local_gath->tcp_qps);
/* debug_st("mean_lat_tcp: %f\n", local_gath->tcp_mean_latency); */
debug_st("UDP/TCP ratio %f\n",
debug_st("UDP/TCP ratio %f\n",
local_gath->udp_qps / local_gath->tcp_qps);
}
}
......
#include "tap_unit.h"
#include "skip-list.h"
#include "malloc.h"
#include <time.h>
static int skiplist_tests_count(int argc, char *argv[]);
......
......@@ -53,9 +53,18 @@ static int slab_tests_run(int argc, char *argv[])
ok(valid_free, "slab: freed memory is correctly invalidated");
// 4. Reap memory
int reaped = slab_cache_reap(&cache) > 0 &&
cache.slabs_empty == 0;
ok(reaped, "slab: cache reaping works");
slab_t* slab = cache.slabs_free;
int free_count = 0;
while (slab) {
slab_t* next = slab->next;
if (slab_isempty(slab)) {
++free_count;
}
slab = next;
}
int reaped = slab_cache_reap(&cache);
cmp_ok(reaped, "==", free_count, "slab: cache reaping works");
// Stress cache
int alloc_count = 73521;
......
......@@ -18,7 +18,7 @@
#include "rdata.h"
#include "rrsig.h"
#include "zone.h"
#include "other/slab.h"
#include "slab.h"
#define MAXRDATALEN 64
#define MAXLABELLEN 63
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment