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 06358C433F5 for ; Mon, 20 Dec 2021 19:39:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 75AAC6B0071; Mon, 20 Dec 2021 14:39:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 709AA6B0073; Mon, 20 Dec 2021 14:39:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5AA156B0074; Mon, 20 Dec 2021 14:39:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0098.hostedemail.com [216.40.44.98]) by kanga.kvack.org (Postfix) with ESMTP id 4CDFF6B0071 for ; Mon, 20 Dec 2021 14:39:25 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id ECA42181AC9C6 for ; Mon, 20 Dec 2021 19:39:24 +0000 (UTC) X-FDA: 78939186648.01.CBF7935 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) by imf15.hostedemail.com (Postfix) with ESMTP id CD74AA003A for ; Mon, 20 Dec 2021 19:39:17 +0000 (UTC) Received: by mail-ed1-f46.google.com with SMTP id w16so14337367edc.11 for ; Mon, 20 Dec 2021 11:39: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=0HEIGasiDjlyDxa0Yi+2EmuRxngp8FedzY8QNTfhikI=; b=X/tYG9QpqUmW6+H6ZYV0nRa4/njzoyToFNJ9zOYVkDvcTiybU29zVqv9btuh6Q6Zb+ ZU8bp6ncsBiJHAlMaETRxIEeO1W44QSEarGybDoySgE1Kihe9Znw3ZOsf+trnjzPi50n 9dzynaN+Ov3/Bl4U4xx2HsvgbBFtRQJeRiMJI= 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=0HEIGasiDjlyDxa0Yi+2EmuRxngp8FedzY8QNTfhikI=; b=1b9rNzd5sC3l2eBNp0R/05sN5LoO0Rv9fjdJGJR2BCV7ESt3NvGGQMT0HZYqbyOJAO N7VdaNlZdVo3FFAMAz6444gx2q9UFbze/3JXF1x0WFCOCT+NUCvf06PIQOonjVJqK6OV g6sCzz1LIvUfpFbbfUpdNsPL36qdWC8ll5I4YwKLfrMZdjiwwx7U6cdC2ZYz9V6SzuEW zCHXxMWpFp1GC1YbqvR4gpusjayELjRfBQHQ6YtxcFup+m+3zQtCIRawk5dU/MSn6BOK XtKSUgyeGfnzxtiYVILARgAlEIpyqixEqyIO1LQxd8a8Ax2vYPG774vxRVflqVKAoh4B Hnzg== X-Gm-Message-State: AOAM531lbRtOl/8MvKvnVwEpVi+lCDzbzUcv3IqzTKAkVIMwzN+umVkl nP07oeO1HPmwNIWlsmdNSXe0x1wTXt/bnT1FzlE= X-Google-Smtp-Source: ABdhPJySLSNis+CkEClKaa95By/QeBpS3DVqZblFn+riHRcO8XQvn/yRBJsJ6KyxySfQcIV6RjjeBQ== X-Received: by 2002:a17:907:6291:: with SMTP id nd17mr14608078ejc.194.1640029162846; Mon, 20 Dec 2021 11:39:22 -0800 (PST) Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com. [209.85.208.51]) by smtp.gmail.com with ESMTPSA id cb3sm2924243edb.35.2021.12.20.11.39.22 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 20 Dec 2021 11:39:22 -0800 (PST) Received: by mail-ed1-f51.google.com with SMTP id b13so14186846edd.8 for ; Mon, 20 Dec 2021 11:39:22 -0800 (PST) X-Received: by 2002:a5d:6211:: with SMTP id y17mr2559324wru.97.1640029151469; Mon, 20 Dec 2021 11:39:11 -0800 (PST) MIME-Version: 1.0 References: <5CA1D89F-9DDB-4F91-8929-FE29BB79A653@vmware.com> <4D97206A-3B32-4818-9980-8F24BC57E289@vmware.com> <5A7D771C-FF95-465E-95F6-CD249FE28381@vmware.com> In-Reply-To: From: Linus Torvalds Date: Mon, 20 Dec 2021 11:38:55 -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: Matthew Wilcox Cc: David Hildenbrand , Nadav Amit , Jason Gunthorpe , Linux Kernel Mailing List , Andrew Morton , Hugh Dickins , David Rientjes , Shakeel Butt , John Hubbard , Mike Kravetz , Mike Rapoport , Yang Shi , "Kirill A . Shutemov" , Vlastimil Babka , Jann Horn , Michal Hocko , 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-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: CD74AA003A X-Stat-Signature: 5rxtti3e36egfbu5a3qpea7dbysczkym Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=google header.b="X/tYG9Qp"; dmarc=none; spf=pass (imf15.hostedemail.com: domain of torvalds@linuxfoundation.org designates 209.85.208.46 as permitted sender) smtp.mailfrom=torvalds@linuxfoundation.org X-HE-Tag: 1640029157-303874 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 Mon, Dec 20, 2021 at 10:53 AM Matthew Wilcox wrote: > > It makes me wonder if reuse_swap_page() can also be based on refcount > instead of mapcount? I suspect it doesn't even need refcount. For regular pages, after we've copied the page, all we do right now is if (page_copied) free_swap_cache(old_page); which is basically just an optimistic trylock_page() followed by try_to_free_swap(). And that then pretty much simply checks "are there any swap users left" and deletes it from the swap cache if not. The "free_swap_cache()" thing is actually just an optimization to avoid having memory pressure do it later. So it doesn't have to be exact. In fact, I thought that swap is so unusual that it's not even needed at all, but I was wrong. See how this was re-introduced in commit f4c4a3f48480 ("mm: free idle swap cache page after COW") because yes, some loads still have swap space allocated. In theory, it would probably be a good idea at COW time to see if the page ref is 2, and if it's a swap cache page, and try to do that swap cache removal even earlier, so that the page actually gets re-used (instead of copied and then the swap entry removed). But swap is such a non-issue these days that I doubt it matters, and it's probably better to keep the swap handling in the unusual path. So mapcount and refcount aren't what matters for the swap cache. The swap count obviously *does* matter - because it means that some mapping has a reference to this swap entry (not as a page, but as an actual swap pointer). But the mapcount is irrelevant - any users that have the swap page actually mapped, don't actually need to be a swapcache page. Even the refcount doesn't really matter, afaik. The only "refcount" we care about is that swapcount - that's what actually reference counts the swap cases. try_to_free_swap() does check for one particular kind of reference: it does a check for PageWriteback(). We don't want to remove the thing from the swap cache if it's under active IO. (This codepath does need the page lock, though, thus all those "page_trylock()" things). Linus