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.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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 379A0C433DB for ; Wed, 17 Mar 2021 13:47:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A4BFF64F6C for ; Wed, 17 Mar 2021 13:47:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A4BFF64F6C 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 C44D76B006E; Wed, 17 Mar 2021 09:47:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BF5E26B0070; Wed, 17 Mar 2021 09:47:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A969B6B0071; Wed, 17 Mar 2021 09:47:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0173.hostedemail.com [216.40.44.173]) by kanga.kvack.org (Postfix) with ESMTP id 8EEAF6B006E for ; Wed, 17 Mar 2021 09:47:27 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 36E37180AD80F for ; Wed, 17 Mar 2021 13:47:27 +0000 (UTC) X-FDA: 77929493334.07.C4D05C1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 0266EC1813A6 for ; Wed, 17 Mar 2021 13:43:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615988585; 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=gMiOTTSKPoh5lSu9vYODrkMH1pSVWBkY0RKftSaZiPM=; b=d11XudQWlBCITZJbfCbihXdXRqeNKF5yLoH4KjsezXMGPFfGWYPdTkSs94b1EaLuar4Ckx BAj+4hzXJ2BBgsYP80a7j8lGLh0S6+IMC9v3/nlAOFmghlKEAItdt6kcXop4j1zDmwlY0J OymR+008Z+oQsrADtxZvokkdFYcJoi0= 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-148-Uy0zgPYtPKOkq9KeMj2Jlw-1; Wed, 17 Mar 2021 09:43:02 -0400 X-MC-Unique: Uy0zgPYtPKOkq9KeMj2Jlw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B7B5A81746B; Wed, 17 Mar 2021 13:43:00 +0000 (UTC) Received: from [10.36.112.124] (ovpn-112-124.ams2.redhat.com [10.36.112.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E8926B8DF; Wed, 17 Mar 2021 13:42:59 +0000 (UTC) To: Matthew Wilcox , Peter Weber Cc: linux-mm@kvack.org References: <20210312151540.GC2577561@casper.infradead.org> <20210312224537.GF2577561@casper.infradead.org> From: David Hildenbrand Organization: Red Hat GmbH Subject: Re: Is anonymous memory part of the page cache on Linux? Message-ID: Date: Wed, 17 Mar 2021 14:42:58 +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: <20210312224537.GF2577561@casper.infradead.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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 X-Stat-Signature: hqp63unfcejgxxttgqpx5jp6bx5xgjne X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 0266EC1813A6 Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf06; 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: 1615988585-550448 Content-Transfer-Encoding: quoted-printable 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 12.03.21 23:45, Matthew Wilcox wrote: > On Fri, Mar 12, 2021 at 04:41:55PM +0100, Peter Weber wrote: >> Thank you Matthew! >> >> >> Am 2021-03-12 16:15, schrieb Matthew Wilcox: >>> The wikipedia diagram is wrong. Anonymous memory is not handled by t= he >>> page cache. >> >> Is it roughly right to say, that the virtual memory uses page tables t= o >> handle anonymous memory? >=20 You'll have to distinguish between private and shared anonymous memory. "private anonymous memory" -- mmap(MAP_ANONYMOUS | MAP_PRIVATE) -- is=20 usually completely managed using the process page tables. The only way=20 to get such pages mapped into another process is via fork(), whereby=20 page table are copied and COW (Copy On Write) applies. Once dereferenced from all page tables, there are no other references=20 anymore; memory is handed back to the buddy as free memory, from where=20 it can be reused for other purposes. Of course, there are case where=20 there might be other references being taken (i.e., GUP, direct I/O ...),=20 but let's ignore that for now. The essence for "private anonymous memory" is, that there is no other=20 way to get access to that memory besides the page tables. If you=20 MADV_DONTNEED virtual memory regions to zap the page table entries and=20 later reaccess the same virtual memory locations, always fresh memory=20 will be populated. "shared anonymous memory" -- mmap(MAP_ANONYMOUS | MAP_SHARED) -- is a=20 little different and involves the page cache (it's pretty much shmem=20 without a user-visible fd). The only way to get such pages mapped into=20 another process is similarly via fork() (AFAIU), whereby page table are=20 copied and COW does _not_ apply. Once dereferenced from all page tables, there is still a reference to=20 the page from the page cache. Only once evicted from the page cache, the=20 memory can be freed up. The essence for "shared anonymous memory" is, that there are ways to get=20 access to that memory besides the page tables. If you MADV_DONTNEED such=20 virtual memory locations to zap the page table entries and later=20 reaccess the same virtual memory location again, the previous page will=20 be re-instantiated from the page cache. To evict the pages from the page=20 cache you would need MADV_REMOVE. --=20 Thanks, David / dhildenb