Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1314931rbb; Mon, 26 Feb 2024 05:50:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUqW6wPywMGfM5Wqfdpvtz0ud4y4T8WoFNCPrZS9i0RHFLtX9k2kkKWmzK3Nn2QAy0hzaopY77ge5KSapzKAiXjbeT6wBMz/Mx7AQCWCw== X-Google-Smtp-Source: AGHT+IFE4JbO69+SKG6K2z6dCg0vjsN6I3SyCkjxkrgw69wX11/+4VPdQX1ZnJfp9QuhtHmPhB/r X-Received: by 2002:a05:6512:a95:b0:513:a6:2f4 with SMTP id m21-20020a0565120a9500b0051300a602f4mr1305324lfu.13.1708955448359; Mon, 26 Feb 2024 05:50:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708955448; cv=pass; d=google.com; s=arc-20160816; b=zoiDHfYTWT2a1YbcfgxrOMh9PLhybdJX7ezEp+ZchlgNdsukFZjEHqavQHmIYEPjyK Uscw63tmG0/2Ur7VoCsOWOCpvbTF+ZZr1Gcqu1q7oV8zXab3eGEJGEbaOEz7KijDq9jI Kj3KznjSfvWUHHNURdz7uUwHvGlvv3yeR82rLbQltsJF14YXWsAtKo77mGgV51gWEyJh 8X7Ed7u87JR7X0BokxnU5dITOtbjaGvrsPLOYLYXzTw3EPvigsp37IPp9xT2r2UrK99V kg0hmjrbHz2d4Qe8n9MaxC7hRBSTDqsjqt0TGiTw4h9P/toRl70jBzG/kiPdmBZJhsbH 3yLw== 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 :references:cc:to:content-language:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=QVCRKSA4ldsqpe3HRG/6UsUQf4b5DTlM1+Qw9DzJKMg=; fh=moxXdPrJyyQT74KtmQqooq0KA6O6Ut2h1nET74Yey7I=; b=Tc+hA9HqFb4qNn45Jgu9ClcYIO3cLRoYS+Xoz5cP5AhAooOuuUTLT0iH37Z03Vlm+A pSlCLrfOrK2B9vqSzDazJ1WHbcvIphIUFEsvIPGI1na+rkt3KmPqDGuRw944Qqi+C7Fz S71l/XZrUyfAvJIj4LK2PlCFa9d4zj2GYY76F81UN0VDdKF8xjK8rQNPgnTPnA9ERD1C HJQVs5vKmL12Oe3DQDcTS0e+S1+9axHwuugeo5HDMZAr2ol+shL9gjW+O6CrvGWHK61P wF9mRpp0VDIkIJMiKVb6Schw/L6eH4Rndf04ACi5ZvFI8fe0min6fxw7K2WV3xTjjAnS 1d2A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YQ5PnwfN; 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-81537-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81537-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 20-20020a508e14000000b0056415926d13si2022480edw.223.2024.02.26.05.50.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 05:50:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-81537-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YQ5PnwfN; 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-81537-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81537-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 1D19D1F2B596 for ; Mon, 26 Feb 2024 13:50:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1C0121292DE; Mon, 26 Feb 2024 13:50:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="YQ5PnwfN" 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 71C63128386 for ; Mon, 26 Feb 2024 13:50:32 +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=1708955434; cv=none; b=gSA9fOn+wAjFOaL5c1s9MUR6m5azhZTlxANMSrE5GuZT5aK2E+cvWGCgcow0AJ9qQjyTCQa4rplIuUlbyjIhJRqwdC5tR7ClvySLr0qjw+oJHp3QtsoWggmo8+E3gaUIDlEEzm66pHeDrFMmCEx4Uv7LeMbKgRLK68srniANGZY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708955434; c=relaxed/simple; bh=1B5ssE9qAKVAfCNNgDaej8Uv0ChLHq2otxvJ/QFbnVk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=IMpe28X1n+2VxW7gaIJHAKIiZm3BjvdFoM3OuAjLbfxhvim8gR5RyAd6Lh55FgvUhlzLTIgbWKBUg5bQCc2SYcsGFl0p+6hfMUCzNyN60SlCYvUVS+o5kXr/0R12lU0l7j5Hfx1STgZSTOwuOCfso+t28xuB90rez+6hkL4spaw= 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=YQ5PnwfN; 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=1708955431; 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=QVCRKSA4ldsqpe3HRG/6UsUQf4b5DTlM1+Qw9DzJKMg=; b=YQ5PnwfNW+myGVO22CdrXzZcBsF+oTaBdeUvxILsz0dRagGQMppUa1y1yj0iG0nQnxC+eh EKREjdhHV/ujdy4aHwK18Soi9AybGzLdlvQ/HXw/wVttU6zXte4bklSC5fylS7w604YaG0 kSlgQ6JSFIXQ9rVYWxk8GtkyErU+tW4= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-246-XUeBvHPNOFajO3-fNEwHkA-1; Mon, 26 Feb 2024 08:50:29 -0500 X-MC-Unique: XUeBvHPNOFajO3-fNEwHkA-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-40d62d3ae0cso17181795e9.2 for ; Mon, 26 Feb 2024 05:50:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708955428; x=1709560228; h=content-transfer-encoding:in-reply-to:organization:autocrypt:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=QVCRKSA4ldsqpe3HRG/6UsUQf4b5DTlM1+Qw9DzJKMg=; b=ckCYhIXQ0b1FEsc6i3MpInzCjFlTBYQba2QjAzRbSTy3NH2j7pTAQycdTjtYpszL0q 76dxRTPrb2AQLw7D51BEyMtUML+LVpDio4WWyQcWy1AQxbAG2qIAWSUQt+kRSB9ldzRb wcsYaT419019DDetfWV0N0kRftqM7syvN16Ag0lnjuT6NKZpEI3UiXHT19bkXSb3Heui PHyprifL72tGHSz3ZUwsXfrgDcgtlLr3nL85QB7a/ccMfMRiTjax9fgHXn/KvTFrIvMk TlHCcNZ4Yis6DQcNWkwzrCVOktVforH8ArkTVIYdA3dCImYtxIgxAduAH/EP4WK0xmLm iaEA== X-Gm-Message-State: AOJu0YwZ2yfqgmJVelkO1OFb+ZqjGtYctlg23xq86bxTinAek8pJqnZx okkLuraP7Mg7tKT/uTPyyllR4NiMKmRZmjfZeKRJGGjkXSt1OJ03HTgheS2oF1duoO9xKnaJEgl g2wJTKtUiqoY+QfX9LNxUi97UV3myO9BhOQM8AJ+3sNlutU7hZQgEaQY9m6oFyw== X-Received: by 2002:a05:600c:1c14:b0:412:6dd7:1d44 with SMTP id j20-20020a05600c1c1400b004126dd71d44mr4842301wms.17.1708955428029; Mon, 26 Feb 2024 05:50:28 -0800 (PST) X-Received: by 2002:a05:600c:1c14:b0:412:6dd7:1d44 with SMTP id j20-20020a05600c1c1400b004126dd71d44mr4842284wms.17.1708955427676; Mon, 26 Feb 2024 05:50:27 -0800 (PST) Received: from ?IPV6:2003:cb:c72f:f700:104b:9184:1b45:1898? (p200300cbc72ff700104b91841b451898.dip0.t-ipconnect.de. [2003:cb:c72f:f700:104b:9184:1b45:1898]) by smtp.gmail.com with ESMTPSA id r1-20020a05600c35c100b0041228b2e179sm8357026wmq.39.2024.02.26.05.50.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 26 Feb 2024 05:50:27 -0800 (PST) Message-ID: Date: Mon, 26 Feb 2024 14:50:26 +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 Content-Language: en-US To: Ryan Roberts , 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 , Kefeng Wang , Matthew Wilcox , Minchan Kim , Vishal Moola , Yang Shi References: <20240221085036.105621-1-21cnbao@gmail.com> <71fa4302-2df6-4e55-a5a8-7609476c41d4@arm.com> 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//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvri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B9sTNHdMrXesX8eBL6T9b+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: <71fa4302-2df6-4e55-a5a8-7609476c41d4@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 26.02.24 14:46, Ryan Roberts wrote: > On 21/02/2024 08: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; > > I wonder if we should change all the instances: > > folio_estimated_sharers() != 1 -> folio_estimated_sharers() > 1 > folio_estimated_sharers() == 1 -> folio_estimated_sharers() <= 1 I'll send out something that wraps that in folio_mapped_shared() later today or tomorrow. -- Cheers, David / dhildenb