Can any Darwin experts answer a kernel question for me?

Discussion in 'macOS' started by foidulus, May 15, 2013.

  1. foidulus macrumors 6502a

    Jan 15, 2007
    I'm wondering if there are any Darwin experts here who can answer a question for me regarding page fragmentation on OS X.

    I recently upgraded to 16 gigs and overall I love it, but I have noticed that the kernel_task seems to eat up an increasingly large amount of memory as time goes on(it's something like 500 megs when I first start up and it's about 2.0 right now, after going for about a week). I'm a developer and frequently launch lots of processes(dev, test, dev, test etc) and have a large amount of web content open. I'm thinking the reason for the kernel memory growth is page fragmentation, the kernel has to keep track of an increasingly large # of page pointers since it runs out of un-allocated, contiguous space in memory and has to split up memory requests into disjoint pages..... and doesn't ever seem to defragment them.

    I know that there has been a lot of work on Linux to defrag pages(not a trivial operation by any stretch of the imagination), but I'm curious if there is anything in Darwin that does something similar? If not I guess I need to start rebooting more often :p
  2. benwiggy macrumors 68020

    Jun 15, 2012
    I just rebooted and kernel_task is running at about 2Gb. It's pretty consistent at that level, even after weeks of running.
  3. cody92 macrumors newbie

    May 3, 2013
    You could be right, but I'm thinking that Mac OS would have implemented some kind of page defragging like linux. It could also be possible that more kernel threads(or page tables like you said or some other kernel structure) are allocated and not deallocated unless under memory pressure. This is probably a performance optimization. At a point in time that you have a ton of applications open, it probably adds to the pool of needed kernel structures to handle these processes. It probably inflates and stays that way, since there is no reason to deallocate yet.

    I bet if you open a couple applications that use a lot of memory(to the brink of ram capacity probably), you will see the kernel_task decrease its memory usage since it is under memory pressure.

    I just started my Air and the kernel_task is using 850MB(on a 4GB ram machine). But I bet if you look on an older Mac Air with only 2GB of ram, it will be using less, since there is more memory pressure. The optimization of having preallocated memory probably won't help if it causes page faults, so it deflates.
  4. cody92 macrumors newbie

    May 3, 2013
    Just tried testing the theory but didn't have enough memory hungry apps going(was only using 1.5-2.5GB). I could get it to go, but don't have time at the moment.

    I did notice kernel_task decreasing memory usage the more applications I opened. Not enough to say for sure.

Share This Page