Journal device and write cache in the file system

Source: Internet
Author: User

It is well known that the Journaldevice in a file system has two main purposes:

1. Ensure consistency of data;

2. Shorten write response time


To ensure the consistency of the data, of course, can not avoid and disk writecache interaction, which is reflected in two levels:


1. Writing to Journaldevice in the file system

Take full advantage of the Journaldevice writing speed characteristics, write operations first to the Journaldevice device, once write to the Journaldevice transaction includes the data to be written and the next time to take it to need the least metadata. There are two ways to ensure that the data falls completely to the Journaldevice:

A. Complete Disabledisk write cache, so that every write to Journaldevice has been returned;

B. Using the Diskwrite cache flush mechanism, each write on a device used as a journaldevice is flashwrite cache at intervals, or


2. File system writes to the physical disk

For the final write on the storage device, because there is a journaldevice endorsement, can be asynchronous or synchronous write, but the requirement is guaranteed for each write transaction: Write return must ensure that the data fell to the disk, and not in the Writecache. Taking into account the Journaldevice, the general process consists of two threads:


2.1 Disk Thread


A. Read the written request record from the Journaldevice to the unfinished disk;

A. Perform a real disk write;

B. Call the Flushwrte cache operation for the disk device;

C. Remove the corresponding record from the Journaldevice for operations that have been completely dropped

D. return


At this point, a complete landing of the writing is completed.


2.2 Write Commit Thread

A. Package write request data and metadata (including offset, start address, etc.), generate the original Journaldevice write

B. From the journaldevice to find the appropriate space, record the above write request, also on the above raw data written;

C. If the Journaldevice write cache is not turned off, brush the Journaldevice write cache to ensure that the data falls on the Journaldevice physical storage device;

D. Returning write requests to the upper layer


At this point, a write request is returned.


Based on the above analysis, the write response time is the time that the write request is issued to step d in the write submission thread. Because log devices are typically read and write faster than regular disks, they can significantly reduce write response time. But if the write request on the Journaldevice is not issued in time, is full, then it is basically only to execute the path of the disk thread, can also meet the write response time will dramatically increase a lot.


Considering the combination of the write submission thread and the disk thread, it can be seen that in the case of the file system Journaldevice endorsement, the landing thread can become asynchronous write from synchronous write, as long as the final guarantee that the write request can be dropped in accordance with the first served order, this can theoretically increase the IO throughput. However, in order to achieve this effect, journaldevice and disk need to be closely coordinated.


3. How to write cache and turn off write cache


You can refer to the following actions for the brush write cache facing the Scsi/sas disk:

Staticint FLUSHSCSIWC (int fd) {

STRUCTSG_IO_HDR Io_hdr;

Unsignedchar sense_b[32];

Unsignedchar CMDP[10];


memset (&io_hdr,0, sizeof (struct SG_IO_HDR));

memset (sense_b,0, sizeof (Sense_b));

memset (cmdp,0, sizeof (CMDP));


Io_hdr.interface_id= ' S ';

Io_hdr.dxfer_direction= Sg_dxfer_none;

Cmdp[0]= 0x35;

Cmdp[1]= 0x00;

Cmdp[2]= 0x00;

Cmdp[3]= 0x00;

Cmdp[4]= 0x00;

Cmdp[5]= 0x00;

Cmdp[6]= 0x00;

Cmdp[7]= 0x00;

Cmdp[8]= 0x00;

Cmdp[9]= 0x00;

Io_hdr.cmdp= CMDP;

io_hdr.cmd_len= sizeof (CMDP);

Io_hdr.sbp= Sense_b;

io_hdr.mx_sb_len= sizeof (SENSE_B);

Io_hdr.timeout= 60000;


if (IOCTL (fd,sg_io, &IO_HDR) = =-1)


if (io_hdr.status!= 0)

Returneio;


Return0;

}


And the way to turn off write caching is simple:

Hdparm-w1/dev/sdq

Of course, you can also use MEGACLI or Lsitutil and other tools to control.



This article from "Storage Chef" blog, reproduced please contact the author!

Journal device and write cache in the file system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.