Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3210577pxv; Sun, 18 Jul 2021 15:01:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtx7vc7GSXZJkeu9RR5UniB3AQfK1hdmoBKbr2wCnleTVzoSHPcungogMZE09R2dhjKpTX X-Received: by 2002:a02:a595:: with SMTP id b21mr18557375jam.122.1626645719681; Sun, 18 Jul 2021 15:01:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626645719; cv=none; d=google.com; s=arc-20160816; b=NVDMHkn6UAtCaS2lviuK2t9GmXVd+CPmdKtgS4I3IpAcCPP0YcudmXjIq3H4PodQYV o98nvsG7JwkBf0n3boNvVH/16c1Zd0dfkQBJD6DfCQ5A2UDuOZbyuOKpzykijE9w16q6 xJom/E7VVv9CMZvQMCSz2dK1qu2+Qg7957mWCk4zOfNa/psC+/vRt4XFWcGOHEOcp+MB IpUg44UHQ6q5r6NyHySHhloF990DSILcA4B0edGNmPjzLCTHGIKHh/NYU4p21StpD8UV k9YRxcmWEjxuwXhnUT6e0wbGGMCze/GOdtey27mGPiT0idYen69F6catBewVcgkHka4i UFnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=pTmQxf6zy7tgDXAHQZQ/3w3DBTHv9qcRwctrA/DmgL8=; b=vrJ0XnWJiNuEzD1WCn0fl1jmzw+Tg5gtq+lxBIpd+BBE3Cz2Zg8eGougbzyMyMmbvy O0uu3025X1IpLbxvuMfRo+8mCI/F0gDvELki0+m+zpQK1YKwKHBOY1GDWJEpfqDBZvb+ M2AuqkgsG2Dr+tAB835dfKsKCUr4Y7wbPtelY57uuuM2khC9XvK0N+QmdRwIQl4kHxKT TOnhYV9Kbt6fkVZdDI3u3eeHMyAnGmwqL4iZN14/HebF8SPTaPApyud+m6d8GuVmL7ho xkSURfmnF6AbSya/4V3o9uZ2gEQIUmOdal3eJm8ndHdJ2e0y4ZDHg6xPf+kFFsdj7m1e +dXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=ImGexmtB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x6si18540138iol.30.2021.07.18.15.01.48; Sun, 18 Jul 2021 15:01:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@shutemov-name.20150623.gappssmtp.com header.s=20150623 header.b=ImGexmtB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232724AbhGRWEJ (ORCPT + 99 others); Sun, 18 Jul 2021 18:04:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231846AbhGRWEI (ORCPT ); Sun, 18 Jul 2021 18:04:08 -0400 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D87C3C061764 for ; Sun, 18 Jul 2021 15:01:08 -0700 (PDT) Received: by mail-lj1-x236.google.com with SMTP id e14so4637818ljo.7 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=IOVuPBqQH37FMDY3pYfAFu1tRj5AGBvhPa1/1B3pC11BuUbAgREQExQ+3vmK2/M1hQ trrjSoBwVA2/MI9zPEMmQHWSifBSjxzhA0kqxC5VjxfTY+O2/XpSSeAf3H1ph1JPptxS /LbSa03vjyRPsoWemxC+d4kU7UigK8igsg5m0H4XeqTyD4JOUAfp9fKtK/K1ON8JQNRX e+5mpT7CNZONrL/Ly/W4aC+hvza0juSE0pcnsBjUEhYGN6FAv2lZ237IGt11MZqJDWj0 SIe/Zg4ikQSOl880zuqS1oGky9A29NsLcLcE1Bwq0CsQQCCF55xkGjgLnxwhoEklc41A dR3A== X-Gm-Message-State: AOAM532XXH2OHcWqv9x0Q5ftO0v2OmI1GbZw8L+lqGQX1TfaBo4XJ83F sGEt86OeVC8lX4GC4HAHxrfXFg== 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> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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