htp layer: add memory cap counter

This patch adds a memcap counter for HTP memory usage. Counter
is increased each time an allocation is not done due to the memcap.
pull/758/head
Eric Leblond 12 years ago committed by Victor Julien
parent d6d8a08a8f
commit 4d6b48ea9e

@ -41,6 +41,7 @@
uint64_t htp_config_memcap = 0; uint64_t htp_config_memcap = 0;
SC_ATOMIC_DECLARE(uint64_t, htp_memuse); SC_ATOMIC_DECLARE(uint64_t, htp_memuse);
SC_ATOMIC_DECLARE(uint64_t, htp_memcap);
void HTPParseMemcap() void HTPParseMemcap()
{ {
@ -75,8 +76,10 @@ void HTPDecrMemuse(uint64_t size)
void HTPMemuseCounter(ThreadVars *tv, TcpReassemblyThreadCtx *trt) void HTPMemuseCounter(ThreadVars *tv, TcpReassemblyThreadCtx *trt)
{ {
uint64_t memusecopy = SC_ATOMIC_GET(htp_memuse); uint64_t tmpval = SC_ATOMIC_GET(htp_memuse);
SCPerfCounterSetUI64(trt->counter_htp_memuse, tv->sc_perf_pca, memusecopy); SCPerfCounterSetUI64(trt->counter_htp_memuse, tv->sc_perf_pca, tmpval);
tmpval = SC_ATOMIC_GET(htp_memcap);
SCPerfCounterSetUI64(trt->counter_htp_memcap, tv->sc_perf_pca, tmpval);
return; return;
} }
/** /**
@ -89,6 +92,7 @@ int HTPCheckMemcap(uint64_t size)
{ {
if (htp_config_memcap == 0 || size + SC_ATOMIC_GET(htp_memuse) <= htp_config_memcap) if (htp_config_memcap == 0 || size + SC_ATOMIC_GET(htp_memuse) <= htp_config_memcap)
return 1; return 1;
(void) SC_ATOMIC_ADD(htp_memcap, 1);
return 0; return 0;
} }

@ -65,6 +65,8 @@ typedef struct TcpReassemblyThreadCtx_ {
/** account memory usage by suricata to handle HTTP protocol (not counting /** account memory usage by suricata to handle HTTP protocol (not counting
* libhtp memory usage)*/ * libhtp memory usage)*/
uint16_t counter_htp_memuse; uint16_t counter_htp_memuse;
/* number of allocation failed due to memcap when handling HTTP protocol */
uint16_t counter_htp_memcap;
} TcpReassemblyThreadCtx; } TcpReassemblyThreadCtx;
#define OS_POLICY_DEFAULT OS_POLICY_BSD #define OS_POLICY_DEFAULT OS_POLICY_BSD

@ -4563,6 +4563,9 @@ TmEcode StreamTcpThreadInit(ThreadVars *tv, void *initdata, void **data)
stt->ra_ctx->counter_htp_memuse = SCPerfTVRegisterCounter("http.memuse", tv, stt->ra_ctx->counter_htp_memuse = SCPerfTVRegisterCounter("http.memuse", tv,
SC_PERF_TYPE_UINT64, SC_PERF_TYPE_UINT64,
"NULL"); "NULL");
stt->ra_ctx->counter_htp_memcap = SCPerfTVRegisterCounter("http.memcap", tv,
SC_PERF_TYPE_UINT64,
"NULL");
SCLogDebug("StreamTcp thread specific ctx online at %p, reassembly ctx %p", SCLogDebug("StreamTcp thread specific ctx online at %p, reassembly ctx %p",
stt, stt->ra_ctx); stt, stt->ra_ctx);

Loading…
Cancel
Save