]> git.proxmox.com Git - ceph.git/blame - ceph/doc/rados/troubleshooting/memory-profiling.rst
update ceph source to reef 18.2.1
[ceph.git] / ceph / doc / rados / troubleshooting / memory-profiling.rst
CommitLineData
7c673cae
FG
1==================
2 Memory Profiling
3==================
4
aee94f69
TL
5Ceph Monitor, OSD, and MDS can report ``TCMalloc`` heap profiles. Install
6``google-perftools`` if you want to generate these. Your OS distribution might
7package this under a different name (for example, ``gperftools``), and your OS
8distribution might use a different package manager. Run a command similar to
9this one to install ``google-perftools``:
7c673cae 10
aee94f69 11.. prompt:: bash
7c673cae 12
aee94f69
TL
13 sudo apt-get install google-perftools
14
15The profiler dumps output to your ``log file`` directory (``/var/log/ceph``).
16See `Logging and Debugging`_ for details.
17
18To view the profiler logs with Google's performance tools, run the following
19command:
20
21.. prompt:: bash
7c673cae
FG
22
23 google-pprof --text {path-to-daemon} {log-path/filename}
24
25For example::
26
27 $ ceph tell osd.0 heap start_profiler
28 $ ceph tell osd.0 heap dump
29 osd.0 tcmalloc heap stats:------------------------------------------------
30 MALLOC: 2632288 ( 2.5 MiB) Bytes in use by application
31 MALLOC: + 499712 ( 0.5 MiB) Bytes in page heap freelist
32 MALLOC: + 543800 ( 0.5 MiB) Bytes in central cache freelist
33 MALLOC: + 327680 ( 0.3 MiB) Bytes in transfer cache freelist
34 MALLOC: + 1239400 ( 1.2 MiB) Bytes in thread cache freelists
35 MALLOC: + 1142936 ( 1.1 MiB) Bytes in malloc metadata
36 MALLOC: ------------
37 MALLOC: = 6385816 ( 6.1 MiB) Actual memory used (physical + swap)
38 MALLOC: + 0 ( 0.0 MiB) Bytes released to OS (aka unmapped)
39 MALLOC: ------------
40 MALLOC: = 6385816 ( 6.1 MiB) Virtual address space used
41 MALLOC:
42 MALLOC: 231 Spans in use
43 MALLOC: 56 Thread heaps in use
44 MALLOC: 8192 Tcmalloc page size
45 ------------------------------------------------
46 Call ReleaseFreeMemory() to release freelist memory to the OS (via madvise()).
47 Bytes released to the OS take up virtual address space but no physical memory.
48 $ google-pprof --text \
49 /usr/bin/ceph-osd \
50 /var/log/ceph/ceph-osd.0.profile.0001.heap
51 Total: 3.7 MB
52 1.9 51.1% 51.1% 1.9 51.1% ceph::log::Log::create_entry
53 1.8 47.3% 98.4% 1.8 47.3% std::string::_Rep::_S_create
54 0.0 0.4% 98.9% 0.0 0.6% SimpleMessenger::add_accept_pipe
55 0.0 0.4% 99.2% 0.0 0.6% decode_message
56 ...
57
aee94f69
TL
58Performing another heap dump on the same daemon creates another file. It is
59convenient to compare the new file to a file created by a previous heap dump to
60show what has grown in the interval. For example::
7c673cae
FG
61
62 $ google-pprof --text --base out/osd.0.profile.0001.heap \
63 ceph-osd out/osd.0.profile.0003.heap
64 Total: 0.2 MB
65 0.1 50.3% 50.3% 0.1 50.3% ceph::log::Log::create_entry
66 0.1 46.6% 96.8% 0.1 46.6% std::string::_Rep::_S_create
67 0.0 0.9% 97.7% 0.0 26.1% ReplicatedPG::do_op
68 0.0 0.8% 98.5% 0.0 0.8% __gnu_cxx::new_allocator::allocate
69
aee94f69
TL
70See `Google Heap Profiler`_ for additional details.
71
72After you have installed the heap profiler, start your cluster and begin using
73the heap profiler. You can enable or disable the heap profiler at runtime, or
74ensure that it runs continuously. When running commands based on the examples
75that follow, do the following:
7c673cae 76
aee94f69
TL
77#. replace ``{daemon-type}`` with ``mon``, ``osd`` or ``mds``
78#. replace ``{daemon-id}`` with the OSD number or the MON ID or the MDS ID
7c673cae
FG
79
80
81Starting the Profiler
82---------------------
83
aee94f69 84To start the heap profiler, run a command of the following form:
7c673cae 85
aee94f69 86.. prompt:: bash
7c673cae 87
aee94f69 88 ceph tell {daemon-type}.{daemon-id} heap start_profiler
7c673cae 89
aee94f69 90For example:
7c673cae 91
aee94f69
TL
92.. prompt:: bash
93
94 ceph tell osd.1 heap start_profiler
95
96Alternatively, if the ``CEPH_HEAP_PROFILER_INIT=true`` variable is found in the
97environment, the profile will be started when the daemon starts running.
7c673cae
FG
98
99Printing Stats
100--------------
101
aee94f69
TL
102To print out statistics, run a command of the following form:
103
104.. prompt:: bash
105
106 ceph tell {daemon-type}.{daemon-id} heap stats
7c673cae 107
aee94f69 108For example:
7c673cae 109
aee94f69 110.. prompt:: bash
7c673cae 111
aee94f69 112 ceph tell osd.0 heap stats
7c673cae 113
aee94f69
TL
114.. note:: The reporting of stats with this command does not require the
115 profiler to be running and does not dump the heap allocation information to
116 a file.
7c673cae
FG
117
118
119Dumping Heap Information
120------------------------
121
aee94f69 122To dump heap information, run a command of the following form:
7c673cae 123
aee94f69 124.. prompt:: bash
7c673cae 125
aee94f69 126 ceph tell {daemon-type}.{daemon-id} heap dump
7c673cae 127
aee94f69 128For example:
7c673cae 129
aee94f69
TL
130.. prompt:: bash
131
132 ceph tell mds.a heap dump
133
134.. note:: Dumping heap information works only when the profiler is running.
7c673cae
FG
135
136
137Releasing Memory
138----------------
139
aee94f69
TL
140To release memory that ``tcmalloc`` has allocated but which is not being used
141by the Ceph daemon itself, run a command of the following form:
142
143.. prompt:: bash
144
145 ceph tell {daemon-type}{daemon-id} heap release
7c673cae 146
aee94f69 147For example:
7c673cae 148
aee94f69 149.. prompt:: bash
7c673cae 150
aee94f69 151 ceph tell osd.2 heap release
7c673cae
FG
152
153
154Stopping the Profiler
155---------------------
156
aee94f69 157To stop the heap profiler, run a command of the following form:
7c673cae 158
aee94f69 159.. prompt:: bash
7c673cae 160
aee94f69 161 ceph tell {daemon-type}.{daemon-id} heap stop_profiler
7c673cae 162
aee94f69
TL
163For example:
164
165.. prompt:: bash
166
167 ceph tell osd.0 heap stop_profiler
7c673cae
FG
168
169.. _Logging and Debugging: ../log-and-debug
31f18b77 170.. _Google Heap Profiler: http://goog-perftools.sourceforge.net/doc/heap_profiler.html
1e59de90 171
aee94f69
TL
172Alternative Methods of Memory Profiling
173----------------------------------------
1e59de90
TL
174
175Running Massif heap profiler with Valgrind
176~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
177
aee94f69
TL
178The Massif heap profiler tool can be used with Valgrind to measure how much
179heap memory is used. This method is well-suited to troubleshooting RadosGW.
180
181See the `Massif documentation
182<https://valgrind.org/docs/manual/ms-manual.html>`_ for more information.
183
184Install Valgrind from the package manager for your distribution then start the
185Ceph daemon you want to troubleshoot:
1e59de90 186
aee94f69 187.. prompt:: bash
1e59de90 188
aee94f69 189 sudo -u ceph valgrind --max-threads=1024 --tool=massif /usr/bin/radosgw -f --cluster ceph --name NAME --setuser ceph --setgroup ceph
1e59de90 190
aee94f69
TL
191When this command has completed its run, a file with a name of the form
192``massif.out.<pid>`` will be saved in your current working directory. To run
193the command above, the user who runs it must have write permissions in the
194current directory.
1e59de90 195
aee94f69
TL
196Run the ``ms_print`` command to get a graph and statistics from the collected
197data in the ``massif.out.<pid>`` file:
1e59de90 198
aee94f69 199.. prompt:: bash
1e59de90 200
aee94f69 201 ms_print massif.out.12345
1e59de90 202
aee94f69 203The output of this command is helpful when submitting a bug report.