Hello and welcome to my User Tip
You might be experiencing some performance issues with your Mac, spinning beach ball, just general slowness and you knew from your PC days about defragging computers.
Well that's for Windows because the way it writes files it breaks them all up, OS X doesn't do that on small files, so it eliminates the need for MOST users to require a regular defrag. Perhaps once every few years after many updates, upgrades, program installs and reinstalls may one require it on a Mac, then rarely again.
I outlined a safe way here that always gives you a bootable backup to check, plus it really optimizes the hard drive in the process.
First if your experiencing computer problems, backup your personal information to a storage drive first, then consult the fix it options as defragging won't necessarily solve problems in software.
So to begin with some facts:
1: Only hard drives require defragging. SSD's no need.
2: You don't need to regularly defrag a Mac's hard drive, OS X writes small files in one batch, eliminating a lot of the need to defrag a Mac regularly.
3: Hard drives are fastest at the beginning of the drive. and slowest at the very end. Data is first written on the top of the drive and works it's way down.However data doesn't magically move up to take available space, holes can develop with a lot of reads and writes.
4: The first 50% of the drive is faster than the second 50% due to more sectors in each track which the heads have less to move and can gather more data at one time.
5: Over time (like years) a Mac can slow down as the adding and reduction of data, OS X upgrades and normal operation tends to move data making it less optimized.
6: If one wants to create a Bootcamp or second partition on the boot drive, there might be OS X data near the bottom where the second partition will go, it's sometimes not easy to move this data further up on the drive.
7: If there are bad or failing sectors on the drive, it can substantially slow down read speeds and the spinning beach ball effect occurs.
8: I don't advise using defragmentation software on a "live" system, it's dangerous and if it messes up your stuck. If anyone has defragged a PC before knows it's never really complete in actuality.
So my solution is if your serious about performance, have large files like video that stretch across many sectors and want it in one piece, want to reduce bad sectors that can corrupt large and even small files, need to free up space for a partition or large file.
If you have Filevault enabled this procedure will not to work because it's one giant encrypted image, this is designed to acquire it's results by copying the parts of files into one piece again and back into a alphabetical order according to the root level directory for optimal results, especially of loading of Applications into memory.
How to proceed
1: Reduce your boot drive user content (files) so it's less than 50% of the drive filled (ideal) but not more than 80% filled. (not mandatory but preferred if you want to see the performance improve)
2: Use a blank powered external drive (formatted GUID and OS X Extended Journaled in Disk Utility) and a copy of Carbon Copy Cloner to clone the OS X boot partition (aka Macintosh HD) to the external drive using the default settings and a full clone.
3: Then reboot the machine holding the option key down, you can now boot from the clone using Startup Manager. Test the clone out for some time so your positive it's solid and reliable, catch any unknown issues.
4: Use Disk Utility to Secure Option Erase with the "Zero" or middle secure selection (on 10.7/10.8) the internal OS X boot partition (Macinstosh HD), this will "Zero" out all the bits, and when it reads it back for confirmation, map off any bad sectors in the process, never to be written to again. It will take some time and it's a very worthwhile step as failing sectors take longer to read from than perfect ones.
5: When completed, reverse clone. the external onto the internal partition. Run Disk Utility > Repair Permissions on both and all the OnyX (Macupdate.com) maintenance and cleaning aspects and reboot. OnyX cleans out the caches and lets them rebuild.
See #12 OnyX Routine here: Step by Step to fix your Mac
You will solve your Bootcamp partition formatting problem, your bad sectors problem, your defrag problems, corrupt or bloated caches and your optimization problems all in one batch. Also have a working bootable backup in the process which is loads safer than a live defrag.
Your Application's will be written to the "hot zone" the fastest part of the drive. They will load as fast as possible.
Your OS X system files will be written next, followed last by your User account data last which tends to grow, expand and contact, suffer with more changes so the defragmentation that occurs will occur at the end and into the slower sections of the hard drive, not where Applications and System are.
Sure over time with OS X updates, upgrades, new app installs and such you can start seeing a loss in performance again (over many years), but another clone/reverse clone will solve that problem.
Also if you want to backup and defrag Windows Bootcamp partition (CCC doesn't do that), there is WinClone for that. I don't know how effective it is as I haven't used it.
There you go enjoy the new performance!
Note: If this doesn't work to improve your performance, you likely don't have enough RAM, or the OS X version is to new/bloated for your hardware or perhaps some other issue. See this and perhaps it will assist in narrowing down the cause.
Note: I see some who have modded this User Tip down, likely from those who use defragging software on OS X successfully.
Please note my User Tip mentions "safely" because it creates a bootable clone that a user can boot and check out to make sure the defrag process was successful BEFORE subjecting their original drive to alteration.
If something goes wrong, the user has a alternate boot option at hand at all times, unlike what a defragging a live system can corrupt the only bootable option.
I also include advice about reducing hard drive space and zero erase of the target drive which will hopefully eliminate any detectable bad sectors, BEFORE the cloned data goes back onto the drive.
Since defragging OS X is a relatively rare occurrence done only after a few years of use, people's drives are usually messed up from other things when they are considering this option, why I advise people to make sure their software is functioning correctly before doing a defragging.
If I have offended software makers of defragging software, sorry. Your solution is not complete or safe enough in my opinion to withstand the various problems we experience on these forums.
If this User Tip has benefited you, please rate it below. Thanks