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 3C16BC4345F for ; Thu, 25 Apr 2024 04:17:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A8DF36B0087; Thu, 25 Apr 2024 00:17:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A16F76B0089; Thu, 25 Apr 2024 00:17:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9051B6B008A; Thu, 25 Apr 2024 00:17:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 75AF36B0087 for ; Thu, 25 Apr 2024 00:17:52 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id CA2D34115B for ; Thu, 25 Apr 2024 04:17:51 +0000 (UTC) X-FDA: 82046745942.09.B8278F0 Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) by imf30.hostedemail.com (Postfix) with ESMTP id 1CB9080004 for ; Thu, 25 Apr 2024 04:17:49 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=aKswdVKT; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of ioworker0@gmail.com designates 209.85.208.174 as permitted sender) smtp.mailfrom=ioworker0@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714018670; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ORT3V7drp4Vta7329poh3R+2iUUd0iHJIKKVjSlmMcs=; b=NIOCHzvaKCGD3mp/BEwyiEbDDKlWH/HhlX8Q+efAdMhwrAcIxcRehhDyOngKvHxggLwGXi AgK6PQsWbl7rFK+4OLFPZjoogOZ2pJXmkDdCQ8Go5ZO14xSa8fN+ibhjs5N2B/8G944B++ GCSy/TDbHXiy533idbc3ndOh0eAP9dg= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=aKswdVKT; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf30.hostedemail.com: domain of ioworker0@gmail.com designates 209.85.208.174 as permitted sender) smtp.mailfrom=ioworker0@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714018670; a=rsa-sha256; cv=none; b=KjdI8Z3XEgDkeYeEiBoVHeW+1v1Ao78d90jz3MePM74gc4u+oBDvZJZ7NoBoaMvsAT9sEc EDP53vOvW1junTHqSrUgMrSpG/h2ahL0UC0u1zxilHupZe//98+EIR1cAD5S07XdfAyCB8 EQxCEYzmkgpPVVH/G6RPNJmWAv3Qou4= Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2dde561f852so5547131fa.2 for ; Wed, 24 Apr 2024 21:17:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714018668; x=1714623468; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ORT3V7drp4Vta7329poh3R+2iUUd0iHJIKKVjSlmMcs=; b=aKswdVKTkVS0pMV7lrcubm2A63uWaanQYAeB/1B+s2sbAqox1CyPLULsN58Jy+n4qS t5GcZKn/umCEaBKXQosO/1GBrD/ClQUOGFMxbjwPtp8Cvg352u2yNcBXSJxrepoUUpZG 6yWVHx4BtAGdSOgGwdN3CQxMnhK8Ovssj7PUdVwv7aTY+7ZDUVoG078xoDRJ+HgwDX5M D626Q9oRnMvqq65ldqIq7PQcSzpWjglh8WnShwbUipuwQrSOjSxnGPoPYxO43D6N6LA9 wkDU5enMsq0Q8zkMSwJpVaFv5xU874ImA9vVULeRhHAnhsUQe/K7fir2p4xuik+EGoyt ZdXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714018668; x=1714623468; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ORT3V7drp4Vta7329poh3R+2iUUd0iHJIKKVjSlmMcs=; b=InG6oK1UN4PwtfhGpgjqrqzRV7zL4vIFAltbS/RVLqJ1qYPGBiKMwVbAjc06jpKKrF 1lFz3VunQeNpE8Z/u6yJ4iAlIknZwcmD9TeSP8v7wiPHyO9kta4jplbxTMNZFSL439x9 Sz3WMO3NmU2QZy1d/HqVAUn/KDmZZmB9rJ3tiF9X1tCx0J97zUYUtMrXYYZb0g/IWgAT Mjv5vx9mBslED2Ojdue137fKKuE3HbdD6pB9tLRM4oImc5ElOefxY2qooWRKdsPeuLgO fHXJkoBMBLj9tc3b4FY3pjeZM0FwR9imr0pl55NPYUXrQuXx/wndracKLtfcCDv6ZR22 9xaQ== X-Forwarded-Encrypted: i=1; AJvYcCWGwnxYdAj7AmHJaQUMCCaN6JwyrOMyv6amO2AfrleC1XZgG1Ljj5q3QHXFgLsw/jFNchBDiofDMKsBL02A/dYnACg= X-Gm-Message-State: AOJu0YxptlI3fj9rRV/DD8xk4Oo2uAR/sKEmg3gKuBiBTVyzlfAAonZB ZTYY3k7PuCp5o8NyHz5sbgqeKKECQMsLvyZb6g2RaxN6drbCRTqcL5tPDEhG1YGZum4FoGtY1R5 OtVrGITqxzbHxm+sfGlroM8BQ010= X-Google-Smtp-Source: AGHT+IEo/He7+zlhE0aKh+ypaRnDjGU5zKmKF+wrxUe/Z5AcuKiJy15+2JFqdUBtDFRLBtqgFfLXhLQTE8iW/SndMp4= X-Received: by 2002:a2e:7a1a:0:b0:2d8:d0c9:1ffc with SMTP id v26-20020a2e7a1a000000b002d8d0c91ffcmr3106078ljc.1.1714018667996; Wed, 24 Apr 2024 21:17:47 -0700 (PDT) MIME-Version: 1.0 References: <20240422055213.60231-1-ioworker0@gmail.com> <1a0ca018-8ad3-42b0-b98a-8e6b6862fc7a@redhat.com> <333181FE-C2E6-4859-AF6A-0667A1F42037@nvidia.com> <51ba6efa-ce5a-49cf-b90e-62310db2c561@redhat.com> In-Reply-To: <51ba6efa-ce5a-49cf-b90e-62310db2c561@redhat.com> From: Lance Yang Date: Thu, 25 Apr 2024 12:17:36 +0800 Message-ID: Subject: Re: [PATCH v2 1/1] mm/vmscan: avoid split PMD-mapped THP during shrink_folio_list() To: David Hildenbrand Cc: Zi Yan , Matthew Wilcox , akpm@linux-foundation.org, maskray@google.com, ryan.roberts@arm.com, 21cnbao@gmail.com, mhocko@suse.com, fengwei.yin@intel.com, zokeefe@google.com, shy828301@gmail.com, xiehuan09@gmail.com, wangkefeng.wang@huawei.com, songmuchun@bytedance.com, peterx@redhat.com, minchan@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 1CB9080004 X-Rspam-User: X-Stat-Signature: fwq5j8nffxb5s78jfk8zjgfsinwza4sa X-HE-Tag: 1714018669-507463 X-HE-Meta: U2FsdGVkX18Aa3KLsdMzfFGdT0LE19/nDw4QBfeEsIVvzOBxJxl/AuZmlSjLoW0xD3GziMjqXE2gASehQZYnmkXOoM80U4+kYwY+vcUZPh4un9AHUjUPwIH3dQjVGoRXYR7CdRHt3FHLEOfPG+3pqyBRbTtJKRXa68GxztgDSZQljmrGMNpaHSAd7/3pZXzOIUGCnLDkmg4hNQD10EZPFfupoPuZO4p93vwZc8PSTItRfGVsmBj5YgxM++QfCsd2GHaw37/esnpAOmaO1ghRG45mPrfghogmghb0cKObtOH1gw0B1doGFFr1/Sap2NgdJ265wpVrBMNXgfgIi4JW5S1GCTsyPkeVeAyPZIyu/X+DFnnZiE23lxWjo7s9WV2XJxZjNlfrw9WGltp7Buug9gHo93/7HfqcGnKnO4yQ7/nhEaHJf7bRRquB2PZUueUC3Fftsiqe4L0y1uFX6jDhB1/Jsuny1Tm23IVj8qsRNHvw8UCM5Lcr1NiCRV0SntEMg3fqUNzRgWcOpUU8kX4DSGP2hElcLhiquKwLwyuiZN6zm2uSHNXdQqDVZoInDNLtOtBvSFAIOYmAGfufYSBFlYN9Ftr5LweTFj/CfwQeL9sPKMxHTkDD6WIDkKDPcbObFRK6IhBSIU1H+qMwbI1DBlRl3n7cTlBN2TSIlKpk7Q8yDGFhTAEkCnMOYdCaG3mQ+CLpgWD9FzwopP5DFhNNx1t2mqoRBbhCi+/K+qtDW0hpMUdFSWUWSZyqfiRXRg3NrReaLUwjHULnDfXBiOuRn7IBi/YAtkQVKO8rVYPi1eLVgwQq483fPhRTNM/lqq0sHRAIKYTCKuIBezrFHwNWnCH+C1YwbTxC60WRq3176EfIJS0r0WNqWYTj6tEQWHxvmVxraP8nM9Yb27O3UzmxCouPntp282KkpK5wDW4dYb7YF/L9ZaFmHQlB3GlYdxO387JcHpv4CncK+WiLQbc pmo3wxL0 mSm1WB8Fhymo8VuorViS3mgveJd0Pj1ZtPJz4uM/jyLPM9duimiUK1OIJauSY5R71SUZ586d5/5FUTDy9EbY5kll8+g== 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: List-Subscribe: List-Unsubscribe: Hey Zi, David, Thanks for taking time to review! On Wed, Apr 24, 2024 at 11:58=E2=80=AFPM David Hildenbrand wrote: > > On 24.04.24 17:57, Zi Yan wrote: > > On 24 Apr 2024, at 3:17, David Hildenbrand wrote: > > > >> On 24.04.24 06:15, Matthew Wilcox wrote: > >>> On Mon, Apr 22, 2024 at 01:52:13PM +0800, Lance Yang wrote: > >>>> When the user no longer requires the pages, they would use > >>>> madvise(MADV_FREE) to mark the pages as lazy free. IMO, they would n= ot > >>>> typically rewrite to the given range. > >>>> > >>>> At present, PMD-mapped THPs that are marked as lazyfree during > >>>> shrink_folio_list() are unconditionally split, which may be unnecess= ary. > >>>> If the THP is clean, its PMD is also clean, and there are no unexpec= ted > >>>> references, then we can attempt to remove the PMD mapping from it. T= his > >>>> change will improve the efficiency of memory reclamation in this cas= e. > >>> > >>> Does this happen outside of benchmarks? I'm really struggling to see > >>> how we end up in this situation. We have a clean THP without swap > >>> backing, so it's full of zeroes, but for some reason we haven't used = the > >>> shared huge zero page? What is going on? > >> > >> It's not full of zeroes. > >> > >> User space called MADV_FREE on a PMD-mapped THP. > >> > >> During MADV_FREE, we mark the PTEs as clean, the folio as clean and sd= "lazyfree" (no swap backend). If, during memory reclaim, we detect that (a= ) the folio is still clean (b) the PTEs are still clean and (c) there are n= o unexpected references (GUP), user space didn't re-write to that memory ag= ain, so we can just discard the memory "lazily". > > > > It seems that try_to_unmap_one() does not support unmapping PMD-mapped = folios. > > Maybe adding that support instead of a special case handling? > > I was thinking the same, and finding a way to avoid TTU_LAZYFREE_THP. Thanks for the suggestions! Yep, I completely agreed. Adding support for unmapping PMD-mapped folios to try_to_unmap_one() would make it more future-proof. Thanks again for the review! Lance > > -- > Cheers, > > David / dhildenb >