Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use shared memory objects for data #429

Merged
merged 59 commits into from
Dec 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
3e88490
Store forward destination IP address and host name in contiguous stri…
DL6ER Aug 1, 2018
b7da12b
Use strbuffer also for client IPs and host names
DL6ER Aug 1, 2018
96928c7
Use strbuffer also for domains
DL6ER Aug 1, 2018
1a508fc
Rename last_pos to next_pos and use struct for string buffer
DL6ER Aug 2, 2018
d7d8518
Store size in string buffer + use long long for string position indices
DL6ER Aug 2, 2018
1b7e084
Add shared memory components to store strings in shared memory
DL6ER Aug 2, 2018
bb51f4e
Improve shmem error outputs
DL6ER Aug 2, 2018
2e12558
Allocate shared memory in units of pages
DL6ER Aug 2, 2018
f1ba139
Unify two if statements into one + allocate already one page size ini…
DL6ER Aug 2, 2018
0ced77c
Also store domains struct in shared memory object
DL6ER Aug 2, 2018
249d236
Also store clients struct in shared memory object
DL6ER Aug 2, 2018
584c23d
Also store forwarded struct in shared memory object
DL6ER Aug 2, 2018
5d22aa7
Also store queries struct in shared memory object
DL6ER Aug 2, 2018
edf7461
Fix wrong pointer reference
DL6ER Aug 2, 2018
74d25d1
Fix wrong error message, remove duplicated resized message, and don't…
DL6ER Aug 3, 2018
0003a41
Use munmap + mmap instead of mremap when enlarging shared memory objects
DL6ER Aug 3, 2018
77f932b
Move query type determination further up
DL6ER Aug 3, 2018
f40d8b1
First munmap() the shared memory object, thereafter resize it (using …
DL6ER Aug 3, 2018
f72a4cd
man shm_open recommends to use shared memory object names starting wi…
DL6ER Aug 3, 2018
9f275a0
Re-open shared memory object when resizing the object using ftruncate…
DL6ER Aug 3, 2018
eb1d851
Allocate more struct memory earlier
DL6ER Aug 4, 2018
bbfe186
Merge branch 'development' into new/shmem
AzureMarker Sep 2, 2018
992726d
Fix compile error due to merge
AzureMarker Sep 2, 2018
99c4e40
Fix getstr parameter warning
AzureMarker Sep 2, 2018
3585043
Use unsigned long long for string positions
AzureMarker Sep 2, 2018
d96c009
Only use a single NULL terminator in strings shared memory
AzureMarker Sep 2, 2018
e91369f
Fix shared memory resize not being remembered
AzureMarker Sep 2, 2018
8401c9b
Add stdbool include to shmem.h
AzureMarker Sep 2, 2018
ae1bb5b
Move counters to shared memory
AzureMarker Sep 3, 2018
3d439ad
Merge remote-tracking branch 'origin/development' into new/shmem
AzureMarker Sep 17, 2018
e1c8ccc
Use negative query IDs for queries loaded from the database
AzureMarker Sep 18, 2018
9e4d77a
Merge pull request #382 from pi-hole/feature/negative-database-query-ids
AzureMarker Sep 19, 2018
cd41aae
Put overTime data into shared memory
AzureMarker Sep 19, 2018
45832da
Merge pull request #385 from pi-hole/feature/shmem-overTime
AzureMarker Sep 21, 2018
b936e2b
Fix error freeing client shared memory
AzureMarker Sep 25, 2018
325fc64
Fix interchanged indizes in GC routine
DL6ER Sep 25, 2018
ea7cdfb
Merge branch 'development' into new/shmem
DL6ER Sep 26, 2018
776f91c
Allocate individual client overTime objects guaranteed pagesize-aligned
DL6ER Sep 26, 2018
8c68aac
Add shared memory lock
AzureMarker Oct 5, 2018
3283d68
Remove threads.o from Makefile
AzureMarker Oct 5, 2018
fa9e7b1
Fix lock initializers for arm build
AzureMarker Oct 5, 2018
215fa14
Review comments
DL6ER Oct 7, 2018
c3934eb
Merge pull request #389 from pi-hole/new/shmem-clients-pagesize
AzureMarker Oct 7, 2018
1279b93
Store database ID in queries struct. This information will be availab…
DL6ER Oct 7, 2018
601722d
Obtain ID before insertion transaction and store IDs only when a quer…
DL6ER Oct 11, 2018
ca2e38b
Initialize db rowID with zero
DL6ER Oct 11, 2018
d7b4ce8
Remove read lock and simplify lock names
AzureMarker Oct 11, 2018
a3e9677
Change shm lock to a robust mutex
AzureMarker Oct 11, 2018
b0c8a54
Use a condition variable and boolean to notify FTL is waiting for a lock
AzureMarker Oct 13, 2018
ece89a5
Remove condition variable from shared memory lock
AzureMarker Oct 24, 2018
100d92b
Set queryID to zero for queries imported from the database on startup
DL6ER Oct 25, 2018
f8ba173
Remove unused variable queryID
DL6ER Oct 25, 2018
f0dabf6
Merge pull request #398 from pi-hole/new/shmem_databaseID
AzureMarker Oct 25, 2018
85290bb
Merge branch 'development' into new/shmem
DL6ER Nov 21, 2018
ff4d985
Merge branch 'new/shmem' into feature/shm-lock
AzureMarker Nov 21, 2018
befc0f8
Fix reference to old lock functions
AzureMarker Nov 21, 2018
0760461
Merge pull request #396 from pi-hole/feature/shm-lock
DL6ER Dec 9, 2018
a595f21
Merge branch 'development' into new/shmem
DL6ER Dec 9, 2018
120aeb4
Remove obsolete constants
DL6ER Dec 9, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 12 additions & 20 deletions FTL.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,6 @@

#include "routines.h"

// Next we define the step size in which the struct arrays are reallocated if they
// grow too large. This number should be large enough so that reallocation does not
// have to run very often, but should be as small as possible to avoid wasting memory
#define QUERIESALLOCSTEP 10000
#define FORWARDEDALLOCSTEP 4
#define CLIENTSALLOCSTEP 10
#define DOMAINSALLOCSTEP 1000
#define OVERTIMEALLOCSTEP 100
#define WILDCARDALLOCSTEP 100

#define SOCKETBUFFERLEN 1024

// How often do we garbage collect (to ensure we only have data fitting to the MAXLOGAGE defined above)? [seconds]
Expand Down Expand Up @@ -166,7 +156,7 @@ typedef struct {
int domainID;
int clientID;
int forwardID;
bool db;
sqlite3_int64 db;
int id; // the ID is a (signed) int in dnsmasq, so no need for a long int here
bool complete;
unsigned char privacylevel;
Expand All @@ -180,25 +170,25 @@ typedef struct {
unsigned char magic;
int count;
int failed;
char *ip;
char *name;
unsigned long long ippos;
unsigned long long namepos;
bool new;
} forwardedDataStruct;

typedef struct {
unsigned char magic;
int count;
int blockedcount;
char *ip;
char *name;
unsigned long long ippos;
unsigned long long namepos;
bool new;
} clientsDataStruct;

typedef struct {
unsigned char magic;
int count;
int blockedcount;
char *domain;
unsigned long long domainpos;
unsigned char regexmatch;
} domainsDataStruct;

Expand All @@ -209,9 +199,7 @@ typedef struct {
int blocked;
int cached;
int forwarded;
int clientnum;
int *clientdata;
int querytypedata[7];
int querytypedata[TYPE_MAX-1];
} overTimeDataStruct;

typedef struct {
Expand All @@ -227,7 +215,7 @@ typedef struct {

extern logFileNamesStruct files;
extern FTLFileNamesStruct FTLfiles;
extern countersStruct counters;
extern countersStruct *counters;
extern ConfigStruct config;

extern queriesDataStruct *queries;
Expand All @@ -236,6 +224,10 @@ extern clientsDataStruct *clients;
extern domainsDataStruct *domains;
extern overTimeDataStruct *overTime;

/// Indexed by client ID, then time index (like `overTime`).
/// This gets automatically updated whenever a new client or overTime slot is added.
extern int **overTimeClientData;

extern FILE *logfile;
extern volatile sig_atomic_t killed;

Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ DNSMASQOPTS = -DHAVE_DNSSEC -DHAVE_DNSSEC_STATIC
# Flags for compiling with libidn : -DHAVE_IDN
# Flags for compiling with libidn2: -DHAVE_LIBIDN2 -DIDN2_VERSION_NUMBER=0x02000003

FTLDEPS = FTL.h routines.h version.h api.h dnsmasq_interface.h
FTLOBJ = main.o memory.o log.o daemon.o datastructure.o signals.o socket.o request.o grep.o setupVars.o args.o threads.o gc.o config.o database.o msgpack.o api.o dnsmasq_interface.o resolve.o regex.o
FTLDEPS = FTL.h routines.h version.h api.h dnsmasq_interface.h shmem.h
FTLOBJ = main.o memory.o log.o daemon.o datastructure.o signals.o socket.o request.o grep.o setupVars.o args.o gc.o config.o database.o msgpack.o api.o dnsmasq_interface.o resolve.o regex.o shmem.o

DNSMASQDEPS = config.h dhcp-protocol.h dns-protocol.h radv-protocol.h dhcp6-protocol.h dnsmasq.h ip6addr.h metrics.h
DNSMASQOBJ = arp.o dbus.o domain.o lease.o outpacket.o rrfilter.o auth.o dhcp6.o edns0.o log.o poll.o slaac.o blockdata.o dhcp.o forward.o loop.o radv.o tables.o bpf.o dhcp-common.o helper.o netlink.o rfc1035.o tftp.o cache.o dnsmasq.o inotify.o network.o rfc2131.o util.o conntrack.o dnssec.o ipset.o option.o rfc3315.o crypto.o dump.o ubus.o metrics.o
Expand Down Expand Up @@ -51,7 +51,7 @@ CCFLAGS=-std=gnu11 -I$(IDIR) -Wall -Wextra -Wno-unused-parameter -D_FILE_OFFSET_
# for dnsmasq we need the nettle crypto library and the gmp maths library
# We link the two libraries statically. Althougth this increases the binary file size by about 1 MB, it saves about 5 MB of shared libraries and makes deployment easier
#LIBS=-pthread -lnettle -lgmp -lhogweed
LIBS=-pthread -Wl,-Bstatic -L/usr/local/lib -lhogweed -lgmp -lnettle -Wl,-Bdynamic
LIBS=-pthread -Wl,-Bstatic -L/usr/local/lib -lhogweed -lgmp -lnettle -Wl,-Bdynamic -lrt
# Flags for compiling with libidn : -lidn
# Flags for compiling with libidn2: -lidn2

Expand Down
Loading