Sunday 25 May 2014

Introduce pinned objects to Pypy

Before the GSOC started, as my proposal plan is kind of huge for 3 month work, so my mentor talked with me about the idea to introduce pinned objects in pypy.

It's the first time I ever heard about the concept so I did some research in this topic(especially in different GC in other languages) and read the current code base before implementation.

I think it's good to wrap up what I have found so far:

1. what's is pinned object?

a pinned object is an object that is not allowed to move.
Sometime GC will compact the memory to create large chunk of free space, so if an object is pinned, it means it tells GC don't move this object.
It's only useful when working with pointers

2.why should pypy add pinned objects?
It's out of performance concern.  For example, without pinning, pypy does a copy each time there is a os.write/read

3.as far as I know every cffi object should be already pinned, what's the implementation of non-movable object in pypy now?

cffi object is now raw malloced. raw malloced object is out of GC control.
so there is a copy version of object that is raw malloced(the so called non-movable object).

the goal is to created a GC manageable object at the creation time instead copying raw-malloced object around.

Things are getting more clear :)  :
Pypy is using a generational GC that heap is divided into two parts -young nursery and old generation.
After minor collection objects in young nursery are all moved in to old generation. But if the object is pinned, we won't move the object and the object will stay in the young generation.

Problems need to be solved:
fragmentation? What if there are too many pinned object in young generation that cause the young generation too fragmented?


As pypy is a test-driven project, I am writing the test cases in the first week and introduce a GC manageable object involves a lot of different layers of pypy so I need.