The best thing with troubleshooting is to isolate the issue and keep good notes when the issue comes and when it goes.
Once you also have an understanding how to make the issue ( in your case, is that glitch constant or does it come and go ) it is then very easy to systematically isolate things.
In your case, switch the ram to the opposite slots, run with only one stick, then the others. Try to find out if it's the ram slot or the motherboard or the ram itself. Then you can isolate the sad by running a while on an external drive.
Repair technicians are very familiar with this process, and due to the volume of work they do, have better feel for what fails more often, have the tools to test booting your Mac from a clean OS externally, etc.
So even though you may not be as fast, skilled or familiar with troubleshooting by isolation, you can still use the same methodology to isolate this failure on your Mac.
I've been researching this very question for some time, and I've come to the conclusion that while there are several so-called "solutions" offered in various places, none of them really fixes the problem or makes the symptoms go away. The best I've found is techniques that change when inactive memory is swapped, such as the use of the purge
command you referred to. I believe that MacLemon is correct that swapping can be disabled only in entirety and not selectively, and so disabling the swapping of inactive memory would in practice be equivalent to disabling virtual memory altogether—which could be a workable solution on a machine with really large amounts of RAM, but is impractical on machines with a low maximum RAM capacity, such as MacBooks or Minis.
The reason that none of the ad-hoc purging solutions make the situation significantly better is that there are really only two ways to force OS X to clear inactive memory: the purge
command, or forcing allocation of all free memory (and since I'm not certain what method purge
uses, these two may actually be more or less the same). purge
, as you mentioned, takes a non-trivial amount of time to complete. Allocating all free memory simply accelerates the process by which the contents of inactive memory would be swapped out naturally, and so still takes up the same large amount of system resources. The only advantage of either of these solutions is that they allow you to choose when the swapping occurs, so it can be done before you would be normally trying to allocate that memory to something else. Whether that is actually useful to you depends on several factors, so the simplest way to find out is to just try it.
I've been testing a few of the memory-clearing utilities out there, and I've found that for me, manually forcing inactive swap requires more active monitoring of memory levels than is practical while I'm actually working, and using a utility that automatically forces the swap when free memory drops below a certain threshold is no better than letting the OS do it on its own, as I still have no control over when the swapping will occur and my apps will SPOD. So while there is an app that will do exactly what your alternative question asks for, that doesn't actually make the situation any less painful.
Until Apple's OS development team decides that the memory management system isn't working the way it's supposed to, and they figure out a way to make it work properly, the only real solution is to identify which apps are generating the most inactive memory and stop using them. In my situation, this has meant changing web browsers. I've been testing a variety of them, and Chrome is so far the one that seems to generate the least inactive memory, probably in part because every tab and every extension runs as a separate process, allowing the OS's native memory management to treat each one separately in terms of prioritizing swapping. Safari is the worst I've tried; starting with Safari 5.1, I could open a few tabs, do absolutely nothing, and watch the inactive memory rise rapidly in Activity Monitor—it would easily go from <1gb inactive to >3gb inactive within about five minutes, run the swap cycle, and then do the exact same thing. (Granted, memory that is doing nothing is exactly what makes it inactive in the first place, but it shouldn't create more inactive memory than was allocated active in the first place.) Safari 6 under Mountain Lion is a bit better, but not better enough to be worth switching back. Firefox, not being based on WebKit, ought to be better about this than either Safari or Chrome, but it has its own legacy of memory management problems, including a history of memory leaks, that make it no better in practice.
What would really fix the issue is if there was an option, likely a hidden option in the OS, telling the OS to simply dump the contents of inactive memory when needed instead of swapping its contents to disk. But I don't expect Apple to ever make such an option available.
Best Answer
kernel_task is not an actual process like the others you see in Activity Monitor, it is a kind of “virtual process” that actually represents the kernel itself.
This means that it is not kernel_task itself that performs some job and in the process writes to disk, rather the kernel is continually (many, many times per second often) asked by your running programs to do stuff on their behalf.
You won’t find any “template” or “fixed model” for how kernel_task behaves, as that depends on whatever the rest of the programs on your computer is doing.
You also write about swapping. This is done when the amount of free RAM is not sufficient to cover the requests from running programs. These requests are dependent on whatever you’re doing with your computer. For example if you’re running a web browser, some sites might require almost no RAM to display - and others might require lots and lots of RAM.
As for why it tends to be more after running your computer for a long time - that is actually quite logical. Over time you have probably run more and more different programs, have more things loaded in (open documents, web site tabs, etc), and even more that contribute to your total RAM Usage than when you just booted the computer.
Some programs might also leak memory due to bugs This means that long running programs request some memory, and then forget about it, never giving it back to the operating system, even though they’re no longer using it. The longer you keep programs running, the more leaks you’ll eventually have. You can reclaim the leaked memory by closing the program - or by rebooting the computer.