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 CB897EB64DD for ; Thu, 3 Aug 2023 14:21:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 09443280262; Thu, 3 Aug 2023 10:21:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 01BF928022C; Thu, 3 Aug 2023 10:21:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD967280262; Thu, 3 Aug 2023 10:21:52 -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 CEF7828022C for ; Thu, 3 Aug 2023 10:21:52 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 9801981202 for ; Thu, 3 Aug 2023 14:21:52 +0000 (UTC) X-FDA: 81083007264.22.44D9E4E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf02.hostedemail.com (Postfix) with ESMTP id 53FEA80022 for ; Thu, 3 Aug 2023 14:21:50 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Hj0sR6uu; spf=pass (imf02.hostedemail.com: domain of david@redhat.com designates 170.10.133.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=1691072510; h=from:from:sender: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:dkim-signature; bh=k2yiRUXToo5dJqxKCedx3xrnV1At5a7zF8MhIPUWxqQ=; b=7Ai1+jaQmytTTfNneETOaRft6H7jSxGT3wKd0KlLXAT07ZMOqBa41abxiTytpvqeVOWk7+ P1+z/pVDkB0OfJQWvkYgUQVT0N+h8vkz2Ht79VwpB57mdNEaFaDmKFZf2XQafR6ofY4iPx PD7371KKUMngOr3M6xAK8vlppMY6p/4= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Hj0sR6uu; spf=pass (imf02.hostedemail.com: domain of david@redhat.com designates 170.10.133.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=1691072510; a=rsa-sha256; cv=none; b=WJIrz4uWmW+e3EPJpsrj+KEQ2m8UDm+z5wHsw3Xbmg97OWBI4B+YGDwFp6SBATnfaysUNS s5BA4QvQx9SBWZnWiqYjKFf1ET8P5raI4GeWZmTLo9QB2t/xvZmGjvSmgdz+tzfl5Zi1Un YYS3LHax3lqVZpGvRAo2xuSNVbTTtWE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691072509; 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; bh=k2yiRUXToo5dJqxKCedx3xrnV1At5a7zF8MhIPUWxqQ=; b=Hj0sR6uuTXm9qX6NbV5RT/HN6bVhD63ujwPiEXdJ6lxtn0goGF8D/I/eVtE4PCnW54zqQg UoW5kC+O/zU6W0lyZeZaeJ0nm/6bHfdJms49F7kitq0AqDlXmaIhHdEGUXBtmeVYzoIpw2 SFeFXw9n+xKc2uFzckjHhK46OKNHMes= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-218-mpJQlbixNtKw5spgF2DwwA-1; Thu, 03 Aug 2023 10:21:45 -0400 X-MC-Unique: mpJQlbixNtKw5spgF2DwwA-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-31785455660so623695f8f.2 for ; Thu, 03 Aug 2023 07:21:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691072503; x=1691677303; h=content-transfer-encoding:in-reply-to:subject:organization:from :references:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=k2yiRUXToo5dJqxKCedx3xrnV1At5a7zF8MhIPUWxqQ=; b=P+jElBJlVzvuzgxRgpdT1bje/KYKAl6zt3iyTktSgqR9EXtuPoLVwVLkuiBw2edf74 3pLOVx/pIEDvneWECrT//AK00Fi6USMoNZbuDiTgtvS0ErkMPfPKOmgh+lzwERfWWcmM 0KfcgyeN42ZqhCR5ilISUOCh4/DKa0tYx85df5MqKU7PMiH6oJK1qeKDmijnKYqaKLJS 1+Uu4BCAPutXD66FjMmdQZiCR6wLJ03QgvYhhrKIczMkIZOwPKsf3agskoQVS4a5CqM7 SxrCfRrYFTK4Cb1P47OmYSyQ37hfIQmNBqsEQXva6m2goPSkMLdvQoEaIV5TXiS+vEYM cmQA== X-Gm-Message-State: ABy/qLYwIef5PZEhdQOfmzc4XUgRnVsl0/l0Z7NhBM3DnNmcgDCa8KeB 41Dd2XFaMqywrGee/1XzgRcAelK49YyAsLxZQrQ0YyJ4NBVcp/pX+kw4Eucvd2Cdyeh8UGogCJF Ld7uST3odPno= X-Received: by 2002:a5d:510a:0:b0:314:bdb:cf71 with SMTP id s10-20020a5d510a000000b003140bdbcf71mr7958349wrt.53.1691072503378; Thu, 03 Aug 2023 07:21:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlEoKLeR8twzhSbAZm0I6RxWS45CD2PcT03DYvDx1v3JuJcxYHcW4fFZFKwkYMBxaPWVbQIFGg== X-Received: by 2002:a5d:510a:0:b0:314:bdb:cf71 with SMTP id s10-20020a5d510a000000b003140bdbcf71mr7958326wrt.53.1691072502978; Thu, 03 Aug 2023 07:21:42 -0700 (PDT) Received: from ?IPV6:2003:cb:c718:9a00:a5f5:5315:b9fa:64df? (p200300cbc7189a00a5f55315b9fa64df.dip0.t-ipconnect.de. [2003:cb:c718:9a00:a5f5:5315:b9fa:64df]) by smtp.gmail.com with ESMTPSA id b18-20020adfe312000000b0031437ec7ec1sm22113249wrj.2.2023.08.03.07.21.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Aug 2023 07:21:42 -0700 (PDT) Message-ID: <6fe2dd45-d634-facc-bb8a-3052ab463abb@redhat.com> Date: Thu, 3 Aug 2023 16:21:41 +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 , Andrew Morton , Matthew Wilcox , Yin Fengwei , Yu Zhao , Yang Shi , "Huang, Ying" , Zi Yan , Nathan Chancellor , Alexander Gordeev , Gerald Schaefer Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20230727141837.3386072-1-ryan.roberts@arm.com> <20230727141837.3386072-4-ryan.roberts@arm.com> <6cda91b3-bb7a-4c4c-a618-2572b9c8bbf9@redhat.com> <4255e71a-63c9-b2f9-5e97-e46834f7837c@arm.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v4 3/3] mm: Batch-zap large anonymous folio PTE mappings In-Reply-To: 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: 53FEA80022 X-Rspam-User: X-Stat-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g8igNCCrFoLAOvWA0Qw0te1upzaob21lBMLouqz489YggcS1ZHSF7qDnMq8gj4GNasvGlbtS97fAS7V/6tAgE7dYhL1enQ1gGl7oi/uFN2wh+KCKGhnUqtzxP8ir5PYHXTDWW+UM5wixabQhQQrzcyrS+1yHIN2+sno34OBL7aAt88dG7m27drzQfUR47f8f0aV3WGhksQJcsebWSXHv/eGRysb+VsQhORcyqa5pc67OQJUTu4ivYoqoW+3TjGttpU+67+GN0sSD5ncJY8MDQQffv7pSHhh6+F8EQxkGwUx2NtKlGfyW75CeafwX5dLYgq1pTFVIuhBtWdY3GPZdDFQHV05OkOHaryzlJVThUe5hsdIdm/dMt+MChKWZ/Ui 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 03.08.23 16:15, Ryan Roberts wrote: > On 03/08/2023 15:10, David Hildenbrand wrote: >>>> >>>> With this patch, you'll might suddenly have mapcount > refcount for a folio, or >>>> am I wrong? >>> >>> Yes you would. Does that break things? >>> >> >> It is problematic whenever you want to check for additional page references that >> are not from mappings (i.e., GUP refs/pins or anything else) >> >> One example lives in KSM code (!compound only): >> >> page_mapcount(page) + 1 + swapped != page_count(page) >> >> Another one in compaction code: >> >> if (!mapping && (folio_ref_count(folio) - 1) > folio_mapcount(folio)) >> >> And another one in khugepaged (is_refcount_suitable) >> >> ... and in THP split can_split_folio() (although that can deal with false >> positives and false negatives). >> >> >> We want to avoid detecting "no other references" if there *are* other >> references. Detecting "there are other references" although there are not is >> usually better. >> >> >> Assume you have mapcount > refcount for some time due to concurrent unmapping, >> AND some unrelated reference. You would suddenly pass these checks (mapcount == >> refcount) and might not detect other references. > > OK. I'll rework with the 2 loop approach, assuming I can calculate the number of > free slots in the mmu_gather ahead of time. Note that I think some of these checks might be racy in corner cases (and we should most probably make them more reliable by enforcing the memory order -- especially a single atomic total_mapcount might help). But for now, at least the idea that seems to work is that a) When you map the page, you first increment the refcount, then the mapcount b) When you unmap a page, you first decrement the mapcount, then the refcount So refcount >= mapcount should in theory always hold when taking a snapshot of both values. Although if the actual sides that check for these additional references might deserve some fine-tuning. -- Cheers, David / dhildenb