Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp978723lqd; Thu, 25 Apr 2024 02:24:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXFLYoCaVEQDSJmpFW3+Qxc+nZQ7MbC7cbKQW3wF7OXGLa9feMP3816VllVM1YU1t+8QN95M25p1NY1Yd5RDymwG4fmruUwOKPKqfEtmw== X-Google-Smtp-Source: AGHT+IHrC9I89boLSq8m6WVf7NzLa6xrSXmlfh6hqK/pgKbLWW6+tMZ4Zc8CPdWuyHqeTwOGgw1g X-Received: by 2002:a05:6a00:138a:b0:6ea:c3bc:2031 with SMTP id t10-20020a056a00138a00b006eac3bc2031mr6933307pfg.7.1714037098570; Thu, 25 Apr 2024 02:24:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714037098; cv=pass; d=google.com; s=arc-20160816; b=VS2IP5dog9oP3tqTWBDUPL4INkytJeiuRYGE42zMfpol2c7WVOYBFV289lub5Hkbct mRJNdlGzsFz8eU6MmQHnfEiDF3t8WPqhEemLt8XJEa0HVeKtL27c+yNScWd3mYch3Fd8 QtnY82szhS95yIlxDqJFnI/W7eEebLb4UxXkN3TdeXuCovU/f05WVq8IPyPiydjHf0pf lauiuOsA/VokEk+oeBWONQ6dmSYH4C3vCBvEgnvSkzSaOhTv/AWC/yjjJjR0Tz6B/5yP x3gNZQu961N2I9HT3iVJcn0s1tqLvkdSu2W6wmnTdjLsNpAC3QhsWi0tmNNQf08us+t6 Ikuw== 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=KE8GiAVvHFw1cHCNgHzSoH9bicMfpW/mOredZ8/si0Q=; fh=rRtuVoHMGlNL8ZV1YgPINSfd8VTu4brjOWoB9Ugb6W8=; b=n5gSW9z16renTJjrAHML8FWf5nok7WfxtEdcf0M1PoenBc82AaAwbBoEaWtJROgSDS iFEQy4aCjsZxA5QE2YLqHXTs1I2iOFjgVwuhEqNLeBDaqcLK0wZG5qzsA2wRyuVZPbJm n99rGj/gkozAgsG6zwOX/+eCUBviiu/6QWWL5zHyWgAyuYkg8jHBZ9BhyXv5VtsXKH00 zmOh35zipQWfLPMPhpw208pHo6aY9nWwvtLGY07rqr5xwLv6QGIDdhyhjKlXznd8QEww At2qBe5692KNH869jciHc/eIGflWrM0WDMKXOZYAH/puDxcsS3gidXTY5uY7JOKH2lFt mz7g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=agv5DHl9; 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-158285-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158285-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id jo11-20020a056a00908b00b006ece021b536si13231554pfb.221.2024.04.25.02.24.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 02:24:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-158285-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=agv5DHl9; 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-158285-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158285-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 31FFD2820E6 for ; Thu, 25 Apr 2024 09:24:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 71DCA84D2D; Thu, 25 Apr 2024 09:21:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="agv5DHl9" Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (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 E2C6337140 for ; Thu, 25 Apr 2024 09:21:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714036885; cv=none; b=i3oe28HaqKgiGguNlnNmNE6BreNt6GlF62dA64DFi1EgzcXQA9CaMxPhTWxj2I9g7CMatZxHXzbugsGlN37gSLGOKfW9PLJFPIQrdNGJRVlqB9lwhW8NvJP0nUfCAhSrl4VTT/GbMk70+h9kPtwNIZyccwikaIyTGf31i3lFVNM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714036885; c=relaxed/simple; bh=w/74jurbDuepqPsA7RpgfY+QKH7zt6UX7ATRPYhZHb8=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=lhad8hfUSolpGAiI7+mNXlgeBsij+Mvg04fumCDzSHT47yQorANLA/GfmQtVn0AMzyyJrPg2S/pSTLtWZzE1SHYx5awcno7JkO8tZmXJ/jkqKAYg070SXx1hzaCn+NvDFmZt/fC4gLnCv6EUxPhhQmHcYD6IMD1OibF+kzm0EdM= 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=agv5DHl9; arc=none smtp.client-ip=209.85.208.48 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-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-56e4a148aeeso235104a12.2 for ; Thu, 25 Apr 2024 02:21:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714036882; x=1714641682; 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=KE8GiAVvHFw1cHCNgHzSoH9bicMfpW/mOredZ8/si0Q=; b=agv5DHl9oz6Md+R9Vf6D3LyptC/GollZ305ZMzMzzhCACqU8QA44khEbgltOYRseUB y74gzYn4nn2azBiQil4raCQhpMV+10gVdQzLjQ4JlIDrWvqA1obr/bLhwYMRNNsa8J6H zFqx5UfOxuXxpT9cBi/WKArIgAHlS4dPwpz6Rff6VrhVpWnKnPm20KwDGMTCkc13lWga nhSpCmeTlqS+CbotYf5NDxTEkUKcRonGzWrMosTvLWSj5exOSxl/0/OKU8KHKp9a6Gq5 QB0xB6KP7v7FvuE9NEe0SaXzv2XsZB+RDP5G3zF81S9gJYI4zCYqUieMwyYm/3EhmmCe 0idg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714036882; x=1714641682; 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=KE8GiAVvHFw1cHCNgHzSoH9bicMfpW/mOredZ8/si0Q=; b=DCuCnXlcK9mwXagX+YkooQvK40nBRJn3bImwTWTeGLcsm8R+W0YRhyYm6ekw1mTe5B WbUnFFNa9yMtbiQed4YSZvXhZlEHzIk6nSUCZsV7n4zZCbX0M6t5d66nUGEzpqexAHKS wEi0V2nmdecHpHxTRqKECncnwIy3jUmLWkWFqSYx2mbSqMcSook4WGUz5ZZjxVpsmpVU /S8TsHj5rKTeblU7ga/3yY49ZpsQ676zQWfZ3xPz04VzsDSqabrc0vs3tZEdw26XWiUG fyjGRllUEM57prLCtLSyiy2nOJUi/qjP7C8GrQxvmmf6y/7O/2/kUBJN7zgmphcSJEB1 KHRw== X-Forwarded-Encrypted: i=1; AJvYcCWgJ5NRfKedhEbH9wtkvsZz5Rio7E1wT9DE9kaDa1M3ZCpjEfF502fw0b81Lks0N75iNi9DhFMId6CCGFf5vHnDoIwsUzKi3DHYWsNS X-Gm-Message-State: AOJu0YzXmzOO61UBwdr32YeY2t9THmgNU6RjZdtOk4O0RbFnqKmv2Y2N 4tyfWfHF1s5u9Nqn5rjXgJ16aoHyBFOK9/ze+MJvrgVTdcGbh8yTRm7UaIT6uHO1UyFq9Lizw2n t+Fg21ewU2GHHq6Uo/Q94vi5Eq/k= X-Received: by 2002:a50:d542:0:b0:570:5b9c:3f25 with SMTP id f2-20020a50d542000000b005705b9c3f25mr2342825edj.26.1714036881928; Thu, 25 Apr 2024 02:21:21 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240425085051.74889-1-ioworker0@gmail.com> <49394660-8455-48ec-8ae1-fbd2d590d27a@redhat.com> In-Reply-To: <49394660-8455-48ec-8ae1-fbd2d590d27a@redhat.com> From: Lance Yang Date: Thu, 25 Apr 2024 17:21:10 +0800 Message-ID: Subject: Re: [PATCH v2 1/1] mm/vmscan: avoid split PMD-mapped THP during shrink_folio_list() To: David Hildenbrand Cc: ziy@nvidia.com, 21cnbao@gmail.com, akpm@linux-foundation.org, fengwei.yin@intel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, maskray@google.com, mhocko@suse.com, minchan@kernel.org, peterx@redhat.com, ryan.roberts@arm.com, shy828301@gmail.com, songmuchun@bytedance.com, wangkefeng.wang@huawei.com, willy@infradead.org, xiehuan09@gmail.com, zokeefe@google.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Apr 25, 2024 at 5:01=E2=80=AFPM David Hildenbrand wrote: > > On 25.04.24 10:50, Lance Yang wrote: > > Hey Zi, David, > > Hi, > > > > > How about this change(diff against mm-unstable) as follows? > > goes into the right direction, please resent the whole thing, that will > make it easier to review. Got it. I=E2=80=98ll keep that in mind, thanks! > > > > > I'd like to add __try_to_unmap_huge_pmd() as a new internal function > > specifically for unmapping PMD-mapped folios. If, for any reason, we ca= nnot > > unmap the folio, then we'll still split it as previously done. > > > > Currently, __try_to_unmap_huge_pmd() only handles lazyfree THPs, but it > > can be extended to support other large folios that are PMD-mapped in th= e > > future if needed. > > > > diff --git a/include/linux/rmap.h b/include/linux/rmap.h > > index 670218f762c8..0f906dc6d280 100644 > > --- a/include/linux/rmap.h > > +++ b/include/linux/rmap.h > > @@ -100,8 +100,6 @@ enum ttu_flags { > > * do a final flush if necessary = */ > > TTU_RMAP_LOCKED =3D 0x80, /* do not grab rmap lock: > > * caller holds it */ > > - TTU_LAZYFREE_THP =3D 0x100, /* avoid splitting PMD-mapped = THPs > > - * that are marked as lazyfree. = */ > > }; > > > > #ifdef CONFIG_MMU > > diff --git a/mm/rmap.c b/mm/rmap.c > > index a7913a454028..879c8923abfc 100644 > > --- a/mm/rmap.c > > +++ b/mm/rmap.c > > @@ -1606,6 +1606,19 @@ void folio_remove_rmap_pmd(struct folio *folio, = struct page *page, > > #endif > > } > > > > +static bool __try_to_unmap_huge_pmd(struct vm_area_struct *vma, > > + unsigned long addr, struct folio *fol= io) > > +{ > > + VM_WARN_ON_FOLIO(!folio_test_pmd_mappable(folio), folio); > > + > > +#ifdef CONFIG_TRANSPARENT_HUGEPAGE > > + if (folio_test_anon(folio) && !folio_test_swapbacked(folio)) > > + return discard_trans_pmd(vma, addr, folio); > > +#endif > > + > > + return false; > > +} > > + > > /* > > * @arg: enum ttu_flags will be passed to this argument > > */ > > @@ -1631,14 +1644,11 @@ static bool try_to_unmap_one(struct folio *foli= o, struct vm_area_struct *vma, > > if (flags & TTU_SYNC) > > pvmw.flags =3D PVMW_SYNC; > > > > -#ifdef CONFIG_TRANSPARENT_HUGEPAGE > > - if (flags & TTU_LAZYFREE_THP) > > - if (discard_trans_pmd(vma, address, folio)) > > + if (flags & TTU_SPLIT_HUGE_PMD) { > > + if (__try_to_unmap_huge_pmd(vma, address, folio)) > > return true; > > -#endif > > - > > - if (flags & TTU_SPLIT_HUGE_PMD) > > split_huge_pmd_address(vma, address, false, folio); > > + } > > > > I was wondering if we can better integrate that into the pagewalk below. > > That is, don't do the TTU_SPLIT_HUGE_PMD immediately. Start the pagewalk > first. If we walk a PMD, try to unmap it. Only if that fails, split it. Nice. Thanks for the suggestion! I'll work on integrating it into the pagewalk as you suggested. > > Less working on "vma + address" and instead directly on PMDs. Yes, some of the work on "vma + address" can be avoided :) Thanks again for the review! Lance > > -- > Cheers, > > David / dhildenb >