Skip to content

cache_req: Allocate topreq only if needed #4270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/varnishd/acceptor/cache_acceptor_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ vca_tcp_make_session(struct worker *wrk, void *arg)

vca_tcp_sockopt_set(wa->acceptlsock, sp);

req = Req_New(sp);
req = Req_New(sp, NULL);
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
req->htc->rfd = &sp->fd;

Expand Down
2 changes: 1 addition & 1 deletion bin/varnishd/acceptor/cache_acceptor_uds.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ vca_uds_make_session(struct worker *wrk, void *arg)

vca_uds_sockopt_set(wa->acceptlsock, sp);

req = Req_New(sp);
req = Req_New(sp, NULL);
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
req->htc->rfd = &sp->fd;

Expand Down
7 changes: 2 additions & 5 deletions bin/varnishd/cache/cache_esi_deliver.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ ved_include(struct req *preq, const char *src, const char *host,
return;
}

req = Req_New(sp);
req = Req_New(sp, preq);
AN(req);
THR_SetRequest(req);
assert(IS_NO_VXID(req->vsl->wid));
Expand All @@ -148,9 +148,6 @@ ved_include(struct req *preq, const char *src, const char *host,

VSLb_ts_req(req, "Start", W_TIM_real(wrk));

memset(req->top, 0, sizeof *req->top);
req->top = preq->top;

HTTP_Setup(req->http, req->ws, req->vsl, SLT_ReqMethod);
HTTP_Dup(req->http, preq->http0);

Expand Down Expand Up @@ -182,7 +179,7 @@ ved_include(struct req *preq, const char *src, const char *host,
req->req_body_status = BS_NONE;

AZ(req->vcl);
AN(req->top);
assert(req->top == preq->top);
if (req->top->vcl0)
req->vcl = req->top->vcl0;
else
Expand Down
15 changes: 10 additions & 5 deletions bin/varnishd/cache/cache_req.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Req_LogStart(const struct worker *wrk, struct req *req)
*/

struct req *
Req_New(struct sess *sp)
Req_New(struct sess *sp, struct req *preq)
{
struct pool *pp;
struct req *req;
Expand All @@ -134,6 +134,7 @@ Req_New(struct sess *sp)
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
pp = sp->pool;
CHECK_OBJ_NOTNULL(pp, POOL_MAGIC);
CHECK_OBJ_ORNULL(preq, REQ_MAGIC);

req = MPL_Get(pp->mpl_req, &sz);
AN(req);
Expand Down Expand Up @@ -181,10 +182,14 @@ Req_New(struct sess *sp)
req->htc->doclose = SC_NULL;
p = (void*)PRNDUP(p + sizeof(*req->htc));

req->top = (void*)p;
INIT_OBJ(req->top, REQTOP_MAGIC);
req->top->topreq = req;
p = (void*)PRNDUP(p + sizeof(*req->top));
if (UNLIKELY(preq != NULL))
req->top = preq->top;
else {
req->top = (void*)p;
INIT_OBJ(req->top, REQTOP_MAGIC);
req->top->topreq = req;
p = (void*)PRNDUP(p + sizeof(*req->top));
}

assert(p < e);

Expand Down
2 changes: 1 addition & 1 deletion bin/varnishd/cache/cache_varnishd.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ void pan_pool(struct vsb *);
int VRG_CheckBo(struct busyobj *);

/* cache_req.c */
struct req *Req_New(struct sess *);
struct req *Req_New(struct sess *, struct req *);
void Req_Release(struct req *);
void Req_Rollback(VRT_CTX);
void Req_Cleanup(struct sess *sp, struct worker *wrk, struct req *req);
Expand Down
2 changes: 1 addition & 1 deletion bin/varnishd/http1/cache_http1_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ http1_unwait(struct worker *wrk, void *arg)
CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
CAST_OBJ_NOTNULL(sp, arg, SESS_MAGIC);
WS_Release(sp->ws, 0);
req = Req_New(sp);
req = Req_New(sp, NULL);
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
req->htc->rfd = &sp->fd;
HTC_RxInit(req->htc, req->ws);
Expand Down
2 changes: 1 addition & 1 deletion bin/varnishd/http2/cache_http2_proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ h2_new_req(struct h2_sess *h2, unsigned stream, struct req *req)

ASSERT_RXTHR(h2);
if (req == NULL)
req = Req_New(h2->sess);
req = Req_New(h2->sess, NULL);
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);

r2 = WS_Alloc(req->ws, sizeof *r2);
Expand Down
2 changes: 1 addition & 1 deletion bin/varnishd/http2/cache_http2_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ h2_init_sess(struct sess *sp,
assert(*up == 0);

if (srq == NULL)
srq = Req_New(sp);
srq = Req_New(sp, NULL);
AN(srq);
h2 = h2s;
AN(h2);
Expand Down