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.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 4D9CEC48BE5 for ; Tue, 22 Jun 2021 17:40:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DB87561107 for ; Tue, 22 Jun 2021 17:40:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DB87561107 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CEDB96B006C; Tue, 22 Jun 2021 13:40:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CC3336B006E; Tue, 22 Jun 2021 13:40:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B3CC06B0070; Tue, 22 Jun 2021 13:40:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0132.hostedemail.com [216.40.44.132]) by kanga.kvack.org (Postfix) with ESMTP id 52B0A6B006C for ; Tue, 22 Jun 2021 13:40:05 -0400 (EDT) Received: from smtpin38.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 899B4181AEF1D for ; Tue, 22 Jun 2021 17:40:05 +0000 (UTC) X-FDA: 78282073170.38.B2D486C Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) by imf27.hostedemail.com (Postfix) with ESMTP id 13340801934D for ; Tue, 22 Jun 2021 17:40:04 +0000 (UTC) Received: by mail-lj1-f181.google.com with SMTP id a21so6146468ljj.1 for ; Tue, 22 Jun 2021 10:40:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=66ra9JcEZ0eBr3diwYDmK55iDML4YsZIlomivlL4MkM=; b=BN8pfadh6kxcRjOo7eBRIxfB3TqOIMMpU5w6SViYi3IbWgrX9pxyb+0MIPuTThh/Uk UI374oOHBtqpQVOc5/7Wjq62OSZlw+Cs0ZJ9RtNvwUC7DVtrhmo38JY5T8rAYwai72SJ tm4pt9J7lEO2DOp7XU52ViFjgfM4TXiIVDMsU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=66ra9JcEZ0eBr3diwYDmK55iDML4YsZIlomivlL4MkM=; b=uZAKCnEmNDKC/+ALw1uBff98evEJvUytQ6HgbnF1wArDVN+yFYmMuGAnj3Zp7284OO H4GYoFvahn/iH7yEOfoaAsUTdkDmPa8UFXKO4tqWuuAqCPxCatJFg+o+rnWNdXIevW4s QlxP6QsT/kjYZn9TKRXJ1oUJrlBBaY0ViDu3ApX/eP2Jyc4uS9imf+sm0HPDOs3G9Hd4 XJoFRNh0sg7tpAFEihgfTyZmwXElGvR6cDcZgRliWsVIS6mNESR41duok27+CTrkMyic w6tG/AKbnhMQtms8mfaxilQAZihHmPUQ5xoWyEfFdN8x5bHFax9B9o4cM58hwYwyvAe+ 6prA== X-Gm-Message-State: AOAM5320q8SZds0AZ7/wNi8aJoLmwwqFOe1H8hkG/gCWy0IKgN/O4YLg ugUcpbgEX4ZUVXUzr+rTAb6rX6H73K6ZjvkBznk= X-Google-Smtp-Source: ABdhPJw2evx76A/jMF41C8t51hc3sV37s6LHGfTgJUKfcsOk/3dR7wmkSPqgOHZQY0jZI204gdHQ+Q== X-Received: by 2002:a2e:3506:: with SMTP id z6mr4455091ljz.238.1624383603069; Tue, 22 Jun 2021 10:40:03 -0700 (PDT) Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com. [209.85.208.172]) by smtp.gmail.com with ESMTPSA id d4sm2267645lfk.295.2021.06.22.10.40.02 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 22 Jun 2021 10:40:02 -0700 (PDT) Received: by mail-lj1-f172.google.com with SMTP id z22so31249247ljh.8 for ; Tue, 22 Jun 2021 10:40:02 -0700 (PDT) X-Received: by 2002:a2e:7813:: with SMTP id t19mr4167347ljc.411.1624383601833; Tue, 22 Jun 2021 10:40:01 -0700 (PDT) MIME-Version: 1.0 References: <3221175.1624375240@warthog.procyon.org.uk> In-Reply-To: From: Linus Torvalds Date: Tue, 22 Jun 2021 10:39:46 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: Do we need to unrevert "fs: do not prefault sys_write() user buffer pages"? To: Matthew Wilcox Cc: Al Viro , David Howells , "Ted Ts'o" , Dave Hansen , Andrew Morton , Linux-MM , Ext4 Developers List , linux-fsdevel , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=google header.b=BN8pfadh; dmarc=none; spf=pass (imf27.hostedemail.com: domain of torvalds@linuxfoundation.org designates 209.85.208.181 as permitted sender) smtp.mailfrom=torvalds@linuxfoundation.org X-Rspamd-Server: rspam02 X-Stat-Signature: ac76t658dy4s7ng5zmgr8nq549cgsd8m X-Rspamd-Queue-Id: 13340801934D X-HE-Tag: 1624383604-211138 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Jun 22, 2021 at 10:26 AM Matthew Wilcox wrote: > > On Tue, Jun 22, 2021 at 03:36:22PM +0000, Al Viro wrote: > > > > Note that the revert you propose is going to do fault-in anyway; we really can't > > avoid it. The only thing it does is optimistically trying without that the > > first time around, which is going to be an overall loss exactly in "slow > > write_begin" case. If source pages are absent, you'll get copyin fail; > > iov_iter_copy_from_user_atomic() (or its replacement) is disabling pagefaults > > itself. > > Let's not overstate the case. I think for the vast majority of write() > calls, the data being written has recently been accessed. So this > userspace access is unnecessary. Note that the fault_in_readable is very much necessary - the only question is whether it happens before the actual access, or after it in the "oh, it failed, need to retry" case. There are two cases: (a) the user page is there and accessible, and fault_in_readable isn't necessary (b) not and as you say, case (a) is generally the common one by far, although it will depend on the exact load (iow, (b) *could* be the common case: you can have situations where you mmap() things only to then write the mapping out, and then accesses will fault a lot). But if it's case (a), then the fault_in_readable is going to be pretty cheap. We're talking "tens of CPU cycles", unlikely to really be an issue. If the case is (b), then the cost is not actually the access at all, it's the *fault* and the retry. Now we're talking easily thousands of cycles. And that's where it matters whether the fault_in_readable is before or after. If it's before the actual access, then you'll have just _one_ fault, and it will handle the fault. If the fault_in_readable is only done in the allegedly unlikely faulting case and is _after_ the actual user space atomic access, you'll have *two* faults. First the copy_from_user_atomic() will fault, and return a partial result. But the page won't actually be populated, so then the fault_in_readable will have to fault _again_, in order to finally populate the page. And then we retry (successfully, except for the unbelievably rare case of racing with pageout) the actual copy_from_user_atomic(). End result: doing the fault_in_readable "unnecessarily" at the beginning is likely the better optimization. It's basically free when it's not necessary, and it avoids an extra fault (and extra lock/unlock and retry) when it does end up faulting pages in. Linus