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 B1BF0D10F31 for ; Mon, 18 Nov 2024 03:35:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 822C86B009E; Sun, 17 Nov 2024 22:35:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7AB526B00A3; Sun, 17 Nov 2024 22:35:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 624E56B00B5; Sun, 17 Nov 2024 22:35:29 -0500 (EST) 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 3C7A16B009E for ; Sun, 17 Nov 2024 22:35:29 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B8BAC120122 for ; Mon, 18 Nov 2024 03:35:28 +0000 (UTC) X-FDA: 82797799266.23.A73DAD7 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) by imf27.hostedemail.com (Postfix) with ESMTP id 674FD40004 for ; Mon, 18 Nov 2024 03:34:36 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=JMgImLnG; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf27.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.180 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731900793; a=rsa-sha256; cv=none; b=DePxTDbjXpuDlvu0R4hAGjFtPxslj2Oalg7bHgmaq5zdRg92+FrLiJmOeG+KTtkCfLbqG7 GSdmKZ6zWs+meHY2/ciZwUCqAPhQ2VF9MHcodiB2l3h014sKyh4n7MBziG3u1FHf1z47LY 5ISATSsUwhMUKbWyWivP1luH/P3L77Y= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=JMgImLnG; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf27.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.215.180 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731900793; 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=fAYOV2IOUo6rjS8pTIiOgTq2N/PP28lI20oMJdYXwLY=; b=hW0oL2cc2Ler1nYGvpUnXBJlRoHIiEAH/U7y5rxYXImgxfhKiRkKVS/t/BkV12Miiarq2T OlWWvOFPKGw8PIGL/RvTUhU14ZiQjjPz7YryjndX9PDga2M4pqMDNYtRsXOWasjEK5E1+U Bz6dyhnO3tX0nO+sFlWw9LWL1erkyLI= Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-7ee020ec76dso2911202a12.3 for ; Sun, 17 Nov 2024 19:35:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1731900924; x=1732505724; darn=kvack.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=fAYOV2IOUo6rjS8pTIiOgTq2N/PP28lI20oMJdYXwLY=; b=JMgImLnGzohEfEtns8eHMdfRigJClMMZ9X/0MIlnZTcAUnXZmcnvgmIM1BaVCwpoik cY0Gn4CVOPqO/RuRSotvBPktqC1PeK93jLviu9GDYrEBRq8f1ISdix8jSJRW+ULL2pF4 yzBwP0Ri/76vhk6pTdh6Az1eIaxL960qpMHLU0YV9Mn5MKTGY+DAnJ1qJMukCQVglobY JbOrkNazPynktFJfWM4FXcSM2UjOyGQTyCMRRivK49lBcUXhnWVXcfMuN7J6+LLL8KgB sZGqOy/woNwwQ1HbvX/G6TVUgPUOl/y9ez14x+y4wZss0ScvO8r4QGJVyjJJ3JkBkx7r 9suQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731900924; x=1732505724; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fAYOV2IOUo6rjS8pTIiOgTq2N/PP28lI20oMJdYXwLY=; b=DzV3JVAoLXhNGOnRwvmfwGV73SiBt0DK3f1yEkYouxdW6ZZCDUam5CObWzwCle/Ut8 WwMSl7+WVi7+NenfZwvqoJOACCAu0fjaya+hZwL8G5WuhlNqNqu1J+U+jvIiGUD7dIXr mwAuroES9zQkITkbkkzvHwtB2GcyS45qX9iDyIXZJXqb6o7jwC2iDYgc4Aw1iCAbOoDI JS+dUPPQGXvbnngDJvGzFJYNO367FFUXsis+h+/k/6AIeVK2H4h4+9FKnfnPF/WFmxd+ RDT27CltvQVVgvICZrrucjxZY0Dhw8w/9o6MBvlDkZSvKSu1NoptwM82YIpTe/B7xhhy D2NA== X-Forwarded-Encrypted: i=1; AJvYcCXECGRKoQwVxKqaLI4sx5J9a2/zj+8qih2nfye4JUVbuGeElcaTvwN4vUUavwZEDt4Q9A4UPlJi4Q==@kvack.org X-Gm-Message-State: AOJu0Yz3AHsj4+JKbx+fm+rd067oEnOO4wGIZe0QeXB+nC1HlQ1MW62s ROw82mGfctujFrrxiP/4pUSA27d2h1ih1zPDsDTKFOiZBurCwp5zK0f8TbvvJxU= X-Google-Smtp-Source: AGHT+IGJ9PVwE31jWWhuyYcnhq9nPi2dLbhq/ndM6SWBSnO7O3ZT02MQhTcQjxiDQC20nehdJUqHhg== X-Received: by 2002:a17:902:8603:b0:20c:7409:bd00 with SMTP id d9443c01a7336-211d0d4c24amr115112385ad.5.1731900924349; Sun, 17 Nov 2024 19:35:24 -0800 (PST) Received: from [10.84.149.95] ([203.208.167.151]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211e9d0c389sm33367775ad.161.2024.11.17.19.35.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 17 Nov 2024 19:35:23 -0800 (PST) Message-ID: <2b48d313-4f66-47c8-98d8-8aa78db62b1b@bytedance.com> Date: Mon, 18 Nov 2024 11:35:15 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 4/9] mm: introduce skip_none_ptes() Content-Language: en-US To: David Hildenbrand 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> From: Qi Zheng In-Reply-To: <4edccc1a-2761-4a5a-89a6-7869c1b6b08a@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 674FD40004 X-Stat-Signature: g337sxddu8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Egs4W1k2j9OQ1cHyYWqaSndPokG4b2r3062uqfbD7Wu7AZ+Kknsijh9t6bzB+sKBWtwavGd2WcihvvCHtm7fFgdgwFTQL14qOh+1ncXoCr0ChIaxq/P/5PGrjUwH7IlQVlTKaG7QPbrVBV0Bdq9W43SrnBl4D8OBjkC/FG6BrusmMTVnXVDPl6xQJ89BX8wSKcbWek6HKmPx+dy6FMn3/BJjI/da9Ol1kTz3InafxSw/i97PuUMZ29KFvZ/Gtg1HyWWN/xfhguRX4KtsvsUtnYIuJIEQlL0ugq0ajQXbDwlb6pI6xlbUErg4xhCfKKC04uEXxM2BY7BPx0Zyyr7gpTqcctWd5GQIvhOKfhENl9BqHwZHXN2IVr3KAGlJIqlrNPHx 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 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() >