[prev in list] [next in list] [prev in thread] [next in thread]
List: squeak-vm-dev
Subject: Re: [Vm-dev] [Pharo-dev] Object>>#pinInMemory performance
From: Eliot Miranda <eliot.miranda () gmail ! com>
Date: 2020-01-20 0:45:57
Message-ID: 9A43B2C8-B06F-48B1-AEF2-EA1632F8FBEB () gmail ! com
[Download RAW message or body]
[Attachment #2 (text/plain)]
[Attachment #3 (multipart/alternative)]
Hi Alex,
> On Jan 19, 2020, at 3:20 PM, Aliaksei Syrel <alex.syrel@gmail.com> wrote:
>
>
> Hello
>
> I stumbled across a performance issue when pinning objects in memory.
> Below I have two scripts that pin and unpin a byte array (or any object) 20k times.
>
> The first script pins each time a new byte array:
> > [ 20000 timesRepeat: [
> > > array wasPinned |
> > array := ByteArray new.
> > wasPinned := array pinInMemory.
> > array setPinnedInMemory: wasPinned.
> > ] ] timeToRunWithoutGC. "4284"
>
> while the second one pins the same instance of array:
> > array := ByteArray new.
> > [ 20000 timesRepeat: [
> > > wasPinned |
> > wasPinned := array pinInMemory.
> > array setPinnedInMemory: wasPinned.
> > ] ] timeToRunWithoutGC "12"
>
>
> However, as you can see there is a huge performance difference between these \
> scripts.
> Is it expected or is it a bug? And if it is expected what can be happening in VM \
> that leads to such huge performance impact? Thanks!
Alas this is expected. The Spur heap is composed of two very different regions, new \
space and old space. New space is a conventional eden plus two survivor semi spaces \
in which most objects are allocated and which is garbage collected using generation \
scavenging. Old space is a segmented space, garbage collected using a mark sweep \
compact collector. The old space compactor does not move pinned objects, sliding \
unpinned objects around pinned objects as it compacts. The system tries to maintain \
one old space segment that contains all pinned objects, but this can be defeated by \
pinning a few very large objects or pining many objects. The generation scavenger \
has no support for pinned objects.
So what the system does when asked to pin an object in new space is to allocate a \
copy of the object in old space with the pinned bit set, if possible in the preferred \
pinned object segment, and become forward the new space object to the pinned copy. \
Once an object is in old space all that needs to happen to pin (or unpin) an object \
is set (or clear) the pinned bit in the object header, which is tested by the \
compactor.
HTH
> Cheers,
> Alex
Eliot
_,,,^..^,,,_ (phone)
[Attachment #6 (text/html)]
<html><head><meta http-equiv="content-type" content="text/html; \
charset=utf-8"></head><body dir="auto">Hi Alex,<div dir="ltr"><br><blockquote \
type="cite">On Jan 19, 2020, at 3:20 PM, Aliaksei Syrel <alex.syrel@gmail.com> \
wrote:<br><br></blockquote></div><blockquote type="cite"><div dir="ltr"><div \
dir="ltr">Hello<div><br></div><div>I stumbled across a performance issue when pinning \
objects in memory.</div><div>Below I have two scripts that pin and unpin a byte array \
(or any object) 20k times.<br><br>The first script pins each time a new byte \
array: <br><div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><font \
face="monospace">[ 20000 timesRepeat: [<br> </font><font \
face="monospace"> | array wasPinned |<br></font><font face="monospace"> \
array := ByteArray new.<br></font><font face="monospace"> wasPinned := array \
pinInMemory.<br></font><font face="monospace"> array setPinnedInMemory: \
wasPinned.<br></font><font face="monospace">] ] timeToRunWithoutGC. \
<b>"4284"</b></font></blockquote><div><br>while the second one pins the same instance \
of array:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><font \
face="monospace">array := ByteArray new.<br></font><font face="monospace">[ 20000 \
timesRepeat: [<br></font><font face="monospace"> | wasPinned \
|<br></font><font face="monospace"> wasPinned := array \
pinInMemory.<br></font><font face="monospace"> array setPinnedInMemory: \
wasPinned.<br></font><font face="monospace">] ] timeToRunWithoutGC \
"<b>12</b>"</font></blockquote></div><div><br>However, as you can see there is a huge \
performance difference between these scripts.</div><div><br></div><div>Is it \
expected or is it a bug? And if it is expected what can be happening in VM that leads \
to such huge performance impact? \
Thanks!</div></div></div></div></div></blockquote><div><br></div>Alas this is \
expected. The Spur heap is composed of two very different regions, new space and old \
space. New space is a conventional eden plus two survivor semi spaces in which \
most objects are allocated and which is garbage collected using generation \
scavenging. Old space is a segmented space, garbage collected using a mark \
sweep compact collector. The old space compactor does not move pinned objects, \
sliding unpinned objects around pinned objects as it compacts. The system tries \
to maintain one old space segment that contains all pinned objects, but this can be \
defeated by pinning a few very large objects or pining many objects. The \
generation scavenger has no support for pinned objects.<div><br></div><div>So what \
the system does when asked to pin an object in new space is to allocate a copy of the \
object in old space with the pinned bit set, if possible in the preferred pinned \
object segment, and become forward the new space object to the pinned copy. \
Once an object is in old space all that needs to happen to pin (or unpin) an \
object is set (or clear) the pinned bit in the object header, which is tested by the \
compactor.<br><div><br></div><div>HTH</div><div><br><blockquote type="cite"><div \
dir="ltr"><div dir="ltr"><div><div><div><div><div dir="ltr" class="gmail_signature" \
data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div \
dir="ltr">Cheers,<div>Alex</div></div></div></div></div></div></div></div></div></div></div></div>
</div></blockquote><br><div>Eliot</div><div>_,,,^..^,,,_ \
(phone)</div></div></div></body></html>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic