Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5385732rwb; Mon, 21 Nov 2022 22:12:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf7YCkozdbMwOint++XOSBaRginBMT1XOkspd4uhBkplzgW7hVT3im3wJ8YOGCAmd1AILLwU X-Received: by 2002:a17:906:38c:b0:78d:4ebb:7ea1 with SMTP id b12-20020a170906038c00b0078d4ebb7ea1mr3438523eja.357.1669097562467; Mon, 21 Nov 2022 22:12:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669097562; cv=none; d=google.com; s=arc-20160816; b=ymR5n7BFwdfLl6vnXjooVvUGowpMogQTfm25VEktQQ1wd5IIb/0QXW32ul7I5e+pK5 EmSMbjvlOLmTglcnVEOgsPOG309qC/wL7yZHgqTxIBlZjHfJuVzyuJcJGH7Qqh6hnCsT xjDgJWWQREyPgwYa85shkM4BaNaAQgsHtcmd7uakIKonSw4KHPOLnVFlLlv2hf4IBtiA zyVyvC+09Qzj1seq6IfCMkS62drMpYzTfj2d9ERyc31aQlWyDn9stpzPyJa94pJ+Z+LA gvW52kE5OvAuzRBs4MhgCMEO/ZKSMVWe6tQrzMTpJi2kpKcKZefpXFzMvCqp19lom/Dw tZ8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=H/dabyszLrJLcZ4mnIdkzcDGXW3b0QS/17vlN2tcOYk=; b=vbcuyy5VD6iGuMx9G3bTv8V0qYAGxZamYhZGFkwIQtwm8JqCLMq07u0pQqNxNNe865 XU3NYWl8bgGtVeC2owOgKeVpLzgkGcT+3+3QkAZ9RUmaWLxK3BZyw3HYpRsDUxgFKcf9 XGu72cOTPYGeqK9PJ1mNPCRMSqaKnA1+z6qNeBSy5LAd5p+qTrVtyTYJDVQYnLFYHrFB ucBlZReGWPXAk8Cwmsqi6/2U9O1CWyfzyk/77iFdAgxZG+j27RxwER8DL55C/Phi6vxn 37g6UqaeaL+T9/JDprR50vDHUCI8UGf6YRCRM3wHQld2t5OxedkyoT19aCsPYmDsNvCM XeJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=qgAqZiQI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cx24-20020a05640222b800b0046979f11f42si4715926edb.466.2022.11.21.22.12.16; Mon, 21 Nov 2022 22:12:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=qgAqZiQI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231895AbiKVF7p (ORCPT + 91 others); Tue, 22 Nov 2022 00:59:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232019AbiKVF7V (ORCPT ); Tue, 22 Nov 2022 00:59:21 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 417E312A9A for ; Mon, 21 Nov 2022 21:57:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=H/dabyszLrJLcZ4mnIdkzcDGXW3b0QS/17vlN2tcOYk=; b=qgAqZiQIlxnncE0oOqdTVVQyUq zdR88DGEE+hpdJp4oF0A5V6ykerYoL5iDYsc5A+An0Nu3u5bFKb9qpgLOjD6aRn4PSBiWvuKfIG/M 3r0gANmpwOfh0uJh439/kL0P5RJQsDMnutkBUN9CAW3N2SHISwkoAHUrovW2PHenKjSETdcPQMsQ8 Y7hAt2lHksolpozX32NJEBcKtL15WkLNfEYAZCl2S/kU5yCNI4kEhG2rO7huIHNQnKQbgM5VmT8LA l9amt7FI+6dJwnoxBt+gx3l/Xrcg5ilTASVpJ4Wdt4Kq9RI1+Tn1rwea+zTlB/BQjQSiWQidytv5r m3iYB0iQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1oxMHu-005zsc-6U; Tue, 22 Nov 2022 05:57:42 +0000 Date: Tue, 22 Nov 2022 05:57:42 +0000 From: Matthew Wilcox To: Johannes Weiner Cc: Shakeel Butt , Hugh Dickins , Andrew Morton , Linus Torvalds , "Kirill A. Shutemov" , David Hildenbrand , Vlastimil Babka , Peter Xu , Yang Shi , John Hubbard , Mike Kravetz , Sidhartha Kumar , Muchun Song , Miaohe Lin , Naoya Horiguchi , Mina Almasry , James Houghton , Zach O'Keefe , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH 0/3] mm,thp,rmap: rework the use of subpages_mapcount Message-ID: References: <5f52de70-975-e94f-f141-543765736181@google.com> <20221121165938.oid3pemsfkaeq3ws@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 21, 2022 at 01:52:23PM -0500, Johannes Weiner wrote: > That leaves clearing writeback. This can't hold the page lock due to > the atomic context, so currently we need to take lock_page_memcg() as > the lock of last resort. > > I wonder if we can have cgroup take the xalock instead: writeback > ending on file pages always acquires the xarray lock. Swap writeback > currently doesn't, but we could make it so (swap_address_space). > > The only thing that gives me pause is the !mapping check in > __folio_end_writeback. File and swapcache pages usually have mappings, > and truncation waits for writeback to finish before axing > page->mapping. So AFAICS this can only happen if we call end_writeback > on something that isn't under writeback - in which case the test_clear > will fail and we don't update the stats anyway. But I want to be sure. > > Does anybody know from the top of their heads if a page under > writeback could be without a mapping in some weird cornercase? I can't think of such a corner case. We should always wait for writeback to finish before removing the page from the page cache; the writeback bit used to be (and kind of still is) an implicit reference to the page, which means that we can't remove the page cache's reference to the page without waiting for writeback. > If we could ensure that the NR_WRITEBACK decs are always protected by > the xalock, we could grab it from mem_cgroup_move_account(), and then > kill lock_page_memcg() altogether. I'm not thrilled by this idea, but I'm not going to veto it.