tags:

views:

458

answers:

3

Is there a reliable, quick, deterministic way (definitely not benchmark) to check whether system drive in Mac OS X is on Solid State Drive?

Is there any other indicator how well disk handles parallel access? I'm trying to adjust number of threads that my program is going to use for disk-bound operations.

I'm not interested in raw speed or seek time, only which type of access – serial or parallel – is faster for the drive. I don't expect users of my program to use iSCSI or RAID. SSD is my focus, anything else is nice-to-have.

Device Characteristics of IOAHCIBlockStorageDevice contains this information. How can I read it programmatically?


So far I've figured out it goes like this: (following is pseudocode)

match = IOBSDNameMatching(kIOMasterPortDefault,0,"disk0s2");
IOServiceGetMatchingServices(kIOMasterPortDefault, match, &iterator);
while(entry = IOIteratorNext(iterator)) {
   do {
     entry = IORegistryEntryGetParentEntry(nextMedia, kIOServicePlane, &entry);
     dict = IORegistryEntryCreateCFProperty(nextMedia, 
            CFSTR(kIOPropertyDeviceCharacteristicsKey), kCFAllocatorDefault, 0);
     [dict objectForKey:CFSTR(kIOPropertyMediumTypeKey)];
   } 
   while(!dict && entry); 
}

Edit: Here's complete source code. I've verified it works with Intel SSD and OCZ Vertex.

+4  A: 

Actually, I think you should go the benchmarking route, because it more accurately answers your question - you don't really care that the disk happens to be an SSD, you just care that the disk is really fast. What if the user is using a fast RAID setup, or a Fiber Channel array, or is using iSCSI?

Just read a bunch of random sectors from the underlying /dev/diskX and if it meets your requirements you can treat it as a "Fast" drive

Paul Betts
I don't have any baseline measurement of "fast". I would have to run two benchmarks and compare. Time spent for reliable benchmarking could be longer than time saved by choosing better strategy. Short benchmark is going to be unreliable, and it's tricky to take caches, latency, etc. into account. I'm looking for fast, deterministic solution. Doesn't need to support anything but SSD.
porneL
Fair enough but I will tell you this, that this is the approach that the Windows OS takes - if you see a bit of statistics, it'll be very easy to see; run 2 tests, one with a backwards sequential read (i.e. sector 5,4,3,2, etc), then a 2nd with a random sector read. If the variance is basically the same, you've got an SSD; on mechanical disks they'll be wildly different
Paul Betts
A: 

The number of threads? 1 is going to overwhelm any disk, SSD, RAID or not. Disk is slow, processor is fast. The OS is going to reorder your disk requests anyhow (or at least it should) to get the least head movements.

Stephan Eggermont
At least on Windows and Linux, the OS will not reorder disk requests for SSDs
Paul Betts
In my experience OS X doesn't do good job managing disk access (parallel access causes trashing rather than more efficient access). Multiple I/O-bound threads accessing SSD are faster - maybe just because there's some CPU overhead involved, but are faster nevertheless.
porneL
+1  A: 

If you're trying to get that kind of information, you're best guess is IOKit.

You can try some of it's functionality using the ioreg command line tool or the IORegistryExplorer.


Here's some code that might help you. It fetches all hard drives that aren't a RAID and aren't partitions. This isn't what you want, but it might get you started.

http://pastie.org/782219

I'll see tomorrow if I've got more time to provide a solution if this didn't help you enough.

Georg
Thanks! I've found that `Device Characteristics` of `IOAHCIBlockStorageDevice` has `Medium Type` `Solid State` which is exactly what I was looking for. How can I get this programmatically?
porneL
@porneL: I've added some code, that might help you.
Georg
Thanks. It was very helpful. Without it I'd be fruitlessly poking IOKit C++ API.
porneL
@porneL: It looks like you've figured it out on your own. I suppose you don't need any more help on this question, is this right?
Georg
Yes, I've got it figured out now. The code I've added to the question seems to work (It'll need some extra work to support File Vault, but I can get it from there - IOKit registry is no longer a mystery to me.)
porneL