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 03921C43219 for ; Mon, 21 Nov 2022 18:52:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24FE16B007B; Mon, 21 Nov 2022 13:52:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1FFEE6B007D; Mon, 21 Nov 2022 13:52:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C95E8E0002; Mon, 21 Nov 2022 13:52:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id EF4386B007B for ; Mon, 21 Nov 2022 13:51:59 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id BDB06A06DB for ; Mon, 21 Nov 2022 18:51:59 +0000 (UTC) X-FDA: 80158343958.23.FA897FA Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) by imf13.hostedemail.com (Postfix) with ESMTP id 47E0320008 for ; Mon, 21 Nov 2022 18:51:59 +0000 (UTC) Received: by mail-qk1-f182.google.com with SMTP id z1so8671351qkl.9 for ; Mon, 21 Nov 2022 10:51:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20210112.gappssmtp.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=AU9IGUZSk0DTVRsNQzhBBdP7igKqLtnqNm+OtNdCI+8=; b=n4CMVsAEvirHNRJzZgWy0d0EEJZKO83tj63ZhvOPbX0vbQImsU3U8AK6cc2IEpKXVV wJbuGkhCPN+RccMbc2h5ko2Bf5SqjtTwi+PRFQXas492osu7EhF65F/Cm7hevl+hHZRu PovR5OgdtiOfbemLhCcey47+k30x+2MA495dsCMDZnZvMmisP6A2WFY4q8wZIVI/l3cs MbOikPqGfoB/nu87OIH3DL5O40Nc0AQHy/83vTFTcHUt4jgXtBEJygfg/TP0D/tA0yrW aFeKH5ou08WzlbiFNI6Uxopq7DL/NeTqMtgnFlw2YEHSu5DNjn+tDJupJ7D/jpRKSvKu dm5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=AU9IGUZSk0DTVRsNQzhBBdP7igKqLtnqNm+OtNdCI+8=; b=DqQeCTZd+h7jES6k2AUuM4hw1+Ni78PQ75PX1xX4eqoyHrIqFh/Kz6cTp77MMOipdF whyorKrxQN8aHMQ44NTk+c2mFdEmMXPWyB6ZfrVhJAY22KyRENbZtqzPdhjwryqkohRt E/lFKxWu2xoxD7zGdPY/IUAPoq0iEDY0XDOieMlttfSB58CPEV4+VXPs3p0/2aE2+LPM Q+IvtYAdLhJJQD4W1UKlI/kQZQfGjeDWb5/0mAPbIWhIaRD5kRl/xIyv1tBjR5S0/PvZ EsH9n1T6V1aLAViceMMxSA2iv1CZlkawO7o1j/IwvUnUbJTd1hcx0YqdI04YqG6oOVE8 n59w== X-Gm-Message-State: ANoB5pnexzxDCzPii698B+OYx4ymaCYIHxrV7CAzQQYNAGFFvXw4CAMZ 82XET6h4MUTWkVTjQjEknCDUBA== X-Google-Smtp-Source: AA0mqf6OsOUZqeWSnhqWKMHf5VPW5a4RVMbvgU/3+25Ie1HN1BA1OXUplLGUzgKGEliGB5hEKHsrig== X-Received: by 2002:ae9:e901:0:b0:6fa:165:131c with SMTP id x1-20020ae9e901000000b006fa0165131cmr2507495qkf.389.1669056718422; Mon, 21 Nov 2022 10:51:58 -0800 (PST) Received: from localhost ([2620:10d:c091:480::1:bc4]) by smtp.gmail.com with ESMTPSA id z63-20020a37b042000000b006fafaac72a6sm8510696qke.84.2022.11.21.10.51.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Nov 2022 10:51:58 -0800 (PST) Date: Mon, 21 Nov 2022 13:52:23 -0500 From: Johannes Weiner To: Shakeel Butt Cc: Hugh Dickins , Andrew Morton , Linus Torvalds , "Kirill A. Shutemov" , Matthew Wilcox , 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: <20221121165938.oid3pemsfkaeq3ws@google.com> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669056719; a=rsa-sha256; cv=none; b=BDHqXCoV3fsXkSDh3uvnn+zXEkUKBXs8nNJlhiAsoT7L+TNkefoznADtuVxLNdmbu/zhxy EmeeDHN7XPTZfMdBjwaSjsuOf2SbFzGMZ4YIaVe3nuUKvNxh36diOdueLXtNj0mSINNat2 JdRgbwj/Jj1NBv9mE8GtKp6wOgSkwvw= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=n4CMVsAE; spf=pass (imf13.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.182 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669056719; 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=AU9IGUZSk0DTVRsNQzhBBdP7igKqLtnqNm+OtNdCI+8=; b=ZwGpf/OEH/+rlchcw2nIXhuZKW6Rl8SG7/f5YLLZ1fhGf9a4xsixZTz5WL2G7RG3kOnYeL ON+bnNCRyYlSnCHghiVoLkm46mEWtlXMu04wcGB7+CW99X3unacyspUfsFvSwmuAc4y29C QL525WXtdznvZeUh0ZqG8UxGTJEW4GQ= X-Rspam-User: X-Stat-Signature: s8otg1k81wsu1jos4ax3sbp44wqcqzpu X-Rspamd-Queue-Id: 47E0320008 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=n4CMVsAE; spf=pass (imf13.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.182 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org X-Rspamd-Server: rspam07 X-HE-Tag: 1669056719-729466 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 04:59:38PM +0000, Shakeel Butt wrote: > On Fri, Nov 18, 2022 at 01:08:13AM -0800, Hugh Dickins wrote: > > Linus was underwhelmed by the earlier compound mapcounts series: > > this series builds on top of it (as in next-20221117) to follow > > up on his suggestions - except rmap.c still using lock_page_memcg(), > > since I hesitate to steal the pleasure of deletion from Johannes. > > Is there a plan to remove lock_page_memcg() altogether which I missed? I > am planning to make lock_page_memcg() a nop for cgroup-v2 (as it shows > up in the perf profile on exit path) but if we are removing it then I > should just wait. We can remove it for rmap at least, but we might be able to do more. Besides rmap, we're left with the dirty and writeback page transitions that wrt cgroups need to be atomic with NR_FILE_DIRTY and NR_WRITEBACK. Looking through the various callsites, I think we can delete it from setting and clearing dirty state, as we always hold the page lock (or the pte lock in some instances of folio_mark_dirty). Both of these are taken from the cgroup side, so we're good there. I think we can also remove it when setting writeback, because those sites have the page locked as well. 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? 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.