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=-4.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 19767C433E8 for ; Tue, 11 Aug 2020 20:06:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D87CC20756 for ; Tue, 11 Aug 2020 20:06:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597176407; bh=9kVJER9GnmAJgIf1v0EsXQx3cmVIVjyDJgu9AFSZDAs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From; b=yMrU+NwTvTldr7CaxGVAZMd9/+BV8dypuhSvtWnl0Z+DzOdDkDrwo1EQ3VbHEJS6U vV8LGD3h7nWcezLXG1u0S1vvimRrklP3/sfMEW74lhfA59cRHC2vL3OaK2eeOsPdCu ILRPwjJeMc759Vy/SuviZv6o2Sr5U67v+vNos8KQ= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726749AbgHKUG0 (ORCPT ); Tue, 11 Aug 2020 16:06:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726564AbgHKUGY (ORCPT ); Tue, 11 Aug 2020 16:06:24 -0400 Received: from mail-io1-xd44.google.com (mail-io1-xd44.google.com [IPv6:2607:f8b0:4864:20::d44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37D62C06174A for ; Tue, 11 Aug 2020 13:06:24 -0700 (PDT) Received: by mail-io1-xd44.google.com with SMTP id z6so85804iow.6 for ; Tue, 11 Aug 2020 13:06:24 -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=x9Z56G7Sq+yoxF26YYsaVBF/VyvZNYi0ExatDmNcea8=; b=CmHP/prH5/FP2ejP8hzk1TIK0ioM1mTElZ2Xxat1dgv6XbaDed3rUDQIZjKALmYmYW M2Wpi1pa2zNkpS0Il8/Tlx3hEW8wDBHDDMl9j+p7tY795MeaYQkirp7mw2hLYW098fYa mvwBVOUXNuGA+5s9y1TTFETU57MNRjCYyagQo= 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=x9Z56G7Sq+yoxF26YYsaVBF/VyvZNYi0ExatDmNcea8=; b=DaIQEeQJnEMcsYY76U2/rNRBh0N81mrDO8GqvN/ETefX8fw8KjECJKuIYuQgXmIH2w q8hWUhMF+Kg7W3BOIx+34ReK+wsDuRxOWIyg2m3qOubk0EMYI22CDZheeZofj+oNzLYb fGcWbiJ8wGQudrWTKCcbVqk8FXQDF04+5qvxo+mLXduZw8dRSX3wlPwGgBfpGhMhUWuB KMZ1li+E5CQEgXI6/qFvZjjzNU9HrENXyfcjVdWglbPh78bCEOGYDmZOSqZDhErYwf6v Jh+pH7eUEXG5wkx2ZCpMFMKRcEtFMfjmEmrQ0yuOEdmhWh/fa/gjGHK/CPALVyYFKM7C nJWQ== X-Gm-Message-State: AOAM532dn3mxRuFVqprsJVz0x03ezB8Np5wEez2w2m0Jgr4eFZCzA+tv tUT+Gg9IzhXdEIXyFPOcl5THb6i9x3o= X-Google-Smtp-Source: ABdhPJxt7J4Yz+saDja0hs4hbbCY2wxkcPJTzkfMm3klrxtA/5R73fQ8qccYz0C7xutctQijFvlhyw== X-Received: by 2002:a05:6602:2d43:: with SMTP id d3mr24043574iow.39.1597176383128; Tue, 11 Aug 2020 13:06:23 -0700 (PDT) Received: from mail-io1-f49.google.com (mail-io1-f49.google.com. [209.85.166.49]) by smtp.gmail.com with ESMTPSA id t26sm7007850ilb.80.2020.08.11.13.06.21 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Aug 2020 13:06:21 -0700 (PDT) Received: by mail-io1-f49.google.com with SMTP id z6so85527iow.6 for ; Tue, 11 Aug 2020 13:06:21 -0700 (PDT) X-Received: by 2002:a02:9247:: with SMTP id y7mr26798836jag.140.1597176381447; Tue, 11 Aug 2020 13:06:21 -0700 (PDT) MIME-Version: 1.0 References: <20200811183950.10603-1-peterx@redhat.com> In-Reply-To: From: Linus Torvalds Date: Tue, 11 Aug 2020 13:06:04 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3] mm/gup: Allow real explicit breaking of COW To: Peter Xu , Andrea Arcangeli Cc: Linux-MM , Linux Kernel Mailing List , Andrew Morton , Marty Mcfadden , "Maya B . Gokhale" , Jann Horn , Christoph Hellwig , Oleg Nesterov , Kirill Shutemov , Jan Kara Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ; On Tue, Aug 11, 2020 at 12:24 PM Linus Torvalds wrote: > > Now I wonder if there's any other case of FOLL_WRITE that is missing. Actually, now I wonder if we really should have tried to handle the wrong-way cow reuse case some other way entirely. When discussing this wrong-way-COW issue originally I looked at just doing struct page *page = vmf->page; if (page_count(page) != 1) goto copy; if (!trylock_page(page)) goto copy; if (page_mapcount(page) != 1 && page_count(page) != 1) { unlock_page(page); goto copy; } /* Ok, we've got the only map reference, and the only * page count reference, and the page is locked, * it's dark out, and we're wearing sunglasses. Hit it. */ wp_page_reuse(vmf); unlock_page(page); return VM_FAULT_WRITE at the top of the PageAnon() case in do_wp_page(), and be entirely done with it. Make the rule be that we *only* re-use the page if there is no question what-so-ever that we're the only possible owner of it. Anything else at all - whether they be GUP users, other processes, KSM, hughepage collapsing, whatever: don't even try. That would possibly cause a lot of extra copies, but our rules for "can we re-use this page" are just crazy complicated. And now the "minimal" thing of just always breaking COW ends up causing complications of its own. IOW, maybe all of this falls under "yeah, we have historical reasons for all of it, but it's just not worth the pain". We do a _lot_ of complex stuff just to check whether we could possibly share the page. Maybe trying to reuse the page just isn't worth it? Adding Andrea to the cc (although he probably sees this through linux-mm anyway). Maybe he can go "naah, that will be horribly bad, because..." Then we could get rid of all the FAULT_FORCE_COW games again entirely, and people can point fingers at me and laugh behind my back because of what a bad idea it was. Linus 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=-4.1 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 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 EEA20C433E0 for ; Tue, 11 Aug 2020 20:06:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A3B8120781 for ; Tue, 11 Aug 2020 20:06:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="CmHP/prH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A3B8120781 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 269116B0002; Tue, 11 Aug 2020 16:06:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F24C6B0005; Tue, 11 Aug 2020 16:06:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 06C476B0006; Tue, 11 Aug 2020 16:06:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0096.hostedemail.com [216.40.44.96]) by kanga.kvack.org (Postfix) with ESMTP id DFAFB6B0002 for ; Tue, 11 Aug 2020 16:06:25 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 882A140E1 for ; Tue, 11 Aug 2020 20:06:25 +0000 (UTC) X-FDA: 77139369930.27.heart41_5b1498026fe5 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin27.hostedemail.com (Postfix) with ESMTP id 553763D66B for ; Tue, 11 Aug 2020 20:06:25 +0000 (UTC) X-HE-Tag: heart41_5b1498026fe5 X-Filterd-Recvd-Size: 5661 Received: from mail-io1-f65.google.com (mail-io1-f65.google.com [209.85.166.65]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Tue, 11 Aug 2020 20:06:24 +0000 (UTC) Received: by mail-io1-f65.google.com with SMTP id q75so152079iod.1 for ; Tue, 11 Aug 2020 13:06:24 -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=x9Z56G7Sq+yoxF26YYsaVBF/VyvZNYi0ExatDmNcea8=; b=CmHP/prH5/FP2ejP8hzk1TIK0ioM1mTElZ2Xxat1dgv6XbaDed3rUDQIZjKALmYmYW M2Wpi1pa2zNkpS0Il8/Tlx3hEW8wDBHDDMl9j+p7tY795MeaYQkirp7mw2hLYW098fYa mvwBVOUXNuGA+5s9y1TTFETU57MNRjCYyagQo= 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=x9Z56G7Sq+yoxF26YYsaVBF/VyvZNYi0ExatDmNcea8=; b=A60lJ5b8qv9pUfgYqxtjR0q7QtUZimpGnuaWVLj7d6CCL2uoYWNwJ7ucj63WXbNqGP YGOAlqWFfXoB9rkko46EzUzLjjoM2koD/YqvsS0AzE4MT3JUea0/Z2CHrcWEWsuSe+Xl Th1sn9v/wu6KeODwiUFtlxq6gz3+zSt52D2uUyXioGVSN3UVDD+RRJWTraXV5PkxT7Qm 1fA35NjCi/SDHyeDFqQxcl7M9Vun9ZEGrz1eJSbAr/7TJfvPLUdap/5kqPvGO0vDcRkI 4NqTaQrT9ism1x9lznqNnSaFXWc6hd9BAhFKlRQOJgDbpdIWIgnfpXWDSqcm+BuhpvDB zYKA== X-Gm-Message-State: AOAM533152IUf1KUGp3xtKRgWtOkZmOnUscunamjL26J5kMiOPrXgD4Q Xt8RMl/bYfbM3MEkE8kkdNC1z7v0DGc= X-Google-Smtp-Source: ABdhPJz63m+l+iXd+OCo0UVLwLG/befIE8y8H8H5VBG7c2com9uNgD+uTGPAgd5FQogMbkTMmW/1jw== X-Received: by 2002:a5d:9b0a:: with SMTP id y10mr24083512ion.86.1597176382699; Tue, 11 Aug 2020 13:06:22 -0700 (PDT) Received: from mail-io1-f44.google.com (mail-io1-f44.google.com. [209.85.166.44]) by smtp.gmail.com with ESMTPSA id e23sm1026974iot.28.2020.08.11.13.06.21 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Aug 2020 13:06:21 -0700 (PDT) Received: by mail-io1-f44.google.com with SMTP id b17so70520ion.7 for ; Tue, 11 Aug 2020 13:06:21 -0700 (PDT) X-Received: by 2002:a02:9247:: with SMTP id y7mr26798836jag.140.1597176381447; Tue, 11 Aug 2020 13:06:21 -0700 (PDT) MIME-Version: 1.0 References: <20200811183950.10603-1-peterx@redhat.com> In-Reply-To: From: Linus Torvalds Date: Tue, 11 Aug 2020 13:06:04 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3] mm/gup: Allow real explicit breaking of COW To: Peter Xu , Andrea Arcangeli Cc: Linux-MM , Linux Kernel Mailing List , Andrew Morton , Marty Mcfadden , "Maya B . Gokhale" , Jann Horn , Christoph Hellwig , Oleg Nesterov , Kirill Shutemov , Jan Kara Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 553763D66B X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 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, Aug 11, 2020 at 12:24 PM Linus Torvalds wrote: > > Now I wonder if there's any other case of FOLL_WRITE that is missing. Actually, now I wonder if we really should have tried to handle the wrong-way cow reuse case some other way entirely. When discussing this wrong-way-COW issue originally I looked at just doing struct page *page = vmf->page; if (page_count(page) != 1) goto copy; if (!trylock_page(page)) goto copy; if (page_mapcount(page) != 1 && page_count(page) != 1) { unlock_page(page); goto copy; } /* Ok, we've got the only map reference, and the only * page count reference, and the page is locked, * it's dark out, and we're wearing sunglasses. Hit it. */ wp_page_reuse(vmf); unlock_page(page); return VM_FAULT_WRITE at the top of the PageAnon() case in do_wp_page(), and be entirely done with it. Make the rule be that we *only* re-use the page if there is no question what-so-ever that we're the only possible owner of it. Anything else at all - whether they be GUP users, other processes, KSM, hughepage collapsing, whatever: don't even try. That would possibly cause a lot of extra copies, but our rules for "can we re-use this page" are just crazy complicated. And now the "minimal" thing of just always breaking COW ends up causing complications of its own. IOW, maybe all of this falls under "yeah, we have historical reasons for all of it, but it's just not worth the pain". We do a _lot_ of complex stuff just to check whether we could possibly share the page. Maybe trying to reuse the page just isn't worth it? Adding Andrea to the cc (although he probably sees this through linux-mm anyway). Maybe he can go "naah, that will be horribly bad, because..." Then we could get rid of all the FAULT_FORCE_COW games again entirely, and people can point fingers at me and laugh behind my back because of what a bad idea it was. Linus