httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Fritsch ...@sfritsch.de>
Subject Some memory usage optimizations
Date Sat, 26 Jun 2010 18:49:58 GMT
Hi,

there are some places where httpd uses more memory than necessary, 
which can increase cache misses and reduce performance on current 
hardware. Things I would like to change:

1) reorder structs to have fewer holes on 64bit arches

httpd.h has this nice comment since the days of 1.3:

/* Things placed at the end of the record to avoid breaking binary
 * compatibility.  It would be nice to remember to reorder the entire
 * record to improve 64bit alignment the next time we need to break
 * binary compatibility for some other reason.
 */

Pro: Examples for space savings on 64bit:

request_rec:   704 -> 672 bytes
server_rec:    208 -> 192 bytes
proxy_worker:  264 -> 208 bytes

Con: In some cases reordering the struct members makes the code harder 
to read because related members may no longer be grouped together.

Is it worth changing? Would somebody be -1?

(BTW, pahole is useful for finding such structs).


2) Use char instead of int for the module_levels vector in struct 
ap_logconfig. The length of the vector is ~100.

Pro: This may save ~300 bytes per server conf which are read often and 
therefore occupy CPU-cache memory

Con: On some architectures, accessing chars is slower than accessing 
ints.

Does anyone have an idea what is better, here? Int or char?

The same argument could be made for boolean flags in various other 
structs. But I don't think those are worth the effort.


3) In server/config.c, many config vectors are created (allocated and 
zeroed) with length (total_modules + DYNAMIC_MODULE_LIMIT). But this 
is only necessary before dynamic modules are loaded. Afterwards, 
total_modules is set to the total number of modules. Therefore 
allocating a vec of length total_modules should be enough. This would 
save zeroing 128 pointers per request and connection.

It seems the attached patch works and I could not find any problems 
when adding/removing modules during graceful restart. Objections?

Cheers,
Stefan

Mime
View raw message