Ubuntu: What is the write-mode policy that is used in Ubuntu?


Is there anyway to see whether Ubuntu uses write through or write back policy?

I know that write back is much better, but when I write a program in C to test the cache, it appears that Ubuntu uses write through.

UPDATE: I mean it's CPU Cache not the filesystem cache. What Im concerned about is the policy of writing to cache L1,L2,L3 and the RAM. Thank you!.


In a write-back cache, when changes are made to cached data, they are not simultaneously made to the original data as well. Instead, the changed data is marked, and the original data is updated when the chached data is deallocated.

In a write-through cache, by contrast changes made to cached data are simultaneously made in the original copy. A write-back cache can perform more quickly than a write-through cache. But in some contexts, differences between cached and original data could lead to problems, and write-through caches must be used


Now, Its doesn't matter what OS are you working on the really thing that affects is the file system you are using.

Ubuntu by default use ext4 as it filesystem and to know ext4 uses the both modes write-back and write-through.

To enable write back mode


 tune2fs -o journal_data_writeback /dev/sd*  

Edit fstab

vi -w /mnt/sdXY/etc/fstab  

Find the line that references sd* It will look something like:

# /dev/sda2  UUID=be2f0ac2-4683-4550-bcd1-704a1a840b3e / ext4 relatime,errors=remount-ro 0 1  

The first entry is the UUID .

The second entry is the path.

Third is the fstype .

Fourth are the options.

Fifth is for dump

Sixth is pass.

Change the options(4th) to:


Reboot your system to complete changes.


Also check this for more information.


You can also consult the current "data=" mode by looking at /proc/mounts. Here is an example from my laptop:

$ grep ext /proc/mounts   /dev/mapper/crypt-root / ext4 rw,noatime,errors=remount-ro,user_xattr,barrier=1,data=ordered 0 0  /dev/mapper/vg0-boot /boot ext4 rw,nosuid,nodev,noexec,noatime,user_xattr,barrier=1,data=ordered 0 0  /dev/mapper/crypt-homes /home ext4 rw,nosuid,noatime,user_xattr,acl,commit=60,barrier=1,data=ordered 0 0  

Also, note that "nobh" is a deprecated mount option.


You could also see if using the O_SYNC | O_DIRECT flags in open() is what you want. The manual states:

"The O_DIRECT flag on its own makes an effort to transfer data synchronously, but does not give the guarantees of the O_SYNC flag that data and necessary metadata are transferred. To guarantee synchronous I/O, O_SYNC must be used in addition to O_DIRECT."

See man 2 open open for more details.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »