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=-7.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 CB4D0C433C1 for ; Mon, 22 Mar 2021 09:19:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6248861931 for ; Mon, 22 Mar 2021 09:19:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6248861931 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1CA9A6B0089; Mon, 22 Mar 2021 05:00:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A1F96B008A; Mon, 22 Mar 2021 05:00:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 041E96B008C; Mon, 22 Mar 2021 05:00:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0066.hostedemail.com [216.40.44.66]) by kanga.kvack.org (Postfix) with ESMTP id DDCCD6B0089 for ; Mon, 22 Mar 2021 05:00:34 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 476595DEB for ; Mon, 22 Mar 2021 09:19:25 +0000 (UTC) X-FDA: 77946961806.26.264C2DA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf05.hostedemail.com (Postfix) with ESMTP id 9D719E0011DD for ; Mon, 22 Mar 2021 09:19:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616404764; 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; bh=BQ2PEiwAq/09jiDmSJr+GA/k9YxJlvMuJkls4tPirHs=; b=K+gar9OiXpeWnhRDRBRNqKWQCZ0OYOT3OXHpgHSbFFcgGdyY5/uN5ot7mM7va/Fjnyo6Dt PbOWY3iLpFE3SwbP8CT/4fEKGU2lqr1gEOtwa+zupc1mIt0b0fbqYVnHXG3gY/gsxn1U3p 7HKiQGOXulNVwCr/OG/GaOMqFcBt+s4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-104-blj1KNpfPNSzYOLwQZRqPg-1; Mon, 22 Mar 2021 05:19:22 -0400 X-MC-Unique: blj1KNpfPNSzYOLwQZRqPg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 056EB108BD0F; Mon, 22 Mar 2021 09:19:21 +0000 (UTC) Received: from [10.36.115.54] (ovpn-115-54.ams2.redhat.com [10.36.115.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id 252856E6FF; Mon, 22 Mar 2021 09:19:08 +0000 (UTC) Subject: Re: Page zapping and page table reclaim To: Balbir Singh Cc: Vlastimil Babka , Linux Memory Management List , Minchan Kim , Matthew Wilcox , Rik van Riel , Michal Hocko , Andrea Arcangeli , Peter Xu References: <20210318235347.GA3346@balbir-desktop> <6f6a0e7b-4b61-cab4-cf8b-7437d7149b21@redhat.com> <20210320015626.GC77072@balbir-desktop> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <385a98ef-fdfb-ed38-b82e-7abf50610cf7@redhat.com> Date: Mon, 22 Mar 2021 10:19:07 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <20210320015626.GC77072@balbir-desktop> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Stat-Signature: zchr3up3ikeq6np6kbdq9rubnddohe94 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 9D719E0011DD Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf05; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=170.10.133.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616404764-393806 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 20.03.21 02:56, Balbir Singh wrote: > On Fri, Mar 19, 2021 at 01:44:55PM +0100, David Hildenbrand wrote: >> On 19.03.21 00:53, Balbir Singh wrote: >>> On Thu, Mar 18, 2021 at 05:57:06PM +0100, Vlastimil Babka wrote: >>>> On 3/11/21 7:14 PM, David Hildenbrand wrote: >>>>> Hi folks, >>>>> >>>>> I was wondering, is there any mechanism that reclaims basically empty page >>>>> tables in a running process? >>>>> >>>>> Like: When I MADV_DONTNEED a huge range, there could be plenty of basically >>>>> empty (e.g., all entries invalid) page tables we could reclaim. As soon as we >>>>> zap a complete PMD we could reclaim (depending on the architecture) a whole page. >>>>> >>>>> Zapping on the PMD level might make most impact I guess. >>>>> >>>>> For 1 GB, we need 262144 4k pages. If we assume each PTE is 8 bytes, we need a >>>>> total of 8 MB for the lowest level page tables (PTE). >>>>> >>>>> OTOH, we would need 512 PMD entries - a single 4k page. Zapping 1 TB would mean >>>>> we can free up another 4MB - rather a corner case and we can live with that. >>>>> >>>>> >>>>> Of course, the same might apply to other cases where we can restore all page >>>>> table content from the VMA again. One example would be after MADV_FREE zapped a >>>>> whole range of entries we marked. >>>> >>>> I don't think we have such mechanism, but IIRC I've heard the idea mentioned >>>> before, probably from Michal Hocko. Definitely an interesting research project >>>> idea to evaluate the cost vs benefits of that. >>>> >>> >>> It might lead to interesting interactions with lockless page table walking >>> with implications on the mmap_lock as well. >>> >> >> I think if lockless page table walks have to be able with THP code swapping >> populated page tables by a PMD back and forth, swapping an unpopulated page >> table by an invalid PMD entry might be quite similar. At least it feels like >> both approaches would rely on similar mechanisms / locking. :) >> > > Yes, but then I suspect you always need destruct page tables by RCU. I envision page table reclaim to happen asynchronously, so that shouldn't be an issue. We can just collect a bunch of reclaimed page tables and then issue an rcu synchronize before handing them back to the buddy. -- Thanks, David / dhildenb