MSYNC(3)                   POSIX Programmer's Manual                  MSYNC(3)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.


NNAAMMEE
       msync -- synchronize memory with physical storage

SSYYNNOOPPSSIISS
       #include <sys/mman.h>

       int msync(void *_a_d_d_r, size_t _l_e_n, int _f_l_a_g_s);

DDEESSCCRRIIPPTTIIOONN
       The _m_s_y_n_c() function shall write all modified data to permanent storage
       locations, if any, in those whole pages containing any part of the
       address space of the process starting at address _a_d_d_r and continuing
       for _l_e_n bytes. If no such storage exists, _m_s_y_n_c() need not have any
       effect. If requested, the _m_s_y_n_c() function shall then invalidate cached
       copies of data.

       The implementation may require that _a_d_d_r be a multiple of the page size
       as returned by _s_y_s_c_o_n_f().

       For mappings to files, the _m_s_y_n_c() function shall ensure that all write
       operations are completed as defined for synchronized I/O data integrity
       completion. It is unspecified whether the implementation also writes
       out other file attributes. When the _m_s_y_n_c() function is called on
       MAP_PRIVATE mappings, any modified data shall not be written to the
       underlying object and shall not cause such data to be made visible to
       other processes. It is unspecified whether data in MAP_PRIVATE mappings
       has any permanent storage locations.  The effect of _m_s_y_n_c() on a shared
       memory object or a typed memory object is unspecified.  The behavior of
       this function is unspecified if the mapping was not established by a
       call to _m_m_a_p().

       The _f_l_a_g_s argument is constructed from the bitwise-inclusive OR of one
       or more of the following flags defined in the _<_s_y_s_/_m_m_a_n_._h_> header:

                 +------------------+------------------------------+
                 |SSyymmbboolliicc CCoonnssttaanntt |         DDeessccrriippttiioonn          |
                 +------------------+------------------------------+
                 |MS_ASYNC          | Perform asynchronous writes. |
                 |MS_SYNC           | Perform synchronous writes.  |
                 |MS_INVALIDATE     | Invalidate cached data.      |
                 +------------------+------------------------------+
       When MS_ASYNC is specified, _m_s_y_n_c() shall return immediately once all
       the write operations are initiated or queued for servicing; when
       MS_SYNC is specified, _m_s_y_n_c() shall not return until all write
       operations are completed as defined for synchronized I/O data integrity
       completion. Either MS_ASYNC or MS_SYNC shall be specified, but not
       both.

       When MS_INVALIDATE is specified, _m_s_y_n_c() shall invalidate all cached
       copies of mapped data that are inconsistent with the permanent storage
       locations such that subsequent references shall obtain data that was
       consistent with the permanent storage locations sometime between the
       call to _m_s_y_n_c() and the first subsequent memory reference to the data.

       If _m_s_y_n_c() causes any write to a file, the file's last data
       modification and last file status change timestamps shall be marked for
       update.

RREETTUURRNN VVAALLUUEE
       Upon successful completion, _m_s_y_n_c() shall return 0; otherwise, it shall
       return -1 and set _e_r_r_n_o to indicate the error.

EERRRROORRSS
       The _m_s_y_n_c() function shall fail if:

       EEBBUUSSYY  Some or all of the addresses in the range starting at _a_d_d_r and
              continuing for _l_e_n bytes are locked, and MS_INVALIDATE is
              specified.

       EEIINNVVAALL The value of _f_l_a_g_s is invalid.

       EENNOOMMEEMM The addresses in the range starting at _a_d_d_r and continuing for
              _l_e_n bytes are outside the range allowed for the address space of
              a process or specify one or more pages that are not mapped.

       The _m_s_y_n_c() function may fail if:

       EEIINNVVAALL The value of _a_d_d_r is not a multiple of the page size as returned
              by _s_y_s_c_o_n_f().

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

EEXXAAMMPPLLEESS
       None.

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       The _m_s_y_n_c() function is only supported if the Synchronized Input and
       Output option is supported, and thus need not be available on all
       implementations.

       The _m_s_y_n_c() function should be used by programs that require a memory
       object to be in a known state; for example, in building transaction
       facilities.

       Normal system activity can cause pages to be written to disk.
       Therefore, there are no guarantees that _m_s_y_n_c() is the only control
       over when pages are or are not written to disk.

RRAATTIIOONNAALLEE
       The _m_s_y_n_c() function writes out data in a mapped region to the
       permanent storage for the underlying object. The call to _m_s_y_n_c()
       ensures data integrity of the file.

       After the data is written out, any cached data may be invalidated if
       the MS_INVALIDATE flag was specified. This is useful on systems that do
       not support read/write consistency.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _m_m_a_p(), _s_y_s_c_o_n_f()

       The Base Definitions volume of POSIX.1-2008, <<ssyyss__mmmmaann..hh>>

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
       -- Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, Copyright (C) 2013 by the Institute of
       Electrical and Electronics Engineers, Inc and The Open Group.  (This is
       POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the
       event of any discrepancy between this version and the original IEEE and
       The Open Group Standard, the original IEEE and The Open Group Standard
       is the referee document. The original Standard can be obtained online
       at http://www.unix.org/online.html .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the source
       files to man page format. To report such errors, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2013                             MSYNC(3)
