5 Ceph Monitor, OSD, and MDS can report ``TCMalloc`` heap profiles. Install
6 ``google-perftools`` if you want to generate these. Your OS distribution might
7 package this under a different name (for example, ``gperftools``), and your OS
8 distribution might use a different package manager. Run a command similar to
9 this one to install ``google-perftools``:
13 sudo apt-get install google-perftools
15 The profiler dumps output to your ``log file`` directory (``/var/log/ceph``).
16 See `Logging and Debugging`_ for details.
18 To view the profiler logs with Google's performance tools, run the following
23 google-pprof --text {path-to-daemon} {log-path/filename}
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
37 MALLOC: = 6385816 ( 6.1 MiB) Actual memory used (physical + swap)
38 MALLOC: + 0 ( 0.0 MiB) Bytes released to OS (aka unmapped)
40 MALLOC: = 6385816 ( 6.1 MiB) Virtual address space used
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 \
50 /var/log/ceph/ceph-osd.0.profile.0001.heap
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
58 Performing another heap dump on the same daemon creates another file. It is
59 convenient to compare the new file to a file created by a previous heap dump to
60 show what has grown in the interval. For example::
62 $ google-pprof --text --base out/osd.0.profile.0001.heap \
63 ceph-osd out/osd.0.profile.0003.heap
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
70 See `Google Heap Profiler`_ for additional details.
72 After you have installed the heap profiler, start your cluster and begin using
73 the heap profiler. You can enable or disable the heap profiler at runtime, or
74 ensure that it runs continuously. When running commands based on the examples
75 that follow, do the following:
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
84 To start the heap profiler, run a command of the following form:
88 ceph tell {daemon-type}.{daemon-id} heap start_profiler
94 ceph tell osd.1 heap start_profiler
96 Alternatively, if the ``CEPH_HEAP_PROFILER_INIT=true`` variable is found in the
97 environment, the profile will be started when the daemon starts running.
102 To print out statistics, run a command of the following form:
106 ceph tell {daemon-type}.{daemon-id} heap stats
112 ceph tell osd.0 heap stats
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
119 Dumping Heap Information
120 ------------------------
122 To dump heap information, run a command of the following form:
126 ceph tell {daemon-type}.{daemon-id} heap dump
132 ceph tell mds.a heap dump
134 .. note:: Dumping heap information works only when the profiler is running.
140 To release memory that ``tcmalloc`` has allocated but which is not being used
141 by the Ceph daemon itself, run a command of the following form:
145 ceph tell {daemon-type}{daemon-id} heap release
151 ceph tell osd.2 heap release
154 Stopping the Profiler
155 ---------------------
157 To stop the heap profiler, run a command of the following form:
161 ceph tell {daemon-type}.{daemon-id} heap stop_profiler
167 ceph tell osd.0 heap stop_profiler
169 .. _Logging and Debugging: ../log-and-debug
170 .. _Google Heap Profiler: http://goog-perftools.sourceforge.net/doc/heap_profiler.html
172 Alternative Methods of Memory Profiling
173 ----------------------------------------
175 Running Massif heap profiler with Valgrind
176 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
178 The Massif heap profiler tool can be used with Valgrind to measure how much
179 heap memory is used. This method is well-suited to troubleshooting RadosGW.
181 See the `Massif documentation
182 <https://valgrind.org/docs/manual/ms-manual.html>`_ for more information.
184 Install Valgrind from the package manager for your distribution then start the
185 Ceph daemon you want to troubleshoot:
189 sudo -u ceph valgrind --max-threads=1024 --tool=massif /usr/bin/radosgw -f --cluster ceph --name NAME --setuser ceph --setgroup ceph
191 When 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
193 the command above, the user who runs it must have write permissions in the
196 Run the ``ms_print`` command to get a graph and statistics from the collected
197 data in the ``massif.out.<pid>`` file:
201 ms_print massif.out.12345
203 The output of this command is helpful when submitting a bug report.