Jump to content

How can I find out which mod is eating my RAM?


Streetwind

Recommended Posts

I currently play a modded carreer mode. I load to 2.4 GB memory usage on the menu screen, which goes up to 2.7 GB after loading the savegame and sitting at the space center screen. So far, so good.

Unfortunately there's a memory leak somewhere. If I keep playing, the memory usage will, guaranteed, without fail, creep up past 3.5 to 3.6 GB and eventually crash the game with an out of memory error. It takes around 1 to 1.5 hours for it to get there, so unfortunately this isn't something I can nail down to doing something specific. I've taken to monitoring my memory usage and just quitting and restarting the client whenever I exceed 3.4 GB, but it's getting annoying. Also, I found another mod I want to add, and that will reduce the amount of headroom that I have before the leak makes me crash.

Is there any way I can track down where my spare RAM is leaking off to?

Link to comment
Share on other sites

I currently play a modded carreer mode. I load to 2.4 GB memory usage on the menu screen, which goes up to 2.7 GB after loading the savegame and sitting at the space center screen. So far, so good.

Unfortunately there's a memory leak somewhere. If I keep playing, the memory usage will, guaranteed, without fail, creep up past 3.5 to 3.6 GB and eventually crash the game with an out of memory error. It takes around 1 to 1.5 hours for it to get there, so unfortunately this isn't something I can nail down to doing something specific. I've taken to monitoring my memory usage and just quitting and restarting the client whenever I exceed 3.4 GB, but it's getting annoying. Also, I found another mod I want to add, and that will reduce the amount of headroom that I have before the leak makes me crash.

Is there any way I can track down where my spare RAM is leaking off to?

Same here man, same here.

I too wish I could see what the source of the memory leaks are when it's a mod.

I know of no easy way to do it like 'aha!, it's ___ 100% for sure'. You'll have to do a binary search to find the problem. Also, having GCmonitor helps so that you can see when it's jumping in RAM usage.

For me, I swear there is some sort of memory leak with MJs landing guidance. There also seems to be some smaller leaks that slowly creep in, but I have no way of telling what is caused by stock KSP (or perhaps Unity) and what is caused by a mod.

Anyhow, what mods do you have?

Link to comment
Share on other sites

I have some of those mods too.

Anyhow, does anybody know of an easy (or easier than most) method to figure out what is causing memory leaks if it's coming from a mod? Because I'm getting small jumps in memory usage over time as well.

Link to comment
Share on other sites

It basically isn't possible to determine which mods are using what memory. Even Squad with access to the full source code and debugging environment would find this awkward as the overhead of tracking this information would probably make the game unplayably slow.

I am not claiming that there aren't any mods that cause memory leaks but it is well known that the stock game also suffers from a number of leaks (scene changes, especially reverts, engineer's report updating, etc.). Also, the constant turnover of memory allocations causes the free memory to become fragmented which can result in more memory being claimed from the OS to satisfy large requests even though the total of free memory is greater than needed.

Link to comment
Share on other sites

I would recommend testing your big plugins first, such as kopernicus and SCANsat, as those are more likely to contain a leak, followed by smaller plugins, than part packs.

Test by moving everything out of game data except the squad folder, the mod you are testing and its hard dependencies

Link to comment
Share on other sites

This plus ModuleManager.

A lot of parts I see.

Also try to start with disabling Trajectories. Some time ago I had suspicions on it but there's a high chance they have fixed them.

Memory rising over time does not necessarily point on memory leak in a mod. I guess parts and textures might be loaded dynamically as they are used. And never get unloaded than. So the problem might be in total quantity of mods.

Edited by Ser
Link to comment
Share on other sites

No, parts are all loaded up front, not dynamically as needed. That's why KSP is such an immense memory hog in the first place :P

I managed to narrow it down a little bit - it's largely scene changes. Whenever I enter or exit a building, switch to a vessel or revert a test flight, there's a small bump in memory usage that never goes away again. Over time it accumulates.

Removing Trajectories is easy enough, I'll test that right now.

Link to comment
Share on other sites

I managed to narrow it down a little bit - it's largely scene changes. Whenever I enter or exit a building, switch to a vessel or revert a test flight, there's a small bump in memory usage that never goes away again. Over time it accumulates.

I'm pretty sure that's just the stock game doing that, though a mod may be exacerbating the issue.

Link to comment
Share on other sites

Well, Trajectories wasn't a culürit. Better Buoyancy not either. I guess if there's no other option, I might eventually go and test plugin by plugin... though it'll take a while to motivate me to do that. I had hoped I could avoid it :(

A quick test with a pure stock instance though, sure. Let's see if I can get stock to leak. Tomorrow.

Link to comment
Share on other sites

No, parts are all loaded up front, not dynamically as needed. That's why KSP is such an immense memory hog in the first place :P

I managed to narrow it down a little bit - it's largely scene changes. Whenever I enter or exit a building, switch to a vessel or revert a test flight, there's a small bump in memory usage that never goes away again. Over time it accumulates.

Removing Trajectories is easy enough, I'll test that right now.

This is a stock memory leak that most people who aren't streamers doing a 24 hour (or some other ridiculous time frame) nonstop KSP livestream run into. That said, adding a lot of mods makes the issue occur far more frequently. I have a similar load of part mods and run into the same problems.

Link to comment
Share on other sites

Streetwind, speaking of scene changes, I have noticed that amount of used memory drops sometimes when exiting to KSP main menu

