Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2243931rdb; Wed, 21 Feb 2024 01:15:53 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWcsuDW7A68kATgcyrjXCS9GJDst3bfGQMmTRdpyivWx8LMJvDeFtm06IKhAgT19FoLdVQvPhetxpmSvpLUSlXxr/qGETKwJa7wjBfOEQ== X-Google-Smtp-Source: AGHT+IHtkSuGxWXG1CgI1NXFjvtWsHJPOme6VrVVGjN8mleSXPMQiqarXX3bKFmt5XZ5xGleGixv X-Received: by 2002:a05:6102:2143:b0:470:4530:33e8 with SMTP id h3-20020a056102214300b00470453033e8mr7089369vsg.23.1708506952763; Wed, 21 Feb 2024 01:15:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708506952; cv=pass; d=google.com; s=arc-20160816; b=hwS0uEfdcCR08O76Eq/Humu6djEAvhVsdZL6mkJp5779+1EScCcN8hq/YVmmL8Szx5 m8HHlN9Oqb2ltn9pek8KKAjQyli4DsJFtF+2ui7kJoI4VY7JLasDA36LuNPHG4ZR9MGz oDcqA4TPUMVoyvfXhL5vfv+VG0vIJpXdO+jZ8xGvdIcFvTVaOCG4+fcFScb/DTLMFV3j qcxb2dVzIY0MOj0z2vp/m8Kr7lAhtDAjkcnXOkb8D4FFBdtzqY+lui9+NWTWKSRCLF84 oUHnxpUU6unZcBgyiEKeNEkZoASO+SISDD4Eyu/1X9tOVKRUY3P6l5UTkHeJo/kBU4yq xfFg== 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:from :content-language:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=F6T4lfbBYjm9+K0rdV6lhOz4YZ8fC6PRsKLFRTgCxXQ=; fh=5SIEdGxxwmP3+UktUjhz4dTqAkYSlVMZ/d44qte/A2c=; b=ZU5otUJ/7XuDjc5JTweDySU103+vY7hItq0NOyOvW2vvl+SB/ZyJYi6dYZlAtSEveC U6Y7sAq0kgjGhW/pKIiStiKvvq/6OnirJfMw7ODDNmiGCeWI7/5y4iLHeeM4gQS5Jh2B hyduun0IOyoP+05rWxB98TxxvCHtFC1fVy6n5nmdov6KNfUDVnIPfUnDtHhyEUZPWQM2 lpVnWyQSYq41rbPWco0iUzjBlNVCKsvGaP9YxWr2cQAjFmtlD2VbFJCMD2/U64zZBBu7 fvK/Q5osO32mBKYSHo0/1VdtuK98Y2612xCe/yFM1EE9XiSolXPvFPUxGUF1OTKJC3uw 5FUg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Xxff+Ts1; 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-74377-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74377-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id z22-20020a05622a029600b0042c44be9c20si5058519qtw.507.2024.02.21.01.15.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 01:15:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-74377-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Xxff+Ts1; 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-74377-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-74377-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 741EA1C210F9 for ; Wed, 21 Feb 2024 09:15:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EB24B3D0A9; Wed, 21 Feb 2024 09:15:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Xxff+Ts1" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 263603C497 for ; Wed, 21 Feb 2024 09:15:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708506939; cv=none; b=npvOM4PYbMJE+Uz6dHwqhGV2kr5gRQ5MtfOSUdd9Ql+lyGg4FiGPxaNgY4lt6T/48+AMqgmIMmhyDGGweTILqqmIC/loQhUMbEDOohWEuHBTN5BMeeOlQPbcTAbMQ072WlnlIDEVe1cMVE7Keo6P++wpVm8T4gVWGgriRVsdgvA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708506939; c=relaxed/simple; bh=8j8CxPWIRsCtueYCxlRlcdGfvemqXnBGj23Bs2qQUlw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=XCESGAXycLSL6bFRVil368bJLNigFSLfZuebXO0ZvIuZWpT2iwI5OHF88n747qF+X7/4DL7WgZTrITXhiz1on+U22/NYK97aZsVgyUjlqymMmGOVco/l4zafnVojAXhStp/g+uUQ2c/bES0esAU0TIxINrRsh6wTUSS5PlvT9tk= 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=Xxff+Ts1; arc=none smtp.client-ip=170.10.129.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=1708506937; 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=F6T4lfbBYjm9+K0rdV6lhOz4YZ8fC6PRsKLFRTgCxXQ=; b=Xxff+Ts1uBB/ggkZBU3PGdv7u9gNF675ENl1fhm84nGLurzgKIJRD0pauJSTPb5M4ChucG ZaNBm9vIuGnbzLA2whCSK0M9Pbx6DdzL0rH/Orranfr+hCqktbDkifHZBMwDO4zS25AM7T TOBKrdfi3P5go4bDHfW4eEaSW4mqMtg= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-149-Bimk5Z7DOQikkQRw4JtZ2A-1; Wed, 21 Feb 2024 04:15:35 -0500 X-MC-Unique: Bimk5Z7DOQikkQRw4JtZ2A-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4127721e3a3so1354735e9.0 for ; Wed, 21 Feb 2024 01:15:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708506934; x=1709111734; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :content-language: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=F6T4lfbBYjm9+K0rdV6lhOz4YZ8fC6PRsKLFRTgCxXQ=; b=dvHVKzi8vHtiWbNHXt6s7Ols6Zf5o9z9zuiauJaAbdZ0KKFxmQP0jtM3IbAKufczI/ HQfBxnm9Bq9ufHMQtkVLGWh+m9gD20DaFyCSCKeWCLPof4CGx/ET3J4YwUNnXw0iqhRP hwA7bBdZsIzPEZ4GRrMk5UqpR1tfpm4ekF1JSpX5/YQkBMD+i60zvFZ0YLXHZiwowEwD cHmZmk+ebuA06zMJRW8LNPy1ysH+57T4nq0+RKjUPEqXTLOYpgfbAKqqgcfKrevI4SHb 85X2GCOgUXjSHZnwEQoqgQZtrnx9GB8F4MVR9XTaNGV7dBxaVDGP0s1UdRRm9DbFMk27 wlVA== X-Gm-Message-State: AOJu0Yx0u734gYppuqQYB2GRAYe/5lpifu3lY+nvpu+EFxeftQ83Cug9 wMRR1ntnnHQeVt/hj75WxyItCvyIqeZeiao7IXgbuBmvRWY2K3/XvPfvyr2M6+W+QRmFVYRiHY4 MDZqzyTB7x9Zl9cDyQottVeKegLq2NlSfmmru7xtCedvkpP/glptzXRak4ztgDQ== X-Received: by 2002:a05:600c:1c83:b0:412:6ddd:460d with SMTP id k3-20020a05600c1c8300b004126ddd460dmr3069922wms.3.1708506934456; Wed, 21 Feb 2024 01:15:34 -0800 (PST) X-Received: by 2002:a05:600c:1c83:b0:412:6ddd:460d with SMTP id k3-20020a05600c1c8300b004126ddd460dmr3069899wms.3.1708506934069; Wed, 21 Feb 2024 01:15:34 -0800 (PST) Received: from [10.32.64.237] (nat-pool-muc-t.redhat.com. [149.14.88.26]) by smtp.gmail.com with ESMTPSA id i22-20020a05600c355600b0041277b5da5csm797595wmq.36.2024.02.21.01.15.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 21 Feb 2024 01:15:33 -0800 (PST) Message-ID: <4c1224e3-5c02-4d5d-9379-d3b74b1174dd@redhat.com> Date: Wed, 21 Feb 2024 10:15:32 +0100 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] madvise:madvise_cold_or_pageout_pte_range(): allow split while folio_estimated_sharers = 0 To: Barry Song <21cnbao@gmail.com>, akpm@linux-foundation.org, linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Barry Song , Yin Fengwei , Yu Zhao , Ryan Roberts , Kefeng Wang , Matthew Wilcox , Minchan Kim , Vishal Moola , Yang Shi References: <20240221085036.105621-1-21cnbao@gmail.com> Content-Language: en-US From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc U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EPeu59Y5vSJOx/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: <20240221085036.105621-1-21cnbao@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 21.02.24 09:50, Barry Song wrote: > From: Barry Song > > The purpose is stopping splitting large folios whose mapcount are 2 or > above. Folios whose estimated_shares = 0 should be still perfect and > even better candidates than estimated_shares = 1. > > Consider a pte-mapped large folio with 16 subpages, if we unmap 1-15, > the current code will split folios and reclaim them while madvise goes > on this folio; but if we unmap subpage 0, we will keep this folio and > break. This is weird. > > For pmd-mapped large folios, we can still use "= 1" as the condition > as anyway we have the entire map for it. So this patch doesn't change > the condition for pmd-mapped large folios. > This also explains why we had been using "= 1" for both pmd-mapped and > pte-mapped large folios before commit 07e8c82b5eff ("madvise: convert > madvise_cold_or_pageout_pte_range() to use folios"), because in the > past, we used the mapcount of the specific subpage, since the subpage > had pte present, its mapcount wouldn't be 0. > > The problem can be quite easily reproduced by writing a small program, > unmapping the first subpage of a pte-mapped large folio vs. unmapping > anyone other than the first subpage. > > Fixes: 2f406263e3e9 ("madvise:madvise_cold_or_pageout_pte_range(): don't use mapcount() against large folio for sharing check") > Cc: Yin Fengwei > Cc: Yu Zhao > Cc: Ryan Roberts > Cc: David Hildenbrand > Cc: Kefeng Wang > Cc: Matthew Wilcox > Cc: Minchan Kim > Cc: Vishal Moola (Oracle) > Cc: Yang Shi > Signed-off-by: Barry Song > --- > mm/madvise.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/mm/madvise.c b/mm/madvise.c > index cfa5e7288261..abde3edb04f0 100644 > --- a/mm/madvise.c > +++ b/mm/madvise.c > @@ -453,7 +453,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, > if (folio_test_large(folio)) { > int err; > > - if (folio_estimated_sharers(folio) != 1) > + if (folio_estimated_sharers(folio) > 1) > break; > if (pageout_anon_only_filter && !folio_test_anon(folio)) > break; That's also what I do in https://lkml.kernel.org/r/20231124132626.235350-4-david@redhat.com I'll revive that soon. -- Cheers, David / dhildenb