# How to enable write cache on sata drives?



## digrouz (Dec 1, 2011)

Hello,

I'm building a NAS at home on FreeBSD 9.0-RC2. I'm wondering how can I enable the write cache on my SATA drives?


----------



## SirDice (Dec 1, 2011)

Write caching is turned on by default.

Handbook 12.12 Tuning Disks


----------



## digrouz (Dec 1, 2011)

Great!

Thanks


----------



## gkontos (Dec 1, 2011)

You might also want to load ahci in your /boot/loader.conf 


```
ahci_load="YES"
```


----------



## digrouz (Dec 1, 2011)

Will that increase performances?

EDIT: Yes it does: *zpool scrub* finished about 10 times faster!


----------



## tyson (Dec 1, 2011)

In 9.0 ahci is used as default.


----------



## gkontos (Dec 1, 2011)

tyson said:
			
		

> In 9.0 ahci is used as default.



Any official reference regarding this ?

Thanks,
George


----------



## digrouz (Dec 1, 2011)

I'm not sure it is the case because I see performance improvements since I enabled it


----------



## wblock@ (Dec 1, 2011)

gkontos said:
			
		

> Any official reference regarding this ?




```
device ahci
```
 is in the 9.0 GENERIC kernel config.


----------



## gkontos (Dec 1, 2011)

I think he is referring to 20110424 revision:


```
The GENERIC kernels for all architectures now default to the new
        CAM-based ATA stack. It means that all legacy ATA drivers were
        removed and replaced by respective CAM drivers.
...
...
        It is possible to load devices ahci, ata, siis and mvs as modules,
        but option ATA_CAM should remain in kernel configuration to make ata
        module work as CAM driver supporting legacy ATA controllers.
...
...

        No kernel config options or code have been removed, so if a problem
        arises, please report it and optionally revert to the old ATA stack.
        In order to do it you can remove from the kernel config:
            options        ATA_CAM
            device         ahci
```

To be honest, I am confused here. Enabling this in /boot/loader.conf does make a difference in performance in all of my SATA based boxes. 

On the other hand:

[CMD=""]hp# kldstat[/CMD]


```
Id Refs Address            Size     Name
 1   11 0xffffffff80200000 11cc3b0  kernel
 2    1 0xffffffff813cd000 203d18   zfs.ko
 3    2 0xffffffff815d1000 5bf8     opensolaris.ko
 4    1 0xffffffff815d7000 f3d0     aio.ko
```

It is obvious that there is no ahci module loaded.

Any ideas please ?

George


----------



## gkontos (Dec 1, 2011)

@wblock,

sorry, it seems we posted at the same time!


----------



## phoenix (Dec 1, 2011)

Check the output of `# kldstat -v` as that will include drivers compiled into the kernel.


----------



## gkontos (Dec 1, 2011)

I guess loading ahci.ko in loader.conf is only a psychological performance boost after all :e


```
gkontos@hp>kldstat -v | grep ahci
                   
Id Refs Address            Size     Name
1   11 0xffffffff80200000 11cc3b0  kernel (/boot/kernel/kernel)
        Contains modules:
		72 pci/ata_ahci
		71 atapci/ata_ahci_ata
		50 pci/ahci
		49 atapci/ahci
		48 ahci/ahcich
```

What a shame :r :r


----------

