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 62680C04A94 for ; Wed, 2 Aug 2023 10:49:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BDCFC28014F; Wed, 2 Aug 2023 06:48:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B8C60280143; Wed, 2 Aug 2023 06:48:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A538F28014F; Wed, 2 Aug 2023 06:48:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 936C8280143 for ; Wed, 2 Aug 2023 06:48:59 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 547E51A0D81 for ; Wed, 2 Aug 2023 10:48:59 +0000 (UTC) X-FDA: 81078841998.29.BC1CF46 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf05.hostedemail.com (Postfix) with ESMTP id A794F10000C for ; Wed, 2 Aug 2023 10:48:55 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=W9Tz5G4t; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf05.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690973335; 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=cLjbWxxoSZ1dNtOUnCKt0nz7AAWcmftqn6oRUggLh9c=; b=JGKCh8PNhtzZQdxE4e5qWh310yiblBx/26NFqGYDi7NK8Y5FwEPLO09pelhKjWT4TzM9nm QlaD9aGVf7E6QCSpAl6CErOrnTZrOypBsPJlsLHoopyFH5Pvy8UYFcFnLPy+gBfrKQH3PQ ssatT5ebIVdYyzsnw47lJzj93LD+Hb0= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=W9Tz5G4t; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf05.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690973335; a=rsa-sha256; cv=none; b=59QIuhNseBw3VPwZ2+jlE26vgU2Yffu+ahtuE6n5BTPpGiDeFEj1OC67aXejokz5oJ5znf m1uB/U6xLKDZ2OeHUYuB7B0QUeLCmjFgti8wj3MdTNMqBhecpA3bmOSSOYZvZIHdEbw2/m WIVg8LHAxggUABQTKsPEVSudpU8K36s= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690973334; 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=cLjbWxxoSZ1dNtOUnCKt0nz7AAWcmftqn6oRUggLh9c=; b=W9Tz5G4tpnGg0b5SGj3thfCuYe8+/BzU3KhPFMD8cikiLF6RYOh7uxd8xVNa4tS0aci6iv 8ICO6NYUPXyGtKA+XTIasr6FBWVbYENYfpwjN1pxx/zzrKKdS/C8k4IThxrb9C6V9vt1iw gv4keGJr7uMuasPC+p9EJimxZ9kbI3A= 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-275-Nf_HNSI-OBqHIztvzcwW-w-1; Wed, 02 Aug 2023 06:48:53 -0400 X-MC-Unique: Nf_HNSI-OBqHIztvzcwW-w-1 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-3fb416d7731so39166295e9.2 for ; Wed, 02 Aug 2023 03:48:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690973332; x=1691578132; 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=cLjbWxxoSZ1dNtOUnCKt0nz7AAWcmftqn6oRUggLh9c=; b=U2F68kZS2Lfj2gw60r4Za7WPr0VuXQqUbq6jxVa1L2fgRIrSHWk4E8jIDTiIaUQ/Bg A3KGBMRFlNXha1jUVcT33VYNpRzAFMsk1QhLOP1yliUhv1V6xdddKqYQiDXH7SaatA1K 0EAX7I++GEzYTaNtloZ26epd5fHFbWIIJlpaMGFaMCYWKx1bYBz139TQmitrtdWHYiYS jVk4r88FtxYII9wmJorjzNeMrKPZr2hw6chYnq0A0w8JKvMorkxQydC3bZWKPAGGtfhW D8HRvnXkvc6/S37ROf3jDHcfMeZ1EALuZ4dsPKiaGm2h/ThJ/WQCKBC9qTKiQ+d6kyuS dPHQ== X-Gm-Message-State: ABy/qLZXAlvwV/qJV+EkxhOB3O8cpkIT+0HZZZX7bCqmT38ywcgVOaov MttJXED4e4gCq5cXZYAcKJBwmiEc0f5wcGbmT1fsU4/yGNgLh6jYGOir7b5H9TvA++7FVs1acgL qvswG6ctTNYg= X-Received: by 2002:a05:600c:2213:b0:3fe:2813:6130 with SMTP id z19-20020a05600c221300b003fe28136130mr4455626wml.22.1690973332523; Wed, 02 Aug 2023 03:48:52 -0700 (PDT) X-Google-Smtp-Source: APBJJlHUEiRrf/4EeUw8aRl0LVFnwaPqfid2665Qb/NZxHkW6b9q3/fmfr2HRSeP6OOAES8r28MCsg== X-Received: by 2002:a05:600c:2213:b0:3fe:2813:6130 with SMTP id z19-20020a05600c221300b003fe28136130mr4455615wml.22.1690973332125; Wed, 02 Aug 2023 03:48:52 -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 c17-20020a7bc011000000b003fe210d8e84sm1373978wmb.5.2023.08.02.03.48.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Aug 2023 03:48:51 -0700 (PDT) Message-ID: <31093c49-5baa-caed-9871-9503cb89454b@redhat.com> Date: Wed, 2 Aug 2023 12:48:50 +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, Kefeng Wang References: <20230728161356.1784568-1-fengwei.yin@intel.com> <3bbfde16-ced1-dca8-6a3f-da893e045bc5@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: <3bbfde16-ced1-dca8-6a3f-da893e045bc5@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: 7bit X-Rspamd-Queue-Id: A794F10000C X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 81qqa7m6e6zjyywuef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J2R5i19qPlWLZwdHV7qSMoovF9Z+EgIJUeLtqsvw5K2qzcmzvwTJsKZMu+XTjbtiyFHuLkA9oxRa39YH/I8eXzS8i2f8jsa2mfb6QqZ8xCvyCosg3yMEABShb0qwU2hZ/QT7HkS5iCtCCGF/R8S5g+xAceY8LDNBXpQcVo8RiY9KBFpUiGY7tSmFewdiu7KFn/dOe/Y7IkkrBNcNfFj+7BthraIK0/NmHKhvJW0sAGae0rIRv8CyLsMiIjq1jOogueCSrwSYoMngmiNWH7hs+pFfvSZSGBynqSQycgtR4h6/ZxBzf7oxe7z5TqmSNTNydDhGh1AdRIpsITOMOK7kK7a0yG+/miKoOXEZf5GE5Ey33nv0yPoErCt5hSK7IUi71WwteN5nw3KwQlW7EtsLTxud41CViKnKgWLlMeRGbFGmSyg3uUgK+3li57TOO3sP8A56vhJe/gMvaUTh4SpydU/UYtfxt2Uo7zRyu9/2l 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 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. 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. But we should definitely spell that out. -- Cheers, David / dhildenb