bskari / pi-rc

Turn your Raspberry Pi into a radio controller for RC toys.
GNU General Public License v2.0
139 stars 38 forks source link

Could not allocate memory #34

Open hepcat72 opened 3 years ago

hepcat72 commented 3 years ago
>sudo -s
# ./pi_pcm
Using mbox device /dev/vcio.
Could not allocate memory.
Terminating with signal 0

This was working up until just recently (likely today). This might have been the result of an update or 2, though I have no specific hunches.

My debug skills with c are very rudimentary, but I determined from some print edits that it's this line that the memory error is coming from:

https://github.com/bskari/pi-rc/blob/bfc74a4d46c104ccb30412e59c9bb62f0549334e/pi_pcm.c#L470-L472

...

Well, actually... a restart seems to have fixed this issue and it is working again... so feel free to close, but I'm going to post to see what you think was going on here... It might happen again, and may indicate some underlying issue I should look into?

hepcat72 commented 3 years ago

Huh. This has happened again... Must be related to a system update I made? This has been stable for years. Now every time I try to use it, I get the vcio memory allocation error.

hepcat72 commented 3 years ago

I luckily had made the backup on a separate Micro SD card right before the updates. I switched back to the pre-update SD card a few days ago and the problem appears to have gone away. I presume that the problem still exists on the other SD card. I need to make another backup (and overwrite that card) since that one apparently has a problem, but it would be nice to know what the problem is.

I don't know exactly what updates I performed, though I know I had performed the updates by installing npm_check to see what was outdated. I was just doing some updates for good measure - no specific reason. It's possible that one of the updates breaks pi_rc on an rPi 3B+, but could it also just be possible that my Pi is overloaded?

hepcat72 commented 3 years ago

Is there a way to compare the 2 disk images to see what's different?

hepcat72 commented 3 years ago

I think I have narrowed in on the cause of the problem. It may be related to ioctl:

https://github.com/bskari/pi-rc/blob/bfc74a4d46c104ccb30412e59c9bb62f0549334e/mailbox.c#L89-L93

I don't see the error in the above code, which suggests that the result must be 0 or positive. This code requires it to be non-zero (positive):

https://github.com/bskari/pi-rc/blob/bfc74a4d46c104ccb30412e59c9bb62f0549334e/pi_pcm.c#L470-L472

but since it is printing the error, it must be 0. However, mem_alloc only returns zero if ioctl returns negative:

https://github.com/bskari/pi-rc/blob/bfc74a4d46c104ccb30412e59c9bb62f0549334e/mailbox.c#L120

but it can't be negative since the error in mbox_property didn't print:

https://github.com/bskari/pi-rc/blob/bfc74a4d46c104ccb30412e59c9bb62f0549334e/mailbox.c#L92

This seems impossible, unless p[5] is 0. I suppose p[5] can be 0 if this is zero:

https://github.com/bskari/pi-rc/blob/bfc74a4d46c104ccb30412e59c9bb62f0549334e/pi_pcm.c#L243

I don't see how that can sometimes be, from an npm update...

hepcat72 commented 3 years ago

Well, this happened again recently after having gone back to a backup, so I'm stumped as to what's causing it. It seems less frequent since going back to the backup, so maybe I've just somehow got too much running on my pi? Memory usage is not anywhere near maxed out.