Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp8431743rwd; Tue, 20 Jun 2023 15:19:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6rXaJFINH8lkkTDtUZqxDJSe7deSsvmi/OzAFtihRBDmauIh6OrhCYcEjsmmJMVe/VMzb+ X-Received: by 2002:a05:6a00:1388:b0:668:6ce8:48ba with SMTP id t8-20020a056a00138800b006686ce848bamr6175630pfg.14.1687299573488; Tue, 20 Jun 2023 15:19:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687299573; cv=none; d=google.com; s=arc-20160816; b=Ec7QEwb4pzcMXVUjxkSV3f5PPPuPIOlx0QeyvdegR7JrEhKB73NCGV2c3lDXNmNknO KLkspChFxVHbTDbMoUT7jig5YCQ1ewh7zVbsExPBC9gIVZVMhFS3qTM4jbdODf3wvPtj oPYUG21BhHhQb5i4HzTmFeQLw1Sz4WwN8Nbfl9lDBlP7M0EIuGW75+dq44mX+qCbI2Po v6PDInExxY+GIy7taNtmr9tNwj951ijtcpzCWWH6CSvz/yHbs4csFWfNEzxmNtfV+J5d oj39BJXwuh2Sr7QnibE2n6gJFQpplOAiNWoGG2ZF0m4/SBeWKNai+5Zj1AT2lwKn4jrc sQpQ== 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=IFjjY5roZiwIkKPSUbI5fcD7pRZU5oiVbQVG2wmNIyk=; b=B9Z8+CpkgxxH3FspE4o6MBIsGE6JN84GkdteTlFs9H3ZM/xx+ylOItEWVaeaMZnSJv dCnwk3S7B1N9qTAwine1HDpmQRu7//UN/bz3B5R8ixPD2pjpvX276CQeAK38jFKhCvBu QfWm09WD0dvLg+5+25qBupRrGnZllMk9Wng4KlXqtmQ2vRJmFVBSAjJrydpH5oSJRsEY JJYz8BYccXM32q4foZyUZxehxFlkiF6j0g+R21wec5Vl77d+a+N1DnMt78m6+FvoluRe GpRbOXsajo+KYdH3EKCFLNhtw3a3JMwXiF7xXaA0HKY2YMCvS5/TlQKI80MoJzEhWDLq tqQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@anarazel.de header.s=fm2 header.b=h1fsw2NW; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=eQVIyGYP; 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-20020aa794b8000000b006543a5c8fb7si544911pfl.286.2023.06.20.15.19.20; Tue, 20 Jun 2023 15:19:33 -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=@anarazel.de header.s=fm2 header.b=h1fsw2NW; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=eQVIyGYP; 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 S229596AbjFTVlN (ORCPT + 99 others); Tue, 20 Jun 2023 17:41:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229506AbjFTVlM (ORCPT ); Tue, 20 Jun 2023 17:41:12 -0400 Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 102F6170D for ; Tue, 20 Jun 2023 14:41:11 -0700 (PDT) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id 59608320091D; Tue, 20 Jun 2023 17:41:07 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Tue, 20 Jun 2023 17:41:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type: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=1687297266; x=1687383666; bh=IF jjY5roZiwIkKPSUbI5fcD7pRZU5oiVbQVG2wmNIyk=; b=h1fsw2NWh5JvfJotED pWAHMvSeuUWwgN6ejG3ulwtxY01wU4Bx3GlAnbfz1blo++XmLfnxHXu5q4uhEg7F +eYLNbG6BoJQ5pRcU5Cj6mdwbCYP6KGF63IR/OZua+A9/TlfNI4tbViujV44QOEs eJ+A1QV2WW2PF9/QZBLhiyrDLnJH0+LJN/vsQvpePaCrxNO8t76TL+UBrhZhmktH LinlWnVdLjxKPSGAd7nPewPGq8+2GADYL66Qi56cApOipg3zouDIsdaZpNISoKEN XKNQ/rz1bMqc641hFOnMTVQRDKuHqKqFDD9aVLSTVA3YCQLv6O544XkAEMdj0kPF JFow== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type: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=fm2; t=1687297266; x=1687383666; bh=IFjjY5roZiwIk KPSUbI5fcD7pRZU5oiVbQVG2wmNIyk=; b=eQVIyGYPd5rS5NNsI653/DGuL5SUK zfEVfjFjKFYyoEX42Mj9taTFKf9Hj1miWpJEAxCHc2kgcdzXvIxgmxVJLC6QpMBh FQF+ow+RfBVHLJC5YdQNGgYpR0eCQWSUq6ZMPVcvI2QIQrS1/H+qUCnwwl7HRAXG H3XCAvT+yEJP1E7MiQdz92pc6oiR2EsO5weP6hyZd1eeh8n6Iovo58AgkEWezbHB P7IUXc/0YuuMuCipInZ/A9Q7IDPtEk43/ap3+XudS15BIho0Yp+tlS/8SOgd7hPh zzhYNjV89pOm0nKV5RD4DidRR/lNXZ8lqsMc+ytjAq1pOo9O7XQcZWrtA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeefiedgtddvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesthdtredttddtvdenucfhrhhomheptehnughr vghsucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrf grthhtvghrnhepueelhedvkeehvddvgeevleektefhteefueefhefhteeigffgtdegkeek geeigeeunecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucevlhhushhtvghrufhiii gvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrnhgurhgvshesrghnrghrrgiivghl rdguvg X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 20 Jun 2023 17:41:06 -0400 (EDT) Date: Tue, 20 Jun 2023 14:41:05 -0700 From: Andres Freund To: Peter Xu Cc: David Stevens , linux-mm@kvack.org, Hugh Dickins , Andrew Morton , Matthew Wilcox , "Kirill A . Shutemov" , Yang Shi , David Hildenbrand , Jiaqi Yan , linux-kernel@vger.kernel.org Subject: Re: [PATCH v6 4/4] mm/khugepaged: maintain page cache uptodate flag Message-ID: <20230620214105.3d4tm54gzodcx3uk@awork3.anarazel.de> References: <20230404120117.2562166-1-stevensd@google.com> <20230404120117.2562166-5-stevensd@google.com> <20230620205547.qzmivkjox2hkpzmm@awork3.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Hi, On 2023-06-20 17:11:30 -0400, Peter Xu wrote: > On Tue, Jun 20, 2023 at 01:55:47PM -0700, Andres Freund wrote: > > On 2023-04-04 21:01:17 +0900, David Stevens wrote: > > > From: David Stevens > > > > > > Make sure that collapse_file doesn't interfere with checking the > > > uptodate flag in the page cache by only inserting hpage into the page > > > cache after it has been updated and marked uptodate. This is achieved by > > > simply not replacing present pages with hpage when iterating over the > > > target range. > > > > > > The present pages are already locked, so replacing them with the locked > > > hpage before the collapse is finalized is unnecessary. However, it is > > > necessary to stop freezing the present pages after validating them, > > > since leaving long-term frozen pages in the page cache can lead to > > > deadlocks. Simply checking the reference count is sufficient to ensure > > > that there are no long-term references hanging around that would the > > > collapse would break. Similar to hpage, there is no reason that the > > > present pages actually need to be frozen in addition to being locked. > > > > > > This fixes a race where folio_seek_hole_data would mistake hpage for > > > an fallocated but unwritten page. This race is visible to userspace via > > > data temporarily disappearing from SEEK_DATA/SEEK_HOLE. This also fixes > > > a similar race where pages could temporarily disappear from mincore. > > > > > > Fixes: f3f0e1d2150b ("khugepaged: add support of collapse for tmpfs/shmem pages") > > > Signed-off-by: David Stevens > > > > I noticed that recently MADV_COLLAPSE stopped being able to collapse a > > binary's executable code, always failing with EAGAIN. I bisected it down to > > a2e17cc2efc7 - this commit. > > > > Using perf trace -e 'huge_memory:*' -a I see > > > > 1000.433 postgres.2/1872144 huge_memory:mm_khugepaged_collapse_file(mm: 0xffff889e800bdf00, hpfn: 46720000, index: 1537, is_shmem: 1, filename: "postgres.2", result: 17) > > 1000.445 postgres.2/1872144 huge_memory:mm_khugepaged_scan_file(mm: 0xffff889e800bdf00, pfn: -1, filename: "postgres.2", present: 512, result: 17) > > 1000.485 postgres.2/1872144 huge_memory:mm_khugepaged_collapse_file(mm: 0xffff889e800bdf00, hpfn: 46720000, index: 2049, is_shmem: 1, filename: "postgres.2", result: 17) > > 1000.489 postgres.2/1872144 huge_memory:mm_khugepaged_scan_file(mm: 0xffff889e800bdf00, pfn: -1, filename: "postgres.2", present: 512, result: 17) > > 1000.526 postgres.2/1872144 huge_memory:mm_khugepaged_collapse_file(mm: 0xffff889e800bdf00, hpfn: 46720000, index: 2561, is_shmem: 1, filename: "postgres.2", result: 17) > > 1000.532 postgres.2/1872144 huge_memory:mm_khugepaged_scan_file(mm: 0xffff889e800bdf00, pfn: -1, filename: "postgres.2", present: 512, result: 17) > > 1000.570 postgres.2/1872144 huge_memory:mm_khugepaged_collapse_file(mm: 0xffff889e800bdf00, hpfn: 46720000, index: 3073, is_shmem: 1, filename: "postgres.2", result: 17) > > 1000.575 postgres.2/1872144 huge_memory:mm_khugepaged_scan_file(mm: 0xffff889e800bdf00, pfn: -1, filename: "postgres.2", present: 512, result: 17) > > > > for every attempt at doing madvise(MADV_COLLAPSE). > > > > > > I'm sad about that, because MADV_COLLAPSE was the first thing that allowed > > using huge pages for executable code that wasn't entirely completely gross. > > > > > > I don't yet have a standalone repro, but can write one if that's helpful. > > There's a fix: > > https://lore.kernel.org/all/20230607053135.2087354-1-stevensd@google.com/ > > Already in today's Andrew's pull for rc7: > > https://lore.kernel.org/all/20230620123828.813b1140d9c13af900e8edb3@linux-foundation.org/ Ah, great! I can confirm that the fix unbreaks our use of MADV_COLLAPSE for executable code... Greetings, Andres Freund