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 134BCC07E9B for ; Mon, 19 Jul 2021 13:31:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 83B1B60D07 for ; Mon, 19 Jul 2021 13:31:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 83B1B60D07 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 19D668D00F4; Mon, 19 Jul 2021 09:31:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 176EC8D00EC; Mon, 19 Jul 2021 09:31:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 03C978D00F4; Mon, 19 Jul 2021 09:31:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0194.hostedemail.com [216.40.44.194]) by kanga.kvack.org (Postfix) with ESMTP id CE0738D00EC for ; Mon, 19 Jul 2021 09:31:56 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 6613D824999B for ; Mon, 19 Jul 2021 13:31:55 +0000 (UTC) X-FDA: 78379425390.18.C673BB6 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by imf14.hostedemail.com (Postfix) with ESMTP id 3EBEA60022DC for ; Mon, 19 Jul 2021 13:31:53 +0000 (UTC) Received: by mail-pg1-f174.google.com with SMTP id o4so14376498pgs.6 for ; Mon, 19 Jul 2021 06:31:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=5yZp7VZOqzRJ1FjiCJg4LSQFQRx2br2QAn//QhHRktM=; b=QO+khtR5mz8ki+MH8XFCQ5Bd9jS6cfXxx2oyG/XH78anP6Bc+tyWkR34msU4pnfrMO 1BlSve+AaXuFLHeI1hzxEm5QLrbEtxdQc2We9tIgRKci8w+F21zza1C+bwT19F5LbZ2F iVg7NrYSm0EzFztAjlmemILd46y8vKGRBULU1AYWlgj0bZbG3YSsmaSGddh54vozH3ou zQ64snFRvZIMuMT38NCrIMHMecSots7seaAQAhhMYdyh7cyz1ce9F6Uy13l/ZnZQLZcr cO4PI8ycAhPP39G+G3EZ07q2/VF5hSx7RKSd5ernEiDjvRIkCWaHqQfFuNbqavasp8Y5 ZOAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=5yZp7VZOqzRJ1FjiCJg4LSQFQRx2br2QAn//QhHRktM=; b=uEkzd9iabI+YVjPO0uo03k5tEm/Xvlgwbeg36lIsxx9/X2N+WfnpROoGZIWSz4w3te BHN5yxuYp7Jz/zsBiNxYDShEWbc6bYGzb5shY6uKy7izH8ZZqDFnIEckr/0a3t0keXFq VNBVcxMYr3IOIG/pOA8f92zprOspq68Kwh7vUB4LGdd8lGj5mKksIrLDXvnClK2jt0gc WPCMlC7axjdxp0lKKb6JbMCX8XjnqPMorMggmmZ9szjSR8IRwJD4fRWf9rUnd1O4ce2H a6P2S94t4nIXHYoXvN2oELb/5v1KMBr+kOZVqQ2MLkFmRCHT1npl1FaUjiJCdE5Mkpoq M5pw== X-Gm-Message-State: AOAM533pwFCk+L7ZuhvfhB0andheYUqKgYsaVhBQFtGdK+ZEID3thuyv FJtefkinqDRu3DNkN5e5sF2slYa7NWQPceqYza5RBg== X-Google-Smtp-Source: ABdhPJxiTW2bFUTE4xsT0zE+moeFlOhucFmKqk25I2Tp7KdXyO4CLoSMFJdS9BFEvKONqZwnyaFeMA5aQB+EzuiOfFY= X-Received: by 2002:a63:4607:: with SMTP id t7mr25333633pga.31.1626701511860; Mon, 19 Jul 2021 06:31:51 -0700 (PDT) MIME-Version: 1.0 References: <20210718043034.76431-1-zhengqi.arch@bytedance.com> <5ce5fb25-df1d-b807-8807-595b8a7bfc63@redhat.com> <089e710c-fb06-e731-6d50-7858d6b9ecdf@redhat.com> In-Reply-To: From: Muchun Song Date: Mon, 19 Jul 2021 21:30:59 +0800 Message-ID: Subject: Re: [PATCH 0/7] Free user PTE page table pages To: David Hildenbrand Cc: Qi Zheng , Andrew Morton , Thomas Gleixner , Johannes Weiner , Michal Hocko , Vladimir Davydov , linux-doc@vger.kernel.org, LKML , Linux Memory Management List Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=QO+khtR5; spf=pass (imf14.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.215.174 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-Rspamd-Server: rspam02 X-Stat-Signature: b6u3tccdnu7b1qz7kmsupjehgfht887n X-Rspamd-Queue-Id: 3EBEA60022DC X-HE-Tag: 1626701513-545173 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 Mon, Jul 19, 2021 at 8:42 PM Muchun Song wrote: > > On Mon, Jul 19, 2021 at 7:28 PM David Hildenbrand wrote: > > > > On 19.07.21 09:34, David Hildenbrand wrote: > > > On 18.07.21 06:30, Qi Zheng wrote: > > >> Hi, > > >> > > >> This patch series aims to free user PTE page table pages when all PTE entries > > >> are empty. > > >> > > >> The beginning of this story is that 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. > > > > > > ... did you see that I am actually looking into this? > > > > > > https://lkml.kernel.org/r/bae8b967-c206-819d-774c-f57b94c4b362@redhat.com > > > > > > and have already spent a significant time on it as part of my research, > > > which is *really* unfortunate and makes me quite frustrated at the > > > beginning of the week alreadty ... > > > > > > Ripping out page tables is quite difficult, as we have to stop all page > > > table walkers from touching it, including the fast_gup, rmap and page > > > faults. This usually involves taking the mmap lock in write. My approach > > > does page table reclaim asynchronously from another thread and do not > > > rely on reference counts. > > > > Hi David, > > > FWIW, I had a quick peek and I like the simplistic approach using > > reference counting, although it seems to come with a price. By hooking > > using pte_alloc_get_map_lock() instead of pte_alloc_map_lock, we can > > handle quite some cases easily. > > Totally agree. > > > > > There are cases where we might immediately see a reuse after discarding > > memory (especially, with virtio-balloon free page reporting), in which > > case it's suboptimal to immediately discard instead of waiting a bit if > > there is a reuse. However, the performance impact seems to be > > comparatively small. > > > > I do wonder if the 1% overhead you're seeing is actually because of > > allcoating/freeing or because of the reference count handling on some > > hot paths. > > Qi Zheng has compared the results collected by using the "perf top" > command. The LRU lock is more contended with this patchset applied. > I think the reason is that this patchset will free more pages (including > PTE page table pages). We don't see the overhead caused by reference > count handling. Sorry for the confusion. I am wrong. The PTE page table page does not add to LRU list, so it should not be the LRU lock. We actually see that _raw_spin_unlock_irqrestore is hotter than before. I guess it is zone lock. > > Thanks, > > Muchun > > > > > I'm primarily looking into asynchronous reclaim, because it somewhat > > makes sense to only reclaim (+ pay a cost) when there is really need to > > reclaim memory -- similar to our shrinker infrastructure. > > > > -- > > Thanks, > > > > David / dhildenb > >