From patchwork Tue Nov 16 16:53:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1555954 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=tBDEThhg; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Htsbr10WVz9sR4 for ; Wed, 17 Nov 2021 03:54:32 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F1E60385AC3D for ; Tue, 16 Nov 2021 16:54:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F1E60385AC3D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1637081670; bh=TurB8ijN/mOUoxwEyaUdi6dD+qEmygTQpKCeLI8dDi4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=tBDEThhgeRUf1z16bQhgH9XkkRU53AcJwWWL5Q8KrH0/drDGYFTavQ4eWZRp1FgQb RTKguKJ7GqqOfpADKxlEcMH1AzATiEGM5Hr+jlSwakiL22W1RtD7jvYPe2R/UMDxxm Yk6siQK1sYf8+L1CEBN9Tl9oM80R6efTP1CQsA6w= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTPS id 03D023857405 for ; Tue, 16 Nov 2021 16:53:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 03D023857405 Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-467-cDOxe0xaNk6kI_Pqr48_yg-1; Tue, 16 Nov 2021 11:53:19 -0500 X-MC-Unique: cDOxe0xaNk6kI_Pqr48_yg-1 Received: by mail-qt1-f197.google.com with SMTP id u14-20020a05622a198e00b002b2f35a6dcfso3499427qtc.21 for ; Tue, 16 Nov 2021 08:53:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=TurB8ijN/mOUoxwEyaUdi6dD+qEmygTQpKCeLI8dDi4=; b=CwcD+Hsin7sYj8fp5NB2xxgMs3/jQUEvHy35V9ZhkaiuZ8/m1RD0kpeP/0OmZrsmWa 1dVWU5kDs9h4xXGg2kYJtrDjA9CthQ1fjo72SeQhv68GySAShDEhyns5cVj4xaxA4ewv i+vYj92TaKjuDN25ef9WSyIS5rOm76FDZUGjXxRBWMpiGHIcDZxfIoWgoDc1afnAmePz e1cwiBk1t2pzi1zlFPeT7D2sJTDRwYmh2p/6NlnkJH7+2WWQrJGBKiqmvQCJmsIAs4jq I1fI8GFmVnOFA/aH4g9v6/tuscrC9qB1QoAmqjScvZIJvRYIFZ0wbpWLwgz3VorcrDBG Rutg== X-Gm-Message-State: AOAM533j5Ugz8KAMDEBWcXXPDmy42VOqObSpTN1PYrHeKBKa1bDPFktq WqqCpgts5iD8HPH5kHkwW9dVrJe2dGljwwMkMVQ36j+e5T8/1DLRaVf342HoF5cjsAhFUg/ilMj Z/IP8xcykIzVynAYy2sbEs/5i6RWx7le384E1ZsanLsQovoPomOm3DwOGU00P7Jsang== X-Received: by 2002:a37:9686:: with SMTP id y128mr7430907qkd.523.1637081598574; Tue, 16 Nov 2021 08:53:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJzZyAeO9QKsFtSbuRRw1mBX8TCNYMYJsAXmXVilIE+geXHee/vea9wy30y1e2DDfFjle5RJ6g== X-Received: by 2002:a37:9686:: with SMTP id y128mr7430862qkd.523.1637081598030; Tue, 16 Nov 2021 08:53:18 -0800 (PST) Received: from barrymore.redhat.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id bm25sm8897151qkb.4.2021.11.16.08.53.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Nov 2021 08:53:17 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [PATCH RFC] c-family: don't cache large vecs Date: Tue, 16 Nov 2021 11:53:14 -0500 Message-Id: <20211116165314.3558115-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Patrick observed recently that an element of the vector cache could be arbitrarily large. Let's only cache relatively small vecs. This has no effect on compiling the libstdc++ stdc++.h, presumably because nothing in the library requires a vec that large. I figure that this makes it more likely that a subsequent long list will reuse the same memory when the later vec gets expanded. Does this make sense to others? gcc/c-family/ChangeLog: * c-common.c (release_tree_vector): Only cache vecs smaller than 16 elements. --- gcc/c-family/c-common.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) base-commit: 132f1c27770fa6dafdf14591878d301aedd5ae16 diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 436df45df68..90e8ec87b6b 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -8213,8 +8213,16 @@ release_tree_vector (vec *vec) { if (vec != NULL) { - vec->truncate (0); - vec_safe_push (tree_vector_cache, vec); + if (vec->allocated () >= 16) + /* Don't cache vecs that have expanded more than once. On a p64 + target, vecs double in alloc size with each power of 2 elements, e.g + at 16 elements the alloc increases from 128 to 256 bytes. */ + vec_free (vec); + else + { + vec->truncate (0); + vec_safe_push (tree_vector_cache, vec); + } } }