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 67BABC4332F for ; Tue, 22 Nov 2022 05:58:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ADBC98E0001; Tue, 22 Nov 2022 00:58:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ABC796B0075; Tue, 22 Nov 2022 00:58:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9A14F8E0001; Tue, 22 Nov 2022 00:58:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 8B4616B0074 for ; Tue, 22 Nov 2022 00:58:09 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 56D36A0F1D for ; Tue, 22 Nov 2022 05:58:09 +0000 (UTC) X-FDA: 80160022698.25.C034130 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf02.hostedemail.com (Postfix) with ESMTP id 3158980006 for ; Tue, 22 Nov 2022 05:58:07 +0000 (UTC) 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: ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669096689; a=rsa-sha256; cv=none; b=Mw+DOmQ5NlkYhcy7OTIZdQhrH6B/HbR2IlbrdVnZ+DufazZgiABlUOjHpWYGtIv7nwXFsj mGpUES2IaGjqnvK1hS3UGj5sL+xx5TLRVu1YLL8YTOdhil9VYciZBF9nt2izjpNFZzdAxq R0qoijk8ormJmQodVGfB+yEJV+r0u10= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=qgAqZiQI; dmarc=none; spf=none (imf02.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669096689; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=H/dabyszLrJLcZ4mnIdkzcDGXW3b0QS/17vlN2tcOYk=; b=Rzq7U4utef6Cq8XSrAq8ksCFKBbzxdyFMBwkZ368DQnOBib8WpC8VY94ImlT2oxKQ40AZA GtVLmG7YTnG1yaweNJj3FO7McNf1zK0Bten6UrQTc0T+cx/3TgqXsL8QvYv4KebaGGvxps Ro7Jzng9mPnCosV0DraEwDZw0AF2nHw= Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=qgAqZiQI; dmarc=none; spf=none (imf02.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-Stat-Signature: tmrtwwfffdyc4aoj4tyuca3nh41uqyyt X-Rspamd-Queue-Id: 3158980006 X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1669096687-580070 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, 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.