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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46CABC05027 for ; Tue, 14 Feb 2023 19:17:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B2736B0080; Tue, 14 Feb 2023 14:17:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9629E6B0081; Tue, 14 Feb 2023 14:17:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B5686B0082; Tue, 14 Feb 2023 14:17:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 69C666B0080 for ; Tue, 14 Feb 2023 14:17:44 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E2B35160956 for ; Tue, 14 Feb 2023 19:17:43 +0000 (UTC) X-FDA: 80466856806.04.4146161 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by imf21.hostedemail.com (Postfix) with ESMTP id 1A25D1C0022 for ; Tue, 14 Feb 2023 19:17:41 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=RD75b2Tb; spf=pass (imf21.hostedemail.com: domain of shiyn.lin@gmail.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=shiyn.lin@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676402262; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=G6VI4UtKMXGf1NILxkcNf7EW/7unsO+N5Ql2yHcyswI=; b=AVidkuFsinP/eTB8rI6UovHPj3vvtrHO2TZBzNHYiqE5b9XyHN0GhSX8nQ9xO8zbJrZk8t qByoyi8VnliGDoQmE2m2MHyZ8em+DPv7oHfmxmoIQcAaHTiV/Rj4S8bskM9IGIarMB74Ie GMdHWluK2qJwpaZWpx9lAgUzsUBBH80= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=RD75b2Tb; spf=pass (imf21.hostedemail.com: domain of shiyn.lin@gmail.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=shiyn.lin@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676402262; a=rsa-sha256; cv=none; b=i4WBIj9VQ7SSgtHmfqIoLa/lLrSu5GrCP/oJ/N35T9VOSOF5o+LoOQKNwyWpCGIDLiLdNg t5gnWq+xx0hZ+SGSbOA5enCD2/g7fibITpsFwvvq/eeNT/A5tEmXIIpAtdOsVWF976CEc4 9NqEjH6OhtK/utvlbujXhy6+ZElGMqw= Received: by mail-pj1-f44.google.com with SMTP id oa11-20020a17090b1bcb00b002341a2656e5so4867000pjb.1 for ; Tue, 14 Feb 2023 11:17:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=G6VI4UtKMXGf1NILxkcNf7EW/7unsO+N5Ql2yHcyswI=; b=RD75b2TbvISNpQa3I0LdGHwJUdi6tx3O6Uqz1DY/dlHboU15NvSDsBv8Lq1f72CV8P F7ApiY7xk9aklr/3IwN3wHEQhzw2Xh0CpapfVgCAsdxo+h1tm2hPwuL6XlR3TH29OcHc AunP9G4sloIKw138O9BYP8/EVaVl5nKcS1wWYJJ9BRt4hcxSrBZ03FLk2yrrCeS78g0e pdPTY5RwZ55QsWpUh03LCfzaFie5td3diC3UQ6NxPJ/eXLDrh7egh3y23ZIfxvk8T2PG Yx8ziVNHlt1m7wSbU/WG2Lc4124UhOS1BjYtxLKL0Tj+qwcevi7ivzeLGFeZWdWUHkUL 0LOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=G6VI4UtKMXGf1NILxkcNf7EW/7unsO+N5Ql2yHcyswI=; b=1uEtvsB6ixoQjMz7DYhBrV+zH9P/PSPcraiXqWYMy2gVyHJ8YVcAl2CO1JD2zD88wh ZtJxH5ufJZJv6Y2hBhxjeHVxQwkyardn+YDSHuk4PHl30mBVG6mBOSWXKXCFAMn9lpiz jX/HClQnj3Ffbi7bhCqrvEyys0rngWtCe58nAC1Y/QKWytIuzFZM6r1Mee2aRNCjOakv HjQx1K3VHX82MlfpRI85upCpeQ4GUrT/0nbgEwwlWkKImVMhD+UCYI8u6Iwcwig2jbjh 8z6kUMj+t0ZMV+DG8qEc/ME9CyfJA1+S51WzmsUpxfSVVi2H2Q/IE5ryhbK4y6sHVC5Q Mg0Q== X-Gm-Message-State: AO0yUKU0QszCtxkPoISUQ8LvnTFUStXqrPzD8ovYGsirqJuQ0TV61r7A QIxttDWAjxjh3Pge4jbU650= X-Google-Smtp-Source: AK7set+cZzS5QlAok+A3hUaDau+IPIxcFuWKmquBgdY6gCbMbiInMO7ULCrCSY5QJmWyZW0RRRY2IA== X-Received: by 2002:a05:6a20:914a:b0:bc:d601:ebfc with SMTP id x10-20020a056a20914a00b000bcd601ebfcmr4361736pzc.54.1676402260776; Tue, 14 Feb 2023 11:17:40 -0800 (PST) Received: from strix-laptop (2001-b011-20e0-1465-11be-7287-d61f-f938.dynamic-ip6.hinet.net. [2001:b011:20e0:1465:11be:7287:d61f:f938]) by smtp.gmail.com with ESMTPSA id h18-20020a656392000000b004fb4489969bsm9231927pgv.49.2023.02.14.11.17.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Feb 2023 11:17:40 -0800 (PST) Date: Wed, 15 Feb 2023 03:17:30 +0800 From: Chih-En Lin To: Pasha Tatashin Cc: David Hildenbrand , Andrew Morton , Qi Zheng , "Matthew Wilcox (Oracle)" , Christophe Leroy , John Hubbard , Nadav Amit , Barry Song , Steven Rostedt , Masami Hiramatsu , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Yang Shi , Peter Xu , Vlastimil Babka , Zach O'Keefe , Yun Zhou , Hugh Dickins , Suren Baghdasaryan , Yu Zhao , Juergen Gross , Tong Tiangen , Liu Shixin , Anshuman Khandual , Li kunyu , Minchan Kim , Miaohe Lin , Gautam Menghani , Catalin Marinas , Mark Brown , Will Deacon , Vincenzo Frascino , Thomas Gleixner , "Eric W. Biederman" , Andy Lutomirski , Sebastian Andrzej Siewior , "Liam R. Howlett" , Fenghua Yu , Andrei Vagin , Barret Rhoden , Michal Hocko , "Jason A. Donenfeld" , Alexey Gladkov , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Dinglan Peng , Pedro Fonseca , Jim Huang , Huichun Feng Subject: Re: [PATCH v4 00/14] Introduce Copy-On-Write to Page Table Message-ID: References: <20230207035139.272707-1-shiyn.lin@gmail.com> <62c44d12-933d-ee66-ef50-467cd8d30a58@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 1A25D1C0022 X-Stat-Signature: cduxrgjnbo1yfzxzmeiar44httohxm4c X-HE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PPczLzxOMrP6OdhKu+uJ9mZcNHUT7VRDrRBCTfetDke4OghuPno01E0ywjwk51CFVXfLqZb26ri8iiZRr5VjjnwsosoFL/nYWFL0+6vvuHGdBvRZyobt3tQIOEUGTNmhDYum34mUTPDelb62L6w+bSlUbVOGFGs+qLQDkVrnxofYjDE0fcSOMq2ud/+ry0BeaI7CG79iyc9NLpDpxTUQonwj9xzKlt/199oOmtEy3zYjnqqvlQU6XMajZQEs+9iP+MIEzS1vyX5Mhs6aVa/HxNoAcY9VZbn+KSkLdoDV3L17+fTt7yUPfY8gHZlOlp/cvA0+bPGsB9n+OI777muwF+G6+R1Y1aluD3MPvSesimtEvSRqoqvLVifbaV/Dk9nENAqq1sd/UI1n+vZ1Ko2Yl0L6WS9H2OerKc852rU2IQUFwKUptK8km25Xau3LSnVHHOLI2u2ykGrAzoSVUgt3SgkjZDXkN9ZNLsnNEH/+L1Kq1xY190mg= 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 Tue, Feb 14, 2023 at 01:52:16PM -0500, Pasha Tatashin wrote: > On Tue, Feb 14, 2023 at 1:42 PM Chih-En Lin wrote: > > > > On Tue, Feb 14, 2023 at 11:30:26AM -0500, Pasha Tatashin wrote: > > > > > The thing with THP is, that during fork(), we always allocate a backup PTE > > > > > table, to be able to PTE-map the THP whenever we have to. Otherwise we'd > > > > > have to eventually fail some operations we don't want to fail -- similar to > > > > > the case where break_cow_pte() could fail now due to -ENOMEM although we > > > > > really don't want to fail (e.g., change_pte_range() ). > > > > > > > > > > I always considered that wasteful, because in many scenarios, we'll never > > > > > ever split a THP and possibly waste memory. > > > > > > > > > > Optimizing that for THP (e.g., don't always allocate backup THP, have some > > > > > global allocation backup pool for splits + refill when close-to-empty) might > > > > > provide similar fork() improvements, both in speed and memory consumption > > > > > when it comes to anonymous memory. > > > > > > > > When collapsing huge pages, do/can they reuse those PTEs for backup? > > > > So, we don't have to allocate the PTE or maintain the pool. > > > > > > It might not work for all pages, as collapsing pages might have had > > > holes in the user page table, and there were no PTE tables. > > > > So if there have holes in the user page table, after we doing the > > collapsing and then splitting. Do those holes be filled? Assume it is, > > then, I think it's the reason why it's not work for all the pages. > > > > But, after those operations, Will the user get the additional and > > unexpected memory (which is from the huge page filling)? > > Yes, more memory is going to be allocated for a process in such THP > collapse case. This is similar to madvise huge pages, and touching the > first byte may allocate 2M. Thanks for the explanation. Yeah, It seems like the reuse case can't work for all the pages. Thanks, Chih-En Lin