I already noticed that too! When I load up KSP, (many mods too) I have about 1.2, 1.3 gb used. When I quit KSP my memory usage goes around 900mb!

When I see this, Hey! It's time to play KSP again! RAM just grow up inside my PC!

Really now, for my experience, when I do a long mission, if the game do not crash and my lander lands on Kerbin, I always do a quicksave before recover because the lag is so much that I just know if I do that the game is gonna crash. Sometime it does not, others do, in any case, I quit KSP and restart it again. Fresh again. :)

Link to comment
Share on other sites

Kar, try not to quit KSP but just going to start menu, that was the thing I've noticed. Of course, if you quit any game back to OS you'll get all the memory back.

Link to comment
Share on other sites

Hello,

He meant Operating System I think.

This problem is well known.

I think atmosphere MOD makes it alot worse (climbs faster); it also has a memory overhead (about +500 then goes back to it's start point); I plan on using it and have to leave memory for it.

The memory creep is still there with no mods; best to try and see how fast memory creeps comparing MODS rather than comparing size.

cmdr zeta

Link to comment
Share on other sites

I already noticed that too! When I load up KSP, (many mods too) I have about 1.2, 1.3 gb used. When I quit KSP my memory usage goes around 900mb!

Going by my Windows experience. that sounds like Task Manager giving different numbers. The graph in the Performance tab is Physical RAM. The memory number shown under Processes is the total RAM, physical and virtual. That's the number for KSP that you need to be aware of.

If you're not running a big program, the Kernel and other permanent tasks stay in physical RAM. Load KSP and a lot will be paged to virtual RAM on disk. Something like the background Google Drive app spends most of its time just waiting, but when there's nothing happening it stays in physical RAM. When you exit KSP, the physical RAM being used by these parts will be much less.

64-bit Windows with enough physical RAM won't have anything delayed by virtual memory. How much is enough? Going by the address-space limits for 32-bit programs, 8GB of physical RAM should be. That 1.3GB wouldn't drop.

Link to comment
Share on other sites

  • 5 months later...
  • 6 months later...

I've allocated about 16 GB worth of virtual RAM in my Windows control panels (about twice the 8GB or physical RAM I have). And that did seem to improve performance a bit.

Lots of guides for doing that on Windows out there, but I can link to one if folks are in need.

Defragmenting the hard-drive where the game app and its assets lives also seems to have a small but noticeable effect.

Just now experimenting with this "-force-opengl" tweak to see how that works . . .

The thing I cannot find is: how to configure a specific application launcher (e.g., the KSP_64.exe launcher, or rather its shortcut) to use a specific amount of virtual memory. I have my suspicions that Windows is not allowing KSP_64.exe to use as much VM as it could use, and that might help.

In any event, thanks for this discussion. It didn't seem reasonable to me that the game (even a heavily modded on) would actually "need" more than 8GB of RAM to functional reasonably well, and the fact others have the same problem (and have noted it to have "leak" like characteristics) is edifying.

Link to comment
Share on other sites

17 hours ago, Diche Bach said:

I have my suspicions that Windows is not allowing KSP_64.exe to use as much VM as it could use, and that might help.

Pssst.... this discussion is from summer 2015, where 64bit KSP was not yet a thing that existed. :P Everyone played under 32bit, with a 3.5 GB hard cap on usable memory.

Also, the memory leak was later confirmed and fixed as a stock issue that was exacerbated (but not caused) by some mods. KSP doesn't leak memory like that anymore nowadays. Which doesn't discount the possibility of other memory leaks, of course. But frankly, ever since we got access to 64bit, I have had absolutely zero memory related problems.

Link to comment
Share on other sites

So am I the only one whose heavily modded KSP_64.exe eats up 95% of 8GB of RAM (not to mention the VGA's RAM)?

If so, how do I become a "cool" kid whose heavily modded build runs pretty good, i.e., how do I get my mod build optimized?

I realize that is a gigantic question, but maybe one of you sages, could just nudge me in the right direction with a little post??

I only ask because: I play many games that are very heavily modded (Skyrim with about 120 mods; Fallout 4 with probably ~90, etc.) and I have never observed the gigantic RAM usage I see with my modded KSP.

Link to comment
Share on other sites

It depends entirely on which mods you install. I've scratched on 9 GB myself, though I do have 16 in the machine, so...

Some mods are so large, they eat a gigabyte by themselves. And some mods consume practically nothing. People have had installs with over 100 mods in the 32bit days despite the limit of 3.5 GB, but if you try, you can easily consume twice as much with a quarter of the mods. As such, how many you have installed is fairly meaningless. It all depends on each individual mod.

As for why so much memory use? Because KSP loads all assets into memory at startup, as opposed to unpacking them on demand. This greatly increases memory use, but also shortens load times of scene changes (particluarly entering the editor or a flight scene) and costs less system performance (as long as there's enough memory available). It's also simpler to implement... always keep in mind that KSP started as a one-man, learning-by-doing project. And for the scope of the stock game, it's perfectly adequate even today. Limitations only begin to pop up once you do something like tripling or quadrupling the amount of parts and assets.

Edited by Streetwind
Link to comment
Share on other sites

The take away (which I had already guessed based on observing how the game behaves and hearing how my machine is whirring at various stages) would seem to be: mods which add lots of new assets (particular "parts") are the most likely to cause performance issues.

That is bad news for a gear fondler like me. I like nothing more than more parts than I can ever possible use

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...