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 A1D8EC3DA4A for ; Fri, 16 Aug 2024 09:22:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3AB5A8D005C; Fri, 16 Aug 2024 05:22:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 35B458D0002; Fri, 16 Aug 2024 05:22:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1D4678D005C; Fri, 16 Aug 2024 05:22:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id F2C558D0002 for ; Fri, 16 Aug 2024 05:22:24 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 94E801C507A for ; Fri, 16 Aug 2024 09:22:24 +0000 (UTC) X-FDA: 82457567808.14.1C3931C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf10.hostedemail.com (Postfix) with ESMTP id 4673FC001A for ; Fri, 16 Aug 2024 09:22:22 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Wqew1i6N; spf=pass (imf10.hostedemail.com: domain of david@redhat.com designates 170.10.129.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=1723800069; 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=M1nw3TI/x8xm8G5ToDEc03hFzXIhWW679Aa76Rk3KUA=; b=RPZMpEjD/WdzDi+7BK30gDLAQu8YHTxZ0Q+6xO92qklQRi99RjFYYIHX+bTkU/MEVOYI6N CoqSIVCk8IELffxC+QLFGkjmCS3yMejv3k3dwWk2LwigeyfuL0HRqX3GLTuZC1zHPXd1bZ BUHXR97+yJsgAjQeT1fhXGRojKo0GjY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723800069; a=rsa-sha256; cv=none; b=iRHWsX6aWPruiJRaa7dDA5H72KNVQLejoyBrbYJTcaKPpqMnIR0IGIAuQ28D4ShSTtJ5L5 xTfY5EalzHMpuZJn/iDnQ8muovuodJ1WruUVhqBI3YoXTvu4o4OlYV/i45R/SosT4vfEY1 +uQBocfgyp85dFGXmA4N9osWuK1Q4AA= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Wqew1i6N; spf=pass (imf10.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723800141; 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=M1nw3TI/x8xm8G5ToDEc03hFzXIhWW679Aa76Rk3KUA=; b=Wqew1i6NA8KDvldPVSdlPcsTVm4plPcgl3QXhZgiQipI/b6PUjJaU3F47yvIJaCH3fcBHp YfMhSoq93Ht274yRFNQkGWYOe/NthDxidcIFGlkN9yp0pDUhlDdaGusCyxzh+YYZlf1bls 6FF0axjkw485MGli/UlMLqJMC1gdJv0= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-333-OOyh9hKPP329PUHmiYMjxA-1; Fri, 16 Aug 2024 05:22:19 -0400 X-MC-Unique: OOyh9hKPP329PUHmiYMjxA-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-42820af1106so12729215e9.2 for ; Fri, 16 Aug 2024 02:22:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723800138; x=1724404938; 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=M1nw3TI/x8xm8G5ToDEc03hFzXIhWW679Aa76Rk3KUA=; b=DvwQiAqJ8pQkIhGIAtv2PFcw8ml1WfahOEc7lYVWRl5MBZc+ZpCLx/gjbbJE+zVMBo bzJTZqkxkyuShosPFdtGF54ibtP9RN/NIrQTwZ5VUDU/cKZTd6CX32MOIvLDffVb2u3d +Kh+h0I864bNaWjwc/vzAs/NL+6NzG0F8Ngd0ZQ48+lyLjRqxPy2qoEQHzJ+tiLQkRnM S9UHt8KXBtmqGFi4VBW2SCiJ9aNjbzNBhx4mp0PSh5SD8n6+FD5x7cDK+Csy63s6Y7ea RCuePK5f+9e/MGJZRCpNHVmX2TMhQ+AFBLNaChjTBcD5hRc1FNcGhKckEsrHpPaq0G/2 ESHQ== X-Forwarded-Encrypted: i=1; AJvYcCUhzHyxiKcuz1tigEbvyVx55DqwX0PLH3pFF0HWyXnZJc59BDcV72Zf94z2shGdu6mgQJWYf+u1x9O12aP4Z0x235E= X-Gm-Message-State: AOJu0Yy1xehmKnwx/4Ume4260PmYw0sqAr8hNXcGtsF2V5HMp1zGaehX oQHfdE312tpSXgPLhNmkdW3HEtyVTo64XAaGuiR6GFZ8pFje7BPS0OT38iuT2uTfsDSmDQZRFRH 8vsSz9GgFwVBT0rZdAgAbD5OJ/w/HQO2x6FAsU2jWlxVtArLV X-Received: by 2002:a05:600c:3587:b0:426:51dc:f6cd with SMTP id 5b1f17b1804b1-429ed7b8883mr15414265e9.18.1723800138028; Fri, 16 Aug 2024 02:22:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IES7VluZXtLEQDwH6+FARixLjnpngjcVpPeq9bi09avGW2l9mXuFy0bHMVDdzJU44v4iQRgZw== X-Received: by 2002:a05:600c:3587:b0:426:51dc:f6cd with SMTP id 5b1f17b1804b1-429ed7b8883mr15413965e9.18.1723800137454; Fri, 16 Aug 2024 02:22:17 -0700 (PDT) Received: from ?IPV6:2003:cb:c721:b900:4f34:b2b7:739d:a650? (p200300cbc721b9004f34b2b7739da650.dip0.t-ipconnect.de. [2003:cb:c721:b900:4f34:b2b7:739d:a650]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-429ded18468sm70216805e9.2.2024.08.16.02.22.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Aug 2024 02:22:17 -0700 (PDT) Message-ID: Date: Fri, 16 Aug 2024 11:22:15 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v2 4/7] mm: pgtable: try to reclaim empty PTE pages in zap_page_range_single() To: Qi Zheng Cc: hughd@google.com, willy@infradead.org, mgorman@suse.de, muchun.song@linux.dev, vbabka@kernel.org, akpm@linux-foundation.org, zokeefe@google.com, rientjes@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <9fb3dc75cb7f023750da2b4645fd098429deaad5.1722861064.git.zhengqi.arch@bytedance.com> <2659a0bc-b5a7-43e0-b565-fcb93e4ea2b7@redhat.com> <42942b4d-153e-43e2-bfb1-43db49f87e50@bytedance.com> From: David Hildenbrand Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgc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BQXWeXhJI9XQssfrf4Gusdqx8nPEpfOqCtbbwJMATbHyqLt7/oz/5deGuwxgb65pWIzufa N7eop7uh+6bezi+rugUI+w6DABEBAAHCwXwEGAEIACYCGwwWIQQb2cqtc1xMOkYN/MpN3hD3 AP+DWgUCXw7HsgUJEqkpoQAKCRBN3hD3AP+DWrrpD/4qS3dyVRxDcDHIlmguXjC1Q5tZTwNB boaBTPHSy/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: <42942b4d-153e-43e2-bfb1-43db49f87e50@bytedance.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: 8bit X-Rspamd-Queue-Id: 4673FC001A X-Stat-Signature: 6bpafjkg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sN964A30zQt8y07FaVf56HdfEijad95FjJ/nXvQddbytpbUcB+K+Q7u2LbtpUtpY2BT5r+YnTRy7o4NyqTJsROZL5dDjgUxEbe6zHvROWNqIlD+CoEgxSi0WwGBBQwKfMg5L/U+1wgf3//aKS2Fi1T9+B67NPROyL7pDtXlaL/GfaMGGp6WtfCqwSSYi2Ft/UZsDJfxGTD+tDscQ/9Ss5evvODQNdRzX/doBtptSN4IgkE2+Hh6SGfJNBO2j/T49LF1VK0opsrZSQDhwQxro17SY/l2o3qDlDj5FelM9WizTtHjvzxAXWwpZzB/fv6CCAPRkS+iRhAS38eveMbuWSEvI1Oh4I19lCccXIullV0l7cgXDe8a4JP2+uBk7Vf6eVSWXDebI0oRBt2mXXj4dQ/8WTJINmoEKRU9veLhe5ls73SY7L6t2e 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 07.08.24 05:58, Qi Zheng wrote: > Hi David, > Really sorry for the slow replies, I'm struggling with a mixture of public holidays, holiday and too many different discussions (well, and some stuff I have to finish myself). > On 2024/8/6 22:40, David Hildenbrand wrote: >> On 05.08.24 14:55, Qi Zheng wrote: >>> Now in order to pursue high performance, applications mostly use some >>> high-performance user-mode memory allocators, such as jemalloc or >>> tcmalloc. These memory allocators use madvise(MADV_DONTNEED or MADV_FREE) >>> to release physical memory, but neither MADV_DONTNEED nor MADV_FREE will >>> release page table memory, which may cause huge page table memory usage. >>> >>> The following are a memory usage snapshot of one process which actually >>> happened on our server: >>> >>>          VIRT:  55t >>>          RES:   590g >>>          VmPTE: 110g >>> >>> In this case, most of the page table entries are empty. For such a PTE >>> page where all entries are empty, we can actually free it back to the >>> system for others to use. >>> >>> As a first step, this commit attempts to synchronously free the empty PTE >>> pages in zap_page_range_single() (MADV_DONTNEED etc will invoke this). In >>> order to reduce overhead, we only handle the cases with a high >>> probability >>> of generating empty PTE pages, and other cases will be filtered out, such >>> as: >> >> It doesn't make particular sense during munmap() where we will just >> remove the page tables manually directly afterwards. We should limit it >> to the !munmap case -- in particular MADV_DONTNEED. > > munmap directly calls unmap_single_vma() instead of > zap_page_range_single(), so the munmap case has already been excluded > here. On the other hand, if we try to reclaim in zap_pte_range(), we > need to identify the munmap case. > > Of course, we could just modify the MADV_DONTNEED case instead of all > the callers of zap_page_range_single(), perhaps we could add a new > parameter to identify the MADV_DONTNEED case? See below, zap_details might come in handy. > >> >> To minimze the added overhead, I further suggest to only try reclaim >> asynchronously if we know that likely all ptes will be none, that is, > > asynchronously? What you probably mean to say is synchronously, right? > >> when we just zapped *all* ptes of a PTE page table -- our range spans >> the complete PTE page table. >> >> Just imagine someone zaps a single PTE, we really don't want to start >> scanning page tables and involve an (rather expensive) walk_page_range >> just to find out that there is still something mapped. > > In the munmap path, we first execute unmap and then reclaim the page > tables: > > unmap_vmas > free_pgtables > > Therefore, I think doing something similar in zap_page_range_single() > would be more consistent: > > unmap_single_vma > try_to_reclaim_pgtables > > And I think that the main overhead should be in flushing TLB and freeing > the pages. Of course, I will do some performance testing to see the > actual impact. > >> >> Last but not least, would there be a way to avoid the walk_page_range() >> and simply trigger it from zap_pte_range(), possibly still while holding >> the PTE table lock? > > I've tried doing it that way before, but ultimately I did not choose to > do it that way because of the following reasons: I think we really should avoid another page table walk if possible. > > 1. need to identify the munmap case We already have "struct zap_details". Maybe we can extend that to specify what our intention are (either where we come from or whether we want to try ripping out apge tables directly). > 2. trying to record the count of pte_none() within the original > zap_pte_range() loop is not very convenient. The most convenient > approach is still to loop 512 times to scan the PTE page. Right, the code might need some reshuffling. As we might temporary drop the PTL (break case), fully relying on everything being pte_none() doesn't always work. We could either handle it in zap_pmd_range(), after we processed a full PMD range. zap_pmd_range() knows for sure whether the full PMD range was covered, even if multiple zap_pte_range() calls were required. Or we could indicate to zap_pte_range() the original range. Or we could make zap_pte_range() simply handle the retrying itself, and not get called multiple times for a single PMD range. So the key points are: (a) zap_pmd_range() should know for sure whether the full range is covered by the zap. (b) zap_pte_range() knows whether it left any entries being (IOW, it n never ran into the "!should_zap_folio" case) (c) we know whether we temporarily had to drop the PTL and someone might have converted pte_none() to something else. Teaching zap_pte_range() to handle a full within-PMD range itself sounds cleanest. Then we can handle it fully in zap_pte_range(): (a) if we had to leave entries behind (!pte_none()), no need to try ripping out the page table. (b) if we didn't have to drop the PTL, we can remove the page table without even re-verifying whether the entries are pte_none(). We know they are. If we had to drop the PTL, we have to re-verify at least the PTEs that were not zapped in the last iteration. So there is the chance to avoid pte_none() checks completely, or minimze them if we had to drop the PTL. Anything I am missing? Please let me know if anything is unclear. Reworking the retry logic for zap_pte_range(), to be called for a single PMD only once is likely the first step. > 3. still need to release the pte lock, and then re-acquire the pmd lock > and pte lock. Yes, if try-locking the PMD fails. -- Cheers, David / dhildenb