Message ID | 20230925035617.84767-1-zhangpeng.00@bytedance.com |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp1041744vqu; Mon, 25 Sep 2023 00:49:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHKTlrNrny7yFvEGoSF02KY+Yh0FpnRNqt0IaVlxmrhxnBjp2oQEglXMV+TqePZZMipKLhB X-Received: by 2002:a17:902:da8e:b0:1c0:d575:d28 with SMTP id j14-20020a170902da8e00b001c0d5750d28mr5122329plx.50.1695628159834; Mon, 25 Sep 2023 00:49:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695628159; cv=none; d=google.com; s=arc-20160816; b=FSl2sIBVWBlfE0CigoUQQgxV6Wqltq3LoYU5QIzE4HShcdaMi6CzNP8Tdk1PhfSX96 uQbFOBukFV8lKN937WVJoXFAfjOYlhYa7/y/5po6/jpsWLigorhmN+hg5q26rENKbA2F dPzCCg9z+MdUxXpVYpn51yYPNh4AfUZrMzw8KAk1QPwaSuxlnqd8uFoKzdyFoEB328Y3 N7mkomJS1iNiWOo1ssDGAlmoD/P7sYByX4bSgRQZjXplAwcpzyhi7bpXBFL7zwqkk9/T eXrSOuSwCTV8u+rUJv5EzB/R+UgYZvsnIHoT+bj2WQPr3XXW0UPL4H9YzBmCEGLQgut0 oUfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=ZL8oS6h/SMWhCHncu4CSFCmNusM3zUoiub5E91Pn6TA=; fh=uq6KVc+CzZ80ucpwrp8f3d+Fe7Ue0w5J0Au2lk064nU=; b=hJtraC2onleMbO1+jYJ673Lcg5Xlxf10El346d71dD8wyAbAd8tqeA9udO9gXT2uPg 9k/X2kQesYMb2TipCdnrNo6pwYw/nbfoSNKA5GoUF9EyL6i9Aqlpxh22vdMW10CxyPTZ +2lTUuv9VRugKwvzE++gzA4V72480sXivDwqm0E+1cz2bP79SYI+a37s2c363QkoWnd2 WRgiscE5nK9CNg9tXeALCHgxE/ooqvYXew1MTEnF+5/nVu+cGIZ8625zdGRHnRtJzVtm Tze7ot/xUcsvljn3bkX2UY1JUsuN8T7MQUR8ikSOVWle0wrdJBQ7U2Oue3aaxsWbHDxR YEtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=X05cR9gb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id lc14-20020a170902fa8e00b001c320085a7esi8966482plb.645.2023.09.25.00.49.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 00:49:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=X05cR9gb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 90C55812E34B; Sun, 24 Sep 2023 20:58:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231712AbjIYD6T (ORCPT <rfc822;ezelljr.billy@gmail.com> + 30 others); Sun, 24 Sep 2023 23:58:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231642AbjIYD6O (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 24 Sep 2023 23:58:14 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93249E1 for <linux-kernel@vger.kernel.org>; Sun, 24 Sep 2023 20:57:45 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-690d8c05784so3890471b3a.2 for <linux-kernel@vger.kernel.org>; Sun, 24 Sep 2023 20:57:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1695614265; x=1696219065; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ZL8oS6h/SMWhCHncu4CSFCmNusM3zUoiub5E91Pn6TA=; b=X05cR9gbgpWsd0WxF7LzGEEkNoOB2lSNWyHrgCKsLdSkUQ9GPgk24OxyjUfmJWf+5s X+wclKE2/DDG+aH5gtS8YgXFfLgsezLkaLA2Q+xHgmd4FP8o0P7l4pRe1wlNj/HrlG7M uNRHOHBniyUAQ5pKWf+Lvl51Dan7sRanpbPU35oWE8HMrBuPJjJMsXEX05vLeSEKFrL4 tADUkI6Eiyh7QQ/FMZGb3G3yOP9+Vb3i/P8xb06KjZ0uVxVAx1g1CjFHPgUMoqy9ujnd 0c6jUq5F4xQ+bIBFtrEWXFS3BP8A+HzNt8nVnfAo8bJUkvfNiyp1/SPde6pqk6PpTvIl FTgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695614265; x=1696219065; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ZL8oS6h/SMWhCHncu4CSFCmNusM3zUoiub5E91Pn6TA=; b=bOOmahBcHCFUZNTh799yzFpCJuh1N1pzUMpugVyaReiI9yfKwhqd0F/h7YOfn6XGMz W8yxB4pUSiOZE/w9uDoMqKSWpPPcjx+FaCLMyrb38PQ05EWNsjhsiN0BVH+qWcS+tMdR BsERQ+44S42L1xkStiJcCwhYR+jm+mU/OU1Tg4KIRNYywCksPjXjnP45gf3fRotWZced 62gv6fKuFIuPIwIeTSPTAMmYxuH6KZrtixF8huIDFW4qQcY9UhFOKBG50ZnEHUc04EBD qSzN5UThbkWhTPnS7lACZALK1QIKdN01MDdGZBfZN9OSnvWtBsULsSBtZqVqf7L9hudg 5uhw== X-Gm-Message-State: AOJu0Yz/2COGooZdgzp8zDtrrbolD1m9YRPU/xnVbA+7K7bcp+TG6qEl Pr40YSmOvLDqumOvXevV83nfCDo6kggl8To3doM= X-Received: by 2002:a05:6a00:1990:b0:68b:fdfe:76c2 with SMTP id d16-20020a056a00199000b0068bfdfe76c2mr4715925pfl.20.1695614264958; Sun, 24 Sep 2023 20:57:44 -0700 (PDT) Received: from GL4FX4PXWL.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id fm1-20020a056a002f8100b00679a4b56e41sm7025387pfb.43.2023.09.24.20.57.37 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 24 Sep 2023 20:57:43 -0700 (PDT) From: Peng Zhang <zhangpeng.00@bytedance.com> To: Liam.Howlett@oracle.com, corbet@lwn.net, akpm@linux-foundation.org, willy@infradead.org, brauner@kernel.org, surenb@google.com, michael.christie@oracle.com, mjguzik@gmail.com, mathieu.desnoyers@efficios.com, npiggin@gmail.com, peterz@infradead.org, oliver.sang@intel.com Cc: zhangpeng.00@bytedance.com, maple-tree@lists.infradead.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v3 0/9] Introduce __mt_dup() to improve the performance of fork() Date: Mon, 25 Sep 2023 11:56:08 +0800 Message-Id: <20230925035617.84767-1-zhangpeng.00@bytedance.com> X-Mailer: git-send-email 2.37.0 (Apple Git-136) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Sun, 24 Sep 2023 20:58:46 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777994993252997804 X-GMAIL-MSGID: 1777994993252997804 |
Series |
Introduce __mt_dup() to improve the performance of fork()
|
|
Message
Peng Zhang
Sept. 25, 2023, 3:56 a.m. UTC
Hi all, This series introduces __mt_dup() to improve the performance of fork(). During the duplication process of mmap, all VMAs are traversed and inserted one by one into the new maple tree, causing the maple tree to be rebalanced multiple times. Balancing the maple tree is a costly operation. To duplicate VMAs more efficiently, mtree_dup() and __mt_dup() are introduced for the maple tree. They can efficiently duplicate a maple tree. By applying __mt_dup() to dup_mmap(), better performance is achieved compared to the original method. After using this method, the average time complexity decreases from O(n * log(n)) to O(n). Here are some algorithmic details about {mtree, __mt}_dup(). We perform a DFS pre-order traversal of all nodes in the source maple tree. During this process, we fully copy the nodes from the source tree to the new tree. This involves memory allocation, and when encountering a new node, if it is a non-leaf node, all its child nodes are allocated at once. Some previous discussions can be referred to as [1]. There is a "spawn" in byte-unixbench[2], which can be used to test the performance of fork(). I modified it slightly to make it work with different number of VMAs. Below are the test results. By default, there are 21 VMAs. The first row shows the number of additional VMAs added on top of the default. The last two rows show the number of fork() calls per ten seconds. The test results were obtained with CPU binding to avoid scheduler load balancing that could cause unstable results. There are still some fluctuations in the test results, but at least they are better than the original performance. Increment of VMAs: 0 100 200 400 800 1600 3200 6400 next-20230921: 112326 75469 54529 34619 20750 11355 6115 3183 Apply this: 116505 85971 67121 46080 29722 16665 9050 4805 +3.72% +13.92% +23.09% +33.11% +43.24% +46.76% +48.00% +50.96% Thanks to kernel test robot <oliver.sang@intel.com> for reporting the warning about nested locks. Thanks to Liam for all the suggestions. Changes since v2: - Some minor modifications to mtree_dup(), __mt_dup() and their test code. - Introduce {mtree, mas}_lock_nested() to address lockdep warnings. - Update the documentation for maple tree. - Introduce undo_dup_mmap() to address the failure of dup_mmap(). - Performance data was retested based on the latest next-20230921, and there were some fluctuations in the results which were expected. [1] https://lore.kernel.org/lkml/463899aa-6cbd-f08e-0aca-077b0e4e4475@bytedance.com/ [2] https://github.com/kdlucas/byte-unixbench/tree/master v1: https://lore.kernel.org/lkml/20230726080916.17454-1-zhangpeng.00@bytedance.com/ v2: https://lore.kernel.org/lkml/20230830125654.21257-1-zhangpeng.00@bytedance.com/ Peng Zhang (9): maple_tree: Add mt_free_one() and mt_attr() helpers maple_tree: Introduce {mtree,mas}_lock_nested() maple_tree: Introduce interfaces __mt_dup() and mtree_dup() maple_tree: Add test for mtree_dup() maple_tree: Update the documentation of maple tree maple_tree: Skip other tests when BENCH is enabled maple_tree: Update check_forking() and bench_forking() maple_tree: Preserve the tree attributes when destroying maple tree fork: Use __mt_dup() to duplicate maple tree in dup_mmap() Documentation/core-api/maple_tree.rst | 4 + include/linux/maple_tree.h | 7 + include/linux/mm.h | 1 + kernel/fork.c | 34 ++- lib/maple_tree.c | 300 ++++++++++++++++++++- lib/test_maple_tree.c | 69 +++-- mm/internal.h | 3 +- mm/memory.c | 7 +- mm/mmap.c | 52 +++- tools/include/linux/spinlock.h | 1 + tools/testing/radix-tree/maple.c | 363 ++++++++++++++++++++++++++ 11 files changed, 787 insertions(+), 54 deletions(-)