From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0822BC001E0 for ; Wed, 2 Aug 2023 11:36:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7DD1D28015D; Wed, 2 Aug 2023 07:36:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 78E2C280143; Wed, 2 Aug 2023 07:36:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6559D28015D; Wed, 2 Aug 2023 07:36:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 558F9280143 for ; Wed, 2 Aug 2023 07:36:35 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1C606408FE for ; Wed, 2 Aug 2023 11:36:35 +0000 (UTC) X-FDA: 81078961950.03.972FDB5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf02.hostedemail.com (Postfix) with ESMTP id DA7F680002 for ; Wed, 2 Aug 2023 11:36:32 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FPO1ayPK; spf=pass (imf02.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690976193; a=rsa-sha256; cv=none; b=atanp2AqR+tJ9+YskdjjwTSlvOXtUA0kxAg8BQdC46Vi/mP0DZY2ARGCVQ5YJCOwyDYJHH pdIQOjYrH8wwbxarjSe3ZCm6gBpwNP3GIOxkHWGUfWCJvw6yzeys49kwmkjkHB3To8shmh 7nSDyV+UP6CWzw/GSB3CKlFxSQZHCsY= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FPO1ayPK; spf=pass (imf02.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690976193; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=QNipgsMHiGdtUITpPGu3dAw5v0sDpWz2SWPH1sSL1Fw=; b=GrMOS2nkP2LC/jsMjLqLCJjcDvNqMpPj9BFYvWN6AzAT8jSGXq8FeyqR49IeOWe0vobvaR kt5fjrHG57aidKXnhXmFnAqG/NQUw153BnZ7k2D7DR3e30GjW/fHXkorNBkLbtzRij88rE Ro7XIy5KhoMV8sp74UYtF+FwN0x6Smk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690976192; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QNipgsMHiGdtUITpPGu3dAw5v0sDpWz2SWPH1sSL1Fw=; b=FPO1ayPKo+JqLMVA030iXgBOuJbN5XQmutsN9/8jQduW5DVDTkajNnqU30tOuOS0mAz/Pu /5h/kRCOTNFEMeoUdzP+ADprNM9bzv8zJCvc/+6+mkIchSBJbYB/bUtYfcqN6+rho5Gv/0 3TkxrdW27iycnmBD0MZ24IV3dg8ymR4= 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-371-LL9qz8J_OSOkX0MkyTpwnw-1; Wed, 02 Aug 2023 07:36:31 -0400 X-MC-Unique: LL9qz8J_OSOkX0MkyTpwnw-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-3fd2dec82a6so42397315e9.3 for ; Wed, 02 Aug 2023 04:36:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690976190; x=1691580990; h=content-transfer-encoding:in-reply-to:subject:organization:from :references:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QNipgsMHiGdtUITpPGu3dAw5v0sDpWz2SWPH1sSL1Fw=; b=R1UAXKKVWynNcuQAoyhVgLBk5luxrAQ0I1YztKi5NMTQQ444R5NgqINDhcPTQj3775 BgpfurROZsBgs/qE5kplgb7Y0QEe7rMndfyqRUx3i238BjF80IjFRxISN/tAP7byR5iX wBHsXzvftT0Np8BC6I1ZyvgVDAJbgXxImmdL8AmJFRzHW5syUTX0tAKMsiqdlOGvlDzH gBn4Ln+O+iCrmFfWRGN8qo/rwoI4VyyBnW4oGYEyFcIxvNjBD8Ub0AnnDTPKLSdO8dWa rM03jY0Lg28Yr49Rzq39Zvrovpici/IljOYBheYmoHDOHA2ScDtoqFwalHQHDerBE/2e 9D4w== X-Gm-Message-State: ABy/qLYJ0eMqG0GigGvGDmdp0L2hmfBh3WY5KLmPA/mgd8IDEn4X3tAd r+H1OroMFkcCVJ0jKamdJ/+E7DQzOi2tvx7QKO5HMX98+ATN4uvlax+4ovQ3R/qHJiOdkjS0Pjw 29C6WyGIhdPI= X-Received: by 2002:a1c:7507:0:b0:3fe:111a:d1d9 with SMTP id o7-20020a1c7507000000b003fe111ad1d9mr4766069wmc.25.1690976189784; Wed, 02 Aug 2023 04:36:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlHZS2OaTjXDVGDs361yJb2dnEvrRsXZqJIy8idD/Yq/NZmIENOwxB1EnvMjWwdyvaoOyqnvTA== X-Received: by 2002:a1c:7507:0:b0:3fe:111a:d1d9 with SMTP id o7-20020a1c7507000000b003fe111ad1d9mr4766050wmc.25.1690976189418; Wed, 02 Aug 2023 04:36:29 -0700 (PDT) Received: from ?IPV6:2003:cb:c70b:e00:b8a4:8613:1529:1caf? (p200300cbc70b0e00b8a4861315291caf.dip0.t-ipconnect.de. [2003:cb:c70b:e00:b8a4:8613:1529:1caf]) by smtp.gmail.com with ESMTPSA id n7-20020a1c7207000000b003fc00212c1esm1417634wmc.28.2023.08.02.04.36.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Aug 2023 04:36:28 -0700 (PDT) Message-ID: <2722c9ad-370a-70ff-c374-90a94eca742a@redhat.com> Date: Wed, 2 Aug 2023 13:36:27 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 To: Ryan Roberts , Yin Fengwei , linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, akpm@linux-foundation.org, willy@infradead.org, vishal.moola@gmail.com, wangkefeng.wang@huawei.com, minchan@kernel.org, yuzhao@google.com, shy828301@gmail.com References: <20230728161356.1784568-1-fengwei.yin@intel.com> <3bbfde16-ced1-dca8-6a3f-da893e045bc5@arm.com> <31093c49-5baa-caed-9871-9503cb89454b@redhat.com> <20419779-b5f5-7240-3f90-fe5c4b590e4d@arm.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH 0/2] don't use mapcount() to check large folio sharing In-Reply-To: <20419779-b5f5-7240-3f90-fe5c4b590e4d@arm.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 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E91laNeiiav379jyStF9s iJvYveVO 6UX6uUyawieXnaaSNdgKCAu+Z9AUy1nCmKDgkA9LxHUHUsjO51TEmXITUpORxv+B6CTnKnJc0CpTBhc4RaWf0G/s+3gw/wUnUUPT6l3Cgo3VGpuO049uYSUShvSz5KL/Aynh8m0u/bI3H1zgSTKsNUWvGdhcxiiOLnGaTOjKBymPBES4moQnNn0O6n7/ZuPwXemIXaVlYv6nmGttA2p2kwdocCHIhyfFK9gAz8VkSUQWkJgerOn20tL5nnoebeyDDtImgy8/XyTaleR5feG2uWidka7cBx4PmkYrauSdhnZfR9jQxVeny9zsIK9MnwDsD+1YhzOmOkvi9rB1IFqX3y9BfhK9c1M4n6fpAZGnLgxWOa2sYo0bqSh9OkikyDFDITgdFxwJCtLSBz3rihLmGP6WIwynSx7aHFO5uQl1iA1V3OgUQZZ/L9elhsnmeu6ol6SV2y81Vk1bQ5qyDfiI0Jf823e6tZLu3B21I4xRLq4jHJana4S3VPKBqQ0R9RSBfIqPDL1U/uDvpXQmpgqlG9/l5/CLVcASGBnGk X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 02.08.23 13:20, Ryan Roberts wrote: > On 02/08/2023 11:48, David Hildenbrand wrote: >> On 02.08.23 12:27, Ryan Roberts wrote: >>> On 28/07/2023 17:13, Yin Fengwei wrote: >>>> In madvise_cold_or_pageout_pte_range() and madvise_free_pte_range(), >>>> folio_mapcount() is used to check whether the folio is shared. But it's >>>> not correct as folio_mapcount() returns total mapcount of large folio. >>>> >>>> Use folio_estimated_sharers() here as the estimated number is enough. >>>> >>>> Yin Fengwei (2): >>>>    madvise: don't use mapcount() against large folio for sharing check >>>>    madvise: don't use mapcount() against large folio for sharing check >>>> >>>>   mm/huge_memory.c | 2 +- >>>>   mm/madvise.c     | 6 +++--- >>>>   2 files changed, 4 insertions(+), 4 deletions(-) >>>> >>> >>> As a set of fixes, I agree this is definitely an improvement, so: >>> >>> Reviewed-By: Ryan Roberts >>> >>> >>> But I have a couple of comments around further improvements; >>> >>> Once we have the scheme that David is working on to be able to provide precise >>> exclusive vs shared info, we will probably want to move to that. Although that >>> scheme will need access to the mm_struct of a process known to be mapping the >> >> There are probably ways to work around lack of mm_struct, but it would not be >> completely for free. But passing the mm_struct should probably be an easy >> refactoring. >> >>> folio. We have that info, but its not passed to folio_estimated_sharers() so we >>> can't just reimplement folio_estimated_sharers() - we will need to rework these >>> call sites again. >> >> We should probably just have a >> >> folio_maybe_mapped_shared() >> >> with proper documentation. Nobody should care about the exact number. >> >> >> If my scheme for anon pages makes it in, that would be precise for anon pages >> and we could document that. Once we can handle pagecache pages as well to get a >> precise answer, we could change to folio_mapped_shared() and adjust the >> documentation. > > Makes sense to me. I'm assuming your change would allow us to get rid of > PG_anon_exclusive too? In which case we would also want a precise API > specifically for anon folios for the CoW case, without waiting for pagecache > page support. Not necessarily and I'm currently not planning that On the COW path, I'm planning on using it only when PG_anon_exclusive is clear for a compound page, combined with a check that there are no other page references besides from mappings: all mappings from me and #refs == #mappings -> reuse (set PG_anon_exclusive). That keeps the default (no fork) as fast as possible and simple. >> >> I just saw >> >> https://lkml.kernel.org/r/20230802095346.87449-1-wangkefeng.wang@huawei.com >> >> that converts a lot of code to folio_estimated_sharers(). >> >> >> That patchset, for example, also does >> >> total_mapcount(page) > 1 -> folio_estimated_sharers(folio) > 1 >> >> I'm not 100% sure what to think about that at this point. We eventually add >> false negatives (actually shared but we fail to detect it) all over the place, >> instead of having false positives (actually exclusive, but we fail to detect it). >> >> And that patch set doesn't even spell that out. >> >> >> Maybe it's as good as we will get, especially if my scheme doesn't make it in. > > I've been working on the assumption that your scheme is plan A, and I'm waiting > for it to unblock forward progress on large anon folios. Is this the right > approach, or do you think your scheme is sufficiently riskly and/or far out that > I should aim not to depend on it? It is plan A. IMHO, it does not feel too risky and/or far out at this point -- and the implementation should not end up too complicated. But as always, I cannot promise anything before it's been implemented and discussed upstream. Hopefully, we know more soon. I'll get at implementing it fairly soon. -- Cheers, David / dhildenb