113

I've been having trouble with the MDS process running wild on my MacBook Pro 13". I've read on other support forums indicating that improperly formatted external drives can be an issue, but I have no drives connected. How can this problem be debugged and fixed?

If it helps, I do have a massive Mail archive. I have not turned off the indexing of this archive, because I haven't been able to find a correlation between the two, but I'm considering it.

(This might be normal right after doing an upgrade from 10.5 to 10.6, in which case the Spotlight search index needs to be rebuilt by mds. But in this case it's been a few weeks.)

Peter Mortensen
  • 12,090
  • 23
  • 70
  • 90
kubi
  • 1,298
  • 2
  • 10
  • 10
  • I did a 'sudo killall -9 mdworker' on my wife's macbook and that seems to have solved her disappearing memory problem. – copper.hat Mar 29 '14 at 06:10
  • For your information, this typical nightmare of `Spotlight` still happens on actual `Yosemite` versions. I can't tell for `El Capitan` yet. – dan Apr 18 '16 at 09:11

3 Answers3

115

To see what mds and more importantly its child mdworker is actually doing - use fs_usage to log what files it is opening:

sudo fs_usage -w -f filesys mdworker

Though there is a lot of unintelligable stuff in there, it does tell you when it opens a file to begin reading from it. Copying a PDF into my filesystem shows mdworker opening the file then immediately after lots of activity...

p.s. if you want a little less detail, this will just list the open file points:

sudo fs_usage -w -f filesys mdworker | egrep "open"
The Tentacle
  • 4,682
  • 1
  • 21
  • 18
  • I wasn't able to solve my problem (haven't seen the MDS issue lately), but I did learn some good debugging commands for situations like this, which is what I asked for. – kubi Sep 28 '09 at 18:20
  • 1
    The Tentacle's answer worked for me. Specifically: My spotlight processes were hanging at 100% CPU and never completed indexing. With `fs_usage` I was able to see exactly which files hung up `mdworker`. I deleted the offending folders (they likely had a symlink loop), restarted the Spotlight processes, and everything worked. – Nathan Bowers Feb 12 '11 at 23:44
  • 9
    IMPORTANT: once you figure out which folders or files are causing Spotlight processes to hang, exclude them from Spotlight indexing via the Spotlight "Privacy" settings tab. Sometimes the problem files are auto generated by OSX. – Nathan Bowers Feb 14 '11 at 21:40
  • 5
    If it really is the `mds` process that runs wild, just replace the `mdworker` in the command with `mds`. (This helped me to diagnose the issue when Spotlight suddenly decided to index my Bootcamp partition.) Thanks! – Jari Keinänen Mar 02 '11 at 18:38
  • This shows the file names but not the folders. Specifically, it is using a lot of CPU while building certain applications in MacPorts. I have already excluded /opt and I think it is indexing /tmp, where some of the compiler files are being written. How do I find the complete path of these files it is indexing? – highBandWidth Jun 09 '11 at 23:17
  • In my case, a series of backups/restores/OS reinstallations meant that Backblaze’s cache (/Library/Backblaze) was removed from Spotlight & Time Machine exclusion rules. – Alan H. Mar 09 '12 at 01:07
  • Hmm - since spotlight seems to be trying to be clever in the UI when disabling time machine backups (it notifies it will still be indexing parts of the drive) - I've resorted to command line stuff from here- http://www.mikesel.info/disable-spotlight/ - to try and stop it hitting it, – Danny Staple Jun 05 '12 at 16:42
  • This answer is gold! I had `mds` and `distnoted` periodically causing a CPU load of ~4. It reduced the battery life of my fairly young mid 2012 MBA 13" to merely 3:45 hrs! The root of the cause was how these processes kept working in Chrome's Application Support directory. Now, I get about 30min more battery life. – king_julien May 01 '13 at 09:27
  • Excellent receipe to analyze this problem. ---- I would suggest to add the following prerequisite since this is an easy to fix and frequent cause of `mds` looping: check the filesystem with `Disk Utility`. – dan Apr 18 '16 at 09:24
30

In the rare case that you would like to disable spotlight, use the following command:

sudo mdutil -a -i off

To re-enable:

sudo mdutil -a -i on
shaond
  • 685
  • 2
  • 7
  • 10
3

Just wanted to note that Spotlight/MDS may not be the issue at all. Errors with Time Machine (particularly where Time Machine takes a long time to "index") can create a situation where Spotlight tries to continually index the same files.

duffbeer703
  • 231
  • 1
  • 7