• Peng Zhang's avatar
    maple_tree: add mt_free_one() and mt_attr() helpers · 4f2267b5
    Peng Zhang authored
    Patch series "Introduce __mt_dup() to improve the performance of fork()", v7.
    
    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.
    
    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.
    
    This idea was originally from Liam R.  Howlett's Maple Tree Work email,
    and I added some of my own ideas to implement it.  Some previous
    discussions can be found in [1].  For a more detailed analysis of the
    algorithm, please refer to the logs for patch [3/10] and patch [10/10].
    
    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.  The first row shows the number of VMAs.  The
    second and third rows show the number of fork() calls per ten seconds,
    corresponding to next-20231006 and the this patchset, respectively.  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.
    
    21     121   221    421    821    1621   3221   6421   12821  25621  51221
    112100 76261 54227  34035  20195  11112  6017   3161   1606   802    393
    114558 83067 65008  45824  28751  16072  8922   4747   2436   1233   599
    2.19%  8.92% 19.88% 34.64% 42.37% 44.64% 48.28% 50.17% 51.68% 53.74% 52.42%
    
    Thanks to Liam and Matthew for the review.
    
    
    This patch (of 10):
    
    Add two helpers:
    1. mt_free_one(), used to free a maple node.
    2. mt_attr(), used to obtain the attributes of maple tree.
    
    Link: https://lkml.kernel.org/r/20231027033845.90608-1-zhangpeng.00@bytedance.com
    Link: https://lkml.kernel.org/r/20231027033845.90608-2-zhangpeng.00@bytedance.com
    
    Signed-off-by: default avatarPeng Zhang <zhangpeng.00@bytedance.com>
    Reviewed-by: default avatarLiam R. Howlett <Liam.Howlett@oracle.com>
    Cc: Christian Brauner <brauner@kernel.org>
    Cc: Jonathan Corbet <corbet@lwn.net>
    Cc: Mateusz Guzik <mjguzik@gmail.com>
    Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
    Cc: Matthew Wilcox <willy@infradead.org>
    Cc: Michael S. Tsirkin <mst@redhat.com>
    Cc: Mike Christie <michael.christie@oracle.com>
    Cc: Nicholas Piggin <npiggin@gmail.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Suren Baghdasaryan <surenb@google.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    4f2267b5
maple_tree.c 181 KB