Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp859413lqd; Wed, 24 Apr 2024 21:18:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVB9D4r5oDl2Jt+bqIZ24GgzQACWikrA7ExHBZcNg18+NGTlXWrWB9xgnLEOONJSBMsFhBnzEQKGPxGcZPiCmqAcxLv+P1yJ9Xfqa0qRA== X-Google-Smtp-Source: AGHT+IFivdhx65Zq1HRUbXqe5FNIcp1jB0uWc3w06qrsu7bYOkm1Ui3WPQp23PQlqeUuEXBIMAty X-Received: by 2002:a50:d70b:0:b0:568:be6d:e5e5 with SMTP id t11-20020a50d70b000000b00568be6de5e5mr2905428edi.37.1714018680580; Wed, 24 Apr 2024 21:18:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714018680; cv=pass; d=google.com; s=arc-20160816; b=bbFt8h0HAVlVjNROwRIXfOyv98ha9BIDNS1h5OqX6KLypJPBB9jh9d8yEYYFPJM+go Qpm0D8AMXurkDm/2mXonbOAm3EwuYSWZU0y6L6V52JPkCSfc8IuvV5wD8e2HYd7SJOZ+ jTiCJQPKKugblis5ewBCPLyqgGEobg+CJl1I19HqK5LOyKfhpvW024w16sXcMODNxtiA oG2rfwvwmYh8wFQ6Qh6Bu3Dg8QEVuj4iRNo/bR1wFOyfx8ockIlZfMnA5M22oKQ4rtZS ev6iWBR+A59dVpUyaGgGcTDurMFznTOxjV5xWOFcb8z/inloBVXTp66NX0oXqbSVpgra 3fPg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=ORT3V7drp4Vta7329poh3R+2iUUd0iHJIKKVjSlmMcs=; fh=w/EjusSukP1b1AfoIEFt4fu+fPTV/6YXJTnkKt1h4ck=; b=ymH00zDnrb8clsXccCV5F1QTL9CERH/lMyMg/tg4nTp6tZI/VjhMGrfGivDzfheODC 875TJ4jg56YMY4Xj1Z28CgxNov4WPhtdKstcTXO0/a6xVc3kMXIX1IXz4/YjEBbVsbO6 R4QJN0lWOwD3lyZvje/E0xeeAysdftaPvriOSjvQ7Wk05X5/3M4ZH/9u2tdsarQx9Bi8 2Dfzd4cp6O2d/egLg6kaPhgqCHN/DksfHaRkL1MhaQ56AchidFBDyVaM13jz3VKyaTER RsLaxAiu2Z+LOQd/qE+jet6EU7A+eZibmADApw//KJ/Xd0dfHYZDs4ihyMLN9xfv9JeQ eaLA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="IaFI/HNP"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-157989-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157989-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id u26-20020a50951a000000b00571e7bc07c7si7011022eda.433.2024.04.24.21.18.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 21:18:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-157989-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="IaFI/HNP"; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-157989-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-157989-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 051481F24525 for ; Thu, 25 Apr 2024 04:18:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BD8C1381BD; Thu, 25 Apr 2024 04:17:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IaFI/HNP" Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 48A80381A1 for ; Thu, 25 Apr 2024 04:17:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714018671; cv=none; b=bHzZSh578xmmNUKcVwju/8y3gxAU9f+p3Og9YT+Yxri4kJK7rnjy0iYDuDXfWHKyda6KpNW91lUlUfgE0OWS1jPrAPXASh5NhgUytKL8RwWD6645VrWJ96hBfTwvZqR+MO6P6Uoo4HQa6bKyiV5uY4saC19Lj1dypnCSdm7dY9M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714018671; c=relaxed/simple; bh=aTJpYtcXJix8jBrR3BkmXNYTay+jk0LXMT/Jk/423xQ=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=AZO23EZqW+UpH3EM7I6JUwsyiqcqMV9IccKC8UQ0ocEOKLQcwRE/ABleCEYGxCRkJTurHDGHqNSyMJ/jXAG5b9reVAKMeQpJSdJHm6TfXeLeOpzEO5F7EWYSF/TVJkadwN7wRB36pO3A0392ke6OGkIjMoD6g1nwvuaR/0OTh80= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IaFI/HNP; arc=none smtp.client-ip=209.85.208.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-2d895e2c6efso7300051fa.0 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=vger.kernel.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=IaFI/HNPVNn1OuG3CQlsehm6SJhAVloJ24ZHLPLvWI5CABfHl4HbSjlMgX5nl1QCZh 5lMq2HK+53ACr0B6lqAugyUffy2GzOp9sxvap1SFOrffhPnfmF668oJ4YidDkQZvlKDl Lu/to8S5onvxhAxLWEcT+tnP3gaV3U7OLdeNRMnbk9PpGwv57shGHxbUDHCoUtIRg6So ddBaksVBHQWdfKl1JKN3gLUOqYy4Eujo0XGwikTwahpOQgnccYQqlgCjiI58yRgp6goa 3/BeKzHFCtPbH3s7NLj8Na99EZ3vcoS/a8pcZY8SX0ZjkN40/CN/dxc8gNkcdWvRBucL gV1A== 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=roO+d9Di5uVe6NBqowFpM4wCr+wl46FBLAEU2wI2Ye+oWqx3rdyeWOscIUN0Iq7yRx 9fUYPJ1MTHTuJN82zuOxndAhvf83ZAOIabHc6oREwKOMojGaR9UIPuyaI9X7iTo4hdFp HTqZKnNxauS0MWH87MUZdG4Jv46toO3pMq3z3B/5CyNgCnHxrnRVNhOyf4aqYuQSi/5I 3Ks1MHhc3q8Qll96VnC1ZfRIcCwZ34SNaJ1GApxgEZjB3cnETugCzknD/w9Xo4Ga4q1A dtKfxqsV5E/0YkVu3MywJhLSJJ5DjxCB1h/pjYMjHu+RBEpngPJTB5vpT/qd5OWFE+78 YQRQ== X-Forwarded-Encrypted: i=1; AJvYcCV+C1uEBXar5gzQ8QP4rRi2yaRdBviyw42luSZvLYn5P+k9yFtr2tIqZuHZKd9jyfYXVbHeMlsy1RambGOoQz0mZFDGTIH+kAwWlj+v X-Gm-Message-State: AOJu0YyZ2yF5zPWFwE2XjUV7UoATFCix6q5LNNiNqMAINv8ZEelqajBm lO0JyC/DDolnBxyWrqwA1nwfSh3/fzhNPZuO0SVxhCyRN/TZ5xuchtEJfG0K/wHpbn8ut7zifU6 lFORcW7k7EQKP0+2L8t1QLlrwyFo= 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) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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 >