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=-5.3 required=3.0 tests=BAYES_00, 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 90DD7C433E0 for ; Thu, 18 Mar 2021 16:57:21 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D3BC564E07 for ; Thu, 18 Mar 2021 16:57:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D3BC564E07 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3E35F6B0072; Thu, 18 Mar 2021 12:57:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 36C986B0073; Thu, 18 Mar 2021 12:57:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E6806B0074; Thu, 18 Mar 2021 12:57:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0186.hostedemail.com [216.40.44.186]) by kanga.kvack.org (Postfix) with ESMTP id F2D576B0072 for ; Thu, 18 Mar 2021 12:57:19 -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 9908A582C for ; Thu, 18 Mar 2021 16:57:19 +0000 (UTC) X-FDA: 77933600598.26.EA6C596 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf14.hostedemail.com (Postfix) with ESMTP id 5A935C0042C1 for ; Thu, 18 Mar 2021 16:57:08 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 7C7D5AC24; Thu, 18 Mar 2021 16:57:06 +0000 (UTC) Subject: Re: Page zapping and page table reclaim To: David Hildenbrand , Linux Memory Management List Cc: Minchan Kim , Matthew Wilcox , Rik van Riel , Michal Hocko , Andrea Arcangeli , Peter Xu References: From: Vlastimil Babka Message-ID: Date: Thu, 18 Mar 2021 17:57:06 +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: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Stat-Signature: nxnc9axju9brqp4ykesq91azw6eimi3y X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 5A935C0042C1 Received-SPF: none (suse.cz>: No applicable sender policy available) receiver=imf14; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: none/none X-HE-Tag: 1616086628-273641 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 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. > Looks like if we happen to zap a THP, we should already get what we want (no > page table, nothing to remove) > > I haven't immediately stumbled over anything, but could be I am missing the > obvious. I guess what would need some thought is concurrent discards/pagefaults > - but it feels like being similar to collapsing/splitting a THP while there is > other system activity. > > Maybe there is already something and I am just not aware of it. > > Thanks! >