Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp885591ybv; Fri, 7 Feb 2020 10:15:10 -0800 (PST) X-Google-Smtp-Source: APXvYqx3rzZbn6JKJF0VpMrOtGW8KEvuEC8AKzfKVpp/JtIxrsbE2Sqox/5zhJ00+BIEfq7x8EpZ X-Received: by 2002:a05:6808:50:: with SMTP id v16mr2784183oic.133.1581099310074; Fri, 07 Feb 2020 10:15:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581099310; cv=none; d=google.com; s=arc-20160816; b=cscCskgX0JUKeA599NbzS8Bu5geg39kJ4ddJekgkKSHtnQSk26RqVq9cQNbNARGR5p P6ORo56/k/dJzuVsmkVtGpv2iGrzP3vz/9PtE0EuIYSmDLgD1aJx+mxIaWvu0F79QdUx pVBNnFWyQmlYSXTrDZ7wKLgUrzfnGHAvd6LFrReeTgkH5IXHJxjXDlUe+mPG1dLmdAPE zXzNvCA1d671CI62vkjD+rpywH95zW4oIAFLaqAIPptxa12uulnENHBv4BunRTKq+yRd bD40UMm4mJ3vz/N87BATSBC/4jz2qUyxF2X0I8lweUGxp7oKB1Njct+KAu6TFoFQZtE5 x/vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=3QoRbAJwf9e+fD3V12EXOHegkqFcVaj2nvLF+jcH13w=; b=b1KZSdWPq5ysmJDWbECUvAy4qB3y3MeTmrPGUiUm6EOD7QzD+R4YJ2t8GaDIUOxmi3 +LjtcaQpcHH53yYP/UADxhfHqeoyI4ulkDgRlPu94V6TkQg1pDjmCs/W7vRKDz7bOgto QUahxPL8Uvx1Y9RK54VfbH7H62OGt4pHgjPxI00QC/mn9xw3ZBotA/PDdZ50e1c2lN9g kaAXl3XW2pblpCm51t6Nrh/G1vqfXihaO15ntxX2zCuAj+wTj+73gEn9hvzBXOVVz5u9 FiKtR3cxLV1Tehp2g4pkOybPOmY+UYP85cEznUOPXddpNEA/Q6o8sz8TVFs5S/ckhCgd K94A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l17si27002otq.59.2020.02.07.10.14.56; Fri, 07 Feb 2020 10:15:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727005AbgBGSOD (ORCPT + 99 others); Fri, 7 Feb 2020 13:14:03 -0500 Received: from mx2.suse.de ([195.135.220.15]:39360 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726900AbgBGSOC (ORCPT ); Fri, 7 Feb 2020 13:14:02 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id B8E38AD3F; Fri, 7 Feb 2020 18:14:00 +0000 (UTC) From: Davidlohr Bueso To: akpm@linux-foundation.org Cc: dave@stgolabs.net, linux-kernel@vger.kernel.org, mcgrof@kernel.org, broonie@kernel.org, alex.williamson@redhat.com Subject: [PATCH -next 0/5] rbtree: optimize frequent tree walks Date: Fri, 7 Feb 2020 10:03:00 -0800 Message-Id: <20200207180305.11092-1-dave@stgolabs.net> X-Mailer: git-send-email 2.16.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This series introduces the ll_rbtree interface to optimize rbtree users that incur in frequent in-order tree iterations (even full traversals). This can be seen as an abstraction to what is already done for dealing with VMAs (albeit non-augmented trees). Mainly, it trades off higher per-node memory footprint (two extra pointers) for minimal runtime overhead to gain O(1) brachless next and prev node pointers. See patch 1 for full details, but, for example, the following tables show the benefits vs the costs of using this new interface. +--------+--------------+-----------+ | #nodes | plain rbtree | ll-rbtree | +--------+--------------+-----------+ | 10 | 138 | 24 | | 100 | 7,200 | 425 | | 1000 | 17,000 | 8,000 | | 10000 | 501,090 | 222,500 | +--------+--------------+-----------+ While there are other node representations that optimize getting such pointers without bloating the nodes as much, such as keeping a parent pointer or threaded trees where the nil prev/next pointers are recycled; both incurring in higher runtime penalization for common modification operations as well as any rotations. The overhead of tree modifications can be seen in the following table, comparing cycles to insert+delete: +--------+--------------+------------------+-----------+ | #nodes | plain rbtree | augmented rbtree | ll-rbtree | +--------+--------------+------------------+-----------+ | 10 | 530 | 840 | 600 | | 100 | 7,100 | 14,200 | 7,800 | | 1000 | 265,000 | 370,000 | 205,200 | | 10000 | 4,400,000 | 5,500,000 | 4,200,000 | +--------+--------------+------------------+-----------+ Patch 1 introduces the ll_rbtree machinery. Patches 2-5 convert users that might benefit from the new interface. Full details and justifications for the conversion are in each individual patch. I am Cc'ing some of the maintainers of the users I have converted to the whole series such that it can the numbers and interface details can be easily seen. Please consider for v5.7. Thanks! Davidlohr Bueso (5): lib/rbtree: introduce linked-list rbtree interface proc/sysctl: optimize proc_sys_readdir regmap: optimize sync() and drop() regcache callbacks vfio/type1: optimize dma_list tree iterations uprobes: optimize build_probe_list() Documentation/rbtree.txt | 74 ++++++++++++++++++++++++ drivers/base/regmap/regcache-rbtree.c | 62 +++++++++++--------- drivers/vfio/vfio_iommu_type1.c | 50 +++++++++-------- fs/proc/proc_sysctl.c | 37 ++++++------ include/linux/ll_rbtree.h | 103 ++++++++++++++++++++++++++++++++++ include/linux/sysctl.h | 6 +- kernel/events/uprobes.c | 47 ++++++++-------- 7 files changed, 286 insertions(+), 93 deletions(-) create mode 100644 include/linux/ll_rbtree.h -- 2.16.4