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

Scripting: better per script memory tracking #23647

Closed
wants to merge 3 commits into from

Conversation

IamPete1
Copy link
Member

This moves away from using the provided lua memory tracking and "manualy" tracking via our alloc function. This means we can track the total allocation per run rather than just the memory change. Just tracking the change masks issues because garbage collection can happen during a script run. This change also allows us to track per script memory.

This adds lots of AP_SCRIPTING_CHECKS defines to check the memory count matches the lua one. It turns out AP_SCRIPTING_CHECKS are always enabled....

I have not tested the checks still all pass for every combination of script errors and garbage collection. Also not tested the repl.

@IamPete1 IamPete1 force-pushed the scripting_mem_tracking branch from c70eecc to ee4aa45 Compare June 18, 2023 20:13
@IamPete1 IamPete1 marked this pull request as ready for review June 18, 2023 20:14
@IamPete1 IamPete1 force-pushed the scripting_mem_tracking branch from ee4aa45 to 3b2ac52 Compare April 23, 2024 17:12
@IamPete1
Copy link
Member Author

This is currently reporting that a script can use a negative amount of memory. There are lots of checks in this, so I wonder if we have a genuine issue.

image

On master we don't get per script memory, so there is no way to tell.

@IamPete1 IamPete1 force-pushed the scripting_mem_tracking branch from f67c410 to aa1faf5 Compare April 23, 2024 23:18
@IamPete1
Copy link
Member Author

Excitingly it panics on real hardware but not in SITL. More testing needed.....

@IamPete1
Copy link
Member Author

IamPete1 commented May 2, 2024

I worked out the issue, when a script is removed it still has some memory cost, this needs to be accounted for so the totals still match up. I guess it gets garbage collected at some later point.

This is also the issue with getting negative per script memory. The total is always correct, but the garbage collector collects from multiple scripts so we cannot assign the collected memory to the script that has just run.

@IamPete1
Copy link
Member Author

IamPete1 commented May 2, 2024

There does not seem to be any nice way to do this. So, I think I will give up for now. Moving to thread per script would be the solution, although would cost more memory overall.

@IamPete1 IamPete1 closed this May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants