Skip to content

Commit

Permalink
* modules/proxy/mod_proxy_fcgi.c (dispatch): Only allocate a heap
Browse files Browse the repository at this point in the history
  buffer if the configured size is greater than the stack-allocated
  buffer.


git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1917576 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
notroj committed May 8, 2024
1 parent c8a9d21 commit aa86530
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion modules/proxy/mod_proxy_fcgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,11 @@ static apr_status_t dispatch(proxy_conn_rec *conn, proxy_dir_conf *conf,
*err = NULL;
if (conn->worker->s->io_buffer_size_set) {
iobuf_size = conn->worker->s->io_buffer_size;
iobuf = apr_palloc(r->pool, iobuf_size);
/* Allocate a buffer if the configured size is larger than the
* stack buffer, otherwise use the stack buffer. */
if (iobuf_size > AP_IOBUFSIZE) {
iobuf = apr_palloc(r->pool, iobuf_size);
}
}

pfd.desc_type = APR_POLL_SOCKET;
Expand Down

5 comments on commit aa86530

@dufuhang
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this modification?

@ylavic
Copy link
Member

@ylavic ylavic commented on aa86530 May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because "Allocate a buffer if the configured size is larger than the stack buffer, otherwise use the stack buffer" to save an allocation?

@dufuhang
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I mean is, before the modification, memory allocation was based on the size of iobuf_size. After the modification, if iobuf_size is not greater than AP_IOBUFSIZE, the default size will be used. This way, there won't be any memory waste, right?

@ylavic
Copy link
Member

@ylavic ylavic commented on aa86530 May 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not the default size that is being used when iobuf_size <= AP_IOBUFSIZE but the default buffer on the stack (char stack_iobuf[AP_IOBUFSIZE];) which already has enough room. iobuf_size will be set to iobuffersize anyway if configured so the I/Os will use that size (or AP_IOBUFSIZE by default).
The point is that we don't need to allocate a new buffer on the heap if the one on the stack (already allocated) fits, even if it's not used to its full capacity.

@dufuhang
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand, thanks your reply

Please sign in to comment.