Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segregating freelists by size, not by type #717

Open
markshannon opened this issue Jan 28, 2025 · 0 comments
Open

Segregating freelists by size, not by type #717

markshannon opened this issue Jan 28, 2025 · 0 comments

Comments

@markshannon
Copy link
Member

Currently we segregate freelists by the class of the object. One for compact ints, one for floats, one for lists, etc.
This means we have many more freelists than we need for the number of different sizes of objects that we store in freelists.

Using a freelist based on the size of the object would increase sharing, but might add overhead as we would need to store the class of the object as well as the refcount when getting the memory from the freelist.

Even with the extra memory write, the improved cache use might make it faster.

We would only need one write if we were to thread the freelist through the ob_type field instead of the ob_refcnt field, keeping the ref count set to 1.

Instead of:

if (--obj->ob_refcnt == 0) {
    put_in_freelist(obj);
}

We would have:

if (obj->ob_refcnt == 1) {
    put_in_freelist(obj);
}
--obj->ob_refcnt;

leaving the refcount as 1 in the freelist.

Let's try out the simpler size based version first, to see if it is faster. We can try preserving the refcount later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant