Turning On NCQ Queing On ICH7 Chipsets With Linux
11 Aug2006

Recently we’ve got critical load on one of our new free web hosting servers that handles millions of hits per day. When I’ve tried to analyze how to get more performance from that servers, I noted that these servers has ICH7 chipsets and Seagate SATA drives with NCQ support… But in closer view I noticed, that NCQ support is not enabled on our servers with ata_piix IDE driver. So, I decided that it would be great to enable NCQ and take a look what will happen with performance (it was obvious, that performance should increase)…

Fast research showed, that first thing I need is to enable AHCI-compatibility more in server’s BIOS to be able to use ahci SATA driver from latest version of Linux 2.6 kernel. After AHCI has been enabled, I saw following info in dmesg log:

ahci 0000:00:1f.2: AHCI 0001.0100 32 slots 4 ports 3 Gbps 0xf impl SATA mode
ahci 0000:00:1f.2: flags: 64bit ncq pm led clo pio slum part
ata1: SATA max UDMA/133 cmd 0xFFFFC20000022500 ctl 0x0 bmdma 0x0 irq 66
ata2: SATA max UDMA/133 cmd 0xFFFFC20000022580 ctl 0x0 bmdma 0x0 irq 66
ata3: SATA max UDMA/133 cmd 0xFFFFC20000022600 ctl 0x0 bmdma 0x0 irq 66
ata4: SATA max UDMA/133 cmd 0xFFFFC20000022680 ctl 0x0 bmdma 0x0 irq 66
scsi0 : ahci
ata1: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
ata1.00: ATA-7, max UDMA/133, 586072368 sectors: LBA48
ata1.00: ata1: dev 0 multi count 16
ata1.00: configured for UDMA/133
scsi1 : ahci
......
  Vendor: ATA       Model: ST3300622AS       Rev: 3.AA
  Type:   Direct-Access                      ANSI SCSI revision: 05
  Vendor: ATA       Model: ST3300622AS       Rev: 3.AA
  Type:   Direct-Access                      ANSI SCSI revision: 05
  Vendor: ATA       Model: ST3300622AS       Rev: 3.AA
  Type:   Direct-Access                      ANSI SCSI revision: 05
  Vendor: ATA       Model: ST3300622AS       Rev: 3.AA
  Type:   Direct-Access                      ANSI SCSI revision: 05
......

As you can see, there is no NCQ support for SATA drives… But official libata site said, that it should be there!

More deep research showed, that libata in linux 2.6 kernel has no NCQ support for AHCI. :-( So, I decided to find out how to get more recent libata in linux 2.6…Unfortunately, official libata site has only outdated patches for linux 2.6. And after long search I found site with libata patches for latest 2.6 kernels that brings latest libata library and allows me to enable NCQ on my drives! This site is home page of Tejun Heo – Korean kernel hacker, that maintains libata-tj-stable patch set.

After applying these patches and rebooting I’ve got following messages for sata channels:

...
ata1: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
ata1.00: ATA-7, max UDMA/133, 586072368 sectors: LBA48 NCQ (depth 31/32)
ata1.00: ata1: dev 0 multi count 16
ata1.00: configured for UDMA/133
...

So, now I have NCQ enabled on my drives and it gabe me some 15-30% of additional performance (I see it from traffic graphs, so I don’t need any deep performance test – it’s obvious) and if you have ICH controller and want to get NCQ queing enabled on your drives, try these patches – they are really stable.