@@ -53,6 +53,8 @@ void ngx_http_lua_limit_data_segment(void);
5353static ngx_int_t ngx_http_lua_pre_config (ngx_conf_t * cf );
5454# endif
5555#endif
56+ static char * ngx_http_lua_malloc_trim (ngx_conf_t * cf , ngx_command_t * cmd ,
57+ void * conf );
5658
5759
5860static ngx_conf_post_t ngx_http_lua_lowat_post =
@@ -578,6 +580,13 @@ static ngx_command_t ngx_http_lua_cmds[] = {
578580
579581#endif /* NGX_HTTP_SSL */
580582
583+ { ngx_string ("lua_malloc_trim" ),
584+ NGX_HTTP_MAIN_CONF |NGX_CONF_TAKE1 ,
585+ ngx_http_lua_malloc_trim ,
586+ NGX_HTTP_MAIN_CONF_OFFSET ,
587+ 0 ,
588+ NULL },
589+
581590 ngx_null_command
582591};
583592
@@ -832,6 +841,10 @@ ngx_http_lua_create_main_conf(ngx_conf_t *cf)
832841 lmcf -> postponed_to_rewrite_phase_end = NGX_CONF_UNSET ;
833842 lmcf -> postponed_to_access_phase_end = NGX_CONF_UNSET ;
834843
844+ #if (NGX_HTTP_LUA_HAVE_MALLOC_TRIM )
845+ lmcf -> malloc_trim_cycle = NGX_CONF_UNSET_UINT ;
846+ #endif
847+
835848#ifndef NGX_LUA_NO_FFI_API
836849 rc = ngx_http_lua_sema_mm_init (cf , lmcf );
837850 if (rc != NGX_OK ) {
@@ -868,6 +881,12 @@ ngx_http_lua_init_main_conf(ngx_conf_t *cf, void *conf)
868881 lmcf -> max_running_timers = 256 ;
869882 }
870883
884+ #if (NGX_HTTP_LUA_HAVE_MALLOC_TRIM )
885+ if (lmcf -> malloc_trim_cycle == NGX_CONF_UNSET_UINT ) {
886+ lmcf -> malloc_trim_cycle = 1000 ; /* number of reqs */
887+ }
888+ #endif
889+
871890 lmcf -> cycle = cf -> cycle ;
872891
873892 return NGX_CONF_OK ;
@@ -1283,4 +1302,39 @@ ngx_http_lua_limit_data_segment(void)
12831302}
12841303#endif
12851304
1305+
1306+ static char *
1307+ ngx_http_lua_malloc_trim (ngx_conf_t * cf , ngx_command_t * cmd , void * conf )
1308+ {
1309+ #if (NGX_HTTP_LUA_HAVE_MALLOC_TRIM )
1310+
1311+ ngx_int_t nreqs ;
1312+ ngx_str_t * value ;
1313+
1314+ ngx_http_lua_main_conf_t * lmcf = conf ;
1315+
1316+ value = cf -> args -> elts ;
1317+
1318+ nreqs = ngx_atoi (value [1 ].data , value [1 ].len );
1319+ if (nreqs == NGX_ERROR ) {
1320+ return "invalid number in the 1st argument" ;
1321+ }
1322+
1323+ lmcf -> malloc_trim_cycle = (ngx_uint_t ) nreqs ;
1324+
1325+ if (nreqs == 0 ) {
1326+ return NGX_CONF_OK ;
1327+ }
1328+
1329+ lmcf -> requires_log = 1 ;
1330+
1331+ #else
1332+
1333+ ngx_conf_log_error (NGX_LOG_WARN , cf , 0 , "lua_malloc_trim is not supported "
1334+ "on this platform, ignored" );
1335+
1336+ #endif
1337+ return NGX_CONF_OK ;
1338+ }
1339+
12861340/* vi:set ft=c ts=4 sw=4 et fdm=marker: */
0 commit comments