From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2CDF1C4321A for ; Wed, 3 Mar 2021 14:51:26 +0000 (UTC) Received: from shelob.surriel.com (shelob.surriel.com [96.67.55.147]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 63A1664E02 for ; Wed, 3 Mar 2021 14:51:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 63A1664E02 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=perches.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kernelnewbies-bounces@kernelnewbies.org Received: from localhost ([::1] helo=shelob.surriel.com) by shelob.surriel.com with esmtp (Exim 4.94) (envelope-from ) id 1lHSqF-0005CX-59; Wed, 03 Mar 2021 09:51:11 -0500 Received: from smtprelay0062.hostedemail.com ([216.40.44.62] helo=smtprelay.hostedemail.com) by shelob.surriel.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1lHSqD-0005CS-49 for kernelnewbies@kernelnewbies.org; Wed, 03 Mar 2021 09:51:09 -0500 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay04.hostedemail.com (Postfix) with ESMTP id 486F81800CDE0; Wed, 3 Mar 2021 14:51:05 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-HE-Tag: crib64_1f0b27a276c6 X-Filterd-Recvd-Size: 2443 Received: from [192.168.1.159] (unknown [47.151.137.21]) (Authenticated sender: joe@perches.com) by omf03.hostedemail.com (Postfix) with ESMTPA; Wed, 3 Mar 2021 14:51:04 +0000 (UTC) Message-ID: Subject: Re: linux-kernel janitorial RFP: Mark static arrays as const From: Joe Perches To: Rasmus Villemoes , kernelnewbies , kernel-janitors , cocci Date: Wed, 03 Mar 2021 06:51:02 -0800 In-Reply-To: References: <053b06c47f08631675c295b5c893b90be4248347.camel@perches.com> User-Agent: Evolution 3.38.1-1 MIME-Version: 1.0 Cc: LKML X-BeenThere: kernelnewbies@kernelnewbies.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Learn about the Linux kernel List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Errors-To: kernelnewbies-bounces@kernelnewbies.org On Wed, 2021-03-03 at 10:41 +0100, Rasmus Villemoes wrote: > On 02/03/2021 18.42, Joe Perches wrote: > > Here is a possible opportunity to reduce data usage in the kernel. > > = > > $ git grep -P -n '^static\s+(?!const|struct)(?:\w+\s+){1,3}\w+\s*\[\s*\= ]' drivers/ | \ > > =A0=A0grep -v __initdata | \ > > =A0=A0wc -l > > 3250 > > = > > Meaning there are ~3000 declarations of arrays with what appears to be > > file static const content that are not marked const. > > = > > So there are many static arrays that could be marked const to move the > > compiled object code from data to text minimizing the total amount of > > exposed r/w data. > = > You can add const if you like, but it will rarely change the generated > code. gcc is already smart enough to take a static array whose contents > are provably never modified within the TU and put it in .rodata: At least some or perhaps even most of the time, true, but the gcc compiler from v5 through at least v10 seems inconsistent about when it does the appropriate conversion. See the example I posted: https://lore.kernel.org/lkml/6b8b250a06a98ce42120a14824531a8641f5e8aa.camel= @perches.com/ It was a randomly chosen source file conversion btw, I had no prior knowledge of whether the text/data use would change. I'm unsure about clang consistently moving static but provably const arrays from data to text. I rarely use clang. At least for v11 it seems to be better though. I didn't try 10.1. _______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies