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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70509C433F5 for ; Fri, 17 Dec 2021 19:23:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C36116B0071; Fri, 17 Dec 2021 14:23:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BE51F6B0073; Fri, 17 Dec 2021 14:23:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A86286B0074; Fri, 17 Dec 2021 14:23:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0205.hostedemail.com [216.40.44.205]) by kanga.kvack.org (Postfix) with ESMTP id 9AB9E6B0071 for ; Fri, 17 Dec 2021 14:23:26 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 6272988CE8 for ; Fri, 17 Dec 2021 19:23:16 +0000 (UTC) X-FDA: 78928259592.08.FE7B5BC Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) by imf24.hostedemail.com (Postfix) with ESMTP id 0602A180018 for ; Fri, 17 Dec 2021 19:23:12 +0000 (UTC) Received: by mail-ed1-f46.google.com with SMTP id y13so11588742edd.13 for ; Fri, 17 Dec 2021 11:23:15 -0800 (PST) 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=wsxPP4x55S3xHdetgetRuLFyO1pK7A4RVTBxuMZfoqY=; b=LN01Ax5zkrMJ36hMWyzfEwjvgOa05trYbyjDx9OvqN5hVC5jgm8DAsreT8ZC9IIalh FdsStvpmEXelZNEqxx+tiW5zfa1gTjPnHrDtMyQU36PnWl7IppVmVyKP51KznO6W4vcH OrJ7ICe+DK/A6cO51E7sHzoyw84upkUlBNY1M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=wsxPP4x55S3xHdetgetRuLFyO1pK7A4RVTBxuMZfoqY=; b=aPocZLQ6ZYgUgO16WZFb9JfRduB1icOgZkQ9A/BeBiKrFuwwMmnFceBzTSsCYKM0SW dfTFrDD8xePqEvVRRAgtTiiW4Di7jtrknlY2mKXzTJ29LxI9fs2uNO6X2TAeZXh3r/Px qoJ1Skqy5k1T0ldvjdzHrgz+dcrmkF5jH36svBpHPYmKRqKA+QD9zd1/zb+yQU1PPBFf xcd/6pAvHrQ99lW9VJgojVX42aogTBUAwxRBwgwQet1Ni3hHlEREVDWLeZxuhyOXztCe iuNAiBfLQnU6SD9kqDvBPP8euSJaHO36W4Ro5/BCpjKT0LIJrwRR81TE4yPwmF2YhFp4 7EpQ== X-Gm-Message-State: AOAM5335aTI6z+5pzp0tV3kjijAlK6CBVtaW5eZrq1Qa2khjoNyIQCX5 eQV+xmmWMWdFfLH+GEsgjqNKPQxd4O+EK6ILskQ= X-Google-Smtp-Source: ABdhPJwN6MqVET7c1aWP9RKyyV6w0RyVQly2juoEd/OJw59F1lzuwFDL20POfYVlo8wHaPj+L1JxnQ== X-Received: by 2002:a17:906:7955:: with SMTP id l21mr3614602ejo.488.1639768994628; Fri, 17 Dec 2021 11:23:14 -0800 (PST) Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com. [209.85.128.44]) by smtp.gmail.com with ESMTPSA id t20sm3853826edv.81.2021.12.17.11.23.14 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 17 Dec 2021 11:23:14 -0800 (PST) Received: by mail-wm1-f44.google.com with SMTP id j140-20020a1c2392000000b003399ae48f58so4733709wmj.5 for ; Fri, 17 Dec 2021 11:23:14 -0800 (PST) X-Received: by 2002:a05:600c:1d97:: with SMTP id p23mr3854552wms.144.1639768983510; Fri, 17 Dec 2021 11:23:03 -0800 (PST) MIME-Version: 1.0 References: <20211217113049.23850-1-david@redhat.com> <20211217113049.23850-7-david@redhat.com> In-Reply-To: From: Linus Torvalds Date: Fri, 17 Dec 2021 11:22:47 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v1 06/11] mm: support GUP-triggered unsharing via FAULT_FLAG_UNSHARE (!hugetlb) To: David Hildenbrand Cc: Linux Kernel Mailing List , Andrew Morton , Hugh Dickins , David Rientjes , Shakeel Butt , John Hubbard , Jason Gunthorpe , Mike Kravetz , Mike Rapoport , Yang Shi , "Kirill A . Shutemov" , Matthew Wilcox , Vlastimil Babka , Jann Horn , Michal Hocko , Nadav Amit , Rik van Riel , Roman Gushchin , Andrea Arcangeli , Peter Xu , Donald Dutile , Christoph Hellwig , Oleg Nesterov , Jan Kara , Linux-MM , "open list:KERNEL SELFTEST FRAMEWORK" , "open list:DOCUMENTATION" Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: erha5aa8kxb16koskhny99hbqydy8j87 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 0602A180018 Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=google header.b=LN01Ax5z; spf=pass (imf24.hostedemail.com: domain of torvalds@linuxfoundation.org designates 209.85.208.46 as permitted sender) smtp.mailfrom=torvalds@linuxfoundation.org; dmarc=none X-HE-Tag: 1639768992-886696 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 Fri, Dec 17, 2021 at 11:04 AM Linus Torvalds wrote: > > If we are doing a COW, we need an *exclusive* access to the page. That > is not mapcount, that is the page ref. > > mapcount is insane, and I think this is making this worse again. Maybe I'm misreading this, but afaik - get a "readonly" copy of a local private page using FAULT_FLAG_UNSHARE. This just increments the page count, because mapcount == 1. - fork() - unmap in the original - child now has "mapcount == 1" on a page again, but refcount is elevated, and child HAS TO COW before writing. Notice? "mapcount" is complete BS. The number of times a page is mapped is irrelevant for COW. All that matters is that we get an exclusive access to the page before we can write to it. Anybody who takes mapcount into account at COW time is broken, and it worries me how this is all mixing up with the COW logic. Now, maybe this "unshare" case is sufficiently different from COW that it's ok to look at mapcount for FAULT_FLAG_UNSHARE, as long as it doesn't happen for a real COW. But honestly, for "unshare", I still don't see that the mapcount matters. What does "mapcount == 1" mean? Why is it meaningful? Because if COW does things right, and always breaks a COW based on refcount, then what's the problem with taking a read-only ref to the page whether it is mapped multiple times or mapped just once? Anybody who already had write access to the page can write to it regardless, and any new writers go through COW and get a new page. I must be missing something realyl fundamental here, but to me it really reads like "mapcount can fundamentally never be relevant for COW, and if it's not relevant for COW, how can it be relevant for a read-only copy?" Linus