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 83A81C433E0 for ; Fri, 19 Mar 2021 12:45:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1F08964EA4 for ; Fri, 19 Mar 2021 12:45:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1F08964EA4 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 B066E8D0002; Fri, 19 Mar 2021 08:45:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ADC696B007B; Fri, 19 Mar 2021 08:45:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9A51E8D0002; Fri, 19 Mar 2021 08:45:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0207.hostedemail.com [216.40.44.207]) by kanga.kvack.org (Postfix) with ESMTP id 7E8396B0078 for ; Fri, 19 Mar 2021 08:45:08 -0400 (EDT) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 3E0AC1814C3D3 for ; Fri, 19 Mar 2021 12:45:08 +0000 (UTC) X-FDA: 77936593854.05.CFA5FA7 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf02.hostedemail.com (Postfix) with ESMTP id C16664080F47 for ; Fri, 19 Mar 2021 12:45:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616157907; 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=Zr7IRvUaS9eF/6BS2aV2AyBfhwA0b7y65cHcnuCCTEs=; b=BGwLpmWdkC/nw+NqD/ZLn99gLCl/+UKIy4YPacf9fLm1LO5e+RnTUa8XcfdAU+l1K3KAwo 66H3RHpa2rxvdbOrS3WeDkB8lBHCUOB9zz6IT70+abpenKR5469JHtkDNHiLcenSkDRDL/ 7GFy21OP746FAkfmIJbAasFXwHuwLB8= 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-196-qQDjmDdxNFumY3jsV2zzeA-1; Fri, 19 Mar 2021 08:45:03 -0400 X-MC-Unique: qQDjmDdxNFumY3jsV2zzeA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 75325A0CA0; Fri, 19 Mar 2021 12:45:02 +0000 (UTC) Received: from [10.36.112.11] (ovpn-112-11.ams2.redhat.com [10.36.112.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id 87CCB19C79; Fri, 19 Mar 2021 12:44:56 +0000 (UTC) Subject: Re: Page zapping and page table reclaim To: Balbir Singh , Vlastimil Babka Cc: Linux Memory Management List , Minchan Kim , Matthew Wilcox , Rik van Riel , Michal Hocko , Andrea Arcangeli , Peter Xu References: <20210318235347.GA3346@balbir-desktop> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <6f6a0e7b-4b61-cab4-cf8b-7437d7149b21@redhat.com> Date: Fri, 19 Mar 2021 13:44:55 +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: <20210318235347.GA3346@balbir-desktop> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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: uco5gb777th9s81ha6g1qncrik5uqqti X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: C16664080F47 Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf02; 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: 1616157907-570073 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 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. :) I'm planning on looking into this, but not sure when I'll have time to prototype something up. > Balbir > > -- Thanks, David / dhildenb