[Turn] discussion on synchronous Io:fsync and Fdatasync

Source: Internet
Author: User

Original link:

Http://www.cnblogs.com/promise6522/archive/2012/05/27/2520028.html

The writing is very good and very detailed. Summary:

Fsync need sync file modification and metadata; Fdatasync only sync metadata when necessary to save a file sync operation.

Berkeley DB ensures that Fdatasync does not go to sync metadata by pre-setting the log file size.

Here is a simple list of the corresponding BDB code:

OS/OS_FSYNC.C:

__os_fsync ()if(Db_global (j_fsync)! =NULL) ret= Db_global (J_fsync) (fhp->FD); User-defined sync functionElse {#ifDefined (F_fullfsync)//MAC OS XRetry_chk ((Fcntl (FHP->FD, F_fullfsync,0) ), ret);        if(ret = =enotsup) Retry_chk ((Fsync (FHP-FD)), ret);#elifDefined (HAVE_QNX)//QNX real-time OSret=__qnx_fsync (FHP);#elifDefined (Have_fdatasync)//priority use FdatasyncRetry_chk ((Fdatasync (FHP-FD)), ret);#elseRetry_chk ((Fsync (FHP-FD)), ret);#endif    }

LOG/LOG_PUT.C:

__log_write () #ifdef Have_filesystem_notzeroif(Lp->w_off = =0&&!__os_fs_notzero ()) {#else    if(Lp->w_off = =0) {//Lp->w_off write offset for the current log file#endif//Lp->w_off is 0, marking the first time this log file is written        (void) __db_file_extend (env, DBLP->LFHP, lp->log_size); if( f_isset (DBLP, Dblog_zero)) (void) __db_zero_extend (env, dblp->LFHP,0, Lp->log_size/lp->buffer_size, lp->buffer_size); }

ENV/ENV_FILE.C:

__db_file_extend ()//size is a log file, the last byte of the write file is    0 '  / ' ;     sizeof (BUF)) / megabyte);     sizeof (BUF)) % megabyte);     if 0 sizeof (buf), &NW);         

[Turn] discussion on synchronous Io:fsync and Fdatasync

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.