Skip to content

Stop double sweeping the heap during compaction #5757

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

Closed

Conversation

eightbitraptor
Copy link
Contributor

In #5637 I reversed the order of steps in the compaction algorithm. This meant changing the way pages are swept during compaction, however because of how gc_sweep_step and gc_sweep_page interact we still required a seperate sweep step after compaction had finished, to finalise the accounting and the free_pages/pool_pages lists.

This PR refactors gc_sweep_step and gc_sweep_page to make them more independent - gc_sweep_page now handles adding the page to the free/pool pages and incrementing the sweeping_page cursor - this is so that we can use gc_sweep_page directly during compaction to fully sweep a page and maintain correct accounting.

This has allowed us to change the entry point for compaction to a branch - either sweep and compact, or just sweep - removing the need for a seperate sweep step post compaction.

@eightbitraptor eightbitraptor force-pushed the mvh-move-heap-page-accounting branch from 7fa3036 to cbd98ff Compare April 4, 2022 13:52
Comment on lines +8165 to +8178
int unlink_pages = GC_SWEEP_PAGES_FREEABLE_PER_STEP;
int swept_slots = 0;
gc_sweep_page(objspace, pool, dheap->sweeping_page, &unlink_pages, &swept_slots, FALSE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is always going to move the page to the tomb heap if the page is empty because unlink_pages > 0 is always true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, good spot, thanks

@@ -5481,6 +5492,46 @@ gc_sweep_page(rb_objspace_t *objspace, rb_heap_t *heap, struct gc_sweep_context
gc_report(2, objspace, "page_sweep: end.\n");
}

static void
gc_sweep_page(rb_objspace_t *objspace, rb_size_pool_t *size_pool, struct heap_page *sweep_page, int *unlink_limit, int *swept_slots, bool need_pool)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think gc_sweep_page should take care of moving pages to pooled pages or to the tomb heap. For compaction, we shouldn't need to do either of the two, so I think the logic here should stay in gc_sweep_step.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Peter - I've had a go at teasing apart some of these conditionals so now gc_sweep_page is responsible for adding the page back to the free_pages where needed, but gc_sweep_step retains the responsibility for adding the page to the tomb, and the pool pages if necessary. What do you think?

@eightbitraptor eightbitraptor force-pushed the mvh-move-heap-page-accounting branch from cbd98ff to d23132c Compare April 4, 2022 18:38
This allows gc_sweep_page to be used independently of gc_sweep_step and
will leave the heap in a consistent state.
@eightbitraptor eightbitraptor force-pushed the mvh-move-heap-page-accounting branch from d23132c to 69222b0 Compare April 4, 2022 20:59
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

Successfully merging this pull request may close these issues.

2 participants