1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-03-15 11:21:19 -07:00

Brief overview of the mps.

Copied from Perforce
 Change: 180000
 ServerID: perforce.ravenbrook.com
This commit is contained in:
Gareth Rees 2012-10-22 10:43:21 +01:00
parent 91c1a0f873
commit 51bd65218f
4 changed files with 535 additions and 14 deletions

View file

@ -0,0 +1,451 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="500"
height="400"
id="svg2"
version="1.1"
inkscape:version="0.47 r22583"
sodipodi:docname="overview.svg">
<defs
id="defs4">
<marker
inkscape:stockid="StopL"
orient="auto"
refY="0"
refX="0"
id="StopL"
style="overflow:visible">
<path
id="path3869"
d="M 0,5.65 0,-5.65"
style="fill:none;stroke:#000000;stroke-width:1pt"
transform="scale(0.8,0.8)" />
</marker>
<marker
inkscape:stockid="Arrow1Mstart"
orient="auto"
refY="0"
refX="0"
id="Arrow1Mstart"
style="overflow:visible">
<path
id="path3705"
d="M 0,0 5,-5 -12.5,0 5,5 0,0 z"
style="fill-rule:evenodd;stroke:#000000;stroke-width:1pt;marker-start:none"
transform="matrix(0.4,0,0,0.4,4,0)" />
</marker>
<marker
inkscape:stockid="Arrow1Mend"
orient="auto"
refY="0"
refX="0"
id="Arrow1Mend"
style="overflow:visible">
<path
id="path3708"
d="M 0,0 5,-5 -12.5,0 5,5 0,0 z"
style="fill-rule:evenodd;stroke:#000000;stroke-width:1pt;marker-start:none"
transform="matrix(-0.4,0,0,-0.4,-4,0)" />
</marker>
<marker
inkscape:stockid="DotM"
orient="auto"
refY="0"
refX="0"
id="DotM"
style="overflow:visible">
<path
id="path3764"
d="m -2.5,-1 c 0,2.76 -2.24,5 -5,5 -2.76,0 -5,-2.24 -5,-5 0,-2.76 2.24,-5 5,-5 2.76,0 5,2.24 5,5 z"
style="fill-rule:evenodd;stroke:#000000;stroke-width:1pt;marker-start:none;marker-end:none"
transform="matrix(0.4,0,0,0.4,2.96,0.4)" />
</marker>
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 526.18109 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="744.09448 : 526.18109 : 1"
inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
id="perspective10" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="1"
inkscape:cx="406.67801"
inkscape:cy="174.24286"
inkscape:document-units="px"
inkscape:current-layer="layer1"
showgrid="true"
inkscape:window-width="1611"
inkscape:window-height="1007"
inkscape:window-x="1280"
inkscape:window-y="0"
inkscape:window-maximized="0">
<inkscape:grid
type="xygrid"
id="grid2816"
empspacing="5"
visible="true"
enabled="true"
snapvisiblegridlinesonly="true" />
</sodipodi:namedview>
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-652.36218)">
<path
style="fill:none;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:1, 3;stroke-dashoffset:0;marker-start:url(#StopL);marker-end:url(#StopL)"
d="m 160,682.36218 220,0"
id="path4558" />
<rect
ry="0"
rx="0"
y="690.36218"
x="412"
height="340"
width="80"
id="rect3596"
style="fill:#ffffff;fill-opacity:1;stroke:#808080;stroke-width:1;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
<rect
style="fill:#ffffff;fill-opacity:1;stroke:#808080;stroke-width:0.96362412;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
id="rect3590"
width="130"
height="340"
x="10"
y="702.36218"
rx="0"
ry="0" />
<rect
style="fill:#ffffff;fill-opacity:1;stroke:#808080;stroke-width:1;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
id="rect3594"
width="80"
height="340"
x="406"
y="696.36218"
rx="0"
ry="0" />
<rect
ry="0"
rx="0"
y="702.36218"
x="400"
height="340"
width="80"
id="rect3592"
style="fill:#ffffff;fill-opacity:1;stroke:#808080;stroke-width:1;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
<rect
style="fill:#ffffff;fill-opacity:1;stroke:#808080;stroke-width:0.99999994;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
id="rect3598"
width="208.6207"
height="40"
x="171.3793"
y="990.36218" />
<rect
y="996.36218"
x="165.68965"
height="40"
width="208.6207"
id="rect3600"
style="fill:#ffffff;fill-opacity:1;stroke:#808080;stroke-width:0.99999994;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
<rect
style="fill:#ffffff;fill-opacity:1;stroke:#808080;stroke-width:0.99999994;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
id="rect3602"
width="208.6207"
height="40"
x="160"
y="1002.3622" />
<rect
y="920.36218"
x="171.3793"
height="40"
width="208.6207"
id="rect3604"
style="fill:#ffffff;fill-opacity:1;stroke:#808080;stroke-width:0.99999994;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
<rect
style="fill:#ffffff;fill-opacity:1;stroke:#808080;stroke-width:0.99999994;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
id="rect3606"
width="208.6207"
height="40"
x="165.68965"
y="926.36218" />
<rect
y="932.36218"
x="160"
height="40"
width="208.6207"
id="rect3608"
style="fill:#ffffff;fill-opacity:1;stroke:#808080;stroke-width:0.99999994;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;line-height:125%;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;font-family:Verdana;-inkscape-font-specification:Verdana"
x="264.21661"
y="1026.3622"
id="text3610"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan3612"
x="264.21661"
y="1026.3622">code (“text”) segments</tspan></text>
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;line-height:125%;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;font-family:Verdana;-inkscape-font-specification:Verdana"
x="269.35938"
y="958.36218"
id="text3614"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan3616"
x="269.35938"
y="958.36218">data segments</tspan></text>
<text
sodipodi:linespacing="125%"
id="text3618"
y="972.36218"
x="436.70703"
style="font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;line-height:125%;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;font-family:Verdana;-inkscape-font-specification:Verdana"
xml:space="preserve"><tspan
y="972.36218"
x="436.70703"
id="tspan3620"
sodipodi:role="line">heap</tspan><tspan
y="987.36218"
x="436.70703"
sodipodi:role="line"
id="tspan3622">managed</tspan><tspan
y="1002.3622"
x="436.70703"
sodipodi:role="line"
id="tspan3624">by other</tspan><tspan
y="1017.3622"
x="436.70703"
sodipodi:role="line"
id="tspan3626">memory</tspan><tspan
y="1032.3622"
x="436.70703"
sodipodi:role="line"
id="tspan3628">managers</tspan></text>
<rect
style="fill:#ffffff;fill-opacity:1;stroke:#808080;stroke-width:1;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
id="rect3644"
width="60.000011"
height="30"
x="160"
y="702.36218" />
<rect
y="702.36218"
x="240"
height="30"
width="60"
id="rect3646"
style="fill:#ffffff;fill-opacity:1;stroke:#808080;stroke-width:1;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />
<rect
style="fill:#ffffff;fill-opacity:1;stroke:#808080;stroke-width:1;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
id="rect3648"
width="60"
height="30"
x="320"
y="702.36218" />
<text
sodipodi:linespacing="125%"
id="text3650"
y="722.36218"
x="269.90411"
style="font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;line-height:125%;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;font-family:Verdana;-inkscape-font-specification:Verdana"
xml:space="preserve"><tspan
y="722.36218"
x="269.90411"
id="tspan3652"
sodipodi:role="line">register files</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;line-height:125%;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;font-family:Verdana;-inkscape-font-specification:Verdana"
x="74.683594"
y="1018.3622"
id="text3654"
sodipodi:linespacing="125%"><tspan
id="tspan3658"
sodipodi:role="line"
x="74.683594"
y="1018.3622">heap managed</tspan><tspan
id="tspan3664"
sodipodi:role="line"
x="74.683594"
y="1033.3622">by the MPS</tspan></text>
<rect
y="742.36218"
x="160"
height="100"
width="60.000011"
id="rect3672"
style="fill:#ffffff;fill-opacity:1;stroke:#808080;stroke-width:1;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />
<rect
style="fill:#ffffff;fill-opacity:1;stroke:#808080;stroke-width:1;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
id="rect3674"
width="60"
height="50"
x="240"
y="742.36218" />
<rect
y="742.36218"
x="320"
height="160"
width="60"
id="rect3676"
style="fill:#ffffff;fill-opacity:1;stroke:#808080;stroke-width:1;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;line-height:125%;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;font-family:Verdana;-inkscape-font-specification:Verdana"
x="270.21661"
y="772.36218"
id="text3678"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan3680"
x="270.21661"
y="772.36218">control stacks</tspan></text>
<rect
style="fill:#ffffff;fill-opacity:1;stroke:#808080;stroke-width:1;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
id="rect3682"
width="110"
height="60"
x="20"
y="762.36218" />
<text
xml:space="preserve"
style="font-size:16px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;line-height:125%;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;font-family:Verdana;-inkscape-font-specification:Verdana"
x="270.38458"
y="678.36218"
id="text3684"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan3686"
x="270.38458"
y="678.36218">threads</tspan></text>
<path
style="fill:none;stroke:#000000;stroke-width:1;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:1, 24;stroke-dashoffset:0"
d="m 310,682.36218 70,0"
id="path3694" />
<rect
y="852.36218"
x="20"
height="60"
width="110"
id="rect4144"
style="fill:#ffffff;fill-opacity:1;stroke:#808080;stroke-width:1;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0" />
<text
sodipodi:linespacing="125%"
id="text4146"
y="722.36218"
x="20"
style="font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;font-family:Verdana;-inkscape-font-specification:Verdana"
xml:space="preserve"><tspan
y="722.36218"
x="20"
sodipodi:role="line"
id="tspan4150">arena</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;font-family:Verdana;-inkscape-font-specification:Verdana"
x="30"
y="782.36218"
id="text4154"
sodipodi:linespacing="125%"><tspan
id="tspan4156"
sodipodi:role="line"
x="30"
y="782.36218">pool</tspan></text>
<text
sodipodi:linespacing="125%"
id="text4158"
y="872.36218"
x="30"
style="font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;font-family:Verdana;-inkscape-font-specification:Verdana"
xml:space="preserve"><tspan
y="872.36218"
x="30"
sodipodi:role="line"
id="tspan4160">pool</tspan></text>
<rect
style="fill:#ffffff;fill-opacity:1;stroke:#808080;stroke-width:1;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
id="rect4162"
width="110"
height="30"
x="20"
y="922.36218" />
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;font-family:Verdana;-inkscape-font-specification:Verdana"
x="30"
y="942.36218"
id="text4164"
sodipodi:linespacing="125%"><tspan
id="tspan4166"
sodipodi:role="line"
x="30"
y="942.36218">pool</tspan></text>
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-start:url(#DotM);marker-end:url(#Arrow1Mend)"
d="m 190,722.36218 -100,60"
id="path4168" />
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-start:url(#DotM);marker-end:url(#Arrow1Mend)"
d="m 350,782.36218 90,20"
id="path4170" />
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-start:url(#DotM);marker-end:url(#Arrow1Mend)"
d="m 440,832.36218 -360,50"
id="path4172" />
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-start:url(#DotM);marker-end:url(#Arrow1Mend)"
d="m 180,952.36218 -80,-10"
id="path4174" />
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-start:url(#DotM);marker-end:url(#Arrow1Mend)"
d="m 189,811.36218 -89,-9"
id="path4176" />
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-start:url(#DotM);marker-end:url(#Arrow1Mend)"
d="m 70,942.36218 -20,-50"
id="path4178" />
<path
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-start:url(#DotM);marker-end:url(#Arrow1Mend)"
d="m 70,782.36218 -30,20"
id="path4182" />
<path
id="path5320"
d="m 470,812.36218 -30,60"
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-start:url(#DotM);marker-end:url(#Arrow1Mend)"
sodipodi:nodetypes="cc" />
<path
sodipodi:nodetypes="cc"
style="fill:none;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;marker-start:url(#DotM);marker-end:url(#Arrow1Mend)"
d="m 80,802.36218 -10,70"
id="path5322" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 17 KiB

View file

@ -1,3 +1,5 @@
.. highlight:: none
.. _guide-debug:
Debugging with the Memory Pool System
@ -17,8 +19,8 @@ delayed. And even if it does die, the space it occupies may not be
re-allocated for some time.
General advice
--------------
General debugging advice
------------------------
1. Compile with debugging information turned on (``-g`` on the GCC or
Clang command line).
@ -43,15 +45,34 @@ General advice
.. _address space layout randomization: http://en.wikipedia.org/wiki/Address_space_layout_randomization
4. Run your test case inside the debugger. Use ``assert`` or ``abort``
in your error handler (rather than ``exit``) so that you can enter
the debugger with the contents of the control stack available for
inspection.
A fact that assists with reproducibility is that the more frequently
the collector runs, the sooner and more reliably errors are
discovered. So if you have a bug that's hard to reproduce, you may
be able to provoke it more reliably by having a mode for testing in
which you run frequent collections (by calling
:c:func:`mps_arena_collect` followed by
:c:func:`mps_arena_release`), perhaps as frequently as every
allocation.
4. Run your test case inside the debugger. Use ``assert`` and
``abort`` in your error handler (rather than ``exit``) so that you
can enter the debugger with the contents of the control stack
available for inspection.
You may need to make sure that the debugger isn't entered on
:term:`barrier (1)` hits (because the MPS uses barriers to protect
parts of memory). In GDB, use these commands::
(gdb) set dont-handle-bad-access 1
(gdb) handle SIGBUS nostop
Add them to your ``.gdbinit`` if appropriate.
.. _guide-debug-underscanning:
Underscanning
-------------
Example: underscanning
----------------------
An easy mistake to make is to omit to :term:`fix` a :term:`reference`
when :term:`scanning <scan>` a :term:`formatted object`. For example,
@ -75,8 +96,6 @@ end up pointing to the start of a valid object (but the wrong one), or
to the middle of a valid object, or to an unused region of memory, or
into an MPS internal control structure.
.. highlight:: none
The reproducible test case is simple. Run a garbage collection by
calling ``(gc)`` and then evaluate any expression::
@ -160,6 +179,8 @@ up to the detection of the error, and in order to enable you to do
that, the MPS provides its :ref:`topic-telemetry` feature.
.. _guide-debug-telemetry:
Telemetry
---------
@ -238,10 +259,13 @@ There are no events related to this address, so in particular this
address was never fixed.
Getting the size wrong
----------------------
.. _guide-debug-size:
Here's another kind of mistake: an off-by-one error in ``make_string``:
Example: allocating with wrong size
-----------------------------------
Here's another kind of mistake: an off-by-one error in ``make_string``
leading to the allocation of string objects with the wrong size:
.. code-block:: c
:emphasize-lines: 5

View file

@ -9,5 +9,5 @@ Guide
build
overview
lang
perf
debug
perf

View file

@ -3,4 +3,50 @@
Overview of the Memory Pool System
==================================
The figure below gives a (simplified) picture of a program's memory
from the point of view of the Memory Pool System.
.. figure:: ../diagrams/overview.svg
:align: center
:alt: Diagram: Overview of the Memory Pool System.
Overview of the Memory Pool System.
The :term:`arena` is the top-level data structure in the MPS. An arena
is responsible for requesting :term:`memory (3)` from the operating
system (and returning it), making memory available to :term:`pools
<pool>`, and for :term:`garbage collection`. It's best to have only
one arena in your program, because the MPS can't collect cyclic
structures that span multiple arenas, but multiple arenas are
supported. (See :ref:`topic-arena`.)
Within the arena you create one or more :term:`pools <pool>`. A pool
is responsible for requesting memory from the :term:`arena` and making
it available to your program. (See :ref:`topic-pool`.)
Pools belong to :term:`pool classes <pool class>` that specify
policies for how their memory is managed. Some pools are
:term:`manually managed <manual memory management>` (you must call
:c:func:`mps_free` to return a block of memory to the pool) and others
are :term:`automatically managed <automatic memory management>` (the
:term:`garbage collector` reclaims :term:`unreachable`
blocks). Automatically managed pools need you to tell them how to find
:term:`references <reference>` to allocated blocks. (See
:ref:`topic-format`.)
The MPS is designed to work with multi-threaded programs. Functions in
the C interface are thread safe, except in a few documented
cases. (See :ref:`topic-thread`.) The :term:`allocation point
protocol` provides fast lock-free allocation on multiple threads
simultaneously. (See :ref:`topic-allocation`.)
The MPS is designed to co-operate with other memory managers (for
example :term:`malloc` and :term:`free (2)` in :term:`C`, or operators
``new`` and ``delete`` in :term:`C++`), so you need not move all your
memory management to the MPS at once, and you can co-operate with
libraries that use standard allocation mechanisms.
The garbage collector is :term:`incremental <incremental garbage
collection>`: it proceeds in small steps interleaved with the execution
of your program, so there are no long waits. (See
:ref:`topic-collection`.)