From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4CA1C43463 for ; Sun, 20 Sep 2020 23:41:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8B76E206B5 for ; Sun, 20 Sep 2020 23:41:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726343AbgITXlR (ORCPT ); Sun, 20 Sep 2020 19:41:17 -0400 Received: from mail104.syd.optusnet.com.au ([211.29.132.246]:45020 "EHLO mail104.syd.optusnet.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726156AbgITXlQ (ORCPT ); Sun, 20 Sep 2020 19:41:16 -0400 Received: from dread.disaster.area (pa49-195-191-192.pa.nsw.optusnet.com.au [49.195.191.192]) by mail104.syd.optusnet.com.au (Postfix) with ESMTPS id CCBD682561D; Mon, 21 Sep 2020 09:41:04 +1000 (AEST) Received: from dave by dread.disaster.area with local (Exim 4.92.3) (envelope-from ) id 1kK8x5-0005ki-Rl; Mon, 21 Sep 2020 09:41:03 +1000 Date: Mon, 21 Sep 2020 09:41:03 +1000 From: Dave Chinner To: Jan Kara Cc: Mikulas Patocka , Dan Williams , Linus Torvalds , Alexander Viro , Andrew Morton , Matthew Wilcox , Eric Sandeen , Dave Chinner , Linux Kernel Mailing List , linux-fsdevel Subject: Re: the "read" syscall sees partial effects of the "write" syscall Message-ID: <20200920234103.GX12096@dread.disaster.area> References: <20200918131317.GH18920@quack2.suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200918131317.GH18920@quack2.suse.cz> X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.3 cv=XJ9OtjpE c=1 sm=1 tr=0 cx=a_idp_d a=vvDRHhr1aDYKXl+H6jx2TA==:117 a=vvDRHhr1aDYKXl+H6jx2TA==:17 a=kj9zAlcOel0A:10 a=reM5J-MqmosA:10 a=uZvujYp8AAAA:8 a=7-415B0cAAAA:8 a=IhRoebVIs0TbUmjakS8A:9 a=CjuIK1q_8ugA:10 a=nv2HPNHG-XcA:10 a=SLzB8X_8jTLwj6mN0q5r:22 a=biEYGPWJfzWAr4FL6Ov7:22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 18, 2020 at 03:13:17PM +0200, Jan Kara wrote: > On Fri 18-09-20 08:25:28, Mikulas Patocka wrote: > > I'd like to ask about this problem: when we write to a file, the kernel > > takes the write inode lock. When we read from a file, no lock is taken - > > thus the read syscall can read data that are halfway modified by the write > > syscall. > > > > The standard specifies the effects of the write syscall are atomic - see > > this: > > https://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html#tag_15_09_07 > > Yes, but no Linux filesystem (except for XFS AFAIK) follows the POSIX spec > in this regard. Mostly because the mixed read-write performance sucks when > you follow it (not that it would absolutely have to suck - you can use > clever locking with range locks but nobody does it currently). In practice, > the read-write atomicity works on Linux only on per-page basis for buffered > IO. We come across this from time to time with POSIX compliant applications being ported from other Unixes that rely on a write from one thread being seen atomically from a read from another thread. There are quite a few custom enterprise apps around that rely on this POSIX behaviour, especially stuff that has come from different Unixes that actually provided Posix compliant behaviour. IOWs, from an upstream POV, POSIX atomic write behaviour doesn't matter very much. From an enterprise distro POV it's often a different story.... Cheers, Dave. -- Dave Chinner david@fromorbit.com