[OSX] mds going crazy on memory

I have recently added a 120GB OWC Mercury Extreme SSD to my Macbook Pro. Since 120GB really isn’t enough for me, I removed the SuperDrive and put the original hard-disk on a bracket in place of the SuperDrive. All is well, and the system is super fast.

But then I noticed that a process called mds was using ridiculous amounts of memory. Not to the point that it was slowing my system down and swapping out - I have 8GB of memory in my MBP - but enough to notice it wasn’t behaving like before. Now, mds is part of the Spotlight indexer, and Spotlight being the internal search engine for Mac OS X. Besides using memory, it is also going over the disks continuesly while indexing. Not good.

Going online to find a solution, I could not find a whole lot. Not that there is nothing to find - there is plenty - but because none of the solutions offered seemed to work.

Here is what I did:

- Clear the indexes. Idea is that if you remove the search index, it will re-index your drives and all should be well. It was not.
# mdutil -a -E

- Reboot. No joy.
- Disable Spotlight. This would fix the memory problem, but Spotlight is actually quite handy. Disabling it will also stop you from searching your e-mail and any other application that uses Spotlight. Not what I want.
# mdutil -a -i off
# mdutil -a -E
# launchctl unload -w com.apple.metadata.mds.plist


What I finally did, and this seems to have done the trick, is disable indexing on all drivers, remove the index, disable Spotlight, remove all Spotlight index related directories, clear my TimeMachine drive, and enable Spotlight again. After this, it immediately started to index my drives again and after it was finished, it is appearing to behave ever since.

# mdutil -a -i off
# mdutil -a -E
# launchctl unload com.apple.metadata.mds.plist
# rm -rf .Spotlight-V100
(on all drives!)

After this, I went in Disk Utility and erased the TimeMachine disk. When the disk was erased, I enabled Spotlight again.

# launchctl load com.apple.metadata.mds.plist

All is well.

What I think has happened, though honestly I have no idea if this is correct, is because I set my SSD up as a bootdisk and the HDD as a secondry which holds my user home directly, the TimeMachine backup sets are completely different to the situation before the SSD. This should not be an issue, but from what I read, Spotlight is tightly integrated into TimeMachine and possibly got confused about the structure file locations of the old backup sets being very different from the new situation. This may have triggered a continuous indexing action, every time it went into the TimeMachine disk and found locations to be different from reality. Again, I have no idea if this is really what happened. Fact of the matter is, after removing the indexes and clearing my TimeMachine backups, the Spotlight indexer is behaving nice again. It can go up to 800MB real memory while indexing (saw that while it was creating the new index, but it also drops between 70-80MB when it isn’t doing much. Whatever it was or is, I am happy with the result.