From owner-freebsd-hackers@freebsd.org Thu Oct 3 08:33:22 2019 Return-Path: Delivered-To: freebsd-hackers@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 24E0912DE22 for ; Thu, 3 Oct 2019 08:33:22 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 46kR9F1NJ5z3K27 for ; Thu, 3 Oct 2019 08:33:20 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.15.2/8.15.2) with ESMTPS id x938XCv4094842 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 3 Oct 2019 11:33:15 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua x938XCv4094842 Received: (from kostik@localhost) by tom.home (8.15.2/8.15.2/Submit) id x938XBcJ094840; Thu, 3 Oct 2019 11:33:11 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 3 Oct 2019 11:33:11 +0300 From: Konstantin Belousov To: Yoshihiro Ota Cc: freebsd-hackers@freebsd.org Subject: Re: Can multiple vm_pages refer to a same swap device page? Message-ID: <20191003083311.GH44691@kib.kiev.ua> References: <20191002163141.1b88c3417e561c37624643b9@j.email.ne.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191002163141.1b88c3417e561c37624643b9@j.email.ne.jp> User-Agent: Mutt/1.12.2 (2019-09-21) X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on tom.home X-Rspamd-Queue-Id: 46kR9F1NJ5z3K27 X-Spamd-Bar: / Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=gmail.com (policy=none); spf=softfail (mx1.freebsd.org: 2001:470:d5e7:1::1 is neither permitted nor denied by domain of kostikbel@gmail.com) smtp.mailfrom=kostikbel@gmail.com X-Spamd-Result: default: False [-1.00 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-0.998,0]; DMARC_POLICY_SOFTFAIL(0.10)[gmail.com : No valid SPF, No valid DKIM,none]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; HAS_XAW(0.00)[]; R_SPF_SOFTFAIL(0.00)[~all]; IP_SCORE_FREEMAIL(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; IP_SCORE(0.00)[ip: (-2.67), ipnet: 2001:470::/32(-4.53), asn: 6939(-3.34), country: US(-0.05)]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US]; SUBJECT_ENDS_QUESTION(1.00)[]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2] X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Oct 2019 08:33:22 -0000 On Wed, Oct 02, 2019 at 04:31:41PM -0400, Yoshihiro Ota wrote: > Hi forks, > > Given a process can allocate lot of memory even cosuming swap space, then fork a child process, and both parent and child processes stay live while doing differen things, I expect a system needs to track how many processes are refering to same swap pages. > No, it does not. > How does FreeBSD keep track of multiple processes refering to same swap pages? > Is it by multiple vm_page objects pointing to same swap device pages with daddr_t? > > I've been looking around swap_pager.h, vm_page, vm_object, struct swblk, and struct swdevt but I don't find reference count for swap device pages. > > Am I missing something? Yes, the mechanism for CoW sharing the same read-only page is called shadowing and it is a form of the content inheritance, where we insert a new default (later swap) object on top of existing object on forking. The sentence above perhaps sounds too cryptic, I recommend you to look at the 'Design and Implementation' book by McKusick and this old article by Dillon https://www.freebsd.org/doc/en_US.ISO8859-1/articles/vm-design/index.html The part about vm objects is still relevant and should answer your question.