Chinaunix首页 | 论坛 | 博客
  • 博客访问: 960035
  • 博文数量: 584
  • 博客积分: 2293
  • 博客等级: 大尉
  • 技术积分: 3045
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-28 11:15
文章分类

全部博文(584)

文章存档

2012年(532)

2011年(47)

2009年(5)

我的朋友

分类: 系统运维

2011-12-30 03:10:53

The purpose of this document is to describe how IOs are queued with SDD, SDDPCM, the disk device driver and the adapter device driver, and to explain how these can be tuned to increase performance. This information is also useful for non-SDD or SDDPCM systems.


Where this stuff fits in the IO stack
Following is the IO stack from the application to the disk:
                  Application
                  File system (optional)
                  LVM (optional)
                  SDD or SDDPCM (if used)
                  hdisk device driver
                  adapter device driver
                  interconnect to the diskSystem przyłączenia dysku
                  Disk subsystem
                  fig.1
Note that even though the disk is attached to the adapter, the hdisk driver code is utilized before the adapter driver code. So this stack represents the order software comes into play over time as the IO traverses the stack. Why do we need to simultaneously submit more than one IO to a disk?
This improves performance. And this would be performance from an application’s point of view. This is especially important with disk subsystems where a virtual disk (or LUN) is backed by multiple physical disks. In such a situation, if we only could submit a single IO at a time, we’d find we get good IO service times, but very poor throughput.
Submitting multiple IOs to a physical disk allows the disk to minimize actuator movement (using an “elevator” algorithm) and get more IOPS than is possible by submitting one IO at a time. The elevator analogy is appropriate. How long would people be waiting to use an elevator if only one person at a time could get on it? In such a situation, we’d expect that people would wait quite a while to use the elevator (queueing time), but once they got on it, they’d get to their destination quickly (service time).


Where are IOs queued?
As IOs traverse the IO stack, AIX needs to keep track of them at each layer. So IOs are essentially queued at each layer in the IO stack (fig.1). Generally, some number of in flight IOs may be issued at each layer and if the number of IO requests exceeds that number, they reside in a wait queue until the required resource becomes available. So there is essentially an “in process” queue and a “wait” queue at each layer (SDD and SDDPCM are a little more complicated)..

At the file system layer, file system buffers limit the maximum number of in flight IOs for each file system. At the LVM layer, hdisk buffers limit the number of in flight IOs. At the SDD layer, IOs are queued if the dpo device’s attribute, qdepth_enable, is set to yes (which it is by default). Some releases of SDD do not queue IOs so it depends on the release of SDD. SDDPCM on the other hand does not queue IOs before sending them to the disk device driver. The hdisks have a maximum number of in flight IOs that’s specified by it’s queue_depth attribute. And FC adapters also have a maximum number of in flight IOs specified by num_cmd_elems. The disk subsystems themselves queue IOs and individual disks can accept multiple IO requests. Here are an ESS hdisk’s attributes:

# lsattr -El hdisk33
PR_key_value none Reserve Key True
location Location Label True
lun_id 0x5515000000000000 Logical Unit Number ID True
lun_reset_spt yes Support SCSI LUN reset True
max_transfer 0x40000 N/A True
node_name 0x5005076300c096ab FC Node Name False
pvid none Physical volume identifier False
q_type simple Queuing TYPE True
qfull_dly 20 delay in seconds for SCSI TASK SET FULL True
queue_depth 20 Queue DEPTH True
reserve_policy single_path Reserve Policy True
rw_timeout 60 READ/WRITE time out value True
scbsy_dly 20 delay in seconds for SCSI BUSY True
scsi_id 0x620713 SCSI ID True
start_timeout 180 START unit time out value True
ww_name 0x5005076300cd96ab FC World Wide Name False

The default queue_depth is 20, but can be changed to as high as 256 for ESS, DS6000 and DS8000. Here’s a FC adapter’s attributes:

# lsattr -El fcs0
bus_intr_lvl 65703 Bus interrupt level False
bus_io_addr 0xdec00 Bus I/O address False
bus_mem_addr 0xe8040000 Bus memory address False
init_link al INIT Link flags True
intr_priority 3 Interrupt priority False
lg_term_dma 0x800000 Long term DMA True
max_xfer_size 0x100000 Maximum Transfer Size True
num_cmd_elems 200 Maximum number of COMMANDS to queue to the adapter True
pref_alpa 0x1 Preferred AL_PA True
sw_fc_class 2 FC Class for Fabric True

The default queue depth (num_cmd_elems) for FC adapters is 200 but can be increased up to 2048. Here’s the dpo device’s attributes for one release of SDD:

# lsattr -El dpo
Enterpr_maxlun 600 Maximum LUNS allowed for Enterprise Products True
Virtual_maxlun 512 Maximum LUNS allowed for Virtualization Products False
persistent_resv yes Subsystem Supports Persistent Reserve Command False
qdepth_enable yes Queue Depth Control True

When qdepth_enable=yes, SDD will only submit queue_depth IOs to any underlying hdisk (where queue_depth here is the value for the underlying hdisk’s queue_depth attribute). When qdepth_enable=no, SDD just passes on the IOs directly to the hdisk driver. So the difference is, if qdepth_enable=yes (the default), IOs exceeding the queue_depth will queue at SDD, and if qdepth_enable=no, then IOs exceed the queue_depth will queue in the hdisk’s wait queue. In other words, SDD with qdepth_enable=no and SDDPCM do not queue IOs and instead just pass them to the hdisk drivers.
Note that at SDD 1.6, it’s preferable to use the datapath command to change qdepth_enable, rather than using chdev, as then it’s a dynamic change, e.g., datapath set qdepth disable will set it to no. Some releases of SDD don’t include SDD queueing, and some do, and some releases don’t show the qdepth_enable attribute. Either check the manual for your version of SDD or try the datapath command to see if it supports turning this feature off.

If you’ve used both SDD and SDDPCM, you’ll remember that with SDD, each LUN has a corresponding vpath and an hdisk for each path to the vpath or LUN. And with SDDPCM, you just have one hdisk per LUN. Thus, with SDD one can submit queue_depth x # paths to a LUN, while with SDDPCM, one can only submit queue_depth IOs to the LUN. If you switch from SDD using 4 paths to SDDPCM, then you’d want to set the SDDPCM hdisks to 4x that of SDD hdisks for an equivalent effective queue depth. And migrating to SDDPCM is recommended as it’s more strategic than SDD.

Both the hdisk and adapter drivers have an “in process” and “wait” queues. Once the queue limit is reached, the IOs wait until an IO completes, freeing up a slot in the service queue. The in process queue is also sometimes referred to as the “service” queue.

It’s worth mentioning, that many applications will not generate many in flight IOs, especially single threaded applications that don’t use asynchronous IO. Applications that use asynchronous IO are likely to generate more in flight IOs.What tools are available to monitor the queues?
For AIX, one can use iostat (at AIX 5.3 or later) and sar (5.1 or later) to monitor some of the queues. The iostat -D command generates output such as:

hdisk6 xfer: %tm_act bps tps bread bwrtn
4.0  2.2M  19.0  0.0  2.2M
read: rps avgserv minserv maxserv timeouts fails
  0.0  0.0  0.0  0.0  0 0
write: wps avgserv minserv maxserv timeouts fails
  19.0  38.9  1.1  190.2  0 0
queue: avgtime mintime maxtime avgwqsz avgsqsz sqfull
15.0  0.0  83.7  0.0  0.0  136

Here, the avgwqsz is the average wait queue size, and avgsqsz is the average service queue size. The average time spent in the wait queue is avgtime. The sqfull value has changed from initially being a count of the times we’ve submitted an IO to a full queue, to now where it’s the rate of IOs submitted to a full queue.
The example report shows the prior case (a count of IOs submitted to a full queue), while newer releases typically show decimal fractions indicating a rate. It’s nice that iostat -Dseparates reads and writes, as we would expect the IO service times to be different when we have a disk subsystem with cache. The most useful report for tuning is just running “iostat -D” which shows statistics since system boot, assuming the system is configured to continuously maintain disk IO history (run # lsattr -El sys0, or smitty chgsys to see if the iostat attribute is set to true).

The sar -d command changed at AIX 5.3, and generates output such as:

16:50:59  device %busy avque  r+w/s Kbs/s avwait avserv
16:51:00 hdisk1    0   0.0    0     0      0.0    0.0
       hdisk0      0   0.0    0     0     0.0     0.0

The avwait and avserv are the average times spent in the wait queue and service queue respectively. And avserv here would correspond to avgserv in the iostat output. The avquevalue changed; at AIX 5.3, it represents the average number of IOs in the wait queue, and prior to 5.3, it represents the average number of IOs in the service queue.

SDD provides the datapath query devstats and datapath query adaptstatscommands to show hdisk and adapter queue statistics. SDDPCM similarly has pcmpath query devstats and pcmpath query adaptstats. You can refer to the SDD manual for syntax, options and explanations of all the fields. Here’s some devstats output for a single LUN:

Device #: 0
=============
Total Read Total Write Active Read Active Write Maximum
I/O: 29007501 3037679 1 0 40
SECTOR: 696124015 110460560 8 0 20480


Transfer Size: <= 512 <= 4k <= 16K <= 64K > 64K
21499 10987037 18892010 1335598 809036


and here’s some adaptstats output:


Adapter #: 0
=============
Total Read Total Write Active Read Active Write Maximum
I/O: 439690333 24726251 7 0 258
SECTOR: 109851534 960137182 608 0 108625


Here, we’re mainly interested in the Maximum field which indicates the maximum number of IOs submitted to the device since system boot. Note that Maximum for devstats will not exceed “queue_depth x # paths” for SDD when qdepth_enable=yes. But Maximum foradaptstats can exceed num_cmd_elems as it represents the maximum number of IOs submitted to the adapter driver and includes IOs for both the service and wait queues. If, in this case, we have 2 paths and are using the default queue_depth of 20, then the 40 indicates we’ve filled the queue at least once and increasing queue_depth can help performance.

One can similarly monitor adapter queues and IOPS: for adapter IOPS, run iostat -at <# of intervals> and for adapter queue information, run iostat -aD, optionally with an interval and number of intervals.

How to tune?
First, one should not indiscriminately just increase these values. It’s possible to overload the disk subsystem or cause problems with device configuration at boot. So the approach of adding up the hdisk’s queue_depths and using that to determine the num_cmd_elems is not wise. Instead, it’s better to use the maximum IOs to each device for tuning. When you increase the queue_depths and number of in flight IOs that are sent to the disk subsystem, the IO service times are likely to increase, but throughput will increase. If IO service times start approaching the disk timeout value, then you’re submitting more IOs than the disk subsystem can handle. If you start seeing IO timeouts and errors in the error log indicating problems completing IOs, then this is the time to look for hardware problems or to make the pipe smaller.

A good general rule for tuning queue_depths, is that one can increase queue_depths until IO service times start exceeding 15 ms for small random reads or writes or one isn’t filling the queues. Once IO service times start increasing, we’ve pushed the bottleneck from the AIX disk and adapter queues to the disk subsystem. Two approaches to tuning queue_depth are 1) use your application and tune the queues from that or 2) use a test tool to see what the disk subsystem can handle and tune the queues from that based on what the disk subsystem can handle. The ndisk tool (part of the nstress package available on the internet at ) can be used to stress the disk subsystem to see what it can handle. The author’s preference is to tune based on your application IO requirements, especially when the disk is shared with other servers.Caches will affect your IO service times and testing results. Read cache hit rates typically increase the second time you run a test and affect repeatability of the results. Write cache helps performance until, and if, the write caches fill up at which time performance goes down, so longer running tests with high write rates can show a drop in performance over time. For read cache either prime the cache (preferably) or flush the cache. And for write caches, consider monitoring the cache to see if it fills up and run your tests long enough to see if the cache continues to fill up faster than the data can be off loaded to disk. Another issue when tuning and using shared disk subsystems, is that IO from the other servers will also affect repeatability.

Examining the devstats, if you see that for SDD, the Maximum field = queue_depth x # pathsand qdepth_enable=yes, then this indicates that increasing the queue_depth for the hdisks may help performance – at least the IOs will queue on the disk subsystem rather than in AIX. It’s reasonable to increase queue depths about 50% at a time.Regarding the qdepth_enableparameter, the default is yes which essentially has SDD handling the IOs beyondqueue_depth for the underlying hdisks. Setting it to no results in the hdisk device driver handling them in it’s wait queue. In other words, with qdepth_enable=yes, SDD handles the wait queue, otherwise the hdisk device driver handles the wait queue. There are error handling benefits to allowing SDD to handle these IOs, e.g., if using LVM mirroring across two ESSs. With heavy IO loads and a lot of queueing in SDD (when qdepth_enable=yes) it’s more efficient to allow the hdisk device drivers to handle relatively shorter wait queues rather than SDD handling a very long wait queue by setting qdepth_enable=no. In other words, SDD’s queue handling is single threaded where there’s a thread for handling each hdisk’s queue. So if error handling is of primary importance (e.g. when LVM mirroring across disk subsystems) then leave qdepth_enable=yes. Otherwise, setting qdepth_enable=no more efficiently handles the wait queues when they are long. Note that one should set theqdepth_enable parameter via the datapath command as it’s a dynamic change that way (using chdev is not dynamic for this parameter).

If error handling is of concern, then it’s also advisable, assuming the disk is SAN switch attached, to set the fscsi device attribute fc_err_recov to fast_fail rather than the default ofdelayed_fail. And if making that change, I also recommend changing the fscsi device dyntrkattribute to yes rather than the default of no. These attributes assume a SAN switch that supports this feature.

For the adapters, look at the adaptstats column. And set num_cmd_elems=Maximum or 200 whichever is greater. Unlike devstats with qdepth_enable=yes, Maximum for adaptstats can exceed num_cmd_elems.

Then after running your application during peak IO periods look at the statistics and tune again.

It’s also reasonable to use the iostat -D command or sar -d to provide an indication if thequeue_depths need to be increased.

The downside of setting queue depths too high, is that the disk subsystem won’t be able to handle the IO requests in a timely fashion, and may even reject the IO or just ignore it. This can result in an IO time out, and IO error recovery code will be called. This isn’t a desirable situation, as the CPU ends up doing more work to handle IOs than necessary. If the IO eventually fails, then this can lead to an application crash or worse.

Queue depths with VIO
When using VIO, one configures VSCSI adapters (for each virtual adapter in a VIOS, known as a vhost device, there will be a matching VSCSI adapter in a VIOC). These adapters have a fixed queue depth that varies depending on how many VSCSI LUNs are configured for the adapter.
There are 512 command elements of which 2 are used by the adapter, 3 are reserved for each VSCSI LUN for error recovery and the rest are used for IO requests. Thus, with the default queue_depth of 3 for VSCSI LUNs, that allows for up to 85 LUNs to use an adapter: (512 – 2) / (3 + 3) = 85 rounding down. So if we need higher queue depths for the devices, then the number of LUNs per adapter is reduced. E.G., if we want to use a queue_depth of 25, that allows 510/28= 18 LUNs.We can configure multiple VSCSI adapters to handle many LUNs with high queue depths. each requiring additional memory. One may have more than one VSCSI adapter on a VIOC connected to the same VIOS if you need more bandwidth.

Also, one should set the queue_depth attribute on the VIOC’s hdisk to match that of the mapped hdisk’s queue_depth on the VIOS.

For a formula, the maximum number of LUNs per virtual SCSI adapter (vhost on the VIOS or vscsi on the VIOC) is =INT(510/(Q+3)) where Q is the queue_depth of all the LUNs (assuming they are all the same).

Note that to change the queue_depth on an hdisk at the VIOS requires that we unmap the disk from the VIOC and remap it back.


A special note on the FC adapter max_xfer_size attribute
This attribute for the fscsi device, which controls the maximum IO size the adapter device driver will handle, also controls a memory area used by the adapter for data transfers. When the default value is used (max_xfer_size=0×100000) the memory area is 16 MB in size.
When setting this attribute to any other allowable value (say 0×200000) then the memory area is 128 MB in size. This memory area is a DMA memory area, but it is different than the DMA memory area controlled by the lg_term_dma attribute (which is used for IO control). This applies to the 2 Gbps FC adapters. The default value for lg_term_dma of 0×800000 is usually adequate.

So for heavy IO and especially for large IOs (such as for backups) it’s recommended to set max_xfer_size=0×200000.

The fcstat command can also be used to examine whether or not increasingnum_cmd_elems or max_xfer_size could increase performance

# fcstat fcs0
...
FC SCSI Adapter Driver Information
No DMA Resource Count: 0
No Adapter Elements Count: 0
No Command Resource Count: 0

This shows an example of an adapter that has sufficient values for num_cmd_elems andmax_xfer_size. Non zero value would indicate a situation in which IOs queued at the adapter due to lack of resources, and increasing num_cmd_elems and max_xfer_size would be appropriate.

Note that changing max_xfer_size uses memory in the PCI Host Bridge chips attached to the PCI slots. The salesmanual, regarding the dual port 4 Gbps PCI-X FC adapter states that “If placed in a PCI-X slot rated as SDR compatible and/or has the slot speed of 133 MHz, the AIX value of the max_xfer_size must be kept at the default setting of 0×100000 (1 megabyte) when both ports are in use. The architecture of the DMA buffer for these slots does not accommodate larger max_xfer_size settings“.

If there are too many FC adapters and too many LUNs attached to the adapter, this will lead to issues configuring the LUNs. Errors will look like:So if you get these errors, you’ll need to change the max_xfer_size back to the default value. It’s worth knowing that for the SVC, the current SVC node limit is 10,000 in-flight SCSI commands per node from the host. There is also a limit of 2048 in-flight IOs per port. So one would want to be sure that where N is number of LUNs served by a node, and Q is the queue depth for the LUN, that N x Q <= 10,000.
Finally, you may want to consider switching to SDDPCM rather than SDD. It's a fairly quick change, but does require a short outage. This will affect your queue_depths, in that with SDDPCM the default queue_depth is 20 for an hdisk, with with SDD you're effective queue_depth is 20 x the number of paths to the storage. Here's how to switch:


Migration from SDD to SDDPCM (or vice versa)

Migration from SDD to SDDPCM (or vice versa, but I expect most migrations will be from SDD to SDDPCM) is fairly straightforward and doesn’t require a lot of time. The procedure is documented in the manual, but to summarize it:
1. Varyoff your SDD VGs
2. Stop the sddsrv daemon via # stopsrc -s sddsrv
3. Remove the SDD devices (both vpaths and hdisks) via instructions below
4. Remove the dpo device
5. Uninstall SDD and the host attachment fileset for SDD
6. Install the host attachment fileset for SDDPCM and SDDPCM (I believe this requires a reboot, but I don’t remember for sure, the output of the installation will tell you for sure)
7. Configure the new disks (if you rebooted it’s done, else run cfgmgr)
8. Varyon your VGs – you’re back in business

To remove the vpaths and hdisks, I use the following inline script:

# for i in `lsdev -Cc disk | egrep "vpath|2105" | cut -f1 -d" "`
> do
> rmdev -dl $i
> done

Or an even easier method!


# rmdev -Rdl dpo  


which removes the dpo device, vpaths and hdisks.

Note that even though your VGs are changing from vpaths to hdisks, LVM keeps PV info by PVID, so it doesn’t matter that the device, or device names, change. So no export/import of the VG(s) is required. Also, in the unlikely event you’ve changed queue_depth information for the devices, these changes will be lost and if you want you’ll have to make them again (prior to step 7).

Note that for disk attached to a VIO server (VIOS), I recommend that one use SDDPCM for the reason that if one has a VG that’s directly attached to an LPAR, and would like to move it to VIOS attached (or vice versa), then one does not need to backup and restore the VG to do it. This also applies to using FlashCopy and accessing the copy from another system.

Sincerely,
Dan Braden

Update History:
6/29/2009 – added formula for maximum number of LUNs per virtual SCSI adapter to avoid queueing at the adapter
3/31/2009 – added information on using fcstat
10/23/2008 – updates for changes in SDD and iostat
3/31/2008 – added section on VIO queue depths and that max_xfer_size applies to the 2 Gbps adapters and the error one gets if max_xfer_size is too big
10/11/2007 – update on tuning via IO service times and use of ndisk
6/25/2007 – update for SDD releases that do not queue IOs
1/24/2007 – typo on max_xfer_size=0×10000 changed to 0×100000
8/15/2006 – added sentence on adapter IOPS and queue monitoring
2/14/2006 – added info on the max_xfer_size attribute


阅读(3147) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~