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 2237CC433F5 for ; Thu, 13 Jan 2022 17:44:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A17B66B0071; Thu, 13 Jan 2022 12:44:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 99F5C6B0073; Thu, 13 Jan 2022 12:44:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 818DB6B0074; Thu, 13 Jan 2022 12:44:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0232.hostedemail.com [216.40.44.232]) by kanga.kvack.org (Postfix) with ESMTP id 6B1CB6B0071 for ; Thu, 13 Jan 2022 12:44:25 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 1065F181B10E7 for ; Thu, 13 Jan 2022 17:44:25 +0000 (UTC) X-FDA: 79025988090.10.D7B5239 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) by imf01.hostedemail.com (Postfix) with ESMTP id A3ADE40005 for ; Thu, 13 Jan 2022 17:44:24 +0000 (UTC) Received: by mail-ed1-f49.google.com with SMTP id i5so25928111edf.9 for ; Thu, 13 Jan 2022 09:44:24 -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=vFoGln4GPtAHnUxFY/ors8ny9KKsd5+31evPartr4oQ=; b=KedncrSCaadRSyFLntxCTXi9z2IIgRLPvIJOHrOOwaHKy8Aobcpbbyw/o5qWtHsFx9 1pQ8ax77ONX1HZ0kM7HrZfEUKEXngbnBIhIQAggDl9GgDj0PTV0AzdaB/O6FG/igexaP tLSO/1ZeLhoMPWJuSxTlzmJxuVLGSMYD4NEh4= 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=vFoGln4GPtAHnUxFY/ors8ny9KKsd5+31evPartr4oQ=; b=1w1dpxTCVihNC+PEAFemx1jNmWncgR+VYuLKsXrsiUKOY2+cTmD1Fo45qs9wspTTVK PejyYj0a/1uTnEZhD9gpvClMOi+lPuhq7G0fMgvOck5L3FPq84tP7qGm3LfGu7D/DxYk 5uA9MiuY1se4BO0mJq9yrINtACdv9TZyGblPrFgsctRazAO6A/ESulhdEIDHe0UfNAM9 Es/vury/Jr8LMxXRyXb7B+nnVov+23hqJRahlXibDw3Uf/x4V1dmYHQsmuH8juH3lzLC cX/Szno+BpuzLacT3DnjonyPiIrRAAo5QQxeu87Tipr0e+M/6TCDciGk/hMe/xkIMceW L3Ug== X-Gm-Message-State: AOAM533Tqyu2w0/ebh/Y53QW2pxi91TgdRWhzEnAaz5lg95/HzGtQsuD rFhD5YEIQEMe2joFeUyL3Z/xZzgOPhq/iFvi X-Google-Smtp-Source: ABdhPJyGGqITVrfI4G1lE6HcDxX8IOeH9rxXgDVMOp+XXXEdTC8QjE51TKTN6uTgMNx2Gehaquhn9g== X-Received: by 2002:a17:906:dc92:: with SMTP id cs18mr4424499ejc.592.1642095863006; Thu, 13 Jan 2022 09:44:23 -0800 (PST) Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com. [209.85.221.47]) by smtp.gmail.com with ESMTPSA id s4sm579571ejm.146.2022.01.13.09.44.21 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 Jan 2022 09:44:21 -0800 (PST) Received: by mail-wr1-f47.google.com with SMTP id h10so11545404wrb.1 for ; Thu, 13 Jan 2022 09:44:21 -0800 (PST) X-Received: by 2002:a5d:6951:: with SMTP id r17mr4798730wrw.274.1642095861186; Thu, 13 Jan 2022 09:44:21 -0800 (PST) MIME-Version: 1.0 References: <20220113140318.11117-1-zhangliang5@huawei.com> <172ccfbb-7e24-db21-7d84-8c8d8c3805fd@redhat.com> In-Reply-To: From: Linus Torvalds Date: Thu, 13 Jan 2022 09:44:04 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] mm: reuse the unshared swapcache page in do_wp_page To: David Hildenbrand Cc: Matthew Wilcox , Liang Zhang , Andrew Morton , Linux-MM , Linux Kernel Mailing List , wangzhigang17@huawei.com Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: 851zoxnu1qf8ezbecjgi4qmwg7crdkoc Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=google header.b=KedncrSC; dmarc=none; spf=pass (imf01.hostedemail.com: domain of torvalds@linuxfoundation.org designates 209.85.208.49 as permitted sender) smtp.mailfrom=torvalds@linuxfoundation.org X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: A3ADE40005 X-HE-Tag: 1642095864-882363 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 Thu, Jan 13, 2022 at 9:25 AM David Hildenbrand wrote: > > I might be missing something, but it's not only about whether we can remove > the page from the swap cache, it's about whether we can reuse the page > exclusively in a process with write access, avoiding a COW. And for that we > have to check if it's mapped somewhere else already (readable). No. The "try to remove from swap cache" is one thing. That uses the swap count. The "see if we can reuse this page for COW" is a completely different test, and that's the "page_count() == 1" one. The two should not be mixed up with each other. Just don't do it. There's no reason - except for legacy confusion that should be actively avoided and removed. IOW, the COW path would do trylock - copy if fails try to remove from swap cache if page_count() is now 1, we can reuse it Note how the "try to remove from swap cache" is entirely independent of whether we then reuse it or not. And yes, we can have optimistic other tests - like not even bothering to trylock if we can see that the page-count is so elevated that it makes no difference and trying to remove from swap cache would be just pointless extra work (both the removal itself, and then potentially later re-additions). But those should be seen for what they are - not important for semantics, only a "don't bother, this page has so many users that we already know that removing the swapcache one doesn't make any difference at all". Now, it's possible that I'm missing something, but I think this kind of clarity is very much what we should aim for. Clear rules, no mixing of "can I COW this" with "can I remove this from the swap cache". And now I need to start my travel nightmare, so I'll be effectively offline for the next 24 hours ;( Linus