From patchwork Mon Nov 27 21:34:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andi Kleen X-Patchwork-Id: 10078169 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8531E602BD for ; Mon, 27 Nov 2017 21:34:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75E182908C for ; Mon, 27 Nov 2017 21:34:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A7D12908F; Mon, 27 Nov 2017 21:34:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7F342908C for ; Mon, 27 Nov 2017 21:34:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752981AbdK0Veo (ORCPT ); Mon, 27 Nov 2017 16:34:44 -0500 Received: from mga05.intel.com ([192.55.52.43]:65529 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752325AbdK0Vem (ORCPT ); Mon, 27 Nov 2017 16:34:42 -0500 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Nov 2017 13:34:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,465,1505804400"; d="scan'208";a="12626826" Received: from tassilo.jf.intel.com (HELO tassilo.localdomain) ([10.7.201.35]) by orsmga002.jf.intel.com with ESMTP; 27 Nov 2017 13:34:30 -0800 Received: by tassilo.localdomain (Postfix, from userid 1000) id 9F7E83010A9; Mon, 27 Nov 2017 13:34:29 -0800 (PST) From: Andi Kleen To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, samitolvanen@google.com, alxmtvv@gmail.com, linux-kbuild@vger.kernel.org, yamada.masahiro@socionext.com, akpm@linux-foundation.org, Andi Kleen , viro@zeniv.linux.org.uk Subject: [PATCH 14/21] lto, fs: Avoid static variable in linux/fs.h Date: Mon, 27 Nov 2017 13:34:16 -0800 Message-Id: <20171127213423.27218-15-andi@firstfloor.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171127213423.27218-1-andi@firstfloor.org> References: <20171127213423.27218-1-andi@firstfloor.org> Sender: linux-kbuild-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kbuild@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Andi Kleen linux/fs.h has a initialized static variable kernel_read_file_str. It doesn't make much sense to have a static variable in a frequently included header file. With LTO -fno-toplevel-reorder gcc is unable to eliminate it, which leads to a lot of unnecessary duplicated copies. Move the static into the scope of the only inline that uses it, this tells the compiler enough to not duplicate it. Right now the inline is only called from one place, so that is ok. If it was called from more places would need to move it somewhere else to avoid unnecessary copies. With LTO this avoids ~100k unnecessary data segment for a x86 defconfig build. Even without LTO it doesn't make any sense. Cc: viro@zeniv.linux.org.uk Signed-off-by: Andi Kleen --- include/linux/fs.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/linux/fs.h b/include/linux/fs.h index 2995a271ec46..2f02f1c991c9 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2821,12 +2821,12 @@ enum kernel_read_file_id { __kernel_read_file_id(__fid_enumify) }; -static const char * const kernel_read_file_str[] = { - __kernel_read_file_id(__fid_stringify) -}; - static inline const char *kernel_read_file_id_str(enum kernel_read_file_id id) { + static const char * const kernel_read_file_str[] = { + __kernel_read_file_id(__fid_stringify) + }; + if ((unsigned)id >= READING_MAX_ID) return kernel_read_file_str[READING_UNKNOWN];