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 8CF2BC433EF for ; Thu, 13 Jan 2022 17:15:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A10BA6B0072; Thu, 13 Jan 2022 12:15:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C0476B0073; Thu, 13 Jan 2022 12:15:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8615D6B0074; Thu, 13 Jan 2022 12:15:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 749056B0072 for ; Thu, 13 Jan 2022 12:15:09 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 31949181D1313 for ; Thu, 13 Jan 2022 17:15:09 +0000 (UTC) X-FDA: 79025914338.30.7BC3F14 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) by imf28.hostedemail.com (Postfix) with ESMTP id 1B0DDC000A for ; Thu, 13 Jan 2022 17:15:07 +0000 (UTC) Received: by mail-ed1-f46.google.com with SMTP id m4so25501610edb.10 for ; Thu, 13 Jan 2022 09:15:07 -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=kS0t9n6WxIZ4bWLd5wtbwG6/RZMrpLppDsAbCaXE63M=; b=YxzTX5Uhqq8IWsJVPAOhmMK2xnzPz7eAXueVAcwmhnWzlL8a0IUxHPtVCqGhIxIINq u5etVqmHwf1LHxwq5QG/zTCtvahIR9hBSYDsx4/mvVoAiR7Hh9WZpYSQZEPo2pUACeva 2JHZIo/uFA2x3txdZZgzgpCWkBdVOVqolnhzI= 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=kS0t9n6WxIZ4bWLd5wtbwG6/RZMrpLppDsAbCaXE63M=; b=vk177Ph4H0JyUPQbpIz7rPQzZbeeF6XsHzABR+clG8kaLFFJiG1+nFvJYSfng86IIx Y0UEQ5JeFc30mD+cbj7OKixZXBaMPY3iyiEIh6dC1e9sGbWQodJMqNhUfqfVMiILw/wn eoCYCI9mDEq92AvNTrk02AgIK8wCPzpAh0+HkZgb+QsUYMMSIb1xUd9d5/5oNCgZInUL VL/iBPVXoENzw7kCsIDO34R84sWqNxxmdmZrWrNwWqg2R8ziV5ne6JMA9iprb5Yb3BKt xv8nEEAk6STuVlt6yxcEzAImxuf/maFQYxnLaMSiivs2miyBWISqG2kTKVGXjTSynS0U O8Zg== X-Gm-Message-State: AOAM531SHgNzeYHXbTbKwJG8Jf2pQ1E32B5/w50TiliHOmdlDcOj3TDN +0n0fWKQxfD+QSR0oHIiFjEyMqWrWOrmqDjy X-Google-Smtp-Source: ABdhPJwyGQbMYfCIQKhryjrNyDuAndALfA4HB3geFrRpafrY+H+FLYQ9cigN1LVsWjeBj4Pcoz4z0w== X-Received: by 2002:a17:906:228d:: with SMTP id p13mr4004509eja.415.1642094106342; Thu, 13 Jan 2022 09:15:06 -0800 (PST) Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com. [209.85.221.43]) by smtp.gmail.com with ESMTPSA id a1sm1377336edu.17.2022.01.13.09.15.04 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 Jan 2022 09:15:04 -0800 (PST) Received: by mail-wr1-f43.google.com with SMTP id x4so11356104wru.7 for ; Thu, 13 Jan 2022 09:15:04 -0800 (PST) X-Received: by 2002:a05:6000:1846:: with SMTP id c6mr4710646wri.193.1642094104088; Thu, 13 Jan 2022 09:15:04 -0800 (PST) MIME-Version: 1.0 References: <20220113140318.11117-1-zhangliang5@huawei.com> <172ccfbb-7e24-db21-7d84-8c8d8c3805fd@redhat.com> In-Reply-To: <172ccfbb-7e24-db21-7d84-8c8d8c3805fd@redhat.com> From: Linus Torvalds Date: Thu, 13 Jan 2022 09:14:48 -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-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 1B0DDC000A X-Stat-Signature: bzbwgq76ibrn6yb794krypamujwazr7y Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=google header.b=YxzTX5Uh; spf=pass (imf28.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: 1642094107-142516 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 8:48 AM David Hildenbrand wrote: > > I'm wondering if we can get rid of the mapcount checks in > reuse_swap_page() and instead check for page_count() and swapcount only. Honestly, I think even checking page_count() is pointless. If the page has users, then that's fine. That's irrelevant for whether it's a swap page or not, no? So if you want to remove it from the swap cache, all that matters is that (a) you have it locked so that there can be no new users trying to mix it up (b) there are no swapcount() users of this page (which don't have a ref to the page itself, they only have a swap entry), so that you can't have somebody trying to look it up (whether some racy "concurrent" lookup _or_ any later one, since we're about to remove the swap cache association). Why would "map_count()" matter - it's now many times the *page* is mapped, it's irrelevant to swap cache status? And for the same reason, what difference does "page_count()" have? One big reason I did the COW rewrite was literally that the rules were pure voodoo and made no sense at all. There was no underlying logic, it was just a random collection of random tests that didn't have any logical architecture to them. Our VM is really really complicated already, so I really want our code to make sense. So even if I'm entirely wrong in my swap/map-count arguments above, I'd like whatever patches in this area to be really well commented and have some fundamental rules and logic to them so that people can read the code and go "Ok, makes sense". Please? Linus