From patchwork Thu Feb 29 06:32:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 21130 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp209248dyb; Wed, 28 Feb 2024 22:33:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVHjlp+Xg56dGVHTCPtsAiWavTFDmIG9ycv7aVIuo/1RwfMP1vGmpzhr5uT9HhZSoq6rsVT3ZvHxLTpxL7sucQ/BJ07HA== X-Google-Smtp-Source: AGHT+IG51svwTnHvB41v+5Jl5n2SwOkMLVcNL7CDHGP+38t5NNhrshnj3yAowbS1t/+eSCy3iY78 X-Received: by 2002:a05:620a:621c:b0:787:caf2:e1b1 with SMTP id ou28-20020a05620a621c00b00787caf2e1b1mr1263507qkn.51.1709188400347; Wed, 28 Feb 2024 22:33:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709188400; cv=pass; d=google.com; s=arc-20160816; b=rcR44qLeMyMxvGxOl90v7fMivtawA13E8j8bVSasKu6lJAKuRprVZ6E1jJNerJPnJA AgkJyzNxL4n+mXILBaH11id2m+5D8Cq2f5hzjPj2owLk9h9jxxUswernh0wkxSY7rOk0 CkL1j4RPdp9Nig0OtLX9kAkOPmlnHE9zYEmaEr79j2RdRA8hUIjt4VvAWKLJQcr8TdKI dPt2g8r6MHJku/L5/03FdnrQAsjI3gNQP+k7sZTTasvPo3uVTMFgERmTTzZOEk9MaODG qvDHQR71tRl+TWkcagUw+rc15TGpzsDUuaYtmylgTkf45WuiJcBYO91rApsm/8HTBxji 1Odg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:from:subject:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:date:dkim-signature; bh=FMG+g1RkoAeOPaJke1hkXlYl72J+qtVpVOKOhfjNYSk=; fh=R8UfMSAudKuU6EF1XEZkcPQUEW6WvESSL9cNMqjf8oI=; b=IsfRnWyZ0suViZMM9ixFqpqRie2Cg4xla64rhZ/xH1aBH9S+Zs54tjSYlxO6aIJyvn UAmD/hpnCubvtlkUNJ7IezEZm0eRUQTQxcuQhdnOFBWUZ+LdWpm1wIg5xuggFtU14cb4 qTfIbdr5cKyiIUEWu9kXmK6c3/6qfBUTmrjR++G7KDnQgAKXDdp2HBbjAJmwH6mKw/dP KnBkXsf/nlFZ9Uwj7jg2xq25mZtwBreYIJfZyPZY/R+S8YaP8SVuSRyCiaRoYR5HGZTo PXDNew9ea6sZ1MZZavhbZuT9+EloU0HituRwezTXVkHPV7A55ofuS2bx2awrIQGCqoqG z0lw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=CuJxVrNt; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-86171-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86171-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id p7-20020a05620a22a700b007877aff36e8si785404qkh.468.2024.02.28.22.33.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 22:33:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-86171-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=CuJxVrNt; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-86171-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86171-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 10BB71C20A41 for ; Thu, 29 Feb 2024 06:33:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2004B3EA62; Thu, 29 Feb 2024 06:33:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="CuJxVrNt" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 049BE36B0A for ; Thu, 29 Feb 2024 06:33:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709188382; cv=none; b=F1g8UkWOaVoKtpzx2x9/aLLO3/7M/s552BfftULNgQbAIUpyeWbM2I60NvBK155DXt9Pow9v+OwhuRNFgF0jzQB9YI/95Q5YTPMxT9KYHd3CJoFpQFWAg+pHOVDoeRnyKkiJ3cAiRYrbayuVx2pdD9Dl11RG3TScRZvKqVCuxoo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709188382; c=relaxed/simple; bh=dFZ2GSzmiKOQGB2rUKRoS+qE2/AFOzCta5z98wxR/38=; h=Date:Message-Id:Mime-Version:Subject:From:To:Content-Type; b=rFajXaUJChfFEd02HGUr4w5AzhLWj6S8Hs8VEG7Y0AHnP7A3a9fY3FXkqvedRL/OEE1lAhjzbeAiXLYKv7j10kXKMxbJS6tT1xPhSh2C34nPmHbPTOK72XQ5wPycUb4+cxlcM1UJ5twGQ5htVkc5QnYAQce2UDvSnQdw8O9scEM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=CuJxVrNt; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-d9a541b720aso1141106276.0 for ; Wed, 28 Feb 2024 22:33:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709188380; x=1709793180; darn=vger.kernel.org; h=to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=FMG+g1RkoAeOPaJke1hkXlYl72J+qtVpVOKOhfjNYSk=; b=CuJxVrNt32UxA02WYQ5u5YLcpxiLfLpq239ASU4EmQgY4IWpoN198ncgK3Tu5y4xLR Ei8yONrgOqh8K5tegakx9UuLVZRNjMAXlCKA+kaO+l/Ap1chVMIh3d34pqyqBGB3VWgn PN87IKeaVe3cq5geSgXgy4LkaTQ1DP0MjiWhVeefbSLfKN3a8wvTIeRNLsRUmlc1lMox KRLt1GzKjmQXQVkQzyFW9pBbgp8liNJShsRq7/CBUllEwoLYHXebFCvW/BMEVpgXEIOH EnV5KAf9xzVuPJ79aJTCjwE1VmxDO2SAX0vLXj9cKsbNguO5279z2HF+FwbE6/oYoF6h 5AhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709188380; x=1709793180; h=to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=FMG+g1RkoAeOPaJke1hkXlYl72J+qtVpVOKOhfjNYSk=; b=I2lu6fYbJplVd28B95Gq8UErzgj3LpUf0FsB+JbBB1Zw9RTr3qJGiDVLQLVAYa9AhY 75mlgwVT88MeHBkl0vcyNcL+rfa/IP4GHqlDT+u7kPYtOIZgNxhm2Ua0fxDfKWYXKff9 UeyInZXEVa5iWFKbeUEN5jGlpC2MnuFhe8uYRGTwgY00gmPhNtgynqDLxc2xsgvZaMt3 c/ziwhNXCx7RlOQifczALIRqoXBFrMyuCIhetL4WNyAssM8w5MkhK30SlFV2k14HbApr cof4UfJFjKo/y4CXPnHF2KcFT9EKX7fdaM8yBeh4uvbuCME02lIk219Jugn0nTYfZlly KOUg== X-Forwarded-Encrypted: i=1; AJvYcCXajaE5jkJtcmxnbK3s0i8Aew0o8BI3egbCtORctvSGCPBtIf5zPHFUikEEME7zRk3vL1qMmdYQSGJ9IDKEjdN95slvLyaUr07VsU06 X-Gm-Message-State: AOJu0Yx9+eO6sogkiAjByJhypxJcA74bqCirKSuOSWsmil8/IVXRE32c 4phjuaZ+4ygybyQ2xhM46JBIv9Iue3SeeiPUhz4H7Nj6ah7w7//JY7SK3WXKmN4GOkJkPtrn8z7 oOe8WIw== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:77dc:144c:334e:e2dd]) (user=irogers job=sendgmr) by 2002:a25:abc5:0:b0:dc6:eea0:1578 with SMTP id v63-20020a25abc5000000b00dc6eea01578mr346976ybi.13.1709188380051; Wed, 28 Feb 2024 22:33:00 -0800 (PST) Date: Wed, 28 Feb 2024 22:32:46 -0800 Message-Id: <20240229063253.561838-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog Subject: [PATCH v3 0/7] Thread memory improvements and fixes From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Oliver Upton , Yang Jihong , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792213936223973824 X-GMAIL-MSGID: 1792213936223973824 The next 6 patches (now 7) from: https://lore.kernel.org/lkml/20240202061532.1939474-1-irogers@google.com/ now the initial maps fixes have landed: https://lore.kernel.org/all/20240210031746.4057262-1-irogers@google.com/ 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 threads 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. v3. Factor threads out of machine in 1 patch, then move threads functions in a second. v2: improve comments and a commit message. Ian Rogers (7): 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 machine: Move machine's threads into its own abstraction perf threads: Move threads to its own files perf threads: Switch from rbtree to hashmap perf threads: Reduce table size from 256 to 8 tools/perf/builtin-report.c | 217 +++++++++------- tools/perf/builtin-trace.c | 41 ++-- tools/perf/util/Build | 1 + tools/perf/util/bpf_lock_contention.c | 4 +- tools/perf/util/machine.c | 341 +++++++------------------- tools/perf/util/machine.h | 30 +-- tools/perf/util/rb_resort.h | 5 - tools/perf/util/thread.c | 2 +- tools/perf/util/thread.h | 6 - tools/perf/util/threads.c | 186 ++++++++++++++ tools/perf/util/threads.h | 35 +++ 11 files changed, 474 insertions(+), 394 deletions(-) create mode 100644 tools/perf/util/threads.c create mode 100644 tools/perf/util/threads.h