40
40
get_memory_use /1 ,
41
41
get_process_memory /0 ,
42
42
get_process_memory /1 ,
43
- get_memory_calculation_strategy /0 ]).
43
+ get_memory_calculation_strategy /0 ,
44
+ get_rss_memory /0 ]).
44
45
45
46
% % for tests
46
47
-export ([parse_line_linux /1 , parse_mem_limit /1 ]).
79
80
-spec get_memory_use (bytes ) -> {non_neg_integer (), float () | infinity };
80
81
(ratio ) -> float () | infinity .
81
82
-spec get_cached_process_memory_and_limit () -> {non_neg_integer (), non_neg_integer ()}.
83
+ -spec get_rss_memory () -> non_neg_integer ().
82
84
83
85
-export_type ([memory_calculation_strategy / 0 ]).
84
86
% %----------------------------------------------------------------------------
@@ -191,7 +193,7 @@ init([MemFraction, AlarmFuns]) ->
191
193
timer = TRef ,
192
194
alarmed = false ,
193
195
alarm_funs = AlarmFuns },
194
- State1 = init_state_by_os (State0 ),
196
+ State1 = update_process_memory ( init_state_by_os (State0 ) ),
195
197
{ok , set_mem_limits (State1 , MemFraction )}.
196
198
197
199
handle_call (get_vm_memory_high_watermark , _From ,
@@ -244,6 +246,10 @@ code_change(_OldVsn, State, _Extra) ->
244
246
% %----------------------------------------------------------------------------
245
247
% % Server Internals
246
248
% %----------------------------------------------------------------------------
249
+ get_rss_memory () ->
250
+ TmpState = init_state_by_os (# state {}),
251
+ {ok , ProcMem } = get_process_memory_using_strategy (rss , TmpState ),
252
+ ProcMem .
247
253
248
254
get_cached_process_memory_and_limit () ->
249
255
try
@@ -255,7 +261,7 @@ get_cached_process_memory_and_limit() ->
255
261
end .
256
262
257
263
get_process_memory_uncached () ->
258
- TmpState = init_state_by_os (# state {}),
264
+ TmpState = update_process_memory ( init_state_by_os (# state {}) ),
259
265
TmpState # state .process_memory .
260
266
261
267
update_process_memory (State ) ->
@@ -270,10 +276,9 @@ init_state_by_os(State = #state{os_type = undefined}) ->
270
276
init_state_by_os (State0 = # state {os_type = {unix , linux }, os_pid = OsPid }) ->
271
277
PageSize = get_linux_pagesize (),
272
278
ProcFile = io_lib :format (" /proc/~s /statm" , [OsPid ]),
273
- State1 = State0 # state {page_size = PageSize , proc_file = ProcFile },
274
- update_process_memory (State1 );
279
+ State0 # state {page_size = PageSize , proc_file = ProcFile };
275
280
init_state_by_os (State ) ->
276
- update_process_memory ( State ) .
281
+ State .
277
282
278
283
get_process_memory_using_strategy (rss , # state {os_type = {unix , linux },
279
284
page_size = PageSize ,
0 commit comments