Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnishevent
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
varnishevent
Commits
abc22cab
Commit
abc22cab
authored
Mar 30, 2015
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prepend freelists on take and return, to favor re-use of memory
parent
7e8a1ad1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
15 deletions
+61
-15
data.c
src/data.c
+16
-2
test_data.c
src/test/test_data.c
+45
-13
No files found.
src/data.c
View file @
abc22cab
...
...
@@ -33,6 +33,7 @@
#include <stdlib.h>
#include <syslog.h>
#include <errno.h>
#include <stddef.h>
#include "varnishevent.h"
#include "vas.h"
...
...
@@ -40,6 +41,19 @@
#include "vqueue.h"
#include "vsb.h"
/* Preprend head2 before head1, result in head1, head2 empty afterward */
#define VSTAILQ_PREPEND(head1, head2) do { \
if (VSTAILQ_EMPTY((head1))) { \
(head1)->vstqh_first = (head2)->vstqh_first; \
(head1)->vstqh_last = (head2)->vstqh_last; \
} \
else if (!VSTAILQ_EMPTY((head2))) { \
(head2)->vstqh_last = &(head1)->vstqh_first; \
(head1)->vstqh_first = (head2)->vstqh_first; \
VSTAILQ_INIT((head2)); \
} \
} while (0)
#define FAKE_DEFAULT_LINES_PER_TX 10
#if 0
...
...
@@ -184,7 +198,7 @@ DATA_Take_Free##type(struct type##head_s *dst) \
unsigned nfree; \
\
AZ(pthread_mutex_lock(&free##type##_lock)); \
VSTAILQ_
CONCAT(dst, &free##type##head);
\
VSTAILQ_
PREPEND(dst, &free##type##head);
\
nfree = global_nfree_##type; \
global_nfree_##type = 0; \
AZ(pthread_mutex_unlock(&free##type##_lock)); \
...
...
@@ -204,7 +218,7 @@ void \
DATA_Return_Free##type(struct type##head_s *returned, unsigned nreturned) \
{ \
AZ(pthread_mutex_lock(&free##type##_lock)); \
VSTAILQ_
CONCAT(&free##type##head, returned);
\
VSTAILQ_
PREPEND(&free##type##head, returned);
\
global_nfree_##type += nreturned; \
AZ(pthread_mutex_unlock(&free##type##_lock)); \
}
...
...
src/test/test_data.c
View file @
abc22cab
...
...
@@ -41,7 +41,7 @@ static txhead_t local_freetx = VSTAILQ_HEAD_INITIALIZER(local_freetx);
static
linehead_t
local_freeline
=
VSTAILQ_HEAD_INITIALIZER
(
local_freeline
);
static
chunkhead_t
local_freechunk
=
VSTAILQ_HEAD_INITIALIZER
(
local_freechunk
);
/* N.B.: Always run th
is test first
*/
/* N.B.: Always run th
e tests in this order
*/
static
char
*
test_data_init
(
void
)
{
...
...
@@ -157,8 +157,6 @@ static const char
static
const
char
*
test_data_return_tx
(
void
)
{
tx_t
*
tx
;
printf
(
"... testing tx freelist return
\n
"
);
DATA_Return_Freetx
(
&
local_freetx
,
config
.
max_data
);
...
...
@@ -166,8 +164,6 @@ static const char
MASSERT
(
VSTAILQ_EMPTY
(
&
local_freetx
));
MASSERT
(
global_nfree_tx
==
config
.
max_data
);
/*MASSERT(!VSTAILQ_EMPTY(&freehead));*/
VSTAILQ_FOREACH
(
tx
,
&
local_freetx
,
freelist
)
MCHECK_OBJ_NOTNULL
(
tx
,
TX_MAGIC
);
return
NULL
;
}
...
...
@@ -175,8 +171,6 @@ static const char
static
const
char
*
test_data_return_rec
(
void
)
{
logline_t
*
rec
;
printf
(
"... testing record freelist return
\n
"
);
DATA_Return_Freeline
(
&
local_freeline
,
nrecords
);
...
...
@@ -184,8 +178,6 @@ static const char
MASSERT
(
VSTAILQ_EMPTY
(
&
local_freeline
));
MASSERT
(
global_nfree_line
==
nrecords
);
/*MASSERT(!VSTAILQ_EMPTY(&freehead));*/
VSTAILQ_FOREACH
(
rec
,
&
local_freeline
,
freelist
)
MCHECK_OBJ_NOTNULL
(
rec
,
LOGLINE_MAGIC
);
return
NULL
;
}
...
...
@@ -193,8 +185,6 @@ static const char
static
const
char
*
test_data_return_chunk
(
void
)
{
chunk_t
*
chunk
;
printf
(
"... testing chunk freelist return
\n
"
);
DATA_Return_Freechunk
(
&
local_freechunk
,
nchunks
);
...
...
@@ -202,8 +192,49 @@ static const char
MASSERT
(
VSTAILQ_EMPTY
(
&
local_freechunk
));
MASSERT
(
global_nfree_chunk
==
nchunks
);
/*MASSERT(!VSTAILQ_EMPTY(&freehead));*/
VSTAILQ_FOREACH
(
chunk
,
&
local_freechunk
,
freelist
)
MCHECK_OBJ_NOTNULL
(
chunk
,
CHUNK_MAGIC
);
return
NULL
;
}
static
const
char
*
test_data_prepend
(
void
)
{
tx_t
*
tx
;
int
n
=
0
;
printf
(
"... testing freelist prepend
\n
"
);
MASSERT
(
VSTAILQ_EMPTY
(
&
local_freetx
));
/* Return an empty list */
DATA_Return_Freetx
(
&
local_freetx
,
0
);
MASSERT
(
VSTAILQ_EMPTY
(
&
local_freetx
));
MASSERT
(
global_nfree_tx
==
config
.
max_data
);
DATA_Take_Freetx
(
&
local_freetx
);
VSTAILQ_INIT
(
&
local_freetx
);
/* insert the first 10 txn to the local list */
for
(
int
i
=
0
;
i
<
10
;
i
++
)
VSTAILQ_INSERT_TAIL
(
&
local_freetx
,
&
txn
[
i
],
freelist
);
/* Prepend them to the global free list */
DATA_Return_Freetx
(
&
local_freetx
,
10
);
/* insert the next 10 txn */
VSTAILQ_INIT
(
&
local_freetx
);
for
(
int
i
=
10
;
i
<
20
;
i
++
)
VSTAILQ_INSERT_TAIL
(
&
local_freetx
,
&
txn
[
i
],
freelist
);
/* Prepend them to the global list */
DATA_Return_Freetx
(
&
local_freetx
,
10
);
/*
* Take the global list, and verify that txn 10-19 are at the front,
* followed by txn 0-9.
*/
DATA_Take_Freetx
(
&
local_freetx
);
VSTAILQ_FOREACH
(
tx
,
&
local_freetx
,
freelist
)
{
if
(
n
<
10
)
MASSERT
(
tx
==
&
txn
[
n
+
10
]);
else
MASSERT
(
tx
==
&
txn
[
n
]);
n
++
;
}
return
NULL
;
}
...
...
@@ -218,6 +249,7 @@ static const char
mu_run_test
(
test_data_return_tx
);
mu_run_test
(
test_data_return_rec
);
mu_run_test
(
test_data_return_chunk
);
mu_run_test
(
test_data_prepend
);
return
NULL
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment