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 00754C433F5 for ; Sat, 21 May 2022 08:59:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5C6046B0072; Sat, 21 May 2022 04:59:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 54EC06B0073; Sat, 21 May 2022 04:59:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3EF756B0074; Sat, 21 May 2022 04:59:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 296716B0072 for ; Sat, 21 May 2022 04:59:37 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id E8A506066C for ; Sat, 21 May 2022 08:59:36 +0000 (UTC) X-FDA: 79489151952.16.E869D69 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by imf02.hostedemail.com (Postfix) with ESMTP id 49F52800E9 for ; Sat, 21 May 2022 08:59:34 +0000 (UTC) Received: by mail-pf1-f181.google.com with SMTP id i24so9553399pfa.7 for ; Sat, 21 May 2022 01:59:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=E0WYc4yl2hOxvVjD014+BuN0fQK0E8cu7fTbPkWjvWI=; b=weN7et924AvUjIP1i8JWA1zL+56fviklm7Aa1heNvbw4MBgbI3uJR454IV1k+DE0ZI Q/7l4h6d59R4X4ZsN3XKqcm7VOv7I11IZyk5g3fl5nUdOsaHrplUI/CmedG2geSnSimU +zcFW0DiFzZ2fac5NArpyiNIlySMEjlY6L8nDH5/B43oQ3LjM3ko9SplFEOfFeoY+V1T RxZiaWNp/rLfb4VZI35L30w+ix46kx4JVu3Jv47IJckKKwWuo67Ec2kobQeqdrLamBVz avWyXwuN+XbVjJzbaWnhfXJjv7UAuqzUr7udXxXQx7YOayobPpwEQD6nUyaN6bCx/P6X s1Bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=E0WYc4yl2hOxvVjD014+BuN0fQK0E8cu7fTbPkWjvWI=; b=y2EDyts3MjW/n6rbfHqivaVub4EQY/3WGue2jptzcMkiOB07Zi2cPp4NCZndAnQtja CsJoYs0cQRuM7EYvFyd5iFDjxAC7r07elWsy6oZKW8my670kXSVD948oPyx2koWm9YnI Rwo/S6+jvxc7sWe+KgARb4CefWObhMg2ix4StuLOBugW42/L6p0PRm1voVuw/mMILhyT BSmAAUYaX+7TvJMLms5X47tClntLmF/C1QORf6r4QxMlU+BYM4rGxDJWvt2WdO0cEwgp qOkVbGV3i2xxgpcm69XxUQE1LHtWMJAhgq60XNvKyQHlRlbY7vSPENLLy3zYCyTNY/J9 LQ6A== X-Gm-Message-State: AOAM530aJAbVtQIQBtGTbQzuZRd8YyVlyayg0FWwmL6X5JWHhuE1WPgn lW2l8iILuYrJEbcFSD9VSWM/iQ== X-Google-Smtp-Source: ABdhPJzOGq7Qvr7EqDbQ61V2idkOnETVQHJJUKZD2Z9unbLOUcA9SSSGfFJvRBY4sSfDpc6Yom6wTg== X-Received: by 2002:a65:550c:0:b0:3da:fde8:62d7 with SMTP id f12-20020a65550c000000b003dafde862d7mr11904351pgr.334.1653123574410; Sat, 21 May 2022 01:59:34 -0700 (PDT) Received: from [10.5.104.119] ([139.177.225.249]) by smtp.gmail.com with ESMTPSA id p12-20020a170902eacc00b0015e8d4eb288sm1063271pld.210.2022.05.21.01.59.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 21 May 2022 01:59:33 -0700 (PDT) Message-ID: Date: Sat, 21 May 2022 16:59:19 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [External] [RFC PATCH 0/6] Introduce Copy-On-Write to Page Table Content-Language: en-US To: Chih-En Lin , David Hildenbrand Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Christian Brauner , "Matthew Wilcox (Oracle)" , Vlastimil Babka , William Kucharski , John Hubbard , Yunsheng Lin , Arnd Bergmann , Suren Baghdasaryan , Colin Cross , Feng Tang , "Eric W. Biederman" , Mike Rapoport , Geert Uytterhoeven , Anshuman Khandual , "Aneesh Kumar K.V" , Daniel Axtens , Jonathan Marek , Christophe Leroy , Pasha Tatashin , Peter Xu , Andrea Arcangeli , Thomas Gleixner , Andy Lutomirski , Sebastian Andrzej Siewior , Fenghua Yu , linux-kernel@vger.kernel.org, Kaiyang Zhao , Huichun Feng , Jim Huang , Andrew Morton , linux-mm@kvack.org References: <20220519183127.3909598-1-shiyn.lin@gmail.com> From: Qi Zheng In-Reply-To: <20220519183127.3909598-1-shiyn.lin@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=weN7et92; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf02.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.210.181 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 49F52800E9 X-Stat-Signature: qauzpeuicysp5cj43pgm91m1k74yf78r X-HE-Tag: 1653123574-692806 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 2022/5/20 2:31 AM, Chih-En Lin wrote: > When creating the user process, it usually uses the Copy-On-Write (COW) > mechanism to save the memory usage and the cost of time for copying. > COW defers the work of copying private memory and shares it across the > processes as read-only. If either process wants to write in these > memories, it will page fault and copy the shared memory, so the process > will now get its private memory right here, which is called break COW. > > Presently this kind of technology is only used as the mapping memory. > It still needs to copy the entire page table from the parent. > It might cost a lot of time and memory to copy each page table when the > parent already has a lot of page tables allocated. For example, here is > the state table for mapping the 1 GB memory of forking. > > mmap before fork mmap after fork > MemTotal: 32746776 kB 32746776 kB > MemFree: 31468152 kB 31463244 kB > AnonPages: 1073836 kB 1073628 kB > Mapped: 39520 kB 39992 kB > PageTables: 3356 kB 5432 kB > > This patch introduces Copy-On-Write to the page table. This patch only > implements the COW on the PTE level. It's based on the paper > On-Demand Fork [1]. Summary of the implementation for the paper: > > - Only implements the COW to the anonymous mapping > - Only do COW to the PTE table which the range is all covered by a > single VMA. > - Use the reference count to control the COW PTE table lifetime. > Decrease the counter when breaking COW or dereference the COW PTE > table. When the counter reduces to zero, free the PTE table. > Hi, To reduce the empty user PTE tables, I also introduced a reference count (pte_ref) for user PTE tables in my patch[1][2], It is used to track the usage of each user PTE tables. The following people will hold a pte_ref: - The !pte_none() entry, such as regular page table entry that map physical pages, or swap entry, or migrate entry, etc. - Visitor to the PTE page table entries, such as page table walker. With COW PTE, a new holder (the process using the COW PTE) is added. It's funny, it leads me to see more meaning of pte_ref. Thanks, Qi [1] [RFC PATCH 00/18] Try to free user PTE page table pages link: https://lore.kernel.org/lkml/20220429133552.33768-1-zhengqi.arch@bytedance.com/ (percpu_ref version) [2] [PATCH v3 00/15] Free user PTE page table pages link: https://lore.kernel.org/lkml/20211110105428.32458-1-zhengqi.arch@bytedance.com/ (atomic count version) -- Thanks, Qi