[master] dd0e30e Finish polishing the session memory management:
Poul-Henning Kamp
phk at varnish-cache.org
Sun Sep 18 10:31:40 CEST 2011
commit dd0e30ee0b53f1a2a0f2f7de460a2dd16431efc3
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Sun Sep 18 08:29:58 2011 +0000
Finish polishing the session memory management:
Also check if the http_max_hdr param changes.
Describe http_max_hdr as per pool.
Add SES_DeletePool() function.
diff --git a/bin/varnishd/cache.h b/bin/varnishd/cache.h
index 122ab34..2a7578d 100644
--- a/bin/varnishd/cache.h
+++ b/bin/varnishd/cache.h
@@ -849,7 +849,6 @@ unsigned WRW_WriteH(struct worker *w, const txt *hh, const char *suf);
void WRW_Sendfile(struct worker *w, int fd, off_t off, unsigned len);
#endif /* SENDFILE_WORKS */
-
/* cache_session.c [SES] */
struct sess *SES_New(struct worker *wrk, struct sesspool *pp);
struct sess *SES_Alloc(void);
@@ -857,7 +856,7 @@ void SES_Close(struct sess *sp, const char *reason);
void SES_Delete(struct sess *sp, const char *reason);
void SES_Charge(struct sess *sp);
struct sesspool *SES_NewPool(void);
-
+void SES_DeletePool(struct sesspool *sp, struct worker *wrk);
/* cache_shmlog.c */
void VSL_Init(void);
diff --git a/bin/varnishd/cache_session.c b/bin/varnishd/cache_session.c
index 7012263..23d15e7 100644
--- a/bin/varnishd/cache_session.c
+++ b/bin/varnishd/cache_session.c
@@ -51,11 +51,14 @@ struct sessmem {
#define SESSMEM_MAGIC 0x555859c5
struct sesspool *pool;
- struct sess sess;
+
unsigned workspace;
+ uint16_t nhttp;
void *wsp;
struct http *http[2];
VTAILQ_ENTRY(sessmem) list;
+
+ struct sess sess;
};
struct sesspool {
@@ -120,14 +123,20 @@ ses_sm_alloc(void)
sm = (void*)p;
p += sizeof *sm;
+
sm->magic = SESSMEM_MAGIC;
sm->workspace = nws;
+ sm->nhttp = nhttp;
+
sm->http[0] = HTTP_create(p, nhttp);
p += hl;
+
sm->http[1] = HTTP_create(p, nhttp);
p += hl;
+
sm->wsp = p;
p += nws;
+
assert(p == q);
return (sm);
@@ -318,6 +327,7 @@ SES_Delete(struct sess *sp, const char *reason)
b->fetch, b->hdrbytes, b->bodybytes);
if (sm->workspace != params->sess_workspace ||
+ sm->nhttp != (uint16_t)params->http_max_hdr ||
pp->nsess > params->max_sess) {
free(sm);
Lck_Lock(&pp->mtx);
@@ -341,7 +351,7 @@ SES_Delete(struct sess *sp, const char *reason)
}
/*--------------------------------------------------------------------
- * Create a new pool to allocate from
+ * Create and delete pools
*/
struct sesspool *
@@ -355,3 +365,25 @@ SES_NewPool(void)
Lck_New(&sp->mtx, lck_sessmem);
return (sp);
}
+
+void
+SES_DeletePool(struct sesspool *sp, struct worker *wrk)
+{
+ struct sessmem *sm;
+
+ CHECK_OBJ_NOTNULL(sp, SESSPOOL_MAGIC);
+ CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+ Lck_Lock(&sp->mtx);
+ while (!VTAILQ_EMPTY(&sp->freelist)) {
+ sm = VTAILQ_FIRST(&sp->freelist);
+ CHECK_OBJ_NOTNULL(sm, SESSMEM_MAGIC);
+ VTAILQ_REMOVE(&sp->freelist, sm, list);
+ FREE_OBJ(sm);
+ wrk->stats.sessmem_free++;
+ sp->nsess--;
+ }
+ AZ(sp->nsess);
+ Lck_Unlock(&sp->mtx);
+ Lck_Delete(&sp->mtx);
+ FREE_OBJ(sp);
+}
diff --git a/bin/varnishd/mgt_param.c b/bin/varnishd/mgt_param.c
index b9067e7..ec38b11 100644
--- a/bin/varnishd/mgt_param.c
+++ b/bin/varnishd/mgt_param.c
@@ -777,7 +777,7 @@ static const struct parspec input_parspec[] = {
"off", "bool" },
{ "session_max", tweak_uint,
&master.max_sess, 1000, UINT_MAX,
- "Maximum number of sessions we will allocate "
+ "Maximum number of sessions we will allocate from one pool "
"before just dropping connections.\n"
"This is mostly an anti-DoS measure, and setting it plenty "
"high should not hurt, as long as you have the memory for "
More information about the varnish-commit
mailing list