OSX Spotlight Hogs CPU

For the past couple of weeks, the fan on my PowerBook would just start spinning like crazy out of the blue. Checking the CPU usage didns’t really yield any satisfactory results. But I finally found the culprit — Spotlight.

According to Many Ayromlou, sometimes Spotlight does hog the CPU, most likely when it’s trying to index corrupted metadata. So I applied the fix suggested by the site:

1) Using the mdutil command-line utility in Terminal, turn off indexing for each of your drives. example:

1
$ sudo mdutil -i off /Volumes/<i>your_hard_drive_name</i>

2) Then use mdutil to remove the indexes from each drive

1
$ sudo mdutil -E /Volumes/<i>your_hard_drive_name</i>

3) Physically remove the .Spotlight directories from the root of each drive.

1
2
$ cd /
$ sudo rm -fr .Spotlight-V100

(do the same for your second or third drive) BE CAREFUL WITH THAT RM COMMAND! One typo could ruin your day.

4) Use mdutil again to turn indexing back on for each drive

1
$ sudo mdutil -i on /Volumes/<i>your_hard_drive_name</i>

5) Spotlight will now re-index all drives and should behave in a normal fashion. (No longer uses 60%-80% of your CPU)

As Spotlight tried to re-index my entire hard drive again, I snapped this shot…
Spotlight indexing

Even though it estimated 10+ hours to index all of 23GB of files on my hard drive, the actual time it took to index everything was more like 2 hours — a far more acceptable time.

All this was done while I was trying to feed Bryan, change his diaper, check my email, read the online forums from SCAD eLearning, browse through the news and send a homework-related mass email.