From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by sourceware.org (Postfix) with ESMTPS id 36B453858CD1 for ; Thu, 11 Apr 2024 17:23:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 36B453858CD1 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 36B453858CD1 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1712856234; cv=pass; b=dqGT6s0A8pkpU0+jgUL4GbAMTHkg/iP4B0v9f4eRukcswZXdJWT4YLw+5aVX8Slu1l19rYPjZ12/7rgzDv41lMHN+hKMJ6ZdZuta0dhjiK06RFJTjvUWjjs/ei+kqsqUd+kp1dNp9QNYrU6fWsfzSs/VudtCYALEluRfjSl5r78= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1712856234; c=relaxed/simple; bh=fW0TJ29TxQ5jh5t9gXadsa0nTaCM6NzO38KIa+HBJZg=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=D421OTI5ycYqpveVQ+YtgpqNBCSK/yQzowS+lZ62E71pKSSO6dQw7q/uuteP/kNF1Bhy0fVSE0Jr9c8QNWo/QqArCuYYCM9r46xXA2vTh5vqVEpTYUEEz1CrrTTOhMFqFc4dcz3wSgfw8J0o7lDjxO/3DGfrkG+NjWFsuttLzto= ARC-Authentication-Results: i=2; server2.sourceware.org Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43BGtBwd012519 for ; Thu, 11 Apr 2024 17:23:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=references : from : to : cc : subject : in-reply-to : date : message-id : content-type : mime-version; s=corp-2023-11-20; bh=2n92FHbcEy3H7BaCWGSQSfyjMW6oklbsqqcgYbXKh/A=; b=LkG1FlDg0AGBIR6aBiSsby7K2a+ezUnRhyEc9Bto4W49TsaukTz3ZCEUenFHn8eyrBxN ekN55y+ia9Y2xqcrPwC8o3mV/gY6Nq9Axd91RpTJZh8lKXL0J13nHJPBh1qfF7TmALUq 1swnN+h+7z/hMFzEfbkEMXFX/t4T0WLYwyz5Lk9b1D4t/HGf65z16DYS1i4ELHP94/up 9oS9dV+CM8+ZKz5QeROOi20DO1yHNbdRbbw2jIHLqjes8RR/S6s1jcnG7vFrTWLoffy4 IfwW7K8YHXAxvdjPRyJxcr4rK8njB76JPDWO9hgMbN3HrT2+lBBv9uwafhc9I7jcfvpa mg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xax0ut5gk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 Apr 2024 17:23:51 +0000 Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43BGKH2o010627 for ; Thu, 11 Apr 2024 17:23:50 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2101.outbound.protection.outlook.com [104.47.55.101]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xavu9uc43-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 11 Apr 2024 17:23:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BU2WerU+NJnpY9rJUrEI2XnAm+pg+hhsigFqQLNAqCIywu5t8m9FAplIbvjsoMc6UjVEaJ/NwxZ065rX1EAqI39aqMh8VcxTjg4N8xBV+H4yOkm9HDgX2ddJFiu+RMuEQhhIc7GWuguZA+Pbh37y/P1lwax3rDR6QfxyctRINwsAQ+Z8vaQmD7QTdGAc9ual9np0kilVJjOzvS6i5F5kFXGjfVrGktom7OrMSwg3XWpscq7XL46EmbsdwDLiZ9yevnw1hsvgaR4LMDKhBNqBNXxzVBEWZGGidYre1hed+2ek3O+kyTwt9SSVRxvxTC4UbxHkTsR7tn8qN6q/ZqljHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=2n92FHbcEy3H7BaCWGSQSfyjMW6oklbsqqcgYbXKh/A=; b=jFrgZAXW2TlCgOtVAEjZTTFLRWMOHT2u8qPP3RDn/j1paduzk53zk21B4MXRaOi2F2540ngeWKZwqAALsFG2W8o4aOodV+0OkflT8p+Wr63/2CJvvHOiNhu5jPatsWOuqv/qcJDRki9G5UZ82+zK4uu/Q1mVUxBSuB75xmXrEtnPIazyX6arYfaz/CYmD8BwasWowQ1IL1o4JSwIuAKi5A05GuKAqA/wVGhQx51+10SVajXPdXRs2sb5xyp+nzyuc2h5v1Yk1rGPSatfCtVLgzvyVytaDR8tMGno7NSLRZqCMrL97A9tr9oGp6zWFt72JacaqtX/QD0JRlOl5R0Hhg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2n92FHbcEy3H7BaCWGSQSfyjMW6oklbsqqcgYbXKh/A=; b=AV4DMpCZks7Gq60brLrXWZS7LGbrlcW5lxtvM3lPuLdMqzrmqVDO+IJ5qV++OMOJEigJN4e7sX+VgbUTwKssVbQwjB0cj5DkoVUlW/It3R4CtqVPi4F9ILiSyQAu+3bNqoPSs9MgZdch2ukpRN8mMMDeefZKkOI9tGAUaReQdaA= Received: from MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) by DS0PR10MB7152.namprd10.prod.outlook.com (2603:10b6:8:f1::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.55; Thu, 11 Apr 2024 17:23:47 +0000 Received: from MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::1e11:7917:d2c:e44c]) by MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::1e11:7917:d2c:e44c%4]) with mapi id 15.20.7409.053; Thu, 11 Apr 2024 17:23:47 +0000 References: <20240411111118.215612-1-cupertino.miranda@oracle.com> <20240411111118.215612-2-cupertino.miranda@oracle.com> <7365c55a-9704-46e8-8413-42e88a865a73@oracle.com> User-agent: mu4e 1.4.15; emacs 28.1 From: Cupertino Miranda To: David Faust Cc: gcc-patches@gcc.gnu.org, jose.marchesi@oracle.com, elena.zannoni@oracle.com Subject: Re: [PATCH 2/3] bpf: remove huge memory waste with string allocation. In-reply-to: <7365c55a-9704-46e8-8413-42e88a865a73@oracle.com> Date: Thu, 11 Apr 2024 18:23:42 +0100 Message-ID: <87h6g7zuch.fsf@oracle.com> Content-Type: text/plain X-ClientProxiedBy: LO4P123CA0635.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:294::12) To MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB4382:EE_|DS0PR10MB7152:EE_ X-MS-Office365-Filtering-Correlation-Id: 1d069a29-84b1-43a7-518f-08dc5a4c2572 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: G3NCRbqhUPqTOctYIYiWE1gyq6eELyK58BwDzR7bt7pa4YVWOl3L+KyzP7Z+f5w/EAdLSlEPRZmEH5geKOw7Zf7+M6z+InwXpijEcUHn5Sd/uvvrFYhPPlTQKG+AQqYf4Jqov/FEJh1Pvte9OIf+DZ3Qp3pRFdmwfZ30Pf15e/0ysBKiDpACHV0+PToTiPNnVGxTfaJkwUBfUSD3eFoFHFQtSddMADnwYnG6CMRID+H4L/79DSILZqYW0M/6+pqocUK+Bl0MbbY5n46KaRZX4JP39C1Oo8znte/smAIn4oF3WCGePWZ9uWCQpy7Im5Wfu8FHDpzihV+7v0oDYqmH0MWLdpsh7LH/9THdUUtQa+EVD2RWK5dGxkm+uR81kP4mPiATh0HPM74tESbMFV3MzHCtDFPZ9XGzF6VGH/Iw1XHo7hO10zgz06nmsiFMdYjR6wTKDBK+g6k4Vmd3VIMI1Ref6eXAwspVZdqEDHNvSNeOivvTox4q+Bc9RRsCjKO8tzeHhnwFd3DdgnFpJXfZuc30yjYJwjq2Sw/A0LD+OsSvc7y0wqxPwa6MYr0zvNHTYRhviHvMLlctQ9jPPYoyJsl6sQUbh7MNImCzCtqKNpBmvGpHCNfMBsWBE8JlLGALYUZCEtHfjaDRw3wL1UzgNoMEdqqtOB0lf85x58J8FwI= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR10MB4382.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(366007)(376005)(1800799015);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-Ant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NpE9BJaO6/35kFTcFiTK0GW7bHAwZ+OoblDk?= =?us-ascii?Q?r7oHlV+V+YPdLYkrRiyM12xeR+DhQ939snfOFTPaSG4BCceaTmvksyOlciUt?= =?us-ascii?Q?WUa6wjhXPemnzALMR+kIrJfNQtpQ+ZvLlViZQQEKZ/0kI25j8nKzMx8sJl3t?= =?us-ascii?Q?g6uGNv98T8MwKHMG/O2MD17dco3sLDHTC2p/txo0irEgrWjAW/W1V4Ztylho?= =?us-ascii?Q?aoCbToLXHob9egCYP4dqFoO85Ye6iuuUJTETUMPNQeWWLrpnblyeeR3TWGoK?= =?us-ascii?Q?FrOPJMxKwUnIacpcoDnUQm9YHlPkyQsiPiP6Qih0zAhxHo3gf9kL/3FpnFlI?= =?us-ascii?Q?5CqcI2defKJWhzsQiD35fHk25U5+aY8D1XV+FlufZi+Q2j5tSFc8H3It+Wpj?= =?us-ascii?Q?U3CnqvdzKj0x8MN8P1JDa+SsesGt6Z2w08pjFjFU0FajTjX+X0Klgdw/JCcO?= =?us-ascii?Q?/xXCjh/N+auxuiCSKFOlXAN1da8uCBsU5CfLLumf1dANPLVg3d6XdDDga0GE?= =?us-ascii?Q?Fx5s7xU0ioMS4kFDzHDUXYQbmPkrRHIrXKs+IiYIqP2Fift4bbi2R17A066M?= =?us-ascii?Q?fJ22N+EJfQjQ8zbNrbevSywtaOg2E21AzuwFNAfD5e/bA+0EbSqmzxEi6Vox?= =?us-ascii?Q?rqxEx78qer1QiSelqoeq/gFvu2j/DLBiQWmFHGmbXwAcEtaogLse6R4h4u06?= =?us-ascii?Q?Gsx8cg3kdtT3FvY1vzjdHgTN5TMSMWinG0yJ/cTnYIuUR1NhYEFYZpjsJTcI?= =?us-ascii?Q?ccVRBIFSbFYl0HDqy//lE1E=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: uRS7gY+B5/aa4jw2+05iohCRewji5kpkZPLEmM1DSQftWKsR9eR/lpZApk47tg2ACnbzGYE1CjjzlXr9t5fIpDEA16+GHUfL1Uqejt+ADaQBL3x8XG8BXCP1uqUF3R36jNVwy9D838bpOFHpOGhepUe4HQYy/8daFii9D1qPPTuv5zNps5I7ph/kvCCrZ2ITJo9SMA6YxyPpqR7rVyWitLc6OXdrk1HSgFqRG/N2bgxWj5HrlCL1zXn1KpSiTKRbB8NRfA+7OqalfMwZI3JZpN8s5qdH5/csHopLFFhINt5h0Jt1yuxD0U5aekVjLSO/es4LVcXXUOhO22WnYHwQhtq+56NfieIS7oZvAaZ5wbetsbsN/f34K9/mR92LASVGUPlfOcT6XDD2BvJd0dIxNjj9CvuYN4yloCvEBAx5k8aKyyvg4RGJbx49BO7jIuc/UUF4LTWUFW1nFqHGYIL+Ap2wdXd3UzwY3twvjVIrZbutOHOWhirjd2lrMhVOg8YqKtV7quLEC2iOcmYCaUL+O58WCcN/7br1F2gysGg+x6Hh4pKk4pDF9I/PptH/0xrw8vDh+1wP+ciTp08PaMRGAW5Cq7gf2zWLJyNKiHPT6yQ= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1d069a29-84b1-43a7-518f-08dc5a4c2572 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4382.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2024 17:23:47.4430 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: l4vp22Uo0SRjZh3pomRm6pkYVfDdUu/buArzRmdj6mKAuv0C0nON8sNAJ3B7eiBoOxRvSLaoIE+EKagU7EIg1s16n5oX0wxwEzEfBZfXgic= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB7152 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-11_10,2024-04-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 suspectscore=0 spamscore=0 mlxscore=0 bulkscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404110126 X-Proofpoint-GUID: LBc9qZRqCyDwRh8L-WoXx9ohfc6THfew X-Proofpoint-ORIG-GUID: LBc9qZRqCyDwRh8L-WoXx9ohfc6THfew X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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: Hi David, Thanks for the review. Will apply the changes. Nice catch and optimization with the vlen size. Cupertino David Faust writes: > Hi Cupertino, > > On 4/11/24 04:11, Cupertino Miranda wrote: >> Code was allocating way too much space for the string. > > A little bit more description would not hurt. Perhaps you could say > something like: > "The BPF backend was allocating an unnecessarily large string when > constructing CO-RE relocations for enum types." > >> >> gcc/ChangeLog: >> * config/bpf/core-builtins.cc (process_enum_value): Corrected >> string allocation. > > nit: present tense, i.e. "Correct" rather than "Corrected" > >> --- >> gcc/config/bpf/core-builtins.cc | 7 ++++--- >> 1 file changed, 4 insertions(+), 3 deletions(-) >> >> diff --git a/gcc/config/bpf/core-builtins.cc b/gcc/config/bpf/core-builtins.cc >> index e03e986e2c1..ead1777d465 100644 >> --- a/gcc/config/bpf/core-builtins.cc >> +++ b/gcc/config/bpf/core-builtins.cc >> @@ -872,10 +872,11 @@ process_enum_value (struct cr_builtins *data) >> { >> if (TREE_VALUE (l) == expr) >> { >> - char *tmp = (char *) ggc_alloc_atomic ((index / 10) + 1); >> + /* Array size is 21 = ceil(log_10(2^64)) + 1 to hold string >> + representations of 64 bit integers. */ >> + char tmp[21]; >> sprintf (tmp, "%d", index); > > It looks like `index' is an `unsigned int', so this sprintf should use > %u rather %d, no? > > Also, it occurs to me that the `vlen' of BTF types is only 16 bits, so > BTF has no way currently to represent enums with more than 65535 > enumerators. It may be worth adding a sanity check to bail out (error) > here if we're going to claim an index higher than that. And if that is > validated before the printf, the buffer can be 6 bytes ("65535\0"). > >> - ret.str = (const char *) tmp; >> - >> + ret.str = CONST_CAST (char *, ggc_strdup(tmp)); >> break; >> } >> index++;