Author Topic: OutOfMemoryError  (Read 730 times)

0 Members and 1 Guest are viewing this topic.

Offline Forestidia86

  • Posts: 433
    • View Profile
Re: OutOfMemoryError
« Reply #15 on: January 31, 2018, 02:22:08 pm »
Attached a video that shows 0.9.10 without crash.

Offline Simon

  • Administrator
  • Posts: 2364
    • View Profile
    • Lix
Re: OutOfMemoryError
« Reply #16 on: February 01, 2018, 02:40:08 pm »
Thanks, helpful videos. The single most important figure is the ballpark guess of how much RAM the app eats over time, and the vids show that clearly.

Allocating 40 MB per second and almost never shrinking is a no-go, even during turbo-fast-forward on a large map.

I have observed similar behavior of my Windows builds in Wine, that's great. I'll slowly gnaw on this problem over the next weeks.

-- Simon

Offline Simon

  • Administrator
  • Posts: 2364
    • View Profile
    • Lix
Re: OutOfMemoryError
« Reply #17 on: February 02, 2018, 04:51:46 pm »
Looks like it's the automatic savestates.

If I disable automatic savestating, Lix will keep only 2 gamestates: The zero state and the active state. Lix will not bookkeep with up to 8 savestates. Together with GC'ing more often in 0.9.10, Windows Lix stays at about 300 MB in large levels. That's getting acceptable, even though still big.

-- Simon

Offline Simon

  • Administrator
  • Posts: 2364
    • View Profile
    • Lix
Re: OutOfMemoryError
« Reply #18 on: February 02, 2018, 10:06:17 pm »
Findings from Linux! Exciting story! :lix-cool: Boring technobabble! :8():

Normal allocation. When I allocate a bitmap of 1,000 x 1,000 pixels and paint them all yellow (to ensure that the lazy library/gfx card really allocates something), VRAM usage goes up by 4 MB. Makes perfect sense, it's 1,000,000 pixels with 32-bit colors.

Maybe the card allocates chunks only powers of two and it really allocates 1,024 x 1,024 pixels, but such details don't matter. The 4 MB is perfectly what we would expect. I've measured this with nvidia-msi, command-line tool from my Linux nvidia driver, but an even broader ballpark guess was available in Lix if you check "show FPS" in the options.

RAM usage doesn't increase when I allocate such VRAM bitmaps, at least as long as the graphics card has free VRAM. I can have 100 MB in VRAM and RAM would merely increase by a couple kB, too little to dent any estimate.

Swapping. When you allocate VRAM and the graphics card grows full, the newer allocations still go through without error -- but the graphics card will swap some bitmaps from VRAM into RAM.

We remember how the bitmap of 1,000 x 1,000 pixels occupied 4 MB of VRAM. Now, when the graphics card swaps VRAM into RAM, suddenly such a swapped bitmap occupies 8 MB.

This still doesn't sum to the 2 GB that I observed on Windows. Certainly, the 10 savestates during networking games aren't 100 MB to 200 MB each -- the biggest ingredients are a physics matrix, a land bitmap, and the arrays of lixes. The swapped land is probably the fattest ingredient.

Still, let's keep in mind for now that the graphics card can swap, and the bitmaps surely won't become any leaner or faster in the RAM.

Deallocation. Allegro VRAM bitmaps are manually managed; I have to call destroy explicitly on them, but then the VRAM is immediately available again. I'm reasonably sure that I have no VRAM leaks, but certainly allocate several fat bitmaps.

Leftovers from un-swapping. Now comes the fun part: A freshly started Lix occupies maybe 50 MB in RAM and 11 MB in VRAM. I begin allocating VRAM test bitmaps. Eventually these get swapped to RAM, as descibed above. Let's continue allocating VRAM until 2 GB of RAM is filled with swapped bitmaps.

Now, we deallocate these test bitmaps one-by-one, until none of them is left. The VRAM of Lix has dropped to around 5 MB, slightly less than the 11 MB from a fresh start. But we still have 1.5 GB of RAM filled! This leftover swap-RAM, or whatever it is, doesn't seem to be freed anytime soon. It's not part of the garbage-collected D heap -- I can call the garbage collection manually as often as I want, with no effect.

Looks like it's private memory allocated by the video driver that is called via Allegro inside Lix. In top, these 1.5 GB are still ascribed to Lix.

-- Simon

Offline Forestidia86

  • Posts: 433
    • View Profile
Re: OutOfMemoryError
« Reply #19 on: February 03, 2018, 06:32:37 am »
Swapping. When you allocate VRAM and the graphics card grows full, the newer allocations still go through without error -- but the graphics card will swap some bitmaps from VRAM into RAM.

That actually fits to what I generally have read about that: If no VRAM is free the RAM takes over, which is said to be less performant then.
(As I indicated laptops often work with that even by design (graphics card uses a part of RAM) (shared memory (graphics cards)) since they often have underpowered graphics cards.)

Do you have any ideas how to clear the RAM from the leftover bitmaps?
« Last Edit: February 03, 2018, 09:17:57 am by Forestidia86 »