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 X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92EBFC636CA for ; Sun, 18 Jul 2021 22:01:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 021D3610A2 for ; Sun, 18 Jul 2021 22:01:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 021D3610A2 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=shutemov.name Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 89F318D00FE; Sun, 18 Jul 2021 18:01:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 84E8D8D00FC; Sun, 18 Jul 2021 18:01:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6EF5C8D00FE; Sun, 18 Jul 2021 18:01:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0048.hostedemail.com [216.40.44.48]) by kanga.kvack.org (Postfix) with ESMTP id 4E6D58D00FC for ; Sun, 18 Jul 2021 18:01:10 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id C89E918232A17 for ; Sun, 18 Jul 2021 22:01:08 +0000 (UTC) X-FDA: 78377079816.17.26623BA Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) by imf24.hostedemail.com (Postfix) with ESMTP id 878ADB00081B for ; Sun, 18 Jul 2021 22:01:08 +0000 (UTC) Received: by mail-lj1-f182.google.com with SMTP id e20so23089754ljn.8 for ; Sun, 18 Jul 2021 15:01:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shutemov-name.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=pTmQxf6zy7tgDXAHQZQ/3w3DBTHv9qcRwctrA/DmgL8=; b=ImGexmtBpNIhLOFUDX+Hg4fdEhz+9f0lA73zW6A4nVTg9Lq+3XMNPk+lksh0Tc1Uvs j773FbOGuzdb5rICHJu0x/mR4MfPLgPeYN7jGFIQb7hCwTDtxw2l6D96Zkt/54mGUPDQ pBdyl/SDjkV983FCXrlNk6b344/0UqOD/0HKkg1Dv2+huQ6JxBpBdNWpmt/EI1AZwAIE mGCdULjCwrVJWFICGTXAr1qQhLfaVpEdiWK7XOtbL7+x4oqfw955VQHoGzGMZ1bmbVsA 7frUOHLj1tAVss5x0h0d0d/waxKEKM8OQmBy885O9ObnvdJswiKEu0NehWcYymF6qLqS 7hGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=pTmQxf6zy7tgDXAHQZQ/3w3DBTHv9qcRwctrA/DmgL8=; b=HM1tJrqtwKfqwpzVxJYQWfBqM5ry8l61WvkU3bImAnIVCFKxaY8qNPyPx79WDXZGCj VP4rJM0GLeY6Shp5NRzlAY68R82icB8MFqxWvI96VoK0dg8a0aHB27nQdmZUxNe6SFGj Gz2ouIIO4UmlPhrBlh/E2qt4N9sFklj4aq7QJ0lxPbdGTCmvgrYN2somR5JWIRIkW4WE PBnD71oPCZFjIJJO+ajG661MyP5WYkkeQ9nxWYXPeFgfc2m4r4VTuk/MPdG5ZqTZzNsW 5On0L2CuB62sL+1oNdNbQIa2/BaheA+HaDK0LPp7ZU4i1zv+x0rgoEu7uL++J8wvWNi+ L+Qg== X-Gm-Message-State: AOAM531tIvmqZ8fCoGQ/4Rkm3PvhXW7Efxj9eWpEr2ZiKTSaNevl485D Eg8INMOozJFXZN5OqHEmaA/87Q== X-Google-Smtp-Source: ABdhPJyWP9/MCe/uj5yxXTZGFXBCLWxqnl6ztQZHqM5uxO9/Yt0DWcwAcoVo3+PYJan0pjRig6b9mQ== X-Received: by 2002:a2e:530e:: with SMTP id h14mr19763188ljb.454.1626645667141; Sun, 18 Jul 2021 15:01:07 -0700 (PDT) Received: from box.localdomain ([86.57.175.117]) by smtp.gmail.com with ESMTPSA id v16sm1874484ljn.93.2021.07.18.15.01.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Jul 2021 15:01:06 -0700 (PDT) Received: by box.localdomain (Postfix, from userid 1000) id 5F6CD10260F; Mon, 19 Jul 2021 01:01:10 +0300 (+03) Date: Mon, 19 Jul 2021 01:01:10 +0300 From: "Kirill A. Shutemov" To: Qi Zheng Cc: akpm@linux-foundation.org, tglx@linutronix.de, hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, songmuchun@bytedance.com Subject: Re: [PATCH 5/7] mm: free user PTE page table pages Message-ID: <20210718220110.nqcd73luncf3v7mk@box.shutemov.name> References: <20210718043034.76431-1-zhengqi.arch@bytedance.com> <20210718043034.76431-6-zhengqi.arch@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210718043034.76431-6-zhengqi.arch@bytedance.com> X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 878ADB00081B X-Stat-Signature: sutzs53pygstji1o1e1qpsnpyegk5tsf Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=ImGexmtB; spf=none (imf24.hostedemail.com: domain of kirill@shutemov.name has no SPF policy when checking 209.85.208.182) smtp.mailfrom=kirill@shutemov.name; dmarc=none X-HE-Tag: 1626645668-310573 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 Sun, Jul 18, 2021 at 12:30:31PM +0800, Qi Zheng wrote: > Some malloc libraries(e.g. jemalloc or tcmalloc) usually > allocate the amount of VAs by mmap() and do not unmap > those VAs. They will use madvise(MADV_DONTNEED) to free > physical memory if they want. But the page tables do not > be freed by madvise(), so it can produce many page tables > when the process touches an enormous virtual address space. > > The following figures are a memory usage snapshot of one > process which actually happened on our server: > > VIRT: 55t > RES: 590g > VmPTE: 110g > > As we can see, the PTE page tables size is 110g, while the > RES is 590g. In theory, the process only need 1.2g PTE page > tables to map those physical memory. The reason why PTE page > tables occupy a lot of memory is that madvise(MADV_DONTNEED) > only empty the PTE and free physical memory but doesn't free > the PTE page table pages. So we can free those empty PTE page > tables to save memory. In the above cases, we can save memory > about 108g(best case). And the larger the difference between > the size of VIRT and RES, the more memory we save. > > In this patch series, we add a pte_refcount field to the > struct page of page table to track how many users of PTE page > table. Similar to the mechanism of page refcount, the user of > PTE page table should hold a refcount to it before accessing. > The PTE page table page will be freed when the last refcount > is dropped. The patch is very hard to review. Could you split up introduction of the new API in the separate patch? With a proper documentation of the API. Why pte_refcount is atomic? Looks like you do everything under pmd_lock(). Do I miss something? And performance numbers should be included. I don't expect pmd_lock() in all hotpaths to scale well. -- Kirill A. Shutemov