From patchwork Tue Feb 9 19:02:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Serapheim Dimitropoulos X-Patchwork-Id: 12078871 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C31EC433DB for ; Tue, 9 Feb 2021 19:03:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C312664E8A for ; Tue, 9 Feb 2021 19:03:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C312664E8A Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=delphix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 28AC36B0005; Tue, 9 Feb 2021 14:03:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 23B6A6B006C; Tue, 9 Feb 2021 14:03:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 17B4E6B006E; Tue, 9 Feb 2021 14:03:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0203.hostedemail.com [216.40.44.203]) by kanga.kvack.org (Postfix) with ESMTP id 0246F6B0005 for ; Tue, 9 Feb 2021 14:03:21 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id B631D180ABF4C for ; Tue, 9 Feb 2021 19:03:21 +0000 (UTC) X-FDA: 77799652602.09.root21_1810d6227609 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id 9E963180AE7E7 for ; Tue, 9 Feb 2021 19:03:21 +0000 (UTC) X-HE-Tag: root21_1810d6227609 X-Filterd-Recvd-Size: 4172 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf50.hostedemail.com (Postfix) with ESMTP for ; Tue, 9 Feb 2021 19:03:21 +0000 (UTC) Received: by mail-pl1-f173.google.com with SMTP id x9so10292896plb.5 for ; Tue, 09 Feb 2021 11:03:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=delphix.com; s=google; h=from:to:cc:subject:date:message-id; bh=3O/mqypFsO3O218VUQ7AaVDZ9919y4ACFmjTnjCZTqU=; b=dMOEzna3+iazmZ7hOhH5wTI57l3vPWBgjjhR0ERX4wB2uI9yQwzXvvpwDSyNrk4kAS Ike6XHQPYvTVdFZqE2hghkphFy1KuTuuL8HYTGNwPGCwtq46I4efHQ45krOKYKhEVo2U Nl6v0Qfa6QJYBrAe4J7yvW04ZwVsrizxNOWR4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=3O/mqypFsO3O218VUQ7AaVDZ9919y4ACFmjTnjCZTqU=; b=gkLOpc/AK/hOG++N1Rw7wmN3akHx24bzivNUwm4SGbAbDFoXM0RDUWXcj6SDr099FN aghysqcESUPvlX3bxHa+RCiPfZUTV+8qSTVImxCiaTQ8nfOY9lh4C9WScQ0bC5u1vlRT 6NekLYMSTNJnGZGNf9OjinhhuWRO4Xz6swiCYnXlNErh/k6AeHU2fNo4wopmTaHn64p1 FTnXQ72A2u4fswQCL/I40TUg2Gkd5405E8xmt7rVEQsVLalK37sGx8TYgBAXpkYU6f9U /Gje3pCuZi1G0ygxMuNox3HzBdMA5q14K/EOMkgb3StKkTrWvjGHeY7CPIblWYh07Xjz rDrg== X-Gm-Message-State: AOAM533FK8KPlsem5IQusW5Q/8F+lp/MfRi+DDRSdMSS0Fi9r4lytBim s4wHZsZ6wCrWSyZ4hX8vRiDu8w== X-Google-Smtp-Source: ABdhPJyfvEp5pATS1gcO5Hh3siii2AtaO2ih6dLkADvoH4jvuRkVkIv4v+Ll+vt/8Rk0YVkUBGGZfg== X-Received: by 2002:a17:902:c284:b029:e1:8863:b3d6 with SMTP id i4-20020a170902c284b02900e18863b3d6mr22312104pld.64.1612897400252; Tue, 09 Feb 2021 11:03:20 -0800 (PST) Received: from sd-kernel.dcol2.delphix.com (DELPHIX-COR.ear1.SanJose1.Level3.net. [4.15.123.66]) by smtp.googlemail.com with ESMTPSA id 123sm23324903pfd.91.2021.02.09.11.03.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Feb 2021 11:03:19 -0800 (PST) From: Serapheim Dimitropoulos X-Google-Original-From: Serapheim Dimitropoulos To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, osandov@osandov.com, urezki@gmail.com, serapheim@delphix.com Subject: [PATCH v2] mm/vmalloc: use rb_tree instead of list for vread() lookups Date: Tue, 9 Feb 2021 19:02:53 +0000 Message-Id: <20210209190253.108763-1-serapheim@delphix.com> X-Mailer: git-send-email 2.17.1 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: vread() has been linearly searching vmap_area_list for looking up vmalloc areas to read from. These same areas are also tracked by a rb_tree (vmap_area_root) which offers logarithmic lookup. This patch modifies vread() to use the rb_tree structure instead of the list and the speedup for heavy /proc/kcore readers can be pretty significant. Below are the wall clock measurements of a Python application that leverages the drgn debugging library to read and interpret data read from /proc/kcore. Before the patch: ----- $ time sudo sdb -e 'dbuf | head 3000 | wc' (unsigned long)3000 real 0m22.446s user 0m2.321s sys 0m20.690s ----- With the patch: ----- $ time sudo sdb -e 'dbuf | head 3000 | wc' (unsigned long)3000 real 0m2.104s user 0m2.043s sys 0m0.921s ----- Signed-off-by: Serapheim Dimitropoulos Reviewed-by: Uladzislau Rezki (Sony) --- Changed in v2: - Use __find_vmap_area() for initial lookup but keep iteration via va->list. mm/vmalloc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 49ab9b6c001d..eb133d000394 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2860,7 +2860,10 @@ long vread(char *buf, char *addr, unsigned long count) count = -(unsigned long) addr; spin_lock(&vmap_area_lock); - list_for_each_entry(va, &vmap_area_list, list) { + va = __find_vmap_area((unsigned long)addr); + if (!va) + goto finished; + list_for_each_entry_from(va, &vmap_area_list, list) { if (!count) break;