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=-5.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 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 09EDFC43464 for ; Fri, 18 Sep 2020 13:13:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C002223888 for ; Fri, 18 Sep 2020 13:13:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726375AbgIRNNX (ORCPT ); Fri, 18 Sep 2020 09:13:23 -0400 Received: from mx2.suse.de ([195.135.220.15]:39982 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726541AbgIRNNT (ORCPT ); Fri, 18 Sep 2020 09:13:19 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 2A077ABF4; Fri, 18 Sep 2020 13:13:52 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id ABB001E12E1; Fri, 18 Sep 2020 15:13:17 +0200 (CEST) Date: Fri, 18 Sep 2020 15:13:17 +0200 From: Jan Kara To: Mikulas Patocka Cc: Dan Williams , Linus Torvalds , Alexander Viro , Andrew Morton , Matthew Wilcox , Jan Kara , Eric Sandeen , Dave Chinner , Linux Kernel Mailing List , linux-fsdevel Subject: Re: the "read" syscall sees partial effects of the "write" syscall Message-ID: <20200918131317.GH18920@quack2.suse.cz> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Honza -- Jan Kara SUSE Labs, CR