Received: by 2002:a05:6358:16cd:b0:dc:6189:e246 with SMTP id r13csp2890409rwl; Sat, 5 Nov 2022 13:33:03 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4uXuEQbVSFSAWPHQkjYZ8qCJwAW9ZwS/oLVpEwe5DzMVZCibIIe6sv6qqW/t+x45VMKI8P X-Received: by 2002:a17:902:e902:b0:186:9c03:5f27 with SMTP id k2-20020a170902e90200b001869c035f27mr42049796pld.16.1667680383489; Sat, 05 Nov 2022 13:33:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667680383; cv=none; d=google.com; s=arc-20160816; b=gDbK2aBdqbKWu1FdRJuquMYJdvMys609Bd4nSDepXarmzDyRHxPwoHy9KVQ6fXFsQU mPYevLENGdKH6CelpYmY3i7P7xvxICD/fq/Bs/4lwGgvMX4J4sG6CDvLVajzuoPTbVDE FSblRurp2S8hwWGonioaYT06Lu01FZxhWjvWKn/ZhiC0Bv0Nz2MqXauYdT9MHqKsvkkd oYAqddcgSp70ulMFCeiq24xT/zysr8XEl9gbY6ovmggbSX7ZxVAeZemUw/IS3YapaFlA NjRUyzwZ84WNjpqQ7f6uJSBWA3Um22QGWlW+8ec/H/zCOFEtN5jRWG0EC83LZOYeRTS0 j8SQ== 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:feedback-id :dkim-signature:dkim-signature; bh=BsCeaf14jLHWb+fLkSxCTF9UB6AbPje9aPDJaF0NlXs=; b=EOl9EeYoqIAwEe0gNKx6Td9lM43EaweSx3YbX+0X2s+9s34iY3cW0YuLe83Jxvn6Ox vy8WfP69Z3XIIF9kEc21dYgvkBHcZEX/NmEPNqQUORyamAIN+rl5/hoOpmjHGoHuTLAi TRkE7Wg28ekPAS1ZjC2Pp3aXsBIequDNRa4bb7uwOV6ZnuE50vjKFUo9ayG3DQwHv9z5 7FwPmdzbLEDCfDjIH9jOeyRDVUEJfG4DaRDyBH1Hh3HyUi0dZPmpez5ELRq2kcq5D+Sa iFhNKX+o/M2eqYRKij5dhvPNTNjBq5gDJzjF0PA68cV7mMLOJnsAJ1vD7yv/mvX1eMSD A2aQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov.name header.s=fm2 header.b=mFdJR4hM; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=WzvdEjYi; 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 a24-20020a170902b59800b0018663949529si3550676pls.162.2022.11.05.13.32.50; Sat, 05 Nov 2022 13:33:03 -0700 (PDT) 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=@shutemov.name header.s=fm2 header.b=mFdJR4hM; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=WzvdEjYi; 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 S229809AbiKEUGy (ORCPT + 97 others); Sat, 5 Nov 2022 16:06:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229788AbiKEUGu (ORCPT ); Sat, 5 Nov 2022 16:06:50 -0400 Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AE2213DCC for ; Sat, 5 Nov 2022 13:06:50 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 7D1D95C00D0; Sat, 5 Nov 2022 16:06:49 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Sat, 05 Nov 2022 16:06:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov.name; h=cc:cc:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm2; t=1667678809; x=1667765209; bh=Bs Ceaf14jLHWb+fLkSxCTF9UB6AbPje9aPDJaF0NlXs=; b=mFdJR4hMQbCC0fNwm9 5D2Ysku7jguxJH5YJQqzSbKuQxQhcKfu/gExHUza1ST+aUe0WRdQm6G9CE3o6emB YsjU/PGP6qgx9u+EBR+DFM1agFPLBasBEm5Ce9ypwy072Dux55D5SWItF8Hjhq7w j2/p+5FHijEKuDQwB3xIAsdr/RJyV5C1IE8mk85RPXcB1mV9+8PsirJ/Ft7IKiEC zYRovfRbis4V3H4Whon1V8fhVckSdM3yG4w0Tm983z6rDUNHJirwMLz63pBzA+1/ aTV4FTgrpfEMmmSrid9mX67F3rLsXMQKzJbPVlNrhwHpeCtFXTAdfORVQmUKgowl bMAw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1667678809; x=1667765209; bh=BsCeaf14jLHWb+fLkSxCTF9UB6Ab Pje9aPDJaF0NlXs=; b=WzvdEjYiIUdCqzI8fZqymDcQ2kIGnEfpVR13xVgU3ky1 wntOBLbC68yGVso9yrkAs45GzXgiIBLI1J6ThCiSHgb0onu6cbBektEbCdmADIwr RYrYcc7CynC0uHP28Bhzhx0lWNQU9vhsmMv/5UHKgrC2c0AXxXgfQ8eJlCo50YD3 nWhMkG5RWnbMGVAvarAjbXP0k+iIx1YglZrP22bc/xMTKl9Ww+Bz+0+KmXp5Z3eC puYArEH7PpW6eHURd4AYsWn+uA4HcgMUhGjxNCdD4XRmGydvOzwl+lyrCmOLM+lE yecJV+sJ2h4dWCFe7Pssow/2J4xB6nkrs75VF6LGIQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrvdeggddujecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehttddttddttddvnecuhfhrohhmpedfmfhirhhi lhhlucetrdcuufhhuhhtvghmohhvfdcuoehkihhrihhllhesshhhuhhtvghmohhvrdhnrg hmvgeqnecuggftrfgrthhtvghrnhephfeigefhtdefhedtfedthefghedutddvueehtedt tdehjeeukeejgeeuiedvkedtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomhepkhhirhhilhhlsehshhhuthgvmhhovhdrnhgrmhgv X-ME-Proxy: Feedback-ID: ie3994620:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 5 Nov 2022 16:06:47 -0400 (EDT) Received: by box.shutemov.name (Postfix, from userid 1000) id 448F9104449; Sat, 5 Nov 2022 23:06:46 +0300 (+03) Date: Sat, 5 Nov 2022 23:06:46 +0300 From: "Kirill A. Shutemov" To: Hugh Dickins Cc: Andrew Morton , 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 3/3] mm,thp,rmap: lock_compound_mapcounts() on THP mapcounts Message-ID: <20221105200646.wmfilka6prusrb56@box.shutemov.name> References: <5f52de70-975-e94f-f141-543765736181@google.com> <1b42bd1a-8223-e827-602f-d466c2db7d3c@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1b42bd1a-8223-e827-602f-d466c2db7d3c@google.com> X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,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 Wed, Nov 02, 2022 at 06:53:45PM -0700, Hugh Dickins wrote: > Fix the races in maintaining compound_mapcount, subpages_mapcount and > subpage _mapcount by using PG_locked in the first tail of any compound > page for a bit_spin_lock() on such modifications; skipping the usual > atomic operations on those fields in this case. > > Bring page_remove_file_rmap() and page_remove_anon_compound_rmap() > back into page_remove_rmap() itself. Rearrange page_add_anon_rmap() > and page_add_file_rmap() and page_remove_rmap() to follow the same > "if (compound) {lock} else if (PageCompound) {lock} else {atomic}" > pattern (with a PageTransHuge in the compound test, like before, to > avoid BUG_ONs and optimize away that block when THP is not configured). > Move all the stats updates outside, after the bit_spin_locked section, > so that it is sure to be a leaf lock. > > Add page_dup_compound_rmap() to manage compound locking versus atomics > in sync with the rest. In particular, hugetlb pages are still using > the atomics: to avoid unnecessary interference there, and because they > never have subpage mappings; but this exception can easily be changed. > Conveniently, page_dup_compound_rmap() turns out to suit an anon THP's > __split_huge_pmd_locked() too. > > bit_spin_lock() is not popular with PREEMPT_RT folks: but PREEMPT_RT > sensibly excludes TRANSPARENT_HUGEPAGE already, so its only exposure > is to the non-hugetlb non-THP pte-mapped compound pages (with large > folios being currently dependent on TRANSPARENT_HUGEPAGE). There is > never any scan of subpages in this case; but we have chosen to use > PageCompound tests rather than PageTransCompound tests to gate the > use of lock_compound_mapcounts(), so that page_mapped() is correct on > all compound pages, whether or not TRANSPARENT_HUGEPAGE is enabled: > could that be a problem for PREEMPT_RT, when there is contention on > the lock - under heavy concurrent forking for example? If so, then it > can be turned into a sleeping lock (like folio_lock()) when PREEMPT_RT. > > A simple 100 X munmap(mmap(2GB, MAP_SHARED|MAP_POPULATE, tmpfs), 2GB) > took 18 seconds on small pages, and used to take 1 second on huge pages, > but now takes 115 milliseconds on huge pages. Mapping by pmds a second > time used to take 860ms and now takes 86ms; mapping by pmds after mapping > by ptes (when the scan is needed) used to take 870ms and now takes 495ms. > Mapping huge pages by ptes is largely unaffected but variable: between 5% > faster and 5% slower in what I've recorded. Contention on the lock is > likely to behave worse than contention on the atomics behaved. > > Signed-off-by: Hugh Dickins Acked-by: Kirill A. Shutemov -- Kiryl Shutsemau / Kirill A. Shutemov