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 DC184D62060 for ; Tue, 19 Nov 2024 09:55:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 20D996B0096; Tue, 19 Nov 2024 04:55:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1BDEA8D0002; Tue, 19 Nov 2024 04:55:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 036C86B0099; Tue, 19 Nov 2024 04:55:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id CCE156B0096 for ; Tue, 19 Nov 2024 04:55:44 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 77371AD511 for ; Tue, 19 Nov 2024 09:55:44 +0000 (UTC) X-FDA: 82802386296.26.503BE10 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf04.hostedemail.com (Postfix) with ESMTP id A18A240008 for ; Tue, 19 Nov 2024 09:54:38 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hbHKh0na; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.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=1732009958; 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=6nGPI4QnXV5oc1GkhBs0z8YWpViNXGdnTtQrcN+bgVw=; b=QM85SjQM54LNYEHjzeCJu/7wxAjhwi7twod3Y/roxmtDhbxoxtURxx5t88ijSArJibCl3R TJm5wtHrH+muE2tNnUTsFIsOLZWk7m+OaNT6i5Hf3F1PjI3xbCqpTFs+u+s9leXV1iZSaQ 2BhEdyEa/YfFuYmEJ7tkG0Vgb3Ux6T0= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hbHKh0na; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf04.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=1732009958; a=rsa-sha256; cv=none; b=rK7JYB5JIBiw8/NwueUn415E8X/8w5BBVEy9uxusK2iGzmf5gvwF8zmnIUVDgsE4nJetrX sSqX2QDX0k1gMpae3HK15xrCgTjsXyTbDzYz5gB7GQbAwIPFD7+ln2JwUkla/pMxeQ8VjO U6ZGzZkFxBLAiejM0Rdhb0ObYwvdl/E= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732010141; 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=6nGPI4QnXV5oc1GkhBs0z8YWpViNXGdnTtQrcN+bgVw=; b=hbHKh0naCneEv3bXaww3UL4/3aAmDfMxAmuT6OPGUvZho6+Cm/bEIJ7XtwyBaSmxwayzmM XQ4KgTmagvE5wLC8qQuaYF3AL3gd0Cf3wW5GSqf3IPRIkJx0pLvlYGr9oTcKacikSlFhSU dyN1CqtBuoPxsh826ElWkWlm2FVCBy0= 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-613-b4aEbyZmPgWBFMDqj1CRiQ-1; Tue, 19 Nov 2024 04:55:38 -0500 X-MC-Unique: b4aEbyZmPgWBFMDqj1CRiQ-1 X-Mimecast-MFC-AGG-ID: b4aEbyZmPgWBFMDqj1CRiQ Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4315d98a75fso5551735e9.2 for ; Tue, 19 Nov 2024 01:55:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732010138; x=1732614938; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from: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=6nGPI4QnXV5oc1GkhBs0z8YWpViNXGdnTtQrcN+bgVw=; b=EujgOtQHMM0bsbwl/3lW4lFsyHTC40JMfRsrmbL1oliWjotmHvxRFcpMR+dufW0o/b ZPmcPYNNEKvMcdZdr2yiuBfoVhFXUwwWRG5b9KJhRp7fBYkHWIyFslz/SdU5iUStlLVP +Xna5+zYnJnUK+4WPVcQTEueyjlqXwEAZVOgMt6Dj1WwCkoKrHytMcT1Q6f0O4owoTCR lQq7nWhxL6M63nIFFCABH4SQJAkHWTUrBwhpU4TGNo1Sm/zAoakacJ1EZtwLyBsbZHLh wgEO+cdbZB3f6NFjnFGSJkbr85ZhFRuElyO1xMYaIkXtoHiwVgAm5QcYemBzDV6JILW2 v3Aw== X-Forwarded-Encrypted: i=1; AJvYcCUQGSJAvivfvQs180m6f/V966f6tSmnBEb0QC9T+ZJLH8NESBk56nl5oXUqH9E5JguyP+HSubQ+zw==@kvack.org X-Gm-Message-State: AOJu0YxpmnqV8MgwLr0QFFjMpvJfTqqxFLHTJKWao/xFSZfzg0gfDvNw GgXGmGSnTD3odIgSPh7689Pgy7T2K/hmxhfbN9O/6apJBX3bwSKKQPEl6id/ERf2GGdKi7Qgqsz bpSVtXuElJeMKTv9TAsJO4nDkVO++bPr0QQGPGGkIHb6aS6jA X-Received: by 2002:a05:600c:348c:b0:42c:bc22:e074 with SMTP id 5b1f17b1804b1-432df7906f0mr124500625e9.29.1732010137750; Tue, 19 Nov 2024 01:55:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IE+DRt85yY09ELSZcncFP954Sunrtltciu/GXArm4CiiPdPr0qWExcEN6T3eDzHyQ/5notiQw== X-Received: by 2002:a05:600c:348c:b0:42c:bc22:e074 with SMTP id 5b1f17b1804b1-432df7906f0mr124500315e9.29.1732010137324; Tue, 19 Nov 2024 01:55:37 -0800 (PST) Received: from ?IPV6:2003:cb:c74b:d000:3a9:de5c:9ae6:ccb3? (p200300cbc74bd00003a9de5c9ae6ccb3.dip0.t-ipconnect.de. [2003:cb:c74b:d000:3a9:de5c:9ae6:ccb3]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-432dac0ae04sm185377065e9.33.2024.11.19.01.55.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 Nov 2024 01:55:36 -0800 (PST) Message-ID: Date: Tue, 19 Nov 2024 10:55:33 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 4/9] mm: introduce skip_none_ptes() To: Qi Zheng Cc: jannh@google.com, hughd@google.com, willy@infradead.org, muchun.song@linux.dev, vbabka@kernel.org, akpm@linux-foundation.org, peterx@redhat.com, mgorman@suse.de, catalin.marinas@arm.com, will@kernel.org, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, x86@kernel.org, lorenzo.stoakes@oracle.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, zokeefe@google.com, rientjes@google.com References: <574bc9b646c87d878a5048edb63698a1f8483e10.1731566457.git.zhengqi.arch@bytedance.com> <617a063e-bd84-4da5-acf4-6ff516512055@bytedance.com> <253e5fd0-7e98-43fd-b0d7-8a5b739ae4aa@bytedance.com> <77b1eddf-7c1b-43e9-9352-229998ce3fc7@redhat.com> <5a3428bd-743a-4d51-8b75-163ab560bca7@bytedance.com> <4edccc1a-2761-4a5a-89a6-7869c1b6b08a@redhat.com> <2b48d313-4f66-47c8-98d8-8aa78db62b1b@bytedance.com> <995804f4-b658-44b2-bb40-c84b8a322616@redhat.com> <4ee60b7b-a81e-4b94-96c9-52b1bd9d5061@redhat.com> <332cbacb-cad3-4522-a74b-b5ad5efee4af@redhat.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//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURfIdKSb B3JfpUqcWwE7vUaYrHG1nw54pLUoPG6sAA7Mehl3nd4pZUALHwARAQABzSREYXZpZCBIaWxk ZW5icmFu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phDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 0CnhknZqcynwEPkSFi2I0_-Lc7NiJZAhifsS3rS-XYs_1732010138 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: A18A240008 X-Stat-Signature: 1cm919uo38uy8b5qc5ttnaoqcqhnxowx X-Rspam-User: X-HE-Tag: 1732010078-410594 X-HE-Meta: U2FsdGVkX1+V7EafN+HwbxBS9zIzXdmww4frsvHWD1/u5SifprPTkeDV5rRAYDQWRom1v00x/cdyxKHSy9jk8/RQmxwnQ358LXW/Se9uBSMmSw4qt0jr+q8zhWt0IRSlVnVYAGD2/sLvCQR/02PeUYDWwE3k8WRQRBuE4sKU0/ib2mhEtskrfbkol0Bio/Dmp+h6N2j7brfCcaoH1riT4cltuc2XRy/DjOYFqTDtlwAAAHA/nVm615NdpHGuQtA8lsbWbZJ497bl0bJTj6fSS1v7wkzev6TZ3XIDV2mEarS9yQAhEmwodQi7kP5lm86p3zB6YXuYiTQ9HThIly+WK4G3gTuTlW3ecQ8NYVob/RIgiKjgXZvskYPhUhicpAXF5qljffIOW5i4J/vPUNhz1nAvCDrJ6bIQT3AJu5HI7XpE7SFCaxzLEJJ5uALHWnovPNO1BXFLW65LEbvO+ZFPLxasyDZb0H3dYT03+wLko9eEysQHGMzOXd14UvhhEO/UrfcESVh0hW+N5NEqsoukGF6pEHxUSALngNqGm9WefMvY9Gld+bB1AT3FoTvU6YKZiFScftDMXYIuQWk4J26w2ft59fXjlB1wB8nL26zqt0iyXN5NVPx+TBIEKD3NI+8U7YXVP275wXbjcAdGHBvWpF1uAk48ZPdjp005SK4C76UfmCKjXPEd27b3bMd78idwT6eUwgzDY4hV7UrbC/IC/se79UDPeRyZ1Nv+Pu7bKBbXlaLpAeJX8q36190nmsSzmPKwrGne6NLeb/ORoftw9nmQwTarqnFysivpXoQbqNpt5IfY77nfqdtwClHLrXLbqJzPJMQgKrSd753MSFM4n3tpnGT17ZNFM3CsTj963T3wUoikPszhBYgq2/8NCSwyEZBZxOmIStoQ9n/k89SIIK+bvM2mcCZ7N9PW92ygwUJrWGnE/xK3QG1HPpSeEKRWvrj3salAr29zLLQavGj 1aGc4nT/ xqDY7/haTz2lZ7qDOLUT+UhhKRRrZKJ47Kq6VTgp/54YfQzhm378mjdzBBVfr8vtWjGx9iONK4SSv5roVxJC7PFwKbMjvq8jNN8/kv1qJMpwYdUdTv2qeNR8+w9ykCfzVwidbxkVyinseEK4oQi4qpfnZYVoQwbF/XGzK5l6LXCWDnHXX9Lc3wUh1TNXdK/gaOcVSIyehYxSdP/Il+oI4Hfk9s5OImn0BXcO96tqDmPpgL6ZUWbpIz2KFgn+BqDyPQvuDYcEciK8AQkldct3e+pqEej9/2iTzz3D1ehIZk54mr6W64LDp1xVksJ3pnmIJsP4hK95Xfv3RraFlzWv3GrrVPuLB1lng4GwAr9GtDv/dIUy8tQaL4QZAAayvlfhamchPazBO0oJ6cQLfSE03z9bh6mchipggCcTYPurT5jUNtC5Lxqn8M9z+E+RHMqhTO87TpVeT1OWEOOgpkqxByLIpvg== 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: List-Subscribe: List-Unsubscribe: On 18.11.24 12:13, Qi Zheng wrote: > > > On 2024/11/18 18:59, David Hildenbrand wrote: >> On 18.11.24 11:56, Qi Zheng wrote: >>> >>> >>> On 2024/11/18 18:41, David Hildenbrand wrote: >>>> On 18.11.24 11:34, Qi Zheng wrote: >>>>> >>>>> >>>>> On 2024/11/18 17:29, David Hildenbrand wrote: >>>>>> On 18.11.24 04:35, Qi Zheng wrote: >>>>>>> >>>>>>> >>>>>>> On 2024/11/15 22:59, David Hildenbrand wrote: >>>>>>>> On 15.11.24 15:41, Qi Zheng wrote: >>>>>>>>> >>>>>>>>> >>>>>>>>> On 2024/11/15 18:22, David Hildenbrand wrote: >>>>>>>>>>>>> *nr_skip = nr; >>>>>>>>>>>>> >>>>>>>>>>>>> and then: >>>>>>>>>>>>> >>>>>>>>>>>>> zap_pte_range >>>>>>>>>>>>> --> nr = do_zap_pte_range(tlb, vma, pte, addr, end, details, >>>>>>>>>>>>> &skip_nr, >>>>>>>>>>>>>                               rss, &force_flush, &force_break); >>>>>>>>>>>>>            if (can_reclaim_pt) { >>>>>>>>>>>>>                none_nr += count_pte_none(pte, nr); >>>>>>>>>>>>>                none_nr += nr_skip; >>>>>>>>>>>>>            } >>>>>>>>>>>>> >>>>>>>>>>>>> Right? >>>>>>>>>>>> >>>>>>>>>>>> Yes. I did not look closely at the patch that adds the >>>>>>>>>>>> counting of >>>>>>>>>>> >>>>>>>>>>> Got it. >>>>>>>>>>> >>>>>>>>>>>> pte_none though (to digest why it is required :) ). >>>>>>>>>>> >>>>>>>>>>> Because 'none_nr == PTRS_PER_PTE' is used in patch #7 to detect >>>>>>>>>>> empty PTE page. >>>>>>>>>> >>>>>>>>>> Okay, so the problem is that "nr" would be "all processed >>>>>>>>>> entries" but >>>>>>>>>> there are cases where we "process an entry but not zap it". >>>>>>>>>> >>>>>>>>>> What you really only want to know is "was any entry not zapped", >>>>>>>>>> which >>>>>>>>>> could be a simple input boolean variable passed into >>>>>>>>>> do_zap_pte_range? >>>>>>>>>> >>>>>>>>>> Because as soon as any entry was processed but  no zapped, you can >>>>>>>>>> immediately give up on reclaiming that table. >>>>>>>>> >>>>>>>>> Yes, we can set can_reclaim_pt to false when a !pte_none() entry is >>>>>>>>> found in count_pte_none(). >>>>>>>> >>>>>>>> I'm not sure if well need cont_pte_none(), but I'll have to take a >>>>>>>> look >>>>>>>> at your new patch to see how this fits together with doing the >>>>>>>> pte_none >>>>>>>> detection+skipping in do_zap_pte_range(). >>>>>>>> >>>>>>>> I was wondering if you cannot simply avoid the additional >>>>>>>> scanning and >>>>>>>> simply set "can_reclaim_pt" if you skip a zap. >>>>>>> >>>>>>> Maybe we can return the information whether the zap was skipped from >>>>>>> zap_present_ptes() and zap_nonpresent_ptes() through parameters >>>>>>> like I >>>>>>> did in [PATCH v1 3/7] and [PATCH v1 4/7]. >>>>>>> >>>>>>> In theory, we can detect empty PTE pages in the following two ways: >>>>>>> >>>>>>> 1) If no zap is skipped, it means that all pte entries have been >>>>>>>        zap, and the PTE page must be empty. >>>>>>> 2) If all pte entries are detected to be none, then the PTE page is >>>>>>>        empty. >>>>>>> >>>>>>> In the error case, 1) may cause non-empty PTE pages to be reclaimed >>>>>>> (which is unacceptable), while the 2) will at most cause empty PTE >>>>>>> pages >>>>>>> to not be reclaimed. >>>>>>> >>>>>>> So the most reliable and efficient method may be: >>>>>>> >>>>>>> a. If there is a zap that is skipped, stop scanning and do not >>>>>>> reclaim >>>>>>>        the PTE page; >>>>>>> b. Otherwise, as now, detect the empty PTE page through >>>>>>> count_pte_none() >>>>>> >>>>>> Is there a need for count_pte_none() that I am missing? >>>>> >>>>> When any_skipped == false, at least add VM_BUG_ON() to recheck none >>>>> ptes. >>>>> >>>>>> >>>>>> Assume we have >>>>>> >>>>>> nr = do_zap_pte_range(&any_skipped) >>>>>> >>>>>> >>>>>> If "nr" is the number of processed entries (including pte_none()), and >>>>>> "any_skipped" is set whenever we skipped to zap a !pte_none entry, we >>>>>> can detect what we need, no? >>>>>> >>>>>> If any_skipped == false after the call, we now have "nr" pte_none() >>>>>> entries. -> We can continue trying to reclaim >>>>> >>>>> I prefer that "nr" should not include pte_none(). >>>>> >>>> >>>> Why? do_zap_pte_range() should tell you how far to advance, nothing >>>> less, nothing more. >>>> >>>> Let's just keep it simple and avoid count_pte_none(). >>>> >>>> I'm probably missing something important? >>> >>> As we discussed before, we should skip all consecutive none ptes, >> > pte and addr are already incremented before returning. >> >> It's probably best to send the resulting patch so I can either >> understand why count_pte_none() is required or comment on how to get rid >> of it. > > Something like this: > > diff --git a/mm/memory.c b/mm/memory.c > index bd9ebe0f4471f..e9bec3cd49d44 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -1657,6 +1657,66 @@ static inline int zap_nonpresent_ptes(struct > mmu_gather *tlb, > return nr; > } > > +static inline int do_zap_pte_range(struct mmu_gather *tlb, > + struct vm_area_struct *vma, pte_t *pte, > + unsigned long addr, unsigned long end, > + struct zap_details *details, int *rss, > + bool *force_flush, bool *force_break, > + bool *any_skipped) > +{ > + pte_t ptent = ptep_get(pte); > + int max_nr = (end - addr) / PAGE_SIZE; I'd do here: int nr = 0; > + > + /* Skip all consecutive pte_none(). */ > + if (pte_none(ptent)) { > + instead of the "int nr" here > + for (nr = 1; nr < max_nr; nr++) { > + ptent = ptep_get(pte + nr); > + if (!pte_none(ptent)) > + break; > + } > + max_nr -= nr; > + if (!max_nr) > + return 0; > + pte += nr; > + addr += nr * PAGE_SIZE; > + } > + > + if (pte_present(ptent)) > + return zap_present_ptes(tlb, vma, pte, ptent, max_nr, > + addr, details, rss, force_flush, > + force_break, any_skipped); and here: if (pte_present(ptent)) nr += zap_present_ptes(...) else nr += zap_nonpresent_ptes(); return nr; So you really return the number of processed items -- how much the caller should advance. > + > + return zap_nonpresent_ptes(tlb, vma, pte, ptent, max_nr, addr, > + details, rss, any_skipped); > +} > + > +static inline int count_pte_none(pte_t *pte, int nr) > +{ > + int none_nr = 0; > + > + /* > + * If PTE_MARKER_UFFD_WP is enabled, the uffd-wp PTEs may be > + * re-installed, so we need to check pte_none() one by one. > + * Otherwise, checking a single PTE in a batch is sufficient. > + */ > +#ifdef CONFIG_PTE_MARKER_UFFD_WP > + for (;;) { > + if (pte_none(ptep_get(pte))) > + none_nr++; > + if (--nr == 0) > + break; > + pte++; > + } > +#else > + if (pte_none(ptep_get(pte))) > + none_nr = nr; > +#endif > + return none_nr; > +} > + > + > static unsigned long zap_pte_range(struct mmu_gather *tlb, > struct vm_area_struct *vma, pmd_t *pmd, > unsigned long addr, unsigned long end, > @@ -1667,6 +1727,7 @@ static unsigned long zap_pte_range(struct > mmu_gather *tlb, > int rss[NR_MM_COUNTERS]; > spinlock_t *ptl; > pte_t *start_pte; > + bool can_reclaim_pt; > pte_t *pte; > int nr; > > @@ -1679,28 +1740,22 @@ static unsigned long zap_pte_range(struct > mmu_gather *tlb, > flush_tlb_batched_pending(mm); > arch_enter_lazy_mmu_mode(); > do { > - pte_t ptent = ptep_get(pte); > - int max_nr; > - > - nr = 1; > - if (pte_none(ptent)) > - continue; > + bool any_skipped; > > if (need_resched()) > break; > > - max_nr = (end - addr) / PAGE_SIZE; > - if (pte_present(ptent)) { > - nr = zap_present_ptes(tlb, vma, pte, ptent, max_nr, > - addr, details, rss, > &force_flush, > - &force_break); > - if (unlikely(force_break)) { > - addr += nr * PAGE_SIZE; > - break; > - } > - } else { > - nr = zap_nonpresent_ptes(tlb, vma, pte, ptent, > max_nr, > - addr, details, rss); > + nr = do_zap_pte_range(tlb, vma, pte, addr, end, details, > + rss, &force_flush, &force_break, > + &any_skipped); > + if (can_reclaim_pt) { > + VM_BUG_ON(!any_skipped && count_pte_none(pte, > nr) == nr); Okay, so this is really only for debugging then? So we can safely drop that for now. I assume it would make sense to check when reclaiming a page table with CONFIG_DEBUG_VM, that the table is actually all-pte_none instead? (as a side note: no VM_BUG_ON, please :) ) -- Cheers, David / dhildenb