Is MDS taking over your CPU on OS X? Try Spotless.

Jeff Mancuso June 24th, 2007

My 5 month old MacBook Pro often has the MDS process chewing about 45-50% of CPU at various points in the day. Given that MDS is supposed to sit around and casually index – so that Spotlight can quickly perform a search, this CPU usage pattern is a red flag. Chances are something is wrong with either the disk or the Spotlight metadata index [what MDS manages]. After using Disk Utility to verify the volume, I tried Spotless. It worked great.

spot10.jpg

Spotless is a nice little $15 nagware utility made by Fixamac Software that helps you delete and recreate the Spotlight metadata folder and index, so that it can let MDS rebuild from scratch. It offers a few other moderately useful features, but if MDS is getting aggressive, this makes it real easy to get a clean rebuild.

Update 8/11/09: JS points out comments that you can instruct MDS to clear out the metadata cache and rebuild from scratch using this command run from Terminal:
sudo mdutil -avE

This is effectively what Spotless does, but without the user interface.

  • ST

    you really shouldn’t pay for something like this. just learn to use mdutil—it’s only one command to turn indexing on off and another to force re-indexing.

  • http://www.expandrive.com Jeff Mancuso

    ST – how about you save everyone some money and tell us what command to enter! :)

  • Ryan

    Um.. looks like he did.. the command is mdutil.

    go to /Applications/Utilities/Terminal, start a shell, and type mdutil

  • http://www.expandrive.com Jeff Mancuso

    To clarify – I know about mdutil, but some other people arriving at this post might not feel awesome about rooting through a man page or USAGE printout.

  • kexofil

    Open a terminal: mdutil -i off

    By just typing mdutil you get some usage information.

    Also, the man-pages are not evil, to survive in a *nix environment you need to learn to read them.

  • SX

    sudo mdutil -a -v -i off to see that it turned off indexing on connected volumes

  • http://xentek.net/articles/475/is-mds-thrashing-your-os-x/ Is mds thrashing your OS X? « xentek

    [...] and Textmate is a no brainer, but I didn’t know what or how to address the problem with mds. Come to find out, mds is responsible for indexing in Spotlight. If its thrashing your CPU and hogging up your RAM, [...]

  • JS

    Erm… for those who are tired of hearing people say “read the man pages” for a Mac, the one simple command to clear out potentially corrupted metadata and rebuild the store from scratch (which is the feature of Spotless being discussed here) is:

    sudo mdutil -avE
    

    That is, sudo (because you have to have admin rights to run this), mdutil (the program that does the work for you) -a for “work on all volumes”, -v for “be verbose in telling me what you’re doing”, and -E for “erase the data store and rebuild it”.

    Honestly guys, why do we have to make every question an opportunity to be superior and arrogant? Yes, mdutil is the command. Did it not occur to you that the question was asking for the specific usage to accomplish this task? So why answer like you didn’t get that? Because you want to show that superior users can read the man pages? Because you feel it’s your responsibility to help people realize that they can’t survive on a Mac without being able to read man pages?

    Come on. This isn’t Slackware. This isn’t Gentoo. This isn’t Solaris. This nix platform is marketed specifically to people who don’t *want to have to RTFM to get by. Give them a break and just answer the questions.

  • MPf

    Thanks SO much, JS.

    I’m probably a bit more tech savvy than your average Mac user, but without clear guidance like yours, I’d be lost.

  • Aaron

    @JS: AMEN! There are a lot of little utilities that Apple includes in Mac OS X that aren’t standard *NIX utilities. This just happens to be one of them.

    By the way, this cleared up my 193% CPU usage of MDS under 10.6.

  • vonspace

    the same here…just installed 10.6 and mds was going 150% cpu usage….now with the sudo mdutil -avE trick works perfectly…thx to all..

  • socalbiker

    Any idea on why we have to use this unix script to solve a problem that shouldn’t exist? I’ve seen kernel_task equally being driven crazy. This code fixes mds, but what’s really driving this instability in 10.6.1?

  • socalbiker

    sudo mdutil -avE appears to have solved the problems. That and a disk repair. Apple should have some OS correction that limits this part of the indexing program.

    Can anyone recommend a good book on these support codes?

  • Chris K

    I had mds at 95% of CPU with 10.6.1. Just did the sudo mdutil -avE command, but a minute later mds was back along with mdworker at 95% combined. What’s up? Did I do something wrong?

  • bjc

    Is there any way of telling which drive is being indexed by mdutil at any given time?

  • bjc

    Woooo Whooo… didn’t want to sound like I couldn’t read… so looked at the man page for mdutil and found I could do this:

    mdutil -s -a

    This told me the status of indexing for all of my volumes. Status… simply whether indexing was enabled or disabled. So… I still don’t have my answer.

  • Steve

    Did you try :

    sudo mdutil -sav

    The v (verbose) may give you a bit more info.

    HTH

  • joe

    I got tired of the high cpu usage and just turned indexing off. Just as I did on my Windows machines. Google Desktop is actually a worthy substitue and I haven’t had any CPU usage problems with it yet.

  • http://twitter.com/parsifal SeanG

    This is a great tip. I suddenly started having lots of hard disk usage after setting up a Boot Camp partition (related?), and I’m suspicious now that it’s mds, so I’m rebuilding my indexes.

    I never used to hear anything out of my hard drive on my MBP before the Boot Camp partition was created — now I hear it rattling away all the time! Anyone else experience this?

  • Michael R. Wolf

    OK for the CPU question. Is there a way to put it on a memory diet? It’s currently taking 500MB real (650MB virtual) memory that could go to better use in Firefox or NeoOffice, the two pigs that I want to feed.

  • Carlos

    JS Thank you very much! I suffered the agony of a slow mac for two weeks, countless hours trying to figure this thing out. Thanks again.

  • Jeremy Pyne

    The cause of this process peaking out the cpu at a constant 100% seams to be related to having Boot Camp volumes. Simply dragging the Boot Camp volume to the trash to unmount t makes the process immediately drop down to 0% utilization. Not sure if there is a more permanent way to fix this, there is a way to add exclusions but that involves writing a file to the volume witch is read only. (Or maybe its related to the fact that it used to use the NTFS3G driver for read/write and I changed it back to the OSX native read only driver.)

  • http://www.jacobwcrosby.net Jacob W. Crosby

    Well, being a Mac lover myself, and finding it easy to use the terminal (Due to an abundance of experience with Linux) I have no problems with these occasional bumps along the way. However, for the majority of the ignorant folks on the PC side of things, this sort of stuff is “unacceptable”. How many terminal commands do you have to enter to repair functionality in windows, along with the disk permissions and the disk repair issues? Hell, most windows users do not even know they need to defrag. However, the windows folks would rather deal with a slow, virus laden, severely fragmented computer, because if everything works they don’t care for the most part, even if it has slowed to a crawl. Whereas OS X is rock solid 99% of the time, but when there is a problem, the solution is often a severe pain in the shitter… Though I would happily be inconvenienced for an hour than to be bogged down by needing an antivirus software to scan every single file I open….

    ~Jacob

  • Jeremy Pyne

    Better then the age old “Your gana have to reinstall windows!”.

  • mehmattski

    I had this problem with 10.6.4, driving my fan crazy with mds, and the unix command worked great!

    I would like to add that I had recently installed some (fairly beefy) software from .dmg files that were mounted. When I executed the command, it told me that indexing was now disabled on the dmg drives. So perhaps it’s the indexing of gigantic dmg files that’s eating CPU.

  • FrankR

    To see what Spotlight is actually doing (and what files it might be having problems with, try running this command in the terminal

    sudo fs_usage -w -f filesys mds mdworker | grep “/”

    which means sudo ==> allows command to operate at root – requires admin password fs_usage ==> command that logs what’s happening in the filesystem in real time -w ==> forces a wide, detailed report in terminal -f filesys ==> limits output to file system mds mdworker ==> further limits output to the Spotlight process ‘mds’ and ‘mdsworker’

    | grep “/” ==> passes the output above to the Unix grep which in turn displays only those lines that contain the “/” character – in other words file and directory names.

    (all this based on what I read over at http://superuser.com/questions/46195/why-does-mds-run-wild-in-mac-os-x-10-6/106932#106932

    If you see one file or directory appear over and over again, you can then open the Spotlight preferences panel and exclude it from Spotlight searches. You mav have to reboot to have it take effect.

  • neil

    same problem when i try the command it asks for a password (which i dont have) and wont let me type in that field. how do i get around it

  • neil

    sorry looked up that problem elsewhere and it solved it

  • http://NA Dave

    I’ve run the commands that JS and Frank R gave. Both were supposed to give detailed logs of what was happening while it was happening.

    All I got for the for the first one was :/

    All I for for the second one was an empty rectangular character.

    Why doesn’t Terminal show me what is happening in real time as I dictated by the command???

    My CPU is overloaded more than it ever was now after running these commands and I have no idea what they did or why they made the problem worse.

Grab the RSS feed
Follow ExpanDrive on Twitter Follow us on Twitter


Try ExpanDrive

If you’ve heard of SSH then you need ExpanDrive.



Try Strongspace

Awesome SFTP/rsync online storage by ExpanDrive.