Photoshop scratch, system swap, and solid state
The first rule of Photoshop club is: don’t let Photoshop use the system disk as a scratch disk. It’s a good rule of thumb and it has helped many people get much better performance from their Photoshop systems. It’s helped even more people think they were getting better perfomance from their Photoshop systems.
The principle is straightforward: Photoshop is prone to using more memory than the systems on which they run have. When modern operating systems run out of memory, they begin using hard disk space as though it were memory. Hard disks are several hundred thousand times slower than RAM when it comes to moving information, so this can take a huge performance toll on your computer. If you have ever opened too many applications and been met with very poor responsiveness on your computer, as well as a lot of extra noise, that’s the hard disk working overtime pretending to be memory. And it’s a good thing; in the old days when computers ran out of memory, they’d just stop working.
The operating system is not the only one playing this game though. The authors of Photoshop, knowing that Photoshop can devour memory, have built routines that do very much the same thing. Rather than asking the operating system for more memory, Photoshop starts creating its own files on disk to hold the information that it would rather have in RAM. It does this in a way that is optimized for its own use. Since Photoshop knows which information is most critical to keep in fast memory, it can cherrypick the best data to spool off to disk.
###Swap versus scratch
Typically, an operating system’s virtual memory disk spooling is referred to as swap (think of it as swapping some disk space for an equal amount of memory) while Photoshop refers to this very similar process as scratch. You can think of it like writing down a phone number on a piece of scratch paper so that you can forget it and look back at the paper later.
Unlike the operating system’s swap space, which is generally not user-configurable, Photoshop provides user control over how it handles scratch. One can assign the drive to be used for Photoshop scratch, and even assign multiple drives and the order in which they ought to be used.
A natural rule one might therefore apply to the assignment of scratch drives therefore, is to assign the drives in order of how fast they are. That can get complicated because there are a number of variables that go into the speed at which one can write or access data from a disk, but basically you want to use up the space on the fast drive before starting to write to the slower disks.
###Can’t you see I’m busy reading and writing?
That’s not the end of it, however. Hard disks can’t really do two things at once, but they will try if you ask them to. Sometimes the information two processes are looking for will be on very different parts of the drive, causing the read and write heads to travel back and forth quite inefficiently, reading part of one file before moving back to write part of another file and then back to the first. Hard drive seek times are typically less than a hundredth of a second, but that can add up if the drive has to go back and forth a lot. When the operating system swaps memory to disk or Photoshop writes scratch data to disk, both want to do a lot of constant reading and writing. When these two processes are competing for the hard disk, it can make an already slow process even slower.
This is why Photoshop users typically prefer to instruct Photoshop to ignore the system disk and only use some other disk — any other disk — for scratch. Reading support forums for Photoshop, you’ll find this same advice doled out again and again: don’t use your system disk as a scratch disk.
Sadly, this often good advice is given both blindly and insistently. In peer support forums such as http://forums.adobe.com/community/photoshop you can see users refusing to help other users with performance tuning unless they first follow the gospel advice: don’t use your system disk as a scratch disk. It’s unfortunate, but sometimes understandable. When troubleshooting, you want to eliminate the obvious causes of issues before moving on to the esoteric.
The unfortunate part is this advice, while good in some circumstances, is by no means universal. Many users are working at resolutions intended for the Web and will never cause their systems to do a meaningful amount of swapping or use of scratch disks. To this objection comes the insistence: no, Photoshop always creates a scratch file. This is true, but if it isn’t done during time you’re waiting for the computer to finish its task, who cares? Many Photoshop users really don’t need to concern themselves with external drives to operate Photoshop any more than they need external hard drives to operate a word processor.
A potential pitfall is when the secondary drive is much slower than the system drive. This can be for a variety of reasons: hard drive controllers inside the computer for the most part are much faster than the external interfaces that are available. Thunderbolt supposedly introduces some very high throughput rates, but a USB or Firewire drive will be quite limited in speed compared to the system drive. Therefore there is a balancing act: does the slowness of the external interface slow the process down more than the competition for the system drive will? In most cases of course the answer is no. Using an external drive as a scratch disk ought to be good for performance.
###What if the internal drive is very, very fast?
The question became a big one for me when I began planning to purchase the workstation on which I make the files for my luxographic prints. I knew that I needed to get as much memory as I could and then get the fastest hard drives I could afford. In truth, I spent more than I could afford, even with the generous help of a friend who works at Apple and who gave me her «friends and family» discount when I bought the machine. Not only did I get a Macintosh with as much memory as was possible in 2008 (32GB), I bought it with a hardware RAID card and four 15,000 RPM SAS drives.
Sorting out the alphabet soup: SAS is an interface that handles multiple simultaneous requests better than the interface most computers come with. These relatively expensive drives spin at 15,000 revolutions per minute, which is about twice as fast as most desktop hard drives spin, and nearly three times as fast as many laptop hard drives. Rotation speed is not the only factor in reading and writing data so it doesn’t mean that these drives can move data two or three times faster than standard drives, but they are quite fast owing in part to the speed at which the platters spin.
RAID configuration can get quite complex, but the feature I wanted most was the additional speed that can be gained by writing to multiple drives at the same time. The electronics that control the drives can handle more data than can be physically written, so they can write to more than one drive at a time and keep track of where each part is stored. One file will end up stored across multiple disks, but it is an effective way to increase the speed.
I reasoned at the time that because all the data would be going through the same controller and all the disks would be written to and read from constantly that I would not need to set aside a separate drive as the conventional wisdom dictated. But I found myself up against the wall when it came time to ask configuration questions of the users that knew more than I did about Photoshop. It did not matter whether I had a RAID, they told me. If I wanted anything other than horrible performance out of Photoshop, I had to set aside a drive other than my system drive for Photoshop to use as scratch.
At the time I did not have the luxury of doing a lot of empirical testing, although I did enough testing to know that the configuration I settled on (one of my four drives for my system, the other three in a RAID0 configuration dedicated to scratch) was much faster than my previous computer. I spent a lot of money on that system, but it let me get as much done in an hour as I’d previously gotten done in a day. It was a big upgrade.
Since then, I’ve often wondered how true the blind assertion about second drives is. The price of solid state drives, which behave much more like RAM than hard drives, has come down somewhat dramatically and the size of the available drives has increased to the point where they could be considered a practical alternative to hard drives with spinning platters. What would happen with fast SSD drives, which don’t have read heads that have to travel from one side of a platter to another, when multiple sources tried to read and write at the same time?
Recently I had the opportunity to do more of this testing, and the results are enlightening. Of course, not everyone does the sort of memory-intensive Photoshop work that I do, but as memory shortages are the primary cause of Photoshop performance issues, doing basic transformations on the enormous files I work with is a good test of how a particular configuration will perform with regard to the use of scratch and swap.
###The gauntlet
I tried a variety of tests on my test machines and settled on just two, or really just one. I recorded the time for file open of a 3.5GB two-layer grayscale Photoshop .psb (large document format) file, and the time to rotate that file 18.5° clockwise. I did not include the results of any further transformations as the memory requirements exceeded the available hard drive space on two of the three test systems when scratch was limited to the system drive. Opening and rotating this file generated a Photoshop scratch file of about 110GB. Further transformations on the configurations that could handle the additional load didn’t yield any surprises, so I hope I’m not missing out on too much by comparing the one transformation.
It’s worth noting that Activity Monitor was run during all these tests, and not once under any configuration did CPU usage rise above 10%. This was not supposed to be a test of CPU power, but a test of swap and scratch handling.
###The configurations
Three machines were used for testing: a 2008 Mac Pro, a 2011 MacBook Air, and a 2011 iMac. The Mac Pro has two quad-core Xeon processors running at 2.8GHz, 32GB of 800MHz DDR2 RAM, an Apple RAID Pro card and four 300GB 15,000RPM SAS drives. I changed the RAID configuration around as will be noted later, and at one point I reduced the memory to 4GB to match the other systems, though only in one of the tests.
The iMac has a single quad-core i5 processor running at 3.1GHz, 4GB of 1333MHz DDR3 RAM, and a single 1TB 7200 RPM SATA hard drive.
The MacBook Air in some regards ought to be considered the lowest-end of the test machines. It has a dual-core i7 advertised at 1.8GHz and 4GB of 1333MHz DDR3 RAM. Two things to note about these specs however: first that the i7 is a variable-speed chip, and reportedly runs as fast as 2.9GHz. Second, the video memory for the MacBook Air is shared with the system memory. Therefore it should be considered to have close to 3.5GB of RAM in comparison to the iMac’s 4GB where the iMac has a graphics card with 1GB of RAM dedicated solely to video. The main difference that takes the MacBook Air out of its «low-end» pigeonhole is the hard drive: it does not have one. Instead the MacBook Air has a 256GB solid-state drive. As we will see, the solid state drive makes a world of difference when it comes to performance.
System | System/swap | PS Scratch | Open 3.5GB file | Rotate 18.5° |
---|---|---|---|---|
2008 Mac Pro (32GB) | Single JBOD drive | 3‑drive RAID5 | 1:37 | 8:00 |
Single JBOD drive | 3‑drive RAID0 | 1:29 | 6:33 | |
Single JBOD drive | 2‑drive RAID0 | 1:31 | 6:49 | |
Single JBOD drive | Second JBOD drive | 1:27 | 7:22 | |
4‑drive RAID5 | same as system | 1:33 | 7:33 | |
4‑drive RAID5 | 500GB Firewire 800 | 2:25 | 11:08 | |
2008 Mac Pro (4GB) | 4‑drive RAID5 | same as system | 5:22 | 14:41 |
2011 iMac | 7200 RPM SATA | same as system | 4:36 | 41:00 |
7200 RPM SATA | 500GB Firewire 800 | 5:06 | 57:05 | |
2011 MacBook Air | 256GB Apple SSD | same as system | 1:45 | 10:04 |
256GB Apple SSD | 500GB USB2 drive | 6:24 | 39:53 |
A few caveats: these tests were performed without any scientific rigor. These are all machines used for daily production, not specially-made testbeds. I did not attempt every possible configuration. For example, a 2‑drive RAID0 for system and a second 2‑drive RAID 0 for scratch, or a single 4‑drive RAID0 on the Mac Pro might be a good configuration for performance, but the increased chance of system failure due to drive failure is too great a risk for my production machine. The system configurations are different enough that only the broadest generalizations should be drawn.
Also, of these systems at the time the tests were run, only the iMac had Photoshop 12 (CS 5.1). The rest ran Photoshop 11 (CS4). CS5 has since been installed on the Mac Pro and it has shown itself to be slightly faster with large files on the Mac Pro due to 64-bit memory addressing, but that gain is (disappointingly) less than 5%. It does not seem to be a big difference, but don’t draw too many conclusions based on a comparison of any two systems by themselves.
That said, some conclusions seem clear. First, using a second drive for Photoshop swap only helps performance when the second drive is as fast or faster than the system drive. Unless your system drive is a slow 5400RPM drive, an external Firewire or USB drive will actually hurt performance. Fibre Channel or Thunderbolt drives should be able to help. A second internal drive if you have one or can install one can also help. But just plugging in a Firewire or USB2 drive and setting it as your first Photoshop scratch disk is likely to slow you down more than competition for your primary drive will.
###Memory is king
Check out the difference in speed on the Mac Pro configured with all four drives into RAID5 between 32GB of RAM and 4GB of RAM. It’s nearly twice as fast with 32GB of RAM. Juggling the drive configurations made significant differences in performance, but boosting the memory made the biggest difference.
###SSD is almost king
The MacBook Air without any external drives ran circles around the iMac. Now, the i7 chip in the MacBook Air has better multithreading than the i5 chip in the iMac, but with a lower maximum clock speed and half the cores, the best case scenario for the MacBook Air is that its processor could be almost as fast as the iMac’s. Between that and the lower available RAM, the only explanation for the MacBook Air finishing four times faster than the iMac is the faster solid-state drive. Note that when the Mac Pro was reduced to 4GB of RAM, it actually finished with an almost 50% greater time than the MacBook Air. Granted, the Mac Pro was not tested in all the RAID configurations at 4GB than it was at 32GB; it might have been useful to time the Mac Pro with the dedicated three-drive RAID0 and only 4GB of RAM but it seems clear that the biggest performance difference there came from the memory, not the RAID configuration, and it is almost certain that the solid state drive outperforms the fastest RAID I could have put together with this hardware.
Solid state drives are still pretty expensive, but then again, so are 15,000 RPM hard drives. Add a few hundred dollars for a hardware RAID controller and the multiple drives that are needed for a RAID, and I no longer see any wisdom in using spinning disks for a workstation. For server situations where redundancy is needed as a failsafe against drive failure, hardware RAID still makes sense.
This is a pragmatic question, so my hope here is not that anyone will use this post to bully anyone over the question of Photoshop performance tuning and configuration. You will want to test and experiment yourself to try to get the best performance. Performance isn’t the only question either, even for someone who works with ginormous files. After all this, I ended up leaving the Mac Pro with all four drives in a RAID5 configuration. It’s not the fastest of the tested options, but if I lose a drive I’ll have time to get a replacement before losing all my data. That’s worth an extra forty-five seconds here and there.
Not that great…
Considering 32GB is more than enough to complete the 3.5GB file rotation solely in memory only gives you twice the performance suggests something is wrong with this test. If PS were actually processing the file only in RAM, that 3.5GB rotate operation would only take a few seconds. Maybe cache levels/history settings would change this much more, but it seems it has a self-defeating method of handing files when it has more than enough memory to do it only in the memory.
I currently own a notebook with 32GB memory, and making a 20GB RAMdisk for PS cache to trick it into performing %100 of operations in the memory boosts an operation like this significantly. You need to set the cache levels and history fairly low if you’re going to edit a file that large with more than a few global filters, though.
Ah crap, somehow I missed
Ah crap, somehow I missed where you mentioned the 120GB of scratch photoshop ate to do the image rotation.
So, now I wanna know why it takes that much space just to rotate. lol. That’s crazy.
So I created a 35000×35000
So I created a 35000×35000 document, filled it with non-uniform color noise, and rotated it, and it took 53 seconds and generated no excess scratch data. I can understand that my processor is faster, but I don’t get at all where the massive 120GB scratch use comes from. 53 seconds is only enough time for my scratch HDD to write 3.1GB at top speeds (60MB/sec x 53 seconds)
For having 32GB of RAM methinks somethings wrong with your system since its generating such a horridly large scratch file.
Big files
Idiot me will have to find the file that I used to be sure, but I believe your tests are done with a much smaller file than I used. 35,000×35,000 would be 1.225MB, and even non-uniform noise will compress pretty well losslessly. 3.5GB on disk could be a much bigger file when opened.
You did not say how much faster your processor is than mine, but that wouldn’t surprise me if it were a factor. 2.8GHz isn’t too bad these days but it’s not top of the line, and new processors at the same clock speed get about twice as much done in the same time. Also, running with eight cores gives me almost no advantage in Photoshop which is almost entirely singlethreaded (neccesarily so due to the nature of the transformations it does — Adobe has done a pretty good job of utilizing multiple processors when possible.) Furthermore, a more modern system will have DDR3 1333MHz (or if you’re really ‘1337 up to 19.2GHz quad-channel) RAM instead of my DDR2-800.
Your suggestion of creating a RAMdisk is an excellent one considering that I’m still running CS4 which is 32-bit and directly accesses only up to 8GB. Though I was surprised to see only a minute (my•newt, not minn•nut) speed advantage when I ran the trial of Photoshop CS5.5 which, in 64-bit mode claimed to see all 32GB of memory.
OK, writing all that gave me time to reinstall Photoshop (when I reconfigured my RAID apparantly I hosed my registration credentials) so now I can look at the file size (assuming I can find the right 3.5GB file.)
The first file I opened is only one layer, 3.54GB on disk, grayscale 59840×59840. That doesn’t sound like there’s (even lossless) compression turned on there. I’m guessing that your 35,000×35,000 was 3‑byte color, which would make it about 3.6GB, right? After 18.5° rotation, that becomes 44,297×44,297 or roughly 5.5GB. My grayscale file goes to 75,736×75,736 — roughly the same. Add the second layer (which if empty would not increase the file size but will nevertheless increase memory requirement and Photoshop would need at least 25GB to do what it does, and 21.5GB of that will automatically spool to disk (again, why your suggestion of creating a RAMdisk is such a good one — at least for CS4 or earlier on the Mac. You Windows people got 64-bit memory addressing with CS4 and I’ll assume that I did something wrong to cripple my CS5.5 trial.) Leaving 19 more levels of undo enabled will add to that dramatically. If my maths are correct that’s another 105GB and it wouldn’t surprise me if Photoshop allocates all of that before it is used.
Keep in mind that the point of the test was to compare the speed of different drive configurations, not to see how well I could optimize Photoshop in all regards. One of the machines was not mine and I did not want to mess with someone else’s settings. The important thing is that the Photoshop installations were configured the same, which I can mostly vouch for.
A little later I’ll try these same tests again with my current configuration on the Mac Pro (3‑drive RAID for system, 1 JBOD sitting idle) since this appears not to be a configuration I ran this test on.