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.9 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 13220C433DF for ; Fri, 21 Aug 2020 12:28:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BEE7520724 for ; Fri, 21 Aug 2020 12:28:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="Uslkk0kL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BEE7520724 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 414678D004F; Fri, 21 Aug 2020 08:28:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C6218D0006; Fri, 21 Aug 2020 08:28:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 28D1A8D004F; Fri, 21 Aug 2020 08:28:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0121.hostedemail.com [216.40.44.121]) by kanga.kvack.org (Postfix) with ESMTP id 13DD48D0006 for ; Fri, 21 Aug 2020 08:28:02 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id B7D4D3631 for ; Fri, 21 Aug 2020 12:28:01 +0000 (UTC) X-FDA: 77174502762.14.pan71_150e66727039 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin14.hostedemail.com (Postfix) with ESMTP id 79B4318229835 for ; Fri, 21 Aug 2020 12:28:01 +0000 (UTC) X-HE-Tag: pan71_150e66727039 X-Filterd-Recvd-Size: 5959 Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Fri, 21 Aug 2020 12:28:00 +0000 (UTC) Received: by mail-lj1-f196.google.com with SMTP id v12so1620109ljc.10 for ; Fri, 21 Aug 2020 05:28:00 -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=vVEnmevXmWjia/tSlEkYasW33doqxhq1hrrAE4gD2Zs=; b=Uslkk0kLQy8rVRDLWSC4ZSu6zvuyMgq+S/0d9jEY3xM3jauyLCUuB1L5uuSRDph/tK EI/3nCJ4e1wvBuC6vpeEHOcGT9fwhPy9TNUii0Ts+Qql8fTUZrxacQGLJO6i9xKFZGss 3ZAdtX/wD7LddOm/Dx5TflS8QpQ9/sGryn/rc= 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=vVEnmevXmWjia/tSlEkYasW33doqxhq1hrrAE4gD2Zs=; b=Z5HF5rLVc26qryS/1CXeVdkLfMtPO4HxDwEMaiN6Lyaga83lWLp8raq++9MMCyrxQs 9IjGSpMoveetBxSbrg3scyi7nW7GbbDkPJj2+h+K7L/udh1Jm6qAqOv+X2ualjBbsUNA C8zC+5b9UiX+Gau5ruh8NJ8DVSP9g/ac+5IeugOJN6wnd2sonmGLqjUzkHlKM3bOvTgf 1Tr4M3qWsl5IjIaGaiKYHAGWNlpJK1Wt5eZf8guCmCKwutIJMoNr9EQkkHeGpnB4D2HM 5pslC+0AHusJ0Bmr4n/eAY+hV3z7PRBxft/G1t4QouLiaxLcrnr6n8UUaHRVGRTt5/Ff Y+6w== X-Gm-Message-State: AOAM533SjwjfFVhxdb9x6qbkA1RM+T1KN9j9X+c2zrWkXs/Odn6LVLsG 3hBpC/DEeZA5hd3DPjc65ER4zr2CHr0gUA== X-Google-Smtp-Source: ABdhPJx6gNArvvhAXQc61lfAHOotaFcc9gOTaTAwqQliUQ/K8PA9Bp6fRNXRQCtCUgXjwUpDs1nSzA== X-Received: by 2002:a2e:9b95:: with SMTP id z21mr1485213lji.83.1598012878850; Fri, 21 Aug 2020 05:27:58 -0700 (PDT) Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com. [209.85.167.49]) by smtp.gmail.com with ESMTPSA id q189sm354806ljq.68.2020.08.21.05.27.57 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 21 Aug 2020 05:27:57 -0700 (PDT) Received: by mail-lf1-f49.google.com with SMTP id b30so815261lfj.12 for ; Fri, 21 Aug 2020 05:27:57 -0700 (PDT) X-Received: by 2002:a19:c206:: with SMTP id l6mr1365004lfc.152.1598012876870; Fri, 21 Aug 2020 05:27:56 -0700 (PDT) MIME-Version: 1.0 References: <20200811183950.10603-1-peterx@redhat.com> <20200811214255.GE6353@xz-x1> <20200820215449.GB358043@xz-x1> <20200821101333.GA3432@quack2.suse.cz> In-Reply-To: <20200821101333.GA3432@quack2.suse.cz> From: Linus Torvalds Date: Fri, 21 Aug 2020 05:27:40 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3] mm/gup: Allow real explicit breaking of COW To: Jan Kara Cc: Peter Xu , Andrea Arcangeli , Linux-MM , Linux Kernel Mailing List , Andrew Morton , Marty Mcfadden , "Maya B . Gokhale" , Jann Horn , Christoph Hellwig , Oleg Nesterov , Kirill Shutemov Content-Type: text/plain; charset="UTF-8" X-Rspamd-Queue-Id: 79B4318229835 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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, Aug 21, 2020 at 3:13 AM Jan Kara wrote: > > > + if (page_mapcount(page) != 1 && page_count(page) != 1) { > > So this condition looks strange to me... Did you mean: > > if (page_mapcount(page) != 1 || page_count(page) != 1) Duh. Yes. > > - if (PageKsm(vmf->page)) { > > Also I know nothing about KSM but looking at reuse_ksm_page() I can see it > plays some tricks with page index & mapping even for pages with page_count > == 1 so you cannot just drop those bits AFAICT. Yeah, I wasn't really sure what we want to do. In an optimal world, I was thinking that we'd actually do exactly what we do at munmap time. Which is not to get the page lock at all. Just look at what zap_pte_range() does for an a page when it unmaps it: page_remove_rmap(page, false); and that's it. No games. And guess what? That "'page_remove_rmap()" is what wp_page_copy() already does. So I really think *all* of these games we play are complete garbage and completely wrong. Because the zap_page_range() path is a *lot* more common than the WP path, and triggers for every single page when we do munmap or exit or whatever. So why would WP need to do anything else for correctness? Absolutely no reason I can see. > Also I'm not sure if dropping this is safe for THP - reuse_swap_page() > seems to be a misnomer and seems to do also some THP handling. Again, I think that's a bogus argument. Because this all is actually not the common path at all, and the thing is, the common path does none of these odd games. I really think this COW handling magic is just legacy garbage because people have carried it along forever and everybody is worried about it. The fact is, the "copy" case is always safe, because all it does is basically the same as zap_page_range() does, with just adding a new page instead. And it's also possible I'm missing something. But yes. That '&&' should very much be a '||'. What can I say? Oops. Linus