summaryrefslogtreecommitdiffstats
path: root/runtime/batch.h
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2013-01-15 15:01:16 +0100
committerRainer Gerhards <rgerhards@adiscon.com>2013-01-15 15:01:16 +0100
commit9273b4bb4dcb6683cf6825fedd3cb5cd0f59805a (patch)
tree57b9d3b9092723e4605206c02f39356ae5dfd698 /runtime/batch.h
parentbd0d7bc621ac78a43a964139242bf3f1983f05b9 (diff)
downloadrsyslog-9273b4bb4dcb6683cf6825fedd3cb5cd0f59805a.tar.gz
rsyslog-9273b4bb4dcb6683cf6825fedd3cb5cd0f59805a.tar.bz2
rsyslog-9273b4bb4dcb6683cf6825fedd3cb5cd0f59805a.zip
optimize memory layout for much better cache hits
Moave element status out of batch_obj_t because we get a *much* better cache hit ratio this way. Note that this is really a HUGE saving, even if it doesn't look so (both profiler data as well as practical tests indicate that!).
Diffstat (limited to 'runtime/batch.h')
-rw-r--r--runtime/batch.h15
1 files changed, 11 insertions, 4 deletions
diff --git a/runtime/batch.h b/runtime/batch.h
index 097e104a..03122bd0 100644
--- a/runtime/batch.h
+++ b/runtime/batch.h
@@ -46,7 +46,6 @@ typedef unsigned char batch_state_t;
*/
struct batch_obj_s {
msg_t *pMsg;
- batch_state_t state; /* associated state */
/* work variables for action processing; these are reused for each action (or block of
* actions)
*/
@@ -84,6 +83,13 @@ struct batch_s {
sbool *active; /* which messages are active for processing, NULL=all */
sbool bSingleRuleset; /* do all msgs of this batch use a single ruleset? */
batch_obj_t *pElem; /* batch elements */
+ batch_state_t *eltState;/* state (array!) for individual objects.
+ NOTE: we have moved this out of batch_obj_t because we
+ get a *much* better cache hit ratio this way. So do not
+ move it back into this structure! Note that this is really
+ a HUGE saving, even if it doesn't look so (both profiler
+ data as well as practical tests indicate that!).
+ */
};
@@ -118,8 +124,8 @@ batchNumMsgs(batch_t *pBatch) {
*/
static inline void
batchSetElemState(batch_t *pBatch, int i, batch_state_t newState) {
- if(pBatch->pElem[i].state != BATCH_STATE_DISC)
- pBatch->pElem[i].state = newState;
+ if(pBatch->eltState[i] != BATCH_STATE_DISC)
+ pBatch->eltState[i] = newState;
}
@@ -128,7 +134,7 @@ batchSetElemState(batch_t *pBatch, int i, batch_state_t newState) {
*/
static inline int
batchIsValidElem(batch_t *pBatch, int i) {
- return( (pBatch->pElem[i].state != BATCH_STATE_DISC)
+ return( (pBatch->eltState[i] != BATCH_STATE_DISC)
&& (pBatch->active == NULL || pBatch->active[i]));
}
@@ -163,6 +169,7 @@ batchInit(batch_t *pBatch, int maxElem) {
pBatch->iDoneUpTo = 0;
pBatch->maxElem = maxElem;
CHKmalloc(pBatch->pElem = calloc((size_t)maxElem, sizeof(batch_obj_t)));
+ CHKmalloc(pBatch->eltState = calloc((size_t)maxElem, sizeof(batch_state_t)));
// TODO: replace calloc by inidividual writes?
finalize_it:
RETiRet;