Commit dd0e30ee authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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.
parent 4571689f
......@@ -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);
......
......@@ -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);
}
......@@ -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 "
......
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