From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 6EB28385414C for ; Mon, 10 Oct 2022 15:10:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6EB28385414C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665414621; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=TpRBARO4jkf2Gyn07FkksevF9cZn8iwiLtsu4Js8XTw=; b=in7gN3f4QnwqPvgHN4Qp4967ce3xioTb3Qc/kTV135x5YDXNN9h6PKbp4njFUsQ2jKO85m Dya5SegI3UyUzDDc35q3L1eGR3SdumkYjn4kNd3q5n/yrJTKwYBvBLa2FXwIGaKa1GGLOm i24PmK9/g6mBBOvuORZvO6P2CWVA5KU= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-501-4FDa1o2fP0Wc8JtBRuedvw-1; Mon, 10 Oct 2022 11:10:20 -0400 X-MC-Unique: 4FDa1o2fP0Wc8JtBRuedvw-1 Received: by mail-qk1-f199.google.com with SMTP id j13-20020a05620a410d00b006e08208eb31so9419696qko.3 for ; Mon, 10 Oct 2022 08:10:20 -0700 (PDT) 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=TpRBARO4jkf2Gyn07FkksevF9cZn8iwiLtsu4Js8XTw=; b=RXicpJc6m7PNPtu1GdU87NW7DMO6EwinjNGqK2tqTFiX6jmxofXnA4x3usBf6nQ/43 82MwOEg6Ijh7mrtck0xfpY451wD5oq1eUSugJVXH5nTfb0eDD1xbusax6phBC0ePcvt9 mdZs2vV9QrU8zuQJSfkNmaWKOT8aHsNiDCRgGlakiwciYjVb/A2ecnpfGYimgzIuCxe2 Lv8VxvrHzmOHxP8uCO0wKGbZm3+abMDp4UAN3GAYUbDllOdKzggA3fKFatd0fJieBPrT J0bEbmnUuZPMgsDO703AN6CysyHNSCRPC4txLgJmgzjH8PMbpjbCgEwYKcLY5fuYFYAQ 0xWA== X-Gm-Message-State: ACrzQf3EEgt9CegHMxhpsrMRaTgsAVf3AE9vuarKAL91Pfykcs59BicT QCd1X/RGOWh19dHP5e0XypumBRU/tn7rwyA0PB3E6CbIKp1DrNjA9K3E3J5LU6IsWVnyC7nfcMb A1urq3ThwKXfi6GGhJ0I0AG99NwGlGE8= X-Received: by 2002:a05:620a:4709:b0:6ce:cb19:3eb2 with SMTP id bs9-20020a05620a470900b006cecb193eb2mr12995313qkb.272.1665414619997; Mon, 10 Oct 2022 08:10:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5eaD4jIVhGWpJ3SlP3MHoKJGF+zczIHV3Q0tMe52Z3PNgy4dylDtXq/nbEn8No2OymBIgFA0DnOHY8qqlI6pU= X-Received: by 2002:a05:620a:4709:b0:6ce:cb19:3eb2 with SMTP id bs9-20020a05620a470900b006cecb193eb2mr12995289qkb.272.1665414619621; Mon, 10 Oct 2022 08:10:19 -0700 (PDT) MIME-Version: 1.0 References: <20221007155452.1299670-1-jwakely@redhat.com> In-Reply-To: From: Jonathan Wakely Date: Mon, 10 Oct 2022 16:10:08 +0100 Message-ID: Subject: Re: [PATCH] libstdc++: Allow emergency EH alloc pool size to be tuned [PR68606] To: Richard Biener Cc: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=unavailable 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, 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. 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.