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

emmalloc_trim broken since #13442? #23343

Open
sbc100 opened this issue Jan 8, 2025 · 6 comments
Open

emmalloc_trim broken since #13442? #23343

sbc100 opened this issue Jan 8, 2025 · 6 comments
Assignees

Comments

@sbc100
Copy link
Collaborator

sbc100 commented Jan 8, 2025

It looks like emmalloc_trim has been broken since #13442. Prior to that change the result of sbrk would reduce in test_emmalloc_trim test but after that change the expecations were updated to reflect an sbrk that never goes down, and indeed if I run that test with -sASSERTIONS=2 I see that this assertion fires every time:

assert((intptr_t)oldSbrk != -1); // Shrinking with sbrk() should never fail.

Basically it looks like sbrk no longer accepts negative values.. which I think was an indended part of #13442. So maybe emmalloc_trim cannot be implement using sbrk along? We would need some kind of new internal function such as sbrk_shrink to make it work?

sbc100 added a commit to sbc100/emscripten that referenced this issue Jan 8, 2025
I believe this function has no been working correctly since emscripten-core#13442
when sbrk stopped accepting negative values.

Maybe we can find a way to bring this functionality back but disabling
it for now seems safest.

See: emscripten-core#23343
@kripken
Copy link
Member

kripken commented Jan 8, 2025

Where do you see that sbrk does not accept negative values? Looking through the code I failed to find anything obvious.

@sbc100
Copy link
Collaborator Author

sbc100 commented Jan 8, 2025

You can see from the expected output of the test.. sbrk could be reduced before but not after. I think its because the increment that sbrk was interpreted as signed before and unsigned after. Whatever the reason the side effect can clearly be seen in the test expectations, or by enabling -sASSERTIONS=2.

@sbc100
Copy link
Collaborator Author

sbc100 commented Jan 8, 2025

-    intptr_t old_brk = *sbrk_ptr;
+    uintptr_t old_brk = *sbrk_ptr;
 #endif
-    intptr_t new_brk = old_brk + increment;
+    uintptr_t new_brk = old_brk + increment;

@sbc100
Copy link
Collaborator Author

sbc100 commented Jan 8, 2025

Actually real problem is probably uintptr_t increment = (uintptr_t)increment_; which was added

@kripken
Copy link
Member

kripken commented Jan 8, 2025

(I commented in #13442 before seeing this, but as I said there, does wrapping mean that the cast to unsigned is ok?)

sbc100 added a commit that referenced this issue Jan 8, 2025
I believe this function has not been working correctly since #13442 when
sbrk stopped accepting negative values.

Maybe we can find a way to bring this functionality back but disabling
it for now seems safest.

See: #23343
@sbc100
Copy link
Collaborator Author

sbc100 commented Jan 13, 2025

@juj I'd be happy to see emmalloc_trim re-enabled if you can figure out a way to make it work again.

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

3 participants