Skip to content

reorder write after free checks away from critical region in allocate_small#335

Open
rdevshp wants to merge 1 commit into
GrapheneOS:mainfrom
rdevshp:lock_content_small
Open

reorder write after free checks away from critical region in allocate_small#335
rdevshp wants to merge 1 commit into
GrapheneOS:mainfrom
rdevshp:lock_content_small

Conversation

@rdevshp

@rdevshp rdevshp commented May 11, 2026

Copy link
Copy Markdown
Contributor

In a local multithread benchmark that I ran on x86-64, I was able to get a ~7% speedup with this patch.

Comment thread h_malloc.c
Comment on lines +667 to +670
if (requested_size) {
write_after_free_check(p, size - canary_size);
set_canary(metadata, p, size);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Don't those operations need to acquired c->lock?

@rdevshp rdevshp May 27, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These operations are done after the c->lock critical region already marked the slot as used with set_used_slot, which means that other concurrent allocations would not touch/allocate this slot.

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