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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1E89C636D3 for ; Tue, 7 Feb 2023 03:56:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230352AbjBGD4Y (ORCPT ); Mon, 6 Feb 2023 22:56:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230305AbjBGDz7 (ORCPT ); Mon, 6 Feb 2023 22:55:59 -0500 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACEFC37541; Mon, 6 Feb 2023 19:55:28 -0800 (PST) Received: by mail-pj1-x102b.google.com with SMTP id rm7-20020a17090b3ec700b0022c05558d22so13497293pjb.5; Mon, 06 Feb 2023 19:55:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mqI9CX9OCLRhinZW0rV2yxCcmMTFndJVCdpXa5ZUnco=; b=o8ui0BwXjQb6Xz0+sV/XmAtBjIzgRNhLYPdfI9IHudkrwl5gTXpIpMOvolOaL9acRP XCdxnPWLWgJw0ORyp798XI/vdNQuP73eC52jwImCAT0YkmN/TUT0tUbkJMmm/mxAgpS0 XwxXjspo5I4w92K8TbwcdAFn+fv7U2jGlSP77xhKOI9/9crgO40/0FZOrKoybVWuIL8t fgIES6vwRi5iZ+RJVoHMkoDuT77EbnvzOn3Wgu+tVadR852ojkBEAyXwqTWHEvQ+/F9D oEoa54gTUp2x7VmLp0YL5AnlSdnytBXcKlTuEBzoyN6tEHrZwBETmGO0jD6Kw2tysYBO mLpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mqI9CX9OCLRhinZW0rV2yxCcmMTFndJVCdpXa5ZUnco=; b=FqKLPSr6YSBVPN7QFrgMu3ZfT2gOq9KxJ8qV2CvYR24T+OWQx8g+BSzt7L2JfIa1rX d+8reyEYiJ0P8zkhu+5n4+PxzCGB+Jb1aszv0NQKS/acON/ToWtk2FLFUcByXuIG9XOA jNq+DHHhz8A4UYOhJ1qgCzerIfqBrry5Q+yq0fA3Ybkd4DYAP4UV8rf42ozaK07Lyf8G kuqsMERA0oXmVohheDuu5qnq49ocLdd0UphQRxD9Whl1gRZ8DxbiUAYHi5IVJXYA+9Vp OAbCs+Iy+p7zRvqAb1zsDvHUrzaOzOxPE3G1gUxk84XPsZZtHQOJ9sthzBqPRSkOR7RZ h51w== X-Gm-Message-State: AO0yUKUbIAeiYS24QtrKikq7vQU6wk8V/lcNJRtnx0VA7BZqaGF1bfxA CPZ/0w3XsakVYh3N0R1Fv/A= X-Google-Smtp-Source: AK7set8xEIMQnqgw2pXG5HFkn5MnGyHjDBNyhDZPYQWQM7saiWZRxmBOABnr1379qxiruU1f4ByBsQ== X-Received: by 2002:a17:903:32c9:b0:196:1425:740c with SMTP id i9-20020a17090332c900b001961425740cmr1762111plr.62.1675742128059; Mon, 06 Feb 2023 19:55:28 -0800 (PST) Received: from strix-laptop.hitronhub.home ([123.110.9.95]) by smtp.googlemail.com with ESMTPSA id q4-20020a170902b10400b0019682e27995sm7647655plr.223.2023.02.06.19.55.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Feb 2023 19:55:27 -0800 (PST) From: Chih-En Lin To: Andrew Morton , Qi Zheng , David Hildenbrand , "Matthew Wilcox (Oracle)" , Christophe Leroy , John Hubbard , Nadav Amit , Barry Song Cc: 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 , Pasha Tatashin , 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 , Chih-En Lin Subject: [PATCH v4 14/14] mm: fork: Enable COW PTE to fork system call Date: Tue, 7 Feb 2023 11:51:39 +0800 Message-Id: <20230207035139.272707-15-shiyn.lin@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230207035139.272707-1-shiyn.lin@gmail.com> References: <20230207035139.272707-1-shiyn.lin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch enables the Copy-On-Write (COW) mechanism to the PTE table in fork system call. To let the process do COW PTE fork, use prctl(PR_SET_COW_PTE), it will set the MMF_COW_PTE_READY flag to the process for enabling COW PTE during the next time of fork. It uses the MMF_COW_PTE flag to distinguish the normal page table and the COW one. Moreover, it is difficult to distinguish whether all the page tables is out of COW state. So the MMF_COW_PTE flag won't be disabled after setup. Signed-off-by: Chih-En Lin --- kernel/fork.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kernel/fork.c b/kernel/fork.c index 9f7fe3541897..94c35c8b31b1 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2678,6 +2678,13 @@ pid_t kernel_clone(struct kernel_clone_args *args) trace = 0; } +#ifdef CONFIG_COW_PTE + if (current->mm && test_bit(MMF_COW_PTE_READY, ¤t->mm->flags)) { + clear_bit(MMF_COW_PTE_READY, ¤t->mm->flags); + set_bit(MMF_COW_PTE, ¤t->mm->flags); + } +#endif + p = copy_process(NULL, trace, NUMA_NO_NODE, args); add_latent_entropy(); -- 2.34.1