åæã«write(2)ããã¨æ··ãããã©ãã
Linux ã®ã·ã¹ãã ã³ã¼ã«ã§ãã write(2) ã® ããã¥ã¡ã³ããèªãã¨
Atomic/non-atomic: A write is atomic if the whole amount written in one operation is not interleaved with data from any other process. This is useful when there are multiple writers sending data to a single reader. Applications need to know how large a write request can be expected to be performed atomically. This maximum is called {PIPE_BUF}. This volume of IEEE Std 1003.1-2001 does not say whether write requests for more than {PIPE_BUF} bytes are atomic, but requires that writes of {PIPE_BUF} or fewer bytes shall be atomic.
ã¨ã®è¨è¼ããããPIPE_BUF(Linux ã§ã¯ 4KB)ã®ãµã¤ãºããå°ããå ´å㯠atomic ãªã®ã§ãã°ãæ··ãããã¨ã¯ãªããããããã大ããå ´åã¯æ··ãããã¨ããããã¨ããããã«èªãã¾ãã
RubyのLoggerはスレッドセーフ(&プロセスセーフ)かどうか調べてみた - sonots:blog
ãã®ä»¶ãå¼ç¨ããããã¨ããã£ã¦ç¢ºèªãããå¤ã linux kernel (2.6.35.13) ã ãã©ã
ã¾ããvfs ã¬ã¤ã¤ã®åä½ã¨ãã¦ã vfs_write -> do_sync_write -> f_op->aio_write ã®é ã§å¼ã³åºãããã
ããã¦ãåfså®è£ (f_op) ã®å¼ã³åºãã以ä¸ã®ããã«ãªãã
ext2/ext3ã®å ´åãaio_write 㯠generic_file_aio_write ãªã®ã§ã以ä¸ã®ããã«è¿½è¨ã¢ã¼ãäºã ã«é¢ä¿ãªãã常ã«ããã¯ãã¨ã*1ã
/** * generic_file_aio_write - write data to a file * @iocb: IO state structure * @iov: vector with data to write * @nr_segs: number of segments in the vector * @pos: position in file where to write * * This is a wrapper around __generic_file_aio_write() to be used by most * filesystems. It takes care of syncing the file in case of O_SYNC file * and acquires i_mutex as needed. */ ssize_t generic_file_aio_write(struct kiocb *iocb, const struct iovec *iov, unsigned long nr_segs, loff_t pos) { struct file *file = iocb->ki_filp; struct inode *inode = file->f_mapping->host; ssize_t ret; BUG_ON(iocb->ki_pos != pos); mutex_lock(&inode->i_mutex); ret = __generic_file_aio_write(iocb, iov, nr_segs, &iocb->ki_pos); mutex_unlock(&inode->i_mutex); if (ret > 0 || ret == -EIOCBQUEUED) { ssize_t err; err = generic_write_sync(file, pos, ret); if (err < 0 && ret > 0) ret = err; } return ret; } EXPORT_SYMBOL(generic_file_aio_write);
xfsã®å ´åã¯xfs_file_aio_writeã®ä¸ã§direct I/Oã§ãªããã°ãããã¯ããã
PS. POSIXçã«ã¯OSã®èªç±ã ãã¨ããnfsã ã£ããã©ãã ãã¨ããè°è«ã¯ããã¨æãã®ã§ç¨æ³ç¨éãå®ã£ã¦ã使ããã ããã