From patchwork Tue Jul 31 07:05:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver O'Halloran X-Patchwork-Id: 951440 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41fnXB6SCxz9ryn for ; Tue, 31 Jul 2018 17:05:46 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="tuLOxcU9"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41fnXB4KyZzF15L for ; Tue, 31 Jul 2018 17:05:46 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="tuLOxcU9"; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400e:c01::244; helo=mail-pl0-x244.google.com; envelope-from=oohall@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="tuLOxcU9"; dkim-atps=neutral Received: from mail-pl0-x244.google.com (mail-pl0-x244.google.com [IPv6:2607:f8b0:400e:c01::244]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41fnX41RPpzF14l for ; Tue, 31 Jul 2018 17:05:39 +1000 (AEST) Received: by mail-pl0-x244.google.com with SMTP id z7-v6so6736404plo.9 for ; Tue, 31 Jul 2018 00:05:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=xXc2cqX1nPP2dGAHNWGIDPM88gdRBtc2FXgsC/cdEHw=; b=tuLOxcU94WTFtjw3CwjFUTGxJ7ltjdkKzDn1X4EKT9A2G8Czg6pgGStABQxWH69iq8 5RR29O2SccOsGnS78MI9yfopHKH6QQkdq67eYS5TJ/BWYJetOGu5/j27q7NjLVhR0Tyr u3S2d1DPZsJMmuFlgRu275me2SFT3PuqadTB228pr2GOlT7g9cXeMsArFfkkLeeMB8RP NoiGf125FcX0SXfUH5v/BGfJZbEtRzgFCR+OQsKCYUok8JgQaxLDzm4KEycCpXKwtt2I +8eqw1GaHZt5A4cZUmTlyXjoIbu4/RvfAqusqzdeX4pJrAX3O83FpNO2GKuEolZtE/lt x/rA== 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=xXc2cqX1nPP2dGAHNWGIDPM88gdRBtc2FXgsC/cdEHw=; b=Biq954nVL/pHXPW42gKnNdNmnqoHIg8huNSX/LD59C4L9pUoa8p6J3OcrsT16+Z5tv JdGEYfXKm9Q9Ra9sbf3LqEXIQfxUO1hn1hAozLzCMzqoKES09O+HBrK1z3WhADfxYXPb MSVRQZ3sRBBBHNt4FNfwIVnRgiEVWVFsDF6GY8QUkRKsJ3+9frsFoCLtL0fA8s/TLh5U eP2VyLTof/R6NJW7xc7rA7EUQcTEu7Z3O8F+ZDWDfV24r4FSI4DIYt+NR6RQuenOXQGX PlwyFxy8i83rnnm0HWa8KRHgP7PWJf1kPZ0wn6hIfU8Whlb4jCEi31ltIsMrDttnaG5r nY4A== X-Gm-Message-State: AOUpUlH73BtZ+RpvzrHwlABmm0AZbnkfwUZKFNHx/AgRLMJGeDxtWvJt zh/f4cuZFt76VJZQCZX5SAPhjIlC X-Google-Smtp-Source: AAOMgpfUJLIF5gE64IRVe24PyUjn25YHvKpwBK1C1NtbD9Rhqyb+cw817uP7DvTTUW4r8gbeOj4AFg== X-Received: by 2002:a17:902:740b:: with SMTP id g11-v6mr19438759pll.85.1533020738116; Tue, 31 Jul 2018 00:05:38 -0700 (PDT) Received: from flat-canetoad.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id f3-v6sm13993641pgq.49.2018.07.31.00.05.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 31 Jul 2018 00:05:37 -0700 (PDT) From: Oliver O'Halloran To: skiboot@lists.ozlabs.org Date: Tue, 31 Jul 2018 17:05:27 +1000 Message-Id: <20180731070527.17632-1-oohall@gmail.com> X-Mailer: git-send-email 2.9.5 Subject: [Skiboot] [PATCH v2] mem_region: Merge similar allocations when dumping X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Currently we print one line for each allocation done at runtime when dumping the memory allocations. We do a few thousand allocations at boot so this can result in a huge amount of text being printed which is a) slow to print, and b) Can result in the log buffer overflowing which destroys otherwise useful information. This patch adds a de-duplication to this memory allocation dump by merging "similar" allocations (same location, same size) into one. Unfortunately, the algorithm used to do the de-duplication is quadratic, but considering we only dump the allocations in the event of a fatal error I think this is acceptable. I also did some benchmarking and found that on a ZZ it takes ~3ms to do a dump with 12k allocations. On a Zaius it's slightly longer at about ~10ms for 10k allocs. However, the difference there was due to the output being written to the UART. This patch also bumps the log level to PR_NOTICE. PR_INFO messages are suppressed at the default log level, which probably isn't something you want considering we only dump the allocations when we run out of skiboot heap space. Signed-off-by: Oliver O'Halloran --- v2: Only perform the dump on the first allocation failure rather than every time. This allows us to extract useful debug information when there is an allocation failure without spamming the console too much. Fixed some 80 cols junk. --- core/mem_region.c | 49 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/core/mem_region.c b/core/mem_region.c index 0051ea6ece61..bd387f3c3773 100644 --- a/core/mem_region.c +++ b/core/mem_region.c @@ -96,7 +96,8 @@ static struct mem_region skiboot_cpu_stacks = { struct alloc_hdr { bool free : 1; bool prev_free : 1; - unsigned long num_longs : BITS_PER_LONG-2; /* Including header. */ + bool printed : 1; + unsigned long num_longs : BITS_PER_LONG-3; /* Including header. */ const char *location; }; @@ -285,7 +286,7 @@ static bool region_is_reserved(struct mem_region *region) void mem_dump_allocs(void) { struct mem_region *region; - struct alloc_hdr *hdr; + struct alloc_hdr *h, *i; /* Second pass: populate property data */ prlog(PR_INFO, "Memory regions:\n"); @@ -301,11 +302,40 @@ void mem_dump_allocs(void) prlog(PR_INFO, " no allocs\n"); continue; } - for (hdr = region_start(region); hdr; hdr = next_hdr(region, hdr)) { - if (hdr->free) + + /* + * XXX: When dumping the allocation list we coalase allocations + * with the same location and size into a single line. This is + * quadratic, but it makes the dump human-readable and the raw + * dump sometimes causes the log buffer to wrap. + */ + for (h = region_start(region); h; h = next_hdr(region, h)) + h->printed = false; + + for (h = region_start(region); h; h = next_hdr(region, h)) { + unsigned long bytes; + int count = 0; + + if (h->free) continue; - prlog(PR_INFO, " 0x%.8lx %s\n", hdr->num_longs * sizeof(long), - hdr_location(hdr)); + if (h->printed) + continue; + + for (i = h; i; i = next_hdr(region, i)) { + if (i->free) + continue; + if (i->num_longs != h->num_longs) + continue; + if (strcmp(i->location, h->location)) + continue; + + i->printed = true; + count++; + } + + bytes = h->num_longs * sizeof(long); + prlog(PR_NOTICE, " % 8d allocs of 0x%.8lx bytes at %s (total 0x%lx)\n", + count, bytes, hdr_location(h), bytes * count); } } } @@ -439,6 +469,7 @@ found: void *mem_alloc(struct mem_region *region, size_t size, size_t align, const char *location) { + static bool dumped = false; void *r; assert(lock_held_by_me(®ion->free_list_lock)); @@ -449,7 +480,11 @@ void *mem_alloc(struct mem_region *region, size_t size, size_t align, prerror("mem_alloc(0x%lx, 0x%lx, \"%s\", %s) failed !\n", size, align, location, region->name); - mem_dump_allocs(); + if (!dumped) { + mem_dump_allocs(); + dumped = true; + } + return NULL; }