Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2749864rdb; Mon, 5 Feb 2024 17:14:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IGDDnZiRumbFXqgKo/9nR+0X9uawmDuTvP+PUk2Da3Wq4lgVB6RFihZPhIC3/3JsMhuUNIF X-Received: by 2002:a17:902:f682:b0:1d9:7ba7:bba with SMTP id l2-20020a170902f68200b001d97ba70bbamr230284plg.20.1707182061322; Mon, 05 Feb 2024 17:14:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707182061; cv=pass; d=google.com; s=arc-20160816; b=iq2/We4Y2M6Yswvi0f9CsevhGtNfKSz7KpOZ0iPqab6J/iEYYoxU2/mrosFYVxKJBF 8GFGfHVPrOEQmG7Wunu9EGdwBPHHXTyEwlbG1Cg7tSr9IOumwKb0wPfnPAKclvoV+HEZ s21v6gqk+9aqoSJci5wq2T62vhztshoIInUZ8mujIkVa85WEe4K0IrpHitFTWM9WTW3p 6y/US/qiPlKFCDnYqwGBfnRfa/EWgBz1DNWHwM4ZSqSSzv0bVHdlE5d3XCO81pGrQvjU vkXfof/jgaPfXoR7j7ijUZH923Kb2b6zTRlA8uI7wYSE/EHY5Eq68UQDAjbXFx94JANi Fs2Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence; bh=3L7hTGKnHQO1yhpr6n5deEhCG4zJbFmaDzbOK4JnIok=; fh=sKBf0PtoPks1d5zOuocCA/eS9GXz74bdapsbRuOknrQ=; b=isex0T1CN2aCEb8EChufvHTHylSardJVkB/JJePLAgFNARG3xYdWwdprRi2S2+oKiW iOnprrMFRKA01VyKQh5UeGIL1fCblDBqbsxVNmGtrVLktTJHNgfDUaoqlMdH0EFSf8XS MWOVcWRwAuPg5agw5hy/EkwKZQSXpmadgeWyyGUHl/VVikTm+i8VQtJDrTIgK4hgR33R futu04q+YI1slwOVRKD//tZ/vdLPTz7UdoFVbHpC8/OqAizNODN6WtJNQf8GMxKtrz+2 gYao+VYbmaGbeoZKQp3F3Fb+gXrMsGa0vnU0ZzWEvyvzznldm1sX7AFXqLpm85jW9BCB L8pA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-54143-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54143-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCXdJbxxXTlQweph/cjp+oPPiLKHgSAuSVnUKxU3ijUoT24yDBGSS1LYjVDQJLqcF1h6ZAWePy1KY8MUvlyG6zRrBPGaTpx1Nfu8IxI1Mg== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id iz13-20020a170902ef8d00b001d98549e72esi711751plb.207.2024.02.05.17.14.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Feb 2024 17:14:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54143-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-54143-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54143-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id E4A4AB21E23 for ; Tue, 6 Feb 2024 01:14:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E00701362; Tue, 6 Feb 2024 01:14:04 +0000 (UTC) Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 80C534A06; Tue, 6 Feb 2024 01:14:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707182044; cv=none; b=BFl26vgpeR2x+r+7sxU7IATasAXhbhTf8uTfv+BjrRMf5vreNSsna0vdhJdD1UOrBoxy+ZXpNXviVuCle+hw0PAvgXVOTf2cK9qnKeyOOkJRxhA64dv1zONw1e72hA76dMj7t0Cbosj9yAzz3n+Cryl2A8kkgrtoBUQGNYi136Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707182044; c=relaxed/simple; bh=pMhiY7dOHzMLKuexGo6Y2Dvwut2S7WBuuFy0mbEgBbo=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=FcvEKzUW5/Lh9hCb9p+dYyHC/6LQl/mE2BecoL8dI6WDsm6Vn4043I860pG2i++fOi6/ntLhonmzQ4fpYDV+7wRqeqzyUyf/8n+/Lz1Au3TxBkpfO3isKJtG19aH5Gp/12LgqTfQoL9ALCIRYh9ZoRNBb5RyFJIryOEsfYwK78o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.215.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-5d8b70b39efso4574871a12.0; Mon, 05 Feb 2024 17:14:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707182042; x=1707786842; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3L7hTGKnHQO1yhpr6n5deEhCG4zJbFmaDzbOK4JnIok=; b=HqujMMnlYOZpymxPiSSN6PwsGKKJtO5OO/2sBTPyt8yyJm1+C/tu5w4eAMRCHtX6Lz iKHPsowpMhBXJBGPyN1aVIh+ie+v0lhUMwlRpoX2bc7ya1sItm2rHbW5HWKQ+VxzhA1v Q4apdBAOEsX7loTk4BKrkjAALReKlvkVV+oGRKMnUh/gTYQE56i8a2ggmxwEjECj8c4d 8GQEj16bjLy3i0vBfQfUEqx08uS0GfMlc9ixNvv8QlORDcXe+vcmkcYFk/qPc2yzHOu9 ewhvoq39i53tMHAwJcKAWLnXrZHTRsYFDLzNZHuHQaX4iyY9EEkW5mGL08hyMVD1DdZs etfA== X-Gm-Message-State: AOJu0Yz6rjHU9bKnbq4tJe4Ys10kiA2La+v44TcE4o68A2hgyeHLRkzA 4jzNHOyLJRPoXpJcmIMUL7W7XSsr5wUi5mh6kaH1vsra86uFI4xB9a+ecFcJaJW+8c+s0j/PDPr /scNfK5HkmmYk3LCcYDvv3p/KDSI= X-Received: by 2002:a05:6a20:9012:b0:19c:881d:78e6 with SMTP id d18-20020a056a20901200b0019c881d78e6mr165482pzc.42.1707182041636; Mon, 05 Feb 2024 17:14:01 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240202061532.1939474-1-irogers@google.com> In-Reply-To: <20240202061532.1939474-1-irogers@google.com> From: Namhyung Kim Date: Mon, 5 Feb 2024 17:13:50 -0800 Message-ID: Subject: Re: [PATCH v8 00/25] maps/threads/dsos memory improvements and fixes To: Ian Rogers Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Nick Terrell , Kan Liang , Andi Kleen , Kajol Jain , Athira Rajeev , Huacai Chen , Masami Hiramatsu , "Steinar H. Gunderson" , Liam Howlett , Miguel Ojeda , Colin Ian King , Dmitrii Dolgov <9erthalion6@gmail.com>, Yang Jihong , Ming Wang , James Clark , K Prateek Nayak , Sean Christopherson , Leo Yan , Ravi Bangoria , German Gomez , Changbin Du , Paolo Bonzini , Li Dong , Sandipan Das , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Guilherme Amadio Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Feb 1, 2024 at 10:15=E2=80=AFPM Ian Rogers wro= te: > > Modify the implementation of maps to not use an rbtree as the > container for maps, instead use a sorted array. Improve locking and > reference counting issues. > > Similar to maps separate out and reimplement threads to use a hashmap > for lower memory consumption and faster look up. The fixes a > regression in memory usage where reference count checking switched to > using non-invasive tree nodes. Reduce its default size by 32 times > and improve locking discipline. Also, fix regressions where tids had > become unordered to make `perf report --tasks` and > `perf trace --summary` output easier to read. > > Better encapsulate the dsos abstraction. Remove the linked list and > rbtree used for faster iteration and log(n) lookup to a sorted array > for similar performance but half the memory usage per dso. Improve > reference counting and locking discipline, adding reference count > checking to dso. > > v8: > - in "perf maps: Switch from rbtree to lazily sorted array for > addresses" use accessors and remove some duplicative invariant checks = as > requested by Namhyung. > > v7: > - rebase to latest perf-tools-next where 22 patches were applied by Arna= ldo. > - resolve merge conflicts, in particular with fc044c53b99f ("perf > annotate-data: Add dso->data_types tree") that required more dso > accessor functions. > > v6 series is here: > https://lore.kernel.org/lkml/20231207011722.1220634-1-irogers@google.com/ > > Ian Rogers (25): > perf maps: Switch from rbtree to lazily sorted array for addresses > perf maps: Get map before returning in maps__find > perf maps: Get map before returning in maps__find_by_name > perf maps: Get map before returning in maps__find_next_entry > perf maps: Hide maps internals > perf maps: Locking tidy up of nr_maps Can you please send patch 1-6 separately with my Ack? - provided you fixed the issue in the patch 1. For patch 1-6: Acked-by: Namhyung Kim I'll review others later. Thanks, Namhyung > perf dso: Reorder variables to save space in struct dso > perf report: Sort child tasks by tid > perf trace: Ignore thread hashing in summary > perf machine: Move fprintf to for_each loop and a callback > perf threads: Move threads to its own files > perf threads: Switch from rbtree to hashmap > perf threads: Reduce table size from 256 to 8 > perf dsos: Attempt to better abstract dsos internals > perf dsos: Tidy reference counting and locking > perf dsos: Add dsos__for_each_dso > perf dso: Move dso functions out of dsos > perf dsos: Switch more loops to dsos__for_each_dso > perf dsos: Switch backing storage to array from rbtree/list > perf dsos: Remove __dsos__addnew > perf dsos: Remove __dsos__findnew_link_by_longname_id > perf dsos: Switch hand code to bsearch > perf dso: Add reference count checking and accessor functions > perf dso: Reference counting related fixes > perf dso: Use container_of to avoid a pointer in dso_data > > tools/perf/arch/x86/tests/dwarf-unwind.c | 1 + > tools/perf/builtin-annotate.c | 8 +- > tools/perf/builtin-buildid-cache.c | 2 +- > tools/perf/builtin-buildid-list.c | 18 +- > tools/perf/builtin-inject.c | 96 +- > tools/perf/builtin-kallsyms.c | 2 +- > tools/perf/builtin-mem.c | 4 +- > tools/perf/builtin-record.c | 2 +- > tools/perf/builtin-report.c | 209 +-- > tools/perf/builtin-script.c | 8 +- > tools/perf/builtin-top.c | 4 +- > tools/perf/builtin-trace.c | 43 +- > tools/perf/tests/code-reading.c | 8 +- > tools/perf/tests/dso-data.c | 67 +- > tools/perf/tests/hists_common.c | 6 +- > tools/perf/tests/hists_cumulate.c | 4 +- > tools/perf/tests/hists_output.c | 2 +- > tools/perf/tests/maps.c | 7 +- > tools/perf/tests/symbols.c | 2 +- > tools/perf/tests/thread-maps-share.c | 8 +- > tools/perf/tests/vmlinux-kallsyms.c | 16 +- > tools/perf/ui/browsers/annotate.c | 6 +- > tools/perf/ui/browsers/hists.c | 8 +- > tools/perf/ui/browsers/map.c | 4 +- > tools/perf/util/Build | 1 + > tools/perf/util/annotate-data.c | 6 +- > tools/perf/util/annotate.c | 45 +- > tools/perf/util/auxtrace.c | 2 +- > tools/perf/util/block-info.c | 2 +- > tools/perf/util/bpf-event.c | 9 +- > tools/perf/util/bpf_lock_contention.c | 8 +- > tools/perf/util/build-id.c | 136 +- > tools/perf/util/build-id.h | 2 - > tools/perf/util/callchain.c | 4 +- > tools/perf/util/data-convert-json.c | 2 +- > tools/perf/util/db-export.c | 6 +- > tools/perf/util/dlfilter.c | 12 +- > tools/perf/util/dso.c | 469 +++--- > tools/perf/util/dso.h | 549 ++++++- > tools/perf/util/dsos.c | 529 ++++--- > tools/perf/util/dsos.h | 40 +- > tools/perf/util/event.c | 12 +- > tools/perf/util/header.c | 8 +- > tools/perf/util/hist.c | 4 +- > tools/perf/util/intel-pt.c | 22 +- > tools/perf/util/machine.c | 570 +++----- > tools/perf/util/machine.h | 32 +- > tools/perf/util/map.c | 73 +- > tools/perf/util/maps.c | 1298 +++++++++++------ > tools/perf/util/maps.h | 65 +- > tools/perf/util/probe-event.c | 26 +- > tools/perf/util/rb_resort.h | 5 - > .../util/scripting-engines/trace-event-perl.c | 6 +- > .../scripting-engines/trace-event-python.c | 21 +- > tools/perf/util/session.c | 21 + > tools/perf/util/session.h | 2 + > tools/perf/util/sort.c | 19 +- > tools/perf/util/srcline.c | 65 +- > tools/perf/util/symbol-elf.c | 132 +- > tools/perf/util/symbol.c | 217 +-- > tools/perf/util/symbol_fprintf.c | 4 +- > tools/perf/util/synthetic-events.c | 24 +- > tools/perf/util/thread.c | 8 +- > tools/perf/util/thread.h | 6 - > tools/perf/util/threads.c | 186 +++ > tools/perf/util/threads.h | 35 + > tools/perf/util/unwind-libunwind-local.c | 20 +- > tools/perf/util/unwind-libunwind.c | 9 +- > tools/perf/util/vdso.c | 56 +- > 69 files changed, 3143 insertions(+), 2160 deletions(-) > create mode 100644 tools/perf/util/threads.c > create mode 100644 tools/perf/util/threads.h > > -- > 2.43.0.594.gd9cf4e227d-goog > >