You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Christophe Jaillet <ch...@wanadoo.fr> on 2005/12/04 00:39:06 UTC

Question about memory in httpd

When going thrue the code, looking at apr_palloc and friends, one can see
that :
    * in some places (few of them) , the returned pointer is checked against
NULL
    * in other places (most of them), it is not.

I've always been told that checking return value is a good idea, (especially
with memory allocation in order to avoid disasters) so should all the
apr_palloc (and friends) calls be checked or are they special reasons in
httpd not to care about short in memory situation ?

CJ.




Re: Question about memory in httpd

Posted by Christophe Jaillet <ch...@wanadoo.fr>.
First of all, thank you for this interresting point of view.

Ok with your comments, but :
    1) apache is not supposed to run *only* on linux and freebsd


    2) if checking memory allocation is really not a concern, should places
in httpd that checks for NULL be removed ?
For exemple, in /modules/proxy/ajp_msg.c
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
    msg->buf = (apr_byte_t *)apr_palloc(pool, AJP_MSG_BUFFER_SZ);

    /* XXX: This should never happen
     * In case if the OS cannont allocate 8K of data
     * we are in serious trouble
     * No need to check the alloc return value, cause the
     * core dump is probably the best solution anyhow.
     */
    if (msg->buf == NULL) {
        ap_log_error(APLOG_MARK, APLOG_ERR, 0, NULL,
                      "ajp_msg_create(): can't allocate AJP message
memory");
        return APR_ENOPOOL;
    }

+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=


    3) in some places, memory allocation can be delayed a bit, do you think
it could be interesting to dig futher in this direction and see if it could
be a win ?
For exemple, in /modules/generators/mod_status.c in function status_handler,
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
    pid_buffer = apr_palloc(r->pool, server_limit * sizeof(pid_t));
    stat_buffer = apr_palloc(r->pool, server_limit * thread_limit *
sizeof(char));

+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
could be set moved around line 312 (instead of 257).
In this case,
        - httpd would maybe not require at all this memory (if one of the
tests at the beginning fails)
        - httpd would request for the memory (a bit) latter


CJ



"Paul Querna" <ch...@force-elite.com> a �crit dans le message de
news:43922FE5.7020707@force-elite.com...
> Christophe Jaillet wrote:
> > When going thrue the code, looking at apr_palloc and friends, one can
see
> > that :
> >     * in some places (few of them) , the returned pointer is checked
against
> > NULL
> >     * in other places (most of them), it is not.
> >
> > I've always been told that checking return value is a good idea,
(especially
> > with memory allocation in order to avoid disasters) so should all the
> > apr_palloc (and friends) calls be checked or are they special reasons in
> > httpd not to care about short in memory situation ?
>
> Actually, on most operating systems, including Linux and FreeBSD, you
> will NEVER get returned NULL.
>
> Instead when your operating system is truly out of memory, it will kill
> your process, and you won't have any chance of handling it.
>
> Read a whole blog post about it:
> http://baus.net/memory-management
>
> -Paul
>




Re: Question about memory in httpd

Posted by Igor Sysoev <is...@rambler-co.ru>.
On Sat, 3 Dec 2005, Paul Querna wrote:

> Christophe Jaillet wrote:
>> When going thrue the code, looking at apr_palloc and friends, one can see
>> that :
>>     * in some places (few of them) , the returned pointer is checked against
>> NULL
>>     * in other places (most of them), it is not.
>>
>> I've always been told that checking return value is a good idea, (especially
>> with memory allocation in order to avoid disasters) so should all the
>> apr_palloc (and friends) calls be checked or are they special reasons in
>> httpd not to care about short in memory situation ?
>
> Actually, on most operating systems, including Linux and FreeBSD, you
> will NEVER get returned NULL.

Actully, Linux and FreeBSD will return NULL and set errno to ENOMEM,
if you try to allocate in sum more than RLIMIT_DATA limit.

> Instead when your operating system is truly out of memory, it will kill
> your process, and you won't have any chance of handling it.
>
> Read a whole blog post about it:
> http://baus.net/memory-management


Igor Sysoev
http://sysoev.ru/en/

Re: Question about memory in httpd

Posted by Paul Querna <ch...@force-elite.com>.
Christophe Jaillet wrote:
> When going thrue the code, looking at apr_palloc and friends, one can see
> that :
>     * in some places (few of them) , the returned pointer is checked against
> NULL
>     * in other places (most of them), it is not.
> 
> I've always been told that checking return value is a good idea, (especially
> with memory allocation in order to avoid disasters) so should all the
> apr_palloc (and friends) calls be checked or are they special reasons in
> httpd not to care about short in memory situation ?

Actually, on most operating systems, including Linux and FreeBSD, you
will NEVER get returned NULL.

Instead when your operating system is truly out of memory, it will kill
your process, and you won't have any chance of handling it.

Read a whole blog post about it:
http://baus.net/memory-management

-Paul