From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B8EF117BB32 for ; Mon, 18 Nov 2024 10:41:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731926514; cv=none; b=IQSf7IwcXFB5vH6hCk8cac6gtgazo91Kx95rJPJopg3EXEpZaMCDzErZdFYbAyTA1v3YefUd7nDtrv2zsWw8YLdrO10CQs7rFxtorPmHkdO4DA1Xz816/qG2ET/9cysyFyJeJS8vkYrdJmv8JPVVCtd0KVBTZPWx0U3AriMmPGg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731926514; c=relaxed/simple; bh=kKOpUNOO9jAM+Ifadp3rV0q3xdmRQPLyWmIQiVtISwM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=IgENV3mJX5OcKlUZ3N76smRaweAlJ6mhyc3bJ5ZzchzmKl3/LeUKoKJHrWe+nCktJyUWR7/Qe/7YBeLbJBtlSLa2i1LL2wMgZVw2uPu5r6mz7FTRJX2WlCtEDdaxCxNmKyPgwbWjPUuOs/ZxhZjouUBM0HnqNkYOBcTPXuour34= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=CnoEc5Xj; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CnoEc5Xj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731926511; 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=VGe5FNOBe6WgynLzggwe+p4nw844IRj0b4Y0ezsiHzY=; b=CnoEc5XjHm8Vcv3ccAGlZFxtJSI5VWnHXMSB59qcz1pbkoJL2I/IAUaUpo2NGlSIloVU8B T3uQjbJ8ZbrZi+YNkKJR7wA5pesGPaFpmRlEhMfG+fNeS+pFi3c9LW24JorB6xC/4KYDHi JKtewWZ9/068WpDvppwkdYRrTWvzr5c= 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-57-Oi8UTC99Mj29naOGuYSD7g-1; Mon, 18 Nov 2024 05:41:50 -0500 X-MC-Unique: Oi8UTC99Mj29naOGuYSD7g-1 X-Mimecast-MFC-AGG-ID: Oi8UTC99Mj29naOGuYSD7g Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-431604a3b47so28989895e9.3 for ; Mon, 18 Nov 2024 02:41:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731926509; x=1732531309; 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=VGe5FNOBe6WgynLzggwe+p4nw844IRj0b4Y0ezsiHzY=; b=JR3Tv1BAsQoIX+6NDto2Vc7DyRxqcI2OHyDjEqWxfZo9Nk/DQ0QpAwUtmXjYyI1Wzh kDXhLIVJpOWC2vT0SMpR9uXf9o6+w+P3miQBgHXKG7aDcH+JG2UisHGQXDQXWPNUkx6P W6zr+gEOKdYUYNA6CirIQdZRPlvbAehIUV1K0hOucsJfEW2pdeLGqVIz5k3APHx0qnz3 o6lIa3F8N0Hey+p5wRB79mRx/mDdTplzwnzfIhSQHGqa4A/8Wjn8dJ12jweGzgpML0SL 8NseTeAilbLqiUI2Qiq4agANb4jN64kx+uXs3GhLTEIm5HlS6g2M90e/PDurnymQiuuR yU/g== X-Forwarded-Encrypted: i=1; AJvYcCXPalCRN+359zwJHres98+idwsIZZzEiOSfUAzPp8VrxfgUk6rc0fj+w/NxbrUpbdL/mj8ADkCQevDrZBM=@vger.kernel.org X-Gm-Message-State: AOJu0YwGCjhGWmAznwMzRwjYCIq/Ol9qx6iP0mvw/bnNoxCljIyBEo4y /koiONh3oV51YCrGlbrAf5+7Etu7fgjwCbJqRkEibVkGI2WxLh8iAIejVqFZUfP5dx+rElDRVez zig87xsVUQ/fWTJbmr4qc33+xMAMLDw6VXQLSch6sRRDpm92E6BHE04Lww62POg== X-Received: by 2002:a5d:64cf:0:b0:382:31ca:4dca with SMTP id ffacd0b85a97d-38231ca4eedmr7817279f8f.7.1731926509035; Mon, 18 Nov 2024 02:41:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IFw5sC6OlBQx7GWigJnwjSntTjd1oHMg4vAalDSVTBfhCrGWb/HctZ8w8bO6LA3cR0CtDGLsQ== X-Received: by 2002:a5d:64cf:0:b0:382:31ca:4dca with SMTP id ffacd0b85a97d-38231ca4eedmr7817259f8f.7.1731926508682; Mon, 18 Nov 2024 02:41:48 -0800 (PST) Received: from ?IPV6:2a09:80c0:192:0:5dac:bf3d:c41:c3e7? ([2a09:80c0:192:0:5dac:bf3d:c41:c3e7]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3823c47f7f8sm5940182f8f.100.2024.11.18.02.41.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Nov 2024 02:41:48 -0800 (PST) Message-ID: <4ee60b7b-a81e-4b94-96c9-52b1bd9d5061@redhat.com> Date: Mon, 18 Nov 2024 11:41:47 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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> From: David Hildenbrand Content-Language: en-US Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1Impa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PHSy/Nksu0eY7x6HfQJ3xajVH32Ms6t1trDQmPx2iP5+7iDsb7OKAb5eOS8h+BEBDeq 3ecsQDv0fFJOA9ag5O3LLNk+3x3q7e0uo06XMaY7UHS341ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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? -- Cheers, David / dhildenb