Commit 385cfc3c authored by Geoff Simmons's avatar Geoff Simmons

varnishevent: encourage re-use of space from the free list

parent 22b77e8b
...@@ -39,6 +39,17 @@ ...@@ -39,6 +39,17 @@
#include "vqueue.h" #include "vqueue.h"
#include "vsb.h" #include "vsb.h"
/*
* Place the contents of head1 before head2, then empty head2
*/
#define VSTAILQ_PREPEND(head1, head2) do { \
if (!VSTAILQ_EMPTY((head2))) { \
*(head2)->vstqh_last = (head1)->vstqh_first; \
(head1)->vstqh_first = (head2)->vstqh_first; \
VSTAILQ_INIT((head2)); \
} \
} while (0)
static const char *statename[3] = { "EMPTY", "OPEN", "DONE" }; static const char *statename[3] = { "EMPTY", "OPEN", "DONE" };
static pthread_mutex_t freelist_lock; static pthread_mutex_t freelist_lock;
...@@ -176,12 +187,14 @@ DATA_Take_Freelist(struct freehead_s *dst) ...@@ -176,12 +187,14 @@ DATA_Take_Freelist(struct freehead_s *dst)
/* /*
* return to global freelist * return to global freelist
* returned must be locked by caller, if required * returned must be locked by caller, if required
* Space is returned to the front of the free list, so that it is likely
* to be re-used
*/ */
void void
DATA_Return_Freelist(struct freehead_s *returned, unsigned nreturned) DATA_Return_Freelist(struct freehead_s *returned, unsigned nreturned)
{ {
AZ(pthread_mutex_lock(&freelist_lock)); AZ(pthread_mutex_lock(&freelist_lock));
VSTAILQ_CONCAT(&freehead, returned); VSTAILQ_PREPEND(&freehead, returned);
global_nfree += nreturned; global_nfree += nreturned;
AZ(pthread_mutex_unlock(&freelist_lock)); AZ(pthread_mutex_unlock(&freelist_lock));
} }
......
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