Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp967645lqd; Thu, 25 Apr 2024 02:01:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUv+YZPNIBpQGjHV4wGNhlkSMRgrlioGC+c6cES/pgQKnQZHDh/wpMw78QSATTH5naXh4z/RrdcoP8sSS6NFF8Mb4d3Pj66UB3huXvjqw== X-Google-Smtp-Source: AGHT+IFjw2V2SeOMwAtYksmIFHMHDeUtG+jQEmqrHVxlcJD0S8ABZspx0EeOxfEwCkYCOl5O/AsC X-Received: by 2002:a05:6e02:156e:b0:36b:fa57:bddb with SMTP id k14-20020a056e02156e00b0036bfa57bddbmr6561797ilu.26.1714035691513; Thu, 25 Apr 2024 02:01:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714035691; cv=pass; d=google.com; s=arc-20160816; b=eDmaf9h4Y3DIBZ+PsWaUyLrvz1KdX0kuOZO2oUBc+Q3aH2eIF6j0xJ03Rt4Xy6L+aZ mALhPHRp3tKG2OYc335RkkK82LQGkCslXqDrBLMcIUzZ+BZ29pNvL7FXl3vO9iBdkUqU TP8pzs+9G9EqV9S5ykWyvYHPzqgkKqqyRXGMgUVnR20WzTd3ixh7gnUQLJzpGQO+eaP1 ExnafLqTpMPPqZFJIBRr6wRKHmDtVxuU+dNDZAofwJ6B6ldd7MVo3ZKozuQWsg3UE2a0 GZHij1mWmVgNlTmEpl1IYpt1NI9oML9nyqJJT+f6BnTAA7BTsC3JX+E9jcwzFZaxczWO Gr0Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :date:message-id:dkim-signature; bh=cTLZcx23+RXa6+to2zh9cSsCTfbEYQvY2lm+ZXLpqes=; fh=3ZgrRZ1v+YKvUyPNlQ8iW/pPcRc0xbGV6KmCX+LfGdw=; b=zpU1rjWKKqHH1AjFznYD95wH8kex0e64+ED6rANvs2H2fL2JBjyBeTTe6ZEBwEZ/E3 5uuxp8HRx0GI6NTQFgyGyj9usmd60qLKHV3IQUFMT8toOr7WBd1HFC0wuI+XGv1Wn2dO t7k1oY2KG9DmVNOMpDVCsCgE+cACnWnV1PlpxERUd3auUXZU7qX4nmU3RvQvZvDRUzSS TcwJMJYEIHUsIAnTjFbC+CqDNL67OP6mGjrz+Tx2u98KPHX6a1NvTNHrwbHSRGRl5s7M YQCRbnUUjDgmw03NLHrg5DZyC9pWlDn5/ywS7Bab2Rpci/Udm72n6R35Ag5dqx4TK7P6 LQPw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TSA1jr50; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-158230-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158230-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id e9-20020a636909000000b005e3cdc24c26si13110210pgc.467.2024.04.25.02.01.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 02:01:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-158230-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TSA1jr50; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-158230-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-158230-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.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 1F834284002 for ; Thu, 25 Apr 2024 09:01:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3C86781AC6; Thu, 25 Apr 2024 09:01:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TSA1jr50" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B60061DFE4 for ; Thu, 25 Apr 2024 09:01:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714035681; cv=none; b=Byn1npXt8NEeZ/4q3EAbfVpmoNFf+/6KRlAlWNhPrtBpZruCyldKvsdIlmcQAPOp7vlUbw5qA/jjdSp45DKsyQRxf+1RTnvqhkNeYnEo1H0Bngtjtvpvr0XIA0aCVlV4L8sG6xP2v3JgC4fszp/yVuRxyeR8vKluWPPchdAF17E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714035681; c=relaxed/simple; bh=R/OeS8T3/7Ad1KMp8ZIyz8a/Q3amLDgC/pqomz/JtTQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=p/dydDIUN8MNSMuRmSoPhxyy9P+7bjPJ7mQ6Z/A0KdQ/4HzkGgUOs/nYunufngdDCjkHjkuDx8x9MYlVX5/1b1pQ6Iv2s+Obvo23RcLrACuKt5Clg7E4tZhOMRPndoqi7qugMSCv4GNlFya4lGaGQAG4/QTtgDvyvoSH9oliT90= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=TSA1jr50; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1714035678; h=from:from: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:autocrypt:autocrypt; bh=cTLZcx23+RXa6+to2zh9cSsCTfbEYQvY2lm+ZXLpqes=; b=TSA1jr50Ic8MfA6zszZqdeguRrAf6CDaRVtPryHjPcwLEix7fWPpBNzu1B8Kgw/2VFfa9q 5z5wWcHftqgbo57cH59T2UJ3tmpVee0kRXsyCyohYAVAMXgSQsXFR8BiG36UlwahoAidoC ou9ibzNT2WIijW5XZMS3NYJoXxbmwuk= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-668-w-2_6FqqO4WWmuW5jIOfEw-1; Thu, 25 Apr 2024 05:01:16 -0400 X-MC-Unique: w-2_6FqqO4WWmuW5jIOfEw-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-416a844695dso3541515e9.2 for ; Thu, 25 Apr 2024 02:01:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714035675; x=1714640475; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=cTLZcx23+RXa6+to2zh9cSsCTfbEYQvY2lm+ZXLpqes=; b=CzA+l4G0bw0WjOFJklnbJk+s1Ejq05LhjNFvrV29FQNEYK5cMltCvoMwgaYKJ99ji+ dJJpAOaucWHS0q0Gs5Qa50TZM6OOvHJJYqNgCqHieQR60FrKvZl4wDwJLlVOAls/bo43 rEFdBex1dk9u/e3sKPJKjfhSWf5nA28UEEuyNHa2LLA3tLsQtATLH5p6Z+GY8XaYn9ul tG3z2tO9Q9r9LL5K9iscFmwJTlbKkUACEAN8x+Q7XnaxoxsWosZ5wCVb8nLyet/XpAfN Aujfk9p9g4GXc/3f56blF7GrNWt9RWZg954vTKz8/q52QlBgHmXgXWU4UsDR9tj7245X WuUg== X-Forwarded-Encrypted: i=1; AJvYcCVTeJmckXIqDDIFU+etW8zgoF4wUg5KgA9YXX880lZWF/URyOqWyD79gxGAd830ec+YP+XmBQ6aMq4t3+9cPSVDsYTyaTJ2NMg3lCBy X-Gm-Message-State: AOJu0Yz3C73Ql6yfBEwUTWi/1mAV8bjNb2BNfkvXGrLT74JTs8UbF9Yl ZSkobtg5YuO9/irJlHt8xCS4IXuZOE90zkQM4kKSEbZW08e+uJ0MZsk5UtRWc8VU7kBtJOnNg4u 8mKjJ6cG17vilfT/1La/UnHg+26iI5mZ9pqJWFScdw/NCQKBgECV5eqQCSOG8zQ== X-Received: by 2002:a05:600c:22c7:b0:418:ee2:5911 with SMTP id 7-20020a05600c22c700b004180ee25911mr3685514wmg.28.1714035675350; Thu, 25 Apr 2024 02:01:15 -0700 (PDT) X-Received: by 2002:a05:600c:22c7:b0:418:ee2:5911 with SMTP id 7-20020a05600c22c700b004180ee25911mr3685490wmg.28.1714035674913; Thu, 25 Apr 2024 02:01:14 -0700 (PDT) Received: from ?IPV6:2003:cb:c719:8200:487a:3426:a17e:d7b7? (p200300cbc7198200487a3426a17ed7b7.dip0.t-ipconnect.de. [2003:cb:c719:8200:487a:3426:a17e:d7b7]) by smtp.gmail.com with ESMTPSA id k41-20020a05600c1ca900b00417e8be070csm26910729wms.9.2024.04.25.02.01.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 25 Apr 2024 02:01:14 -0700 (PDT) Message-ID: <49394660-8455-48ec-8ae1-fbd2d590d27a@redhat.com> Date: Thu, 25 Apr 2024 11:01:12 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/1] mm/vmscan: avoid split PMD-mapped THP during shrink_folio_list() To: Lance Yang , ziy@nvidia.com Cc: 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 References: <20240425085051.74889-1-ioworker0@gmail.com> From: David Hildenbrand Content-Language: en-US Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qa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xDcDHIlmguXjC1Q5tZTwNB boaBTPHSy/Nksu0eY7x6HfQJ3xajVH32Ms6t1trDQmPx2iP5+7iDsb7OKAb5eOS8h+BEBDeq 3ecsQDv0fFJOA9ag5O3LLNk+3x3q7e0uo06XMaY7UHS341ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: <20240425085051.74889-1-ioworker0@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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. > > 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 cannot > 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 the > 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 = 0x80, /* do not grab rmap lock: > * caller holds it */ > - TTU_LAZYFREE_THP = 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 *folio) > +{ > + 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 *folio, struct vm_area_struct *vma, > if (flags & TTU_SYNC) > pvmw.flags = 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. Less working on "vma + address" and instead directly on PMDs. -- Cheers, David / dhildenb