[master] 903f1a0 Reduce the scope of the SHA256 contexts memory demand, we only need it during vcl_hash{}

Poul-Henning Kamp phk at varnish-cache.org
Mon Dec 26 11:33:36 CET 2011


commit 903f1a06e7e4ebf40c99a158fa0e62b9bf01ee6c
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Dec 26 10:32:58 2011 +0000

    Reduce the scope of the SHA256 contexts memory demand, we only
    need it during vcl_hash{}

diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c
index 81a0c67..4967c82 100644
--- a/bin/varnishd/cache/cache_center.c
+++ b/bin/varnishd/cache/cache_center.c
@@ -1459,6 +1459,7 @@ static int
 cnt_recv(struct sess *sp, struct worker *wrk, struct req *req)
 {
 	unsigned recv_handling;
+	struct SHA256Context sha256ctx;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
@@ -1502,10 +1503,12 @@ cnt_recv(struct sess *sp, struct worker *wrk, struct req *req)
 		}
 	}
 
+	req->sha256ctx = &sha256ctx;
 	SHA256_Init(req->sha256ctx);
 	VCL_hash_method(sp);
 	assert(req->handling == VCL_RET_HASH);
 	SHA256_Final(req->digest, req->sha256ctx);
+	req->sha256ctx = NULL;
 
 	if (!strcmp(req->http->hd[HTTP_HDR_REQ].b, "HEAD"))
 		req->wantbody = 0;
diff --git a/bin/varnishd/cache/cache_hash.c b/bin/varnishd/cache/cache_hash.c
index 643eb94..d967291 100644
--- a/bin/varnishd/cache/cache_hash.c
+++ b/bin/varnishd/cache/cache_hash.c
@@ -158,6 +158,7 @@ HSH_AddString(const struct sess *sp, const char *str)
 		str = "";
 	l = strlen(str);
 
+	AN(sp->req->sha256ctx);
 	SHA256_Update(sp->req->sha256ctx, str, l);
 	SHA256_Update(sp->req->sha256ctx, "#", 1);
 
diff --git a/bin/varnishd/cache/cache_session.c b/bin/varnishd/cache/cache_session.c
index d26bd8f..ee5060f 100644
--- a/bin/varnishd/cache/cache_session.c
+++ b/bin/varnishd/cache/cache_session.c
@@ -42,7 +42,6 @@
 #include "cache.h"
 
 #include "waiter/waiter.h"
-#include "vsha256.h"
 #include "vtim.h"
 
 static unsigned ses_size = sizeof (struct sess);
@@ -271,10 +270,7 @@ SES_GetReq(struct sess *sp)
 	nhttp = (uint16_t)cache_param->http_max_hdr;
 	hl = HTTP_estimate(nhttp);
 
-	xxxassert(sz > 3 * hl + sizeof(struct SHA256Context) + 128);
-
-	sp->req->sha256ctx = (void*)p;
-	p += sizeof(struct SHA256Context);
+	xxxassert(sz > 3 * hl + 128);
 
 	sp->req->http = HTTP_create(p, nhttp);
 	p += hl;		// XXX: align ?



More information about the varnish-commit mailing list