Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp4739685rwb; Mon, 21 Nov 2022 11:13:29 -0800 (PST) X-Google-Smtp-Source: AA0mqf6PeTqy5T4UoOyN+IOY0OVMyatrbOjQDq71D2Ve+Ye+XOAcyzM3M/B1SqJvGSPK+3Z3uO6J X-Received: by 2002:a17:902:74c7:b0:188:ad33:23c with SMTP id f7-20020a17090274c700b00188ad33023cmr1922101plt.108.1669058009676; Mon, 21 Nov 2022 11:13:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669058009; cv=none; d=google.com; s=arc-20160816; b=hKYnIqfDtsTyYaP6XveODHZxhMVX69u2RfM9wO2oBw+3m/cNniQ1QsHMYktcbIQqS2 jnXheWVO7LG4ppEPT+2b4Oi9v8U5zqA0n/3dBHP0Qpx0T8QLbX+1xjk0ALjdc3Y2/dec gcbjGXufPNxaNuugdAw3nwkvTbFU3DTDJ2ZI2k9AWwX/ebtWmbtD1yQNTIAXcNHZbD0r /+ed/iBQ8hnZ3V3+xR/buccvg8NauYDBkaxBZssnGPIZNNrgAVXrmVRJsYvL9rzCy0At 5JQ8Fj9AroShzeXzfiMDfwqDdDlrRp+MWGvjGaX1oGBCbzikwzwNlkc7uD8WRg++L9aJ wudw== 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=AU9IGUZSk0DTVRsNQzhBBdP7igKqLtnqNm+OtNdCI+8=; b=bL+t/mdO+2oxL+tgtEKLQ0wEATOWIWeJmLXLcyjGltD5awadMpMntRWhZNiXLItPSL AC6lFdBUNburKDP/3aQybS1VCn4A19CJ/CXuK9+3g65W0B8i43xFQlNP0yay9IjMq/DJ 8UUIz+AISb3MBV2ahYOYsIbvqmJzMN+4J2aQ0XQ7FzF2BjUUYidHItQpLfu8T7oKXhzU J8xr9cyb6ITB23IYt+ox04lxBV9kvazh3GejCOg9BbYE0SPWdoKrPInjAd5QE7bqVLrn tnHTU07EthbUfdxVsQKX4eKgtmA7tblWJf3DMBnkZTnM8ymJV6+oQ0v8supcLA2/S/Oi VsZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=n4CMVsAE; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y1-20020a17090a2b4100b00216616c5fc4si13832961pjc.166.2022.11.21.11.13.17; Mon, 21 Nov 2022 11:13:29 -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=@cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=n4CMVsAE; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230241AbiKUSwG (ORCPT + 92 others); Mon, 21 Nov 2022 13:52:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229750AbiKUSwA (ORCPT ); Mon, 21 Nov 2022 13:52:00 -0500 Received: from mail-qk1-x72d.google.com (mail-qk1-x72d.google.com [IPv6:2607:f8b0:4864:20::72d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A83AD0DE7 for ; Mon, 21 Nov 2022 10:51:59 -0800 (PST) Received: by mail-qk1-x72d.google.com with SMTP id k2so8657499qkk.7 for ; Mon, 21 Nov 2022 10:51:59 -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=V0syzS67WHW/bNqhjkLltVt/Lz+rXdtqbvgdD2oDY7dAm5ghhPHnHDMQEFUWkGYsOr sPvymi8m4mO7lhXoQx6DdlSxTu/Ptl0fxTBjiUzxeBWt6UO6/wyD4Gys/4QXp6h+5pFX MDU2pfYzdabeFCLUZU0bca9XzTvdfLlCl0AWZjDmjd186RZU2n5Jwfd8uIC3aiS3cKvs +0V0gmlj9eFrrIyfzU+Sw5ee1dKzB/ximrNjge2zByPBra28t2YLDSctD3MAzLBWamvP NdRJnzs8xxvdhiKwOgg9qFbx9hi+CJzlL+9a2lF7bKLUZHExwGSdRgq+7FSWGpvLUob1 pG9Q== X-Gm-Message-State: ANoB5pnyIm7qvdRnK3xvYqOQ6f/n3IAFGXxs004ofH77Ojvy0RTvX2M8 b1CUa0OibQtYCeCDbyiedioTaA== 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> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 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.