Non-interleaved Writes



next up previous contents
Next: l_pid Returned by Up: Semantic Issues Previous: Remote FIFOs and

Non-interleaved Writes

 

When a process writes data to a file, each implementation determines how much data can be written in one atomic operation, i.e., a single operation which cannot be interrupted. For example, a process does a write(fildes,buf,nbytes). The nbytes of data may not be written as one atomic operation. The implementation may write the nbytes of data in several operations or the write operation may be interrupted. This situation leaves open the following possibilities:

  1. The block of data written by one process is interleaved with data written by another process.
  2. Parts of the data written by one process are overwritten by data from other processes before all of the data from the first process has been written.

For many implementations (not including IEEE 1003.1-1990), there is a value of nbytes which guarantees that neither of the situations above will occur. In some cases, an application may need to know how much data it can write without being interleaved or overwritten by another process. One example of such an application is a server process which uses a pipe as an input request queue to accept service requests from several other processes.

If the file system is local, it is possible that for all values of nbytes, an implementation may write all nbytes of data in one operation and that operation is not interruptible. However, if the file system is remote, it is more likely that there is a maximum number of bytes that can be written in one atomic operation. The reason for this is that transparent access to a remote file system may be implemented using existing network protocols. Such protocols may already be standardized and specify a maximum packet size. This maximum packet size may become the maximum number of bytes that can be written atomically. Thus, for a remote file system, the maximum number of bytes that can be written in a single atomic operation is usually the minimum of:

  1. the maximum number of bytes which the client implementation can write atomically, and
  2. the maximum number of bytes allowed in a packet by the underlying protocols supporting the transparent file access.

One solution to this problem is to specify the maximum number of bytes which may be written in one atomic operation as a parameter which the application program can obtain. A similar approach is already used for pipes. Because of the nature of pipes, it is usually not practical to guarantee that write operations of any size are not interleaved by write operations from other processes. In IEEE 1003.1-1990, the parameter PIPE_BUF specifies the maximum number of bytes which can be written atomically to a pipe or a FIFO. A similar parameter could be used for regular files. Note that in the local environment, the value of PIPE_BUF applies to pipes and FIFOs. However, in a transparent file access environment, the value of a parameter for files similar to PIPE_BUF may be different for each remote file system.



next up previous contents
Next: l_pid Returned by Up: Semantic Issues Previous: Remote FIFOs and



Karen Olsen
Mon Aug 21 10:18:32 EDT 1995