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 30071C433EF for ; Thu, 13 Jan 2022 16:38:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD8196B0071; Thu, 13 Jan 2022 11:38:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A873B6B0073; Thu, 13 Jan 2022 11:38:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 94FDC6B0074; Thu, 13 Jan 2022 11:38:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0003.hostedemail.com [216.40.44.3]) by kanga.kvack.org (Postfix) with ESMTP id 86C566B0071 for ; Thu, 13 Jan 2022 11:38:04 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 49DBA181FC556 for ; Thu, 13 Jan 2022 16:38:04 +0000 (UTC) X-FDA: 79025820888.27.FE50CC8 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) by imf31.hostedemail.com (Postfix) with ESMTP id D86BC20004 for ; Thu, 13 Jan 2022 16:38:03 +0000 (UTC) Received: by mail-ed1-f49.google.com with SMTP id k15so25081725edk.13 for ; Thu, 13 Jan 2022 08:38:03 -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=1Cw+BPG1jU+zkMoF65IWzxVy0JjRkQm3f4AM/UiMJ3w=; b=cAQMLvY1l+pxTUzA5wD4375Pjo+U8FLdlE1SAXOB4zC66tjEqU49Kkv1M3vtcRqvX/ y7ehbaOeOoLvUewb1BgOa33+reC3WKmZaGzF/ik+pMaZoN8NBPjb3ZMM6WdV5jYPAPCO MCVR3XG4DBGrpONMVQnSsmcNWF0/dsXOu63gc= 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=1Cw+BPG1jU+zkMoF65IWzxVy0JjRkQm3f4AM/UiMJ3w=; b=dQbjsaPdOw6iJ8jE3Vym4T6iElXMWExy3xpUOYkB1xPgyYgHAxGjoQC5rgKzIYPMxh RyOD02bF2Bmw6+gGR80uDPVA7UfwEo4EYsb7ivQUfxJ/eErq+bdtFdzrtqIl3gN3D+n0 RjCzWPHTDjl1IYf4Hfe4eVbOvygI83EswDft5A0adC36GT7P3YbytQJQ48DWKBfFsnPw f9iF17d4CegizcxLsWPLFKGS1tMBdJaBjUQroJpc87vXvHz05whR1bighW7WIxYlfzZO egeWYyfc3znRtoJBgHOs21h9tOXkAiLoQJdhou6LXHeIvDxzcJ/KAelv+CG30EhXQ5yB CyzQ== X-Gm-Message-State: AOAM5316Q7o2KkgrwPqg/HjD2K6YHcS7i7OX9MhxP3iqHUO+gSG0UENh cW4YN7fSRyeXQkgsyFDr1X/AW9IwyT3m7TlM X-Google-Smtp-Source: ABdhPJzQBhdjkBmUvc/T547ESCUidCH7D77wJMOyBTVW+qU5jP0/KE2jvD9U8OkPUWoHGF3kAQQIQw== X-Received: by 2002:a17:906:58c8:: with SMTP id e8mr3990575ejs.444.1642091882244; Thu, 13 Jan 2022 08:38:02 -0800 (PST) Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com. [209.85.128.43]) by smtp.gmail.com with ESMTPSA id s5sm1031060ejn.205.2022.01.13.08.37.59 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 Jan 2022 08:38:00 -0800 (PST) Received: by mail-wm1-f43.google.com with SMTP id ay4-20020a05600c1e0400b0034a81a94607so3113936wmb.1 for ; Thu, 13 Jan 2022 08:37:59 -0800 (PST) X-Received: by 2002:a7b:ca42:: with SMTP id m2mr4583261wml.144.1642091879565; Thu, 13 Jan 2022 08:37:59 -0800 (PST) MIME-Version: 1.0 References: <20220113140318.11117-1-zhangliang5@huawei.com> In-Reply-To: From: Linus Torvalds Date: Thu, 13 Jan 2022 08:37:43 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] mm: reuse the unshared swapcache page in do_wp_page To: Matthew Wilcox Cc: Liang Zhang , Andrew Morton , Linux-MM , Linux Kernel Mailing List , wangzhigang17@huawei.com, David Hildenbrand Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: D86BC20004 X-Stat-Signature: gjh46o6qtnzkn8jwmajjjmy6jwfk7e1s Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=google header.b=cAQMLvY1; spf=pass (imf31.hostedemail.com: domain of torvalds@linuxfoundation.org designates 209.85.208.49 as permitted sender) smtp.mailfrom=torvalds@linuxfoundation.org; dmarc=none X-HE-Tag: 1642091883-960326 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 6:39 AM Matthew Wilcox wrote: > > Let's bring Linus in on this, but I think this reintroduces all of the > mapcount problems that we've been discussing recently. > > How about this as an alternative? No, at that point reuse_swap_page() is the better thing to do. Don't play games with page_count() (or even worse games with swap_count). The page count is only stable if it's 1. Any other value means that it can fluctuate due to concurrent lookups, some of which can be done locklessly under RCU. The biggest problem in the COW path used to be that it was completely incomprehensible. Plus it had that pointless synchronization if the page was locked for entirely unrelated reasons. Doing a "trylock()" - and just copying if it fails fixes that pointless "let's wait because we know somebody else is doing something to this page". And doing the if (PageSwapCache(page) && reuse_swap_page(page, NULL)) { thing after holding the lock is certainly not incomprehensible. I just wanted to try to avoid that on the assumption that swap really isn't all that relevant any more - even swap cache. The most incomprehensible part in that sequence is actually the KSM tests. I think they are BS and should be removed (the page_count() check should be sufficient), but they are so incomprehensible that I left them when I did my crapectomy. Linus