Skip to content

Commit 21879a9

Browse files
Merge branch 'stable'
Conflicts: src/rabbit_vm.erl
2 parents cb8de07 + c06a1f1 commit 21879a9

File tree

1 file changed

+33
-24
lines changed

1 file changed

+33
-24
lines changed

src/rabbit_vm.erl

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ memory() ->
5151
0
5252
end,
5353
MgmtDbETS = ets_memory([rabbit_mgmt_storage]),
54-
VMTotal = vm_memory_monitor:get_process_memory(),
55-
5654
[{total, ErlangTotal},
5755
{processes, Processes},
5856
{ets, ETS},
@@ -62,48 +60,59 @@ memory() ->
6260
{system, System}] =
6361
erlang:memory([total, processes, ets, atom, binary, code, system]),
6462

65-
Unaccounted = case VMTotal - ErlangTotal of
66-
GTZ when GTZ > 0 -> GTZ;
67-
_LTZ -> 0
63+
Strategy = vm_memory_monitor:get_memory_calculation_strategy(),
64+
{Allocated, VMTotal} = case Strategy of
65+
erlang -> {ErlangTotal, ErlangTotal};
66+
allocated ->
67+
Alloc = recon_alloc:memory(allocated),
68+
{Alloc, Alloc};
69+
rss ->
70+
Alloc = recon_alloc:memory(allocated),
71+
Vm = vm_memory_monitor:get_process_memory(current),
72+
{Alloc, Vm}
6873
end,
6974

75+
AllocatedUnused = max(Allocated - ErlangTotal, 0),
76+
OSReserved = max(VMTotal - Allocated, 0),
77+
7078
OtherProc = Processes
7179
- ConnsReader - ConnsWriter - ConnsChannel - ConnsOther
7280
- Qs - QsSlave - MsgIndexProc - Plugins - MgmtDbProc - MetricsProc,
7381

7482
[
7583
%% Connections
76-
{connection_readers, ConnsReader},
77-
{connection_writers, ConnsWriter},
78-
{connection_channels, ConnsChannel},
79-
{connection_other, ConnsOther},
84+
{connection_readers, ConnsReader},
85+
{connection_writers, ConnsWriter},
86+
{connection_channels, ConnsChannel},
87+
{connection_other, ConnsOther},
8088

8189
%% Queues
82-
{queue_procs, Qs},
83-
{queue_slave_procs, QsSlave},
90+
{queue_procs, Qs},
91+
{queue_slave_procs, QsSlave},
8492

8593
%% Processes
86-
{plugins, Plugins},
87-
{other_proc, lists:max([0, OtherProc])}, %% [1]
94+
{plugins, Plugins},
95+
{other_proc, lists:max([0, OtherProc])}, %% [1]
8896

8997
%% Metrics
90-
{metrics, MetricsETS + MetricsProc},
91-
{mgmt_db, MgmtDbETS + MgmtDbProc},
98+
{metrics, MetricsETS + MetricsProc},
99+
{mgmt_db, MgmtDbETS + MgmtDbProc},
92100

93101
%% ETS
94-
{mnesia, MnesiaETS},
95-
{other_ets, ETS - MnesiaETS - MetricsETS - MgmtDbETS - MsgIndexETS},
102+
{mnesia, MnesiaETS},
103+
{other_ets, ETS - MnesiaETS - MetricsETS - MgmtDbETS - MsgIndexETS},
96104

97105
%% Messages (mostly, some binaries are not messages)
98-
{binary, Bin},
99-
{msg_index, MsgIndexETS + MsgIndexProc},
106+
{binary, Bin},
107+
{msg_index, MsgIndexETS + MsgIndexProc},
100108

101109
%% System
102-
{code, Code},
103-
{atom, Atom},
104-
{other_system, System - ETS - Bin - Code - Atom + Unaccounted},
105-
106-
{total, VMTotal}
110+
{code, Code},
111+
{atom, Atom},
112+
{other_system, System - ETS - Bin - Code - Atom},
113+
{allocated_unused, AllocatedUnused},
114+
{reserved_unallocated, OSReserved},
115+
{total, VMTotal}
107116
].
108117
%% [1] - erlang:memory(processes) can be less than the sum of its
109118
%% parts. Rather than display something nonsensical, just silence any

0 commit comments

Comments
 (0)