Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp132456lqp; Fri, 12 Apr 2024 12:36:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXa3CeOgGm7S+K7IwA+X1qOuBx6rM75GM600K5iiGbl6BjXfq/xi2i0r1I3WNCQkwteKY+xEg3WD+U+wx4Q0rmR+flu0dgywpWd3ryrZg== X-Google-Smtp-Source: AGHT+IGRXsVOYa5Be0wGpIjOBv9FbIpgUEhEhnk9cjim8knokKhMrvH3nrBOpsQH1zc7EWw4VdDp X-Received: by 2002:a50:9ea2:0:b0:56e:1010:cd7c with SMTP id a31-20020a509ea2000000b0056e1010cd7cmr3010385edf.12.1712950608825; Fri, 12 Apr 2024 12:36:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712950608; cv=pass; d=google.com; s=arc-20160816; b=OFnhZ/jDlW0St7oX8hyrTs1oJecj91H5M9gQmsP7Asna68kEeICYWIouVVInuBTwzX N6ACIdocLx2ZmbGnk8j0hiU87aAGsd7sNK56hiQkzoMorsWF4YCx5HdkR5NssDzwKIDi 3WdDg6Mk7x5JvtgCMuLRrwQUfwud2feR5LjXnLS3penQtgwqJRsytR89D4cMRxNvhNy1 TVknA/1R4eXV23VM3Y02+5+0d+n+Lcj2z7MnCHP2akjsNJ8bcKow2/Q2xEcHcLDmFTvI 2EVQGl5c+HC8GDgY32W9L7PXze+6v6sUfnwiZnfCjzDIg84Y9xER6ahIgYLThOS1Lo37 WhVw== 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=7lw2j25KX+wcPzP04xZOFjcfz+3FArGQa2Ad8UAwKP8=; fh=sZl5f5f/ffbgNf/OfYxtr4+/VDeeClp0DblVXr+6RwA=; b=jKhEX7GkaQTN/xkpoPjxXnY1dw1+durSCJWiineBgGIQwUVlixrFD0vcAaBSy9PNCA 5p0OzAiKLp2jlkfEvYGXzHRLJJcnnKmhpQxdgUA/T2juNUXx8bT6XjExMXwT+N8S0ugh 4SfeoNZRvHhDG386WEmQTd2nykuThMHbS8p2y8V2Kw4dqJz6/liNQqaVOCaTPlAqrID0 0Jli0HW5KqMh7LZ+YEZFWQYNeN4KxDFiAadqJhB7XSmNCer80QDFiZpi7Dt7CQBuDL8F sw3PLGlPXdfMTNaNcCVHy4ik0Izw96pD7326E9QxFJ/3Ir85Ns4R9vZISKpyJV1EEUjU iC7Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Xg9phIU1; 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-143264-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143264-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 c7-20020a50f607000000b0056c288897d7si1963161edn.208.2024.04.12.12.36.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 12:36:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-143264-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=Xg9phIU1; 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-143264-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143264-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 D1C1D1F22A70 for ; Fri, 12 Apr 2024 19:36:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9FC7914F9EE; Fri, 12 Apr 2024 19:36:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Xg9phIU1" 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 8DA42482C1 for ; Fri, 12 Apr 2024 19:36:38 +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=1712950600; cv=none; b=p0ZUOXvXdB1Hdx2dJwEJDShQb/9h24xl0ka1NQoHFgTEZhlWorFhsQ6xBbaAe2FxO+6/452Ram9zLscAL3gpWDOQCuNQOoaOS7qK0+I3gm+2JGsIhF0ZBRk2e6xmuDlBvoI5jh03aOZ3zlpno/4KNIkSSfbqIktqmxsq+p72Q/w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712950600; c=relaxed/simple; bh=dMZDUwIdMyG/Dh6MDWS4q9Rs003F2tbDJB2Y66o3kiE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=RDKD14iatbss8vKQOQAjR1FJWGUk7PNBZL8HeBS/ayS6//m83MCReUF1+cZagCxi9mrGqXCD1j2Orcjn/e8ewipS8/lbgos4GMXRrRQaECoXr49ttuY/g/csM+lpVey0sCw25to3HQ480QfOMIAsNk9BZ0e2fwKNJXH+bZqFNFs= 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=Xg9phIU1; 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=1712950597; 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=7lw2j25KX+wcPzP04xZOFjcfz+3FArGQa2Ad8UAwKP8=; b=Xg9phIU1j7FDG91TwynLWcHcbb2LaFkxL9KrJ5UQMjFPpi0o/PAwDpFLe1siVGzhhusdE8 HrVu4HRdBM32VElgy6CjRbBIxJdJEDz49EWOdNg5hm3g5X7QjjuRpohf0t4p7egARBKghK CM4UcRF/hOIJUoscGJlH2wzuqYDDLS0= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-372-EueRfOUmO1SYvYt4q75Oww-1; Fri, 12 Apr 2024 15:36:36 -0400 X-MC-Unique: EueRfOUmO1SYvYt4q75Oww-1 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-343ee8b13aeso933456f8f.2 for ; Fri, 12 Apr 2024 12:36:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712950595; x=1713555395; 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=7lw2j25KX+wcPzP04xZOFjcfz+3FArGQa2Ad8UAwKP8=; b=oJs5X0F+M/lev6yA5BRmGeFlIlbuZVNtyj1iGMvN4qSrnCcSLLSG3kCapLgHG/Y4ji AwPHTax1zozlj32M3g+y5I+Uc0YkcmD7qy0VY85DcurRUvF76J/DG7GF4mVepzAXYXEH KYekh31MvhVJ+ZwQEyhS6W3PrPONaj9/4Z8NcW/clIM1t1h3EYGLQTSxDMM5W7XdGDEc LWtZcaF1SZVLqh4TR3nZ6z/i6ak6Y50/0xOOmTeRhMfd62ppVkjdP76amR2F1OvOSC9u JiKmJvkxhP3o2+EV9atgJmbYM1has2lKo6P3SO0x8s+RVO3Y09MkQwXvdS7y1kRfOxmy DNVQ== X-Forwarded-Encrypted: i=1; AJvYcCVGUS6WfgIb0mvEB5nP3iOl35BUKKzURSPWfGH2qCIfthhyZ28I5pTJY36A8dxdVaffk5q9NjDnXiwVprnPnVShxHNbY7vplY9NGHxU X-Gm-Message-State: AOJu0YxwlQ0XKMB+KcpizazRkaFIx41qjaQd2ijPGtvn20Q1b/jnqSff 18jQuVmjUO29j6cpiMXwSMUNbR7nG3YpDIHgPDUqRZMCX9mUprLMYlHFIM3qQmALV/rKStCz2dS /zae4j7KiAUcpIN9PoEhsE/dRmHLR0dtcLsDkHkaF0UHRuGwJGJfaU0ge5NJZtg== X-Received: by 2002:a5d:44ce:0:b0:343:7653:ad14 with SMTP id z14-20020a5d44ce000000b003437653ad14mr2441903wrr.30.1712950594877; Fri, 12 Apr 2024 12:36:34 -0700 (PDT) X-Received: by 2002:a5d:44ce:0:b0:343:7653:ad14 with SMTP id z14-20020a5d44ce000000b003437653ad14mr2441889wrr.30.1712950594474; Fri, 12 Apr 2024 12:36:34 -0700 (PDT) Received: from [192.168.3.108] (p4ff23ff1.dip0.t-ipconnect.de. [79.242.63.241]) by smtp.gmail.com with ESMTPSA id g16-20020a05600c311000b00417e31724c3sm5299796wmo.13.2024.04.12.12.36.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Apr 2024 12:36:34 -0700 (PDT) Message-ID: <9e4516d9-b861-4501-84d3-31f5e8e5dfef@redhat.com> Date: Fri, 12 Apr 2024 21:36:32 +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] mm/rmap: do not add fully unmapped large folio to deferred split list To: Yang Shi , Zi Yan Cc: linux-mm@kvack.org, Andrew Morton , Matthew Wilcox , Ryan Roberts , Barry Song <21cnbao@gmail.com>, linux-kernel@vger.kernel.org References: <20240411153232.169560-1-zi.yan@sent.com> <86722546-1d54-4224-9f31-da4f368cd47e@redhat.com> <0A4D2CA1-E156-43E9-A1C9-E09E62E760A3@nvidia.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/E8M7TEwuCZQArqqTCmkG6HGc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e0uo06XMaY7UHS341ozXUUI7wC7iKfoUTv03iO9El5f 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: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 12.04.24 20:29, Yang Shi wrote: > On Fri, Apr 12, 2024 at 7:31 AM Zi Yan wrote: >> >> On 12 Apr 2024, at 10:21, Zi Yan wrote: >> >>> On 11 Apr 2024, at 17:59, Yang Shi wrote: >>> >>>> On Thu, Apr 11, 2024 at 2:15 PM David Hildenbrand wrote: >>>>> >>>>> On 11.04.24 21:01, Yang Shi wrote: >>>>>> On Thu, Apr 11, 2024 at 8:46 AM David Hildenbrand wrote: >>>>>>> >>>>>>> On 11.04.24 17:32, Zi Yan wrote: >>>>>>>> From: Zi Yan >>>>>>>> >>>>>>>> In __folio_remove_rmap(), a large folio is added to deferred split list >>>>>>>> if any page in a folio loses its final mapping. It is possible that >>>>>>>> the folio is unmapped fully, but it is unnecessary to add the folio >>>>>>>> to deferred split list at all. Fix it by checking folio mapcount before >>>>>>>> adding a folio to deferred split list. >>>>>>>> >>>>>>>> Signed-off-by: Zi Yan >>>>>>>> --- >>>>>>>> mm/rmap.c | 9 ++++++--- >>>>>>>> 1 file changed, 6 insertions(+), 3 deletions(-) >>>>>>>> >>>>>>>> diff --git a/mm/rmap.c b/mm/rmap.c >>>>>>>> index 2608c40dffad..d599a772e282 100644 >>>>>>>> --- a/mm/rmap.c >>>>>>>> +++ b/mm/rmap.c >>>>>>>> @@ -1494,7 +1494,7 @@ static __always_inline void __folio_remove_rmap(struct folio *folio, >>>>>>>> enum rmap_level level) >>>>>>>> { >>>>>>>> atomic_t *mapped = &folio->_nr_pages_mapped; >>>>>>>> - int last, nr = 0, nr_pmdmapped = 0; >>>>>>>> + int last, nr = 0, nr_pmdmapped = 0, mapcount = 0; >>>>>>>> enum node_stat_item idx; >>>>>>>> >>>>>>>> __folio_rmap_sanity_checks(folio, page, nr_pages, level); >>>>>>>> @@ -1506,7 +1506,8 @@ static __always_inline void __folio_remove_rmap(struct folio *folio, >>>>>>>> break; >>>>>>>> } >>>>>>>> >>>>>>>> - atomic_sub(nr_pages, &folio->_large_mapcount); >>>>>>>> + mapcount = atomic_sub_return(nr_pages, >>>>>>>> + &folio->_large_mapcount) + 1; >>>>>>> >>>>>>> That becomes a new memory barrier on some archs. Rather just re-read it >>>>>>> below. Re-reading should be fine here. >>>>>>> >>>>>>>> do { >>>>>>>> last = atomic_add_negative(-1, &page->_mapcount); >>>>>>>> if (last) { >>>>>>>> @@ -1554,7 +1555,9 @@ static __always_inline void __folio_remove_rmap(struct folio *folio, >>>>>>>> * is still mapped. >>>>>>>> */ >>>>>>>> if (folio_test_large(folio) && folio_test_anon(folio)) >>>>>>>> - if (level == RMAP_LEVEL_PTE || nr < nr_pmdmapped) >>>>>>>> + if ((level == RMAP_LEVEL_PTE && >>>>>>>> + mapcount != 0) || >>>>>>>> + (level == RMAP_LEVEL_PMD && nr < nr_pmdmapped)) >>>>>>>> deferred_split_folio(folio); >>>>>>>> } >>>>>>> >>>>>>> But I do wonder if we really care? Usually the folio will simply get >>>>>>> freed afterwards, where we simply remove it from the list. >>>>>>> >>>>>>> If it's pinned, we won't be able to free or reclaim, but it's rather a >>>>>>> corner case ... >>>>>>> >>>>>>> Is it really worth the added code? Not convinced. >>>>>> >>>>>> It is actually not only an optimization, but also fixed the broken >>>>>> thp_deferred_split_page counter in /proc/vmstat. >>>>>> >>>>>> The counter actually counted the partially unmapped huge pages (so >>>>>> they are on deferred split queue), but it counts the fully unmapped >>>>>> mTHP as well now. For example, when a 64K THP is fully unmapped, the >>>>>> thp_deferred_split_page is not supposed to get inc'ed, but it does >>>>>> now. >>>>>> >>>>>> The counter is also useful for performance analysis, for example, >>>>>> whether a workload did a lot of partial unmap or not. So fixing the >>>>>> counter seems worthy. Zi Yan should have mentioned this in the commit >>>>>> log. >>>>> >>>>> Yes, all that is information that is missing from the patch description. >>>>> If it's a fix, there should be a "Fixes:". >>>>> >>>>> Likely we want to have a folio_large_mapcount() check in the code below. >>>>> (I yet have to digest the condition where this happens -- can we have an >>>>> example where we'd use to do the wrong thing and now would do the right >>>>> thing as well?) >>>> >>>> For example, map 1G memory with 64K mTHP, then unmap the whole 1G or >>>> some full 64K areas, you will see thp_deferred_split_page increased, >>>> but it shouldn't. >>>> >>>> It looks __folio_remove_rmap() incorrectly detected whether the mTHP >>>> is fully unmapped or partially unmapped by comparing the number of >>>> still-mapped subpages to ENTIRELY_MAPPED, which should just work for >>>> PMD-mappable THP. >>>> >>>> However I just realized this problem was kind of workaround'ed by commit: >>>> >>>> commit 98046944a1597f3a02b792dbe9665e9943b77f28 >>>> Author: Baolin Wang >>>> Date: Fri Mar 29 14:59:33 2024 +0800 >>>> >>>> mm: huge_memory: add the missing folio_test_pmd_mappable() for THP >>>> split statistics >>>> >>>> Now the mTHP can also be split or added into the deferred list, so add >>>> folio_test_pmd_mappable() validation for PMD mapped THP, to avoid >>>> confusion with PMD mapped THP related statistics. >>>> >>>> Link: https://lkml.kernel.org/r/a5341defeef27c9ac7b85c97f030f93e4368bbc1.1711694852.git.baolin.wang@linux.alibaba.com >>>> Signed-off-by: Baolin Wang >>>> Acked-by: David Hildenbrand >>>> Cc: Muchun Song >>>> Signed-off-by: Andrew Morton >>>> >>>> This commit made thp_deferred_split_page didn't count mTHP anymore, it >>>> also made thp_split_page didn't count mTHP anymore. >>>> >>>> However Zi Yan's patch does make the code more robust and we don't >>>> need to worry about the miscounting issue anymore if we will add >>>> deferred_split_page and split_page counters for mTHP in the future. >>> >>> Actually, the patch above does not fix everything. A fully unmapped >>> PTE-mapped order-9 THP is also added to deferred split list and >>> counted as THP_DEFERRED_SPLIT_PAGE without my patch, since nr is 512 >>> (non zero), level is RMAP_LEVEL_PTE, and inside deferred_split_folio() >>> the order-9 folio is folio_test_pmd_mappable(). >>> >>> I will add this information in the next version. >> >> It might >> Fixes: b06dc281aa99 ("mm/rmap: introduce folio_remove_rmap_[pte|ptes|pmd]()"), >> but before this commit fully unmapping a PTE-mapped order-9 THP still increased >> THP_DEFERRED_SPLIT_PAGE, because PTEs are unmapped individually and first PTE >> unmapping adds the THP into the deferred split list. This means commit b06dc281aa99 >> did not change anything and before that THP_DEFERRED_SPLIT_PAGE increase is >> due to implementation. I will add this to the commit log as well without Fixes >> tag. > > Thanks for digging deeper. The problem may be not that obvious before > mTHP because PMD-mappable THP is converted to PTE-mapped due to > partial unmap in most cases. But mTHP is always PTE-mapped in the > first place. The other reason is batched rmap remove was not supported > before David's optimization. Yes. > > Now we do have reasonable motivation to make it precise and it is also > easier to do so than before. If by "precise" you mean "less unreliable in some cases", yes. See my other mail. -- Cheers, David / dhildenb