Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1656995pxm; Thu, 24 Feb 2022 07:08:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJx16IB1lJpV215ZqLHd8kpSHWnplzoc9gD4ghHqAmZiSc+Ggtbd8Xktlqk0rd3bzVkPOS9r X-Received: by 2002:a63:e59:0:b0:374:a169:d558 with SMTP id 25-20020a630e59000000b00374a169d558mr2599421pgo.304.1645715327253; Thu, 24 Feb 2022 07:08:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645715327; cv=none; d=google.com; s=arc-20160816; b=fdP9Skfi80eLXkl7PRSf/hxS7cZm6EI7QdHK9CwWQx+idf3hSiGiDYzOwcoR9errHB Gn2tUoFcGm1fT5Xwxh2DaDSvtNd4bxCTQa7QLWx3cWKi+6scj1NHDCy9yELS7HmXWDX+ nvup8yiitAU7qBmSpMQOfYWKv/0VqQE2XScWvJeykZvl5pSsfU0J0VbU41yCevW1gCJx VUJ5TEHI0DZK/Yq4yy7SLoIrMzs0JtL/YZvPHWc1f3gkpASAVKGpCkiLOJ+ND7diIprl zGfhQroq8DoAPRDn7TwNutIu34fIX8V5vxmEg78b4jANhk1pWTKM314a4OX6m04RftFA hGWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:feedback-id:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from; bh=kfd5voI3bt6+I/6cX/Q9UqpIm75WxiwyFckehjgHfGA=; b=YPnVE5k7j+ZD+vc1GSQJDHBuzEIxO7boeM5U11mpUkJR5eTTuT23dWtY+/KPC7RcqI UJtPEcUqAXfCzEXy+S02Ub3brX+oT3/OLBFdYdCAmdFKdwy+HhlT5doVwTH/2OxO2a01 WFm3gSXVsE686O8+bAxnEBu7nGRv9yslqlPkZvHXJB5a51E+3OR9bMH+YDu8v8a+R96o e5G6Nkq47NcErvSRkiM3gJm8EkZL8BMUQEYRKqlO/uiMZ3xow9GX1PCbNTr2reBq1I3X GFBDVEzcxJ0MToHvJeElki82l9VyN431JoKJOyfqRF3koswOmNrRHZ3LDrOQNPvZSdBG M+5Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b7-20020a17090aa58700b001b8a42457acsi5104932pjq.63.2022.02.24.07.08.23; Thu, 24 Feb 2022 07:08:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234048AbiBXNdU (ORCPT + 99 others); Thu, 24 Feb 2022 08:33:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235025AbiBXNdT (ORCPT ); Thu, 24 Feb 2022 08:33:19 -0500 Received: from smtpbg153.qq.com (smtpbg153.qq.com [13.245.218.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADB8F16DAEB for ; Thu, 24 Feb 2022 05:32:47 -0800 (PST) X-QQ-mid: bizesmtp70t1645709547tpwkhq7i Received: from localhost.localdomain (unknown [58.240.82.166]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 24 Feb 2022 21:32:20 +0800 (CST) X-QQ-SSF: 01400000002000B0F000B00A0000000 X-QQ-FEAT: /38I06TeVDt/A9RUhVZYOINAD/wPpx9pW1Fb3qmhzq4x7Q2Ua+MBKouMh0Uzn mF7ioiAmnlUyMwrWJmNKv+nmVGoBWKsVxjGl5q6nYE8pE+TExWnUpBh5SlcD/UZFVCM8Isk bRvIkO+BkFI+Vo+R9MC3qN9npU/RvArveLimfqrBtfH1aUfXiI8dUS4EHHNz68oxLxEUFUJ j4VSg9QJkWUkJBIMdt8Y2FgEob+tjpdKZ0jxDzHys7ObyddxOeYpBCEG5EBa7OsZwYK7XSy 3wxpQ7bLzxjCGFutx+fQbnjEOV6rtr4OuEtPMNineyYAsgPwEn3u+IcmfHlX0l7XI4xJ46X Ev8c7UftVm2ZQSwKxnjYepAa9bYffdyMQ1gKLRZqw1Q1vTfZvQ= X-QQ-GoodBg: 2 From: Meng Tang To: mcgrof@kernel.org, keescook@chromium.org, yzaikin@google.com Cc: guoren@kernel.org, nickhu@andestech.com, green.hu@gmail.com, deanbo422@gmail.com, ebiggers@kernel.org, tytso@mit.edu, wad@chromium.org, john.johansen@canonical.com, jmorris@namei.org, serge@hallyn.com, linux-csky@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Meng Tang Subject: [PATCH v3 1/2] fs/proc: Optimize arrays defined by struct ctl_path Date: Thu, 24 Feb 2022 21:32:16 +0800 Message-Id: <20220224133217.1755-1-tangmeng@uniontech.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:uniontech.com:qybgforeign:qybgforeign2 X-QQ-Bgrelay: 1 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Previously, arrays defined by struct ctl_path is terminated with an empty one. When we actually only register one ctl_path, we've gone from 8 bytes to 16 bytes. So, I use ARRAY_SIZE() as a boundary condition to optimize it. Since the original __register_sysctl_paths is only used in fs/proc/proc_sysctl.c, in order to not change the usage of register_sysctl_paths, delete __register_sysctl_paths from include/linux/sysctl.h, change it to __register_sysctl_paths_init in fs/proc/proc_sysctl.c, and modify it with static. The register_sysctl_paths becomes __register_sysctl_paths, and the macro definition is used in include/linux/sysctl.h to expand register_sysctl_paths(path, table) to __register_sysctl_paths(path, ARRAY_SIZE(path), table). Signed-off-by: Meng Tang --- fs/proc/proc_sysctl.c | 22 +++++++++++++--------- include/linux/sysctl.h | 9 ++++----- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 9ecd5c87e8dd..721a8bec63d6 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -1589,9 +1589,10 @@ static int register_leaf_sysctl_tables(const char *path, char *pos, } /** - * __register_sysctl_paths - register a sysctl table hierarchy + * __register_sysctl_paths_init - register a sysctl table hierarchy * @set: Sysctl tree to register on * @path: The path to the directory the sysctl table is in. + * @ctl_path_num: The numbers(ARRAY_SIZE(path)) of ctl_path * @table: the top-level table structure * * Register a sysctl table hierarchy. @table should be a filled in ctl_table @@ -1599,22 +1600,23 @@ static int register_leaf_sysctl_tables(const char *path, char *pos, * * See __register_sysctl_table for more details. */ -struct ctl_table_header *__register_sysctl_paths( +static struct ctl_table_header *__register_sysctl_paths_init( struct ctl_table_set *set, - const struct ctl_path *path, struct ctl_table *table) + const struct ctl_path *path, int ctl_path_num, struct ctl_table *table) { struct ctl_table *ctl_table_arg = table; int nr_subheaders = count_subheaders(table); struct ctl_table_header *header = NULL, **subheaders, **subheader; const struct ctl_path *component; char *new_path, *pos; + int i; pos = new_path = kmalloc(PATH_MAX, GFP_KERNEL); if (!new_path) return NULL; pos[0] = '\0'; - for (component = path; component->procname; component++) { + for (component = path, i = 0; component->procname && i < ctl_path_num; component++, i++) { pos = append_path(new_path, pos, component->procname); if (!pos) goto out; @@ -1663,20 +1665,22 @@ struct ctl_table_header *__register_sysctl_paths( /** * register_sysctl_paths - register a sysctl table hierarchy * @path: The path to the directory the sysctl table is in. + * @ctl_path_num: The numbers(ARRAY_SIZE(path)) of ctl_path * @table: the top-level table structure * * Register a sysctl table hierarchy. @table should be a filled in ctl_table * array. A completely 0 filled entry terminates the table. * - * See __register_sysctl_paths for more details. + * See __register_sysctl_paths_init for more details. */ -struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, +struct ctl_table_header *__register_sysctl_paths(const struct ctl_path *path, + int ctl_path_num, struct ctl_table *table) { - return __register_sysctl_paths(&sysctl_table_root.default_set, - path, table); + return __register_sysctl_paths_init(&sysctl_table_root.default_set, + path, ctl_path_num, table); } -EXPORT_SYMBOL(register_sysctl_paths); +EXPORT_SYMBOL(__register_sysctl_paths); /** * register_sysctl_table - register a sysctl table hierarchy diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h index 889c995d8a08..37958aeecfb5 100644 --- a/include/linux/sysctl.h +++ b/include/linux/sysctl.h @@ -219,13 +219,12 @@ extern void retire_sysctl_set(struct ctl_table_set *set); struct ctl_table_header *__register_sysctl_table( struct ctl_table_set *set, const char *path, struct ctl_table *table); -struct ctl_table_header *__register_sysctl_paths( - struct ctl_table_set *set, - const struct ctl_path *path, struct ctl_table *table); struct ctl_table_header *register_sysctl(const char *path, struct ctl_table *table); struct ctl_table_header *register_sysctl_table(struct ctl_table * table); -struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path, - struct ctl_table *table); +#define register_sysctl_paths(path, table) \ + __register_sysctl_paths(path, ARRAY_SIZE(path), table) +extern struct ctl_table_header *__register_sysctl_paths(const struct ctl_path *path, + int ctl_path_num, struct ctl_table *table); void unregister_sysctl_table(struct ctl_table_header * table); -- 2.20.1