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

Crash when AI allocates too much memory #7513

Open
SamuXarick opened this Issue Apr 14, 2019 · 8 comments

Comments

Projects
None yet
5 participants
@SamuXarick
Copy link
Contributor

commented Apr 14, 2019

Version of OpenTTD

1.9.1

Expected result

crash with a dump/not crash

Actual result

OpenTTD closes itself without a dump.

Steps to reproduce

Configure one NoCAB v499 to start.
Set up opcodes to 250000 to speed things up.
Start a 4096x4096 map with high number of towns and industries.
Wait for no more than 30 minutes, for a crash/poof.

@SamuXarick

This comment has been minimized.

Copy link
Contributor Author

commented Apr 14, 2019

debug build x64 gives me this.
2019-04-14

@SamuXarick

This comment has been minimized.

Copy link
Contributor Author

commented Apr 14, 2019

When trying this with monthly autosaves , it seems to be more prevalent.

@SamuXarick

This comment has been minimized.

Copy link
Contributor Author

commented Apr 15, 2019

Crash without autosaving:
2019-04-15
callstack.txt

@glx22

This comment has been minimized.

Copy link
Contributor

commented Apr 15, 2019

Seems AI creates too many and too big arrays (but expected with this map size and the number of towns and industries I guess).

@PeterN

This comment has been minimized.

Copy link
Member

commented Apr 15, 2019

So we need to memory limit squirrel. I started a patch but didn't get too far, perhaps I should revisit.

@nielsmh

This comment has been minimized.

Copy link
Contributor

commented Apr 15, 2019

Squirrel is a bit annoying in that it doesn't allow using a stateful per-VM memory allocator. You can add some logic to the allocator functions to keep track of the total allocation size of all Squirrel VMs, but that won't help limiting each AI or GS, or detect which one is having the biggest impact.

I explored letting it use a stateful allocator (e.g. arena allocator) and it will involve touching lots of Squirrel internals.

@PeterN

This comment has been minimized.

Copy link
Member

commented Apr 15, 2019

As each VM is run serially, not concurrently, an allocator can be told which VM is currently running. It makes running VMs concurrently unfeasible but I think that is already the case.

@JGRennison

This comment has been minimized.

Copy link
Contributor

commented Apr 15, 2019

Using recursion for GC marking is problematic even if the total memory allocation is limited.
Data structures like linked lists or unbalanced trees can use up an excessive amount of stack even if their total size is quite modest.
Mark and sweep implementations usually use queues or sets rather than the stack to avoid this.

@LordAro LordAro changed the title OpenTTD closes itself with no crash dump Crash when AI allocates too much memory Apr 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.