Skip to content

Commit

Permalink
PJ adjustable pool sizes (pjsip#2395)
Browse files Browse the repository at this point in the history
Make several pool sizes settable via compile time macro settings. This can be used to deal with memory fragmentation issues in long running applications that encounter temporary high loads.
  • Loading branch information
andreas-wehrmann authored Jul 15, 2020
1 parent 40dd48d commit 973bb67
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 10 deletions.
13 changes: 13 additions & 0 deletions pjmedia/include/pjmedia-codec/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,19 @@
# define PJMEDIA_HAS_G722_CODEC 1
#endif

/**
* Initial memory block for G.722 codec implementation.
*/
#ifndef PJMEDIA_POOL_LEN_G722_CODEC
# define PJMEDIA_POOL_LEN_G722_CODEC 1000
#endif

/**
* Memory increment for G.722 codec implementation.
*/
#ifndef PJMEDIA_POOL_INC_G722_CODEC
# define PJMEDIA_POOL_INC_G722_CODEC 1000
#endif

/**
* Default G.722 codec encoder and decoder level adjustment. The G.722
Expand Down
28 changes: 28 additions & 0 deletions pjmedia/include/pjmedia/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,34 @@
# include <pjmedia/config_auto.h>
#endif

/**
* Initial memory block for media endpoint.
*/
#ifndef PJMEDIA_POOL_LEN_ENDPT
# define PJMEDIA_POOL_LEN_ENDPT 512
#endif

/**
* Memory increment for media endpoint.
*/
#ifndef PJMEDIA_POOL_INC_ENDPT
# define PJMEDIA_POOL_INC_ENDPT 512
#endif

/**
* Initial memory block for event manager.
*/
#ifndef PJMEDIA_POOL_LEN_EVTMGR
# define PJMEDIA_POOL_LEN_EVTMGR 500
#endif

/**
* Memory increment for evnt manager.
*/
#ifndef PJMEDIA_POOL_INC_EVTMGR
# define PJMEDIA_POOL_INC_EVTMGR 500
#endif

/**
* Specify whether we prefer to use audio switch board rather than
* conference bridge.
Expand Down
6 changes: 3 additions & 3 deletions pjmedia/src/pjmedia-codec/g722.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
# define TRACE_(expr)
#endif


/* Prototypes for G722 factory */
static pj_status_t g722_test_alloc(pjmedia_codec_factory *factory,
const pjmedia_codec_info *id );
Expand Down Expand Up @@ -174,8 +173,9 @@ PJ_DEF(pj_status_t) pjmedia_codec_g722_init( pjmedia_endpt *endpt )
g722_codec_factory.endpt = endpt;
g722_codec_factory.pcm_shift = PJMEDIA_G722_DEFAULT_PCM_SHIFT;

g722_codec_factory.pool = pjmedia_endpt_create_pool(endpt, "g722", 1000,
1000);
g722_codec_factory.pool = pjmedia_endpt_create_pool(endpt, "g722",
PJMEDIA_POOL_LEN_G722_CODEC,
PJMEDIA_POOL_INC_G722_CODEC);
if (!g722_codec_factory.pool)
return PJ_ENOMEM;

Expand Down
3 changes: 2 additions & 1 deletion pjmedia/src/pjmedia/endpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ PJ_DEF(pj_status_t) pjmedia_endpt_create2(pj_pool_factory *pf,
PJ_ASSERT_RETURN(pf && p_endpt, PJ_EINVAL);
PJ_ASSERT_RETURN(worker_cnt <= MAX_THREADS, PJ_EINVAL);

pool = pj_pool_create(pf, "med-ept", 512, 512, NULL);
pool = pj_pool_create(pf, "med-ept", PJMEDIA_POOL_LEN_ENDPT,
PJMEDIA_POOL_INC_ENDPT, NULL);
if (!pool)
return PJ_ENOMEM;

Expand Down
4 changes: 3 additions & 1 deletion pjmedia/src/pjmedia/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ PJ_DEF(pj_status_t) pjmedia_event_mgr_create(pj_pool_t *pool,
pj_status_t status;

mgr = PJ_POOL_ZALLOC_T(pool, pjmedia_event_mgr);
mgr->pool = pj_pool_create(pool->factory, "evt mgr", 500, 500, NULL);
mgr->pool = pj_pool_create(pool->factory, "evt mgr",
PJMEDIA_POOL_LEN_EVTMGR,
PJMEDIA_POOL_INC_EVTMGR, NULL);
pj_list_init(&mgr->esub_list);
pj_list_init(&mgr->free_esub_list);

Expand Down
30 changes: 28 additions & 2 deletions pjsip/include/pjsip/sip_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -937,8 +937,19 @@ PJ_INLINE(pjsip_cfg_t*) pjsip_cfg(void)
# define PJSIP_POOL_RDATA_INC 4000
#endif

#define PJSIP_POOL_LEN_TRANSPORT 512
#define PJSIP_POOL_INC_TRANSPORT 512
/**
* Initial memory block for SIP transport.
*/
#ifndef PJSIP_POOL_LEN_TRANSPORT
# define PJSIP_POOL_LEN_TRANSPORT 512
#endif

/**
* Memory increment for SIP transport.
*/
#ifndef PJSIP_POOL_INC_TRANSPORT
# define PJSIP_POOL_INC_TRANSPORT 512
#endif

/**
* Initial memory block size for tdata.
Expand Down Expand Up @@ -968,6 +979,21 @@ PJ_INLINE(pjsip_cfg_t*) pjsip_cfg(void)
# define PJSIP_POOL_INC_UA 512
#endif

/**
* Initial memory block for event subscription module.
*/
#ifndef PJSIP_POOL_EVSUB_LEN
# define PJSIP_POOL_EVSUB_LEN 512
#endif

/**
* Memory increment for event subscription module.
*/
#ifndef PJSIP_POOL_EVSUB_INC
# define PJSIP_POOL_EVSUB_INC 512
#endif


#define PJSIP_MAX_FORWARDS_VALUE 70

#define PJSIP_RFC3261_BRANCH_ID "z9hG4bK"
Expand Down
27 changes: 27 additions & 0 deletions pjsip/include/pjsua-lib/pjsua.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,33 @@ typedef struct pjsua_msg_data pjsua_msg_data;
/** Forward declaration for pj_stun_resolve_result */
typedef struct pj_stun_resolve_result pj_stun_resolve_result;

/**
* Initial memory block for PJSUA.
*/
#ifndef PJSUA_POOL_LEN
# define PJSUA_POOL_LEN 1000
#endif

/**
* Memory increment for PJSUA.
*/
#ifndef PJSUA_POOL_INC
# define PJSUA_POOL_INC 1000
#endif

/**
* Initial memory block for PJSUA account.
*/
#ifndef PJSUA_POOL_LEN_ACC
# define PJSUA_POOL_LEN_ACC 512
#endif

/**
* Memory increment for PJSUA account.
*/
#ifndef PJSUA_POOL_INC_ACC
# define PJSUA_POOL_INC_ACC 256
#endif

/**
* Maximum proxies in account.
Expand Down
4 changes: 3 additions & 1 deletion pjsip/src/pjsip-simple/evsub.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ PJ_DEF(pj_status_t) pjsip_evsub_init_module(pjsip_endpoint *endpt)
pj_list_init(&mod_evsub.pkg_list);

/* Create pool: */
mod_evsub.pool = pjsip_endpt_create_pool(endpt, "evsub", 512, 512);
mod_evsub.pool = pjsip_endpt_create_pool(endpt, "evsub",
PJSIP_POOL_EVSUB_LEN,
PJSIP_POOL_EVSUB_INC);
if (!mod_evsub.pool)
return PJ_ENOMEM;

Expand Down
3 changes: 2 additions & 1 deletion pjsip/src/pjsua-lib/pjsua_acc.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,8 @@ PJ_DEF(pj_status_t) pjsua_acc_add( const pjsua_acc_config *cfg,
if (acc->pool)
pj_pool_reset(acc->pool);
else
acc->pool = pjsua_pool_create("acc%p", 512, 256);
acc->pool = pjsua_pool_create("acc%p", PJSUA_POOL_LEN_ACC,
PJSUA_POOL_INC_ACC);

/* Copy config */
pjsua_acc_config_dup(acc->pool, &pjsua_var.acc[id].cfg, cfg);
Expand Down
2 changes: 1 addition & 1 deletion pjsip/src/pjsua-lib/pjsua_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ PJ_DEF(pj_status_t) pjsua_create(void)
pj_caching_pool_init(&pjsua_var.cp, NULL, 0);

/* Create memory pools for application and internal use. */
pjsua_var.pool = pjsua_pool_create("pjsua", 1000, 1000);
pjsua_var.pool = pjsua_pool_create("pjsua", PJSUA_POOL_LEN, PJSUA_POOL_INC);
pjsua_var.timer_pool = pjsua_pool_create("pjsua_timer", 500, 500);
if (pjsua_var.pool == NULL || pjsua_var.timer_pool == NULL) {
pj_log_pop_indent();
Expand Down

0 comments on commit 973bb67

Please sign in to comment.