From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id 62D623858C2D; Tue, 11 Oct 2022 06:41:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 62D623858C2D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-x62c.google.com with SMTP id sc25so23122866ejc.12; Mon, 10 Oct 2022 23:41:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=yZtmFfRhcu3seTwMJOXDnpwjQ15KLd/COmWixILI+Uc=; b=SqyhDMWyN7FXA0m/ALAZxEntLEhg/A0wdzXkUz5Q8JyvC4fxkHDeIcqZ3SU0kka4yV OOKGg60jNOm3Q/PtL2NsRzLvt9Dz+qpJxCIN8NATUOB1VnqmMaPFd2siU30ACb7OyF8r m8RkiQFx6k8qIoZjhAUJY4s6lnu9qN8aEpQfY/R7h68mhIaoYtoiucqtBfBXTQOYjJFC M4jFzaZ7CSNeo38wgFY+mKC8qobarDNr07O8fZME3dJ4Mf6uCwB5YeMgyYbYVyfXQ/GZ oFIuqzqB9q5mJoqBm+zn0z9pU9XEc+NEPwMgrPKtmpMhZ415aOr69gv4WPfPSlOROvRw lg9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=yZtmFfRhcu3seTwMJOXDnpwjQ15KLd/COmWixILI+Uc=; b=txwaPoF+zGqQ634h18Q+r3Q7zTNn1cZr39y2/MVxl9BvaRX/bERy+xdO3C8ccB7p2t 5JxBHMIX0/EQrJ/bcj6bwQAHyXKAaOJCGGgMHzELSc49zybgoeMQfl3lPI8mdsQg/+sf GGMFtZFiiv/3RIjHpy45z+YssS155xUOd0Ei3ZDvoSteNSKP9irL0tzoZF651bHKYmnZ z6WzZrVq98P79MtqRRshd6upsVpFYiziFiY2elrlrhVfxAQKr2GvLvyHSHqBAYBXDaBK 9RXR2bnpRVvPvcV4EOvZWFlUmEqQ/JrwyrEZtyWg/LXQWULaVvrWZyMN9FBIrjmd+zdo SxNw== X-Gm-Message-State: ACrzQf1V2GBStjRs0akvKqNqLtucSBEIW/Tht4+hCq+8Fx1NvoSPTHjg bCKuri8JDMo9r2qpkI3zkwhfGKPSnisSEoFqaMo= X-Google-Smtp-Source: AMsMyM42sAMwmKSHkEurB9yhGFlItGXzJj2jggNKBy495YTWiWf0A3BH61IIweEUyIj/Io+e6xihHnO8AJZZGrS5hhQ= X-Received: by 2002:a17:906:8251:b0:781:8016:2dc9 with SMTP id f17-20020a170906825100b0078180162dc9mr17944594ejx.488.1665470494892; Mon, 10 Oct 2022 23:41:34 -0700 (PDT) MIME-Version: 1.0 References: <20221007155452.1299670-1-jwakely@redhat.com> In-Reply-To: From: Richard Biener Date: Tue, 11 Oct 2022 08:41:22 +0200 Message-ID: Subject: Re: [PATCH] libstdc++: Allow emergency EH alloc pool size to be tuned [PR68606] To: Jonathan Wakely Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Mon, Oct 10, 2022 at 5:10 PM Jonathan Wakely wrote: > > On Mon, 10 Oct 2022 at 12:17, Jonathan Wakely wrote: > > > > On Mon, 10 Oct 2022 at 07:18, Richard Biener wrote: > > > > > > On Fri, Oct 7, 2022 at 5:55 PM Jonathan Wakely via Gcc-patches > > > wrote: > > > > > > > > This needs a little more documentation (see the TODO in the manual), > > > > rather than just the comments in the source. This isn't final, but I > > > > think it's the direction I want to take. > > > > > > > > -- >8 -- > > > > > > > > Implement a long-standing request to support tuning the size of the > > > > emergency buffer for allocating exceptions after malloc fails, or to > > > > disable that buffer entirely. > > > > > > > > It's now possible to disable the dynamic allocation of the buffer and > > > > use a fixed-size static buffer, via --enable-libstdcxx-static-eh-pool. > > > > This is a built-time choice that is baked into libstdc++ and so affects > > > > all code linked against that build of libstdc++. > > > > > > > > The size of the pool can be set by --with-libstdcxx-eh-pool-obj-count=N > > > > which is measured in units of sizeof(void*) not bytes. A given exception > > > > type such as std::system_error depends on the target, so giving a size > > > > in bytes wouldn't be portable across 16/32/64-bit targets. > > > > > > > > When libstdc++ is configured to use a dynamic buffer, the size of that > > > > buffer can now be tuned at runtime by setting the GLIBCXX_TUNABLES > > > > environment variable (c.f. PR libstdc++/88264). The number of exceptions > > > > to reserve space for is controlled by the "glibcxx.eh_pool.obj_count" > > > > and "glibcxx.eh_pool.obj_size" tunables. The pool will be sized to be > > > > able to allocate obj_count exceptions of size obj_size*sizeof(void*) and > > > > obj_count "dependent" exceptions rethrown by std::rethrow_exception. > > > > > > > > With the ability to tune the buffer size, we can reduce the default pool > > > > size. Most users never need to throw 1kB exceptions in parallel from > > > > hundreds of threads after malloc is OOM. > > > > > > But does it hurt? Back in time when I reworked the allocator to be less > > > wasteful the whole point was to allow more exceptions to be in-flight > > > during OOM shutdown of a process with many threads. > > > > It certainly hurts for small systems, but maybe we can keep the large > > allocation for 64-bit targets (currently 73kB) and only reduce it for > > 32-bit (19kB) and 16-bit (3kB IIRC) targets. > > Maybe this incremental diff would be an improvement: > > @@ -90,7 +90,7 @@ using namespace __cxxabiv1; > // Assume that the number of concurrent exception objects scales with the > // processor word size, i.e., 16-bit systems are not likely to have hundreds > // of threads all simultaneously throwing on OOM conditions. > -# define EMERGENCY_OBJ_COUNT (8 * __SIZEOF_POINTER__) > +# define EMERGENCY_OBJ_COUNT (4 * __SIZEOF_POINTER__ * __SIZEOF_POINTER__) > # define MAX_OBJ_COUNT (16 << __SIZEOF_POINTER__) > #else > # define EMERGENCY_OBJ_COUNT 4 > > This makes it quadratic in the word size, so on 64-bit targets we'd > have space for 256 "reasonable size" exceptions (and twice as many > single word exceptions like std::bad_alloc), but only 64 on 32-bit > targets, and only 16 on 16-bit ones. So can we then commonize some of the #defines by using sizeof(void *) (taking pointer size as word size?) > > This slightly increases the initial allocation on x86_64 from 72,704 > bytes to 73,728 bytes, but reduces 32-bit from 18,944 bytes to 12,800. > If more is needed, it can be chosen via configure or the environment. >