Hacker News new | past | comments | ask | show | jobs | submit login

Oh wow that is a really interesting test solution. That would be an interesting thing to add to all zig tests (I know they already have the testing allocator and good valgrind support but I don't think that tests/simulates oom).

I love things like these that use existing tests and expand the to just test further thing in already covered flows. We have done similar things at my work where we test expansion of data models against old models to check that we cover upgrade scenarios.




There's support for exactly this type of OOM testing in Zig via std.testing.checkAllAllocationFailures:

- https://github.com/ziglang/zig/blob/1606717b5fed83ee64ba1a91...

- https://www.ryanliptak.com/blog/zig-intro-to-check-all-alloc...


This is a clear sign of a badly designed language. You should never see a fixed-size (less than page size) allocation fail, simply because there's nothing you can reasonably do if it does fail. Either you should crash or it should block until it is possible again.

(Where crash means a worker process or something limited to something less than the entire system. See Erlang for the logical extension of this.)

I realize this implies Windows and Java are badly designed and my answer to that is "yes".


So if my browser tries to allocate memory for a tab and the allocation fails it should just crash or block instead of handling the failure gracefully by not creating a new tab and telling me the system is running low on memory?


Tabs are separate processes in every modern browser.

Actually since you skipped all the less than a page stuff I'm not sure you actually understand what my post is about…?


Is Linux designed in such a way that less-than-page size allocations never fail? How would that work?


As long as the syscalls don't themselves fail, it's no problem until you run out of address space. At which point you should crash because you probably need to allocate to handle any reasonable errors.


So is there no point to checking malloc return ?


Oh cool, didn't know that. Thanks.


I've been using this helper: https://github.com/judofyr/zini/blob/ea91f645b7dc061adcedc91.... It starts by making the first allocation fail, then the second, then the third, and so on. As long as it returns OutOfMemory (without leaking memory) then everything is fine.




Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: