Note: This was an internal support article I wrote at work a few years ago. People have found it useful and to this day I still see people running into these problems publicly. I hope you find it useful! Thanks to my work for letting me publish it here.
Other problems this article might improve upon:
- Why is kernel_task consuming a lot of CPU on my machine?
- Why is macOS so unresponsive at times?
- Why is my machine showing a beachball frequently?
- Why is
pmset -g thermlogshowing my system is thermally throttled?
I was having a big problem with the app I was working on at work & Xcode on my computer. Often kernel_task would take %50-%75 of my CPU usage and make my entire system unresponsive. I couldn’t find anything on how to inspect what kernel_task is doing. Articles just gave a list of possible solutions to kernel_task problems and told you to try them one by one to see which one it is, and unfortunately this one is fairly similar for kernel_task issues.
I did all of the actions below and it fixed my Xcode problems. The debugger doesn’t crash & freeze and my laptop doesn’t beachball nearly as much anymore. I wasn’t able to isolate the specific causes, but doing all of the things below, my system has been performing better. The vast majority of these tips apply to anybody developing software on a Mac.
Turn Off File Scanning Software
File scanners can consume a lot of CPU and I/O resources as they interact with each other. Dropbox’s support page on CPU usage outlines why this happens:
Some third-party apps access files in your Dropbox folder. Dropbox may interpret this access as edits to the files, and it will sync these perceived changes. If a third-party app continually requests access to your files, Dropbox will continue to sync, which will in turn lead to high CPU usage.
This loop usually occurs with third-party syncing apps, backup apps, and anti-virus or security software.
To isolate a third-party app as the cause of high CPU usage, temporarily disable each third-party app in your Activity Monitor or Task Manager and see if CPU usage for Dropbox decreases.
Software that are typical file watchers are:
- Antivirus / Anti-malware software (this is usually implemented as a kernel extension, so it’s CPU usage might show up as kernel_task in activity monitor). Carbon Black and Crowdstrike are examples of these anti-malware packages.
- Hopefully with the new Endpoint Security API, these applications won’t murder your computers performance as badly in the future.
- Apple suggests turning these off for now in their Xcode 11.4 Release Notes
- “Third-party “endpoint security” software may cause slow simulators, system freezes, or prevent debug processes from running in simulators reliably. This sometimes manifests as debugserver disconnections, or sends simulator applications a SIGKILL signal. (55853555) Workaround: Uninstall the third-party software.”
- Automatic backup software such as Time Machine, Crashplan or Backblaze
- File sync apps such as Dropbox, Box, or Google Drive File Stream
- Source control support in Xcode. Or at least turn off refresh local/server status automatically if you want to keep some git integration. You could also turn the git setting on selectively as you need it.
- BUCK / Bazel watchman
- Apple mds/spotlight. How to disable link
I turned off a portion of these items, but you should experiment with what works best for you.
Cool Your System Down
In macOS, kernel_task creates ‘fake’ CPU usage to reduce the total cpu load to reduce heat. It’s a macOS version of thermal throttling. You can also check if your CPU is thermally throttling with the
pmset -g thermlog command.
- Unplug your 2 monitor setup, make it the macbook + 1 monitor or no monitors. External monitors run off the discrete GPU, which generates a significant amount of heat by themselves.
- “getting down to a Speed Limit of 20 is highly correlated with whether the device has a high-resolution monitor (4k) or multiple lower resolution monitors. I’ve heard suggestions that macOS will prioritize the graphics chip to prevent visual tearing of the screen and the discrete processor can take up to 20W of the power/heat budget leaving very little left for the CPU.”
- A laptop cooling pad or fan can help keep your machine ventilated.
- Make sure the sun doesn’t directly shine on your computer.
- An open macbook might stay cooler than a closed macbook.
- The Apple Thunderbolt Display radiates heat on the bottom edge of the monitor. Leaving your laptop closed under it increases the ambient heat around your macbook pro. Move it away from there if you usually put it there.
- Even if you don’t have a thunderbolt display, don’t put your macbook around the heat outtakes of other devices in general
- Do not block the air outtakes at the back of the laptop around the screen hinge and the air intakes around the left and right sides of the macbook pro.
- This can happen when it is inside a small space, or when you put the macbook on a pillow or something else that is fluffy.
- Move your macbook to a colder environment
- Turn on your AC and put on a sweater
Charge Your USB-C MacBook From the Right Side vs the Left Side
- Due to the placement of the CPU or CPU temp sensor, charging from the left generates more heat around that part and thus the CPU thermally throttles itself more.
- Source: https://apple.stackexchange.com/questions/363337/how-to-find-cause-of-high-kernel-task-cpu-usage/363933#363933
Unload Third Party Kernel Extensions
- Look at what other third party kernel extensions (kexts) might be installed on your computer with the command: kextstat | grep -v com.apple
- Badly written kexts might be causing high kernel_task CPU usage. Look into uninstalling the bad software.
- You can also unload bad extensions with the command
sudo kextunload -b $extension_nameEx:
sudo kextunload -b com.raidcorp.raiddevicedriver. The software using the kext has to be killed before you can successfully unload the kext.
Give Enough Power to Your MacBook
- The 15”/16” macbooks need +87/96 W to power it fully when the CPU is at full throttle. Make sure you are not using a 60W power source. The white apple 87/96 W power bricks are a little bigger and heavier than the 60W ones and will say 87W on them vs 60W on them. If not, your battery will probably slowly deplete and the OS might not be letting it go as fast as it could due to a lack of power.
Other Possible Fixes
- Maybe using the apple thunderbolt monitor causes complications inside the kernel itself, I went from a Dell 4k & apple thunderbolt monitor setup to just a Dell 4k monitor setup. After I did so, I noticed less OS bugs when I plugged in and unplugged my monitors.
- Reset your SMC, it might be inducing high kernel_task usage.
- Minimize regenerating your project frequently with bazelw project / git pull. Keep it to once a day and necessary updates only so caches can do their job.
- It’s been recently reported that chrome might be causing performance problems on people’s machines due to it’s autoupdater: https://chromeisbad.com/ , but it has been contested: https://9to5mac.com/2020/12/14/chrome-slowing-down-mac-performance/ . A workaround is to uninstall chrome & it’s autoupdater and either use safari, firefox or another chromium browser such as brave or vivaldi.