Skip to content

Commit 4a7b29f

Browse files
t-8chJoelgranados
authored andcommitted
sysctl: move sysctl type to ctl_table_header
Move the SYSCTL_TABLE_TYPE_{DEFAULT,PERMANENTLY_EMPTY} enums from ctl_table to ctl_table_header. Removing the mutable member is necessary to constify static instances of struct ctl_table. Move the initialization of the sysctl_mount_point type into init_header() where all the other header fields are also initialized. As a side-effect the memory usage of the sysctl core is reduced. Each ctl_table_header instance can manage multiple ctl_table instances and is only allocated when the table is actually registered. This saves 8 bytes of memory per ctl_table on 64bit, 4 due to the enum field itself and 4 due to padding. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Signed-off-by: Joel Granados <j.granados@samsung.com>
1 parent eb32d3a commit 4a7b29f

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

fs/proc/proc_sysctl.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static const struct inode_operations proc_sys_dir_operations;
3131

3232
/* Support for permanently empty directories */
3333
static struct ctl_table sysctl_mount_point[] = {
34-
{.type = SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY }
34+
{ }
3535
};
3636

3737
/**
@@ -49,11 +49,11 @@ struct ctl_table_header *register_sysctl_mount_point(const char *path)
4949
EXPORT_SYMBOL(register_sysctl_mount_point);
5050

5151
#define sysctl_is_perm_empty_ctl_header(hptr) \
52-
(hptr->ctl_table[0].type == SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY)
52+
(hptr->type == SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY)
5353
#define sysctl_set_perm_empty_ctl_header(hptr) \
54-
(hptr->ctl_table[0].type = SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY)
54+
(hptr->type = SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY)
5555
#define sysctl_clear_perm_empty_ctl_header(hptr) \
56-
(hptr->ctl_table[0].type = SYSCTL_TABLE_TYPE_DEFAULT)
56+
(hptr->type = SYSCTL_TABLE_TYPE_DEFAULT)
5757

5858
void proc_sys_poll_notify(struct ctl_table_poll *poll)
5959
{
@@ -208,6 +208,8 @@ static void init_header(struct ctl_table_header *head,
208208
node++;
209209
}
210210
}
211+
if (table == sysctl_mount_point)
212+
sysctl_set_perm_empty_ctl_header(head);
211213
}
212214

213215
static void erase_header(struct ctl_table_header *head)

include/linux/sysctl.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,6 @@ struct ctl_table {
137137
void *data;
138138
int maxlen;
139139
umode_t mode;
140-
/**
141-
* enum type - Enumeration to differentiate between ctl target types
142-
* @SYSCTL_TABLE_TYPE_DEFAULT: ctl target with no special considerations
143-
* @SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY: Used to identify a permanently
144-
* empty directory target to serve
145-
* as mount point.
146-
*/
147-
enum {
148-
SYSCTL_TABLE_TYPE_DEFAULT,
149-
SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY
150-
} type;
151140
proc_handler *proc_handler; /* Callback for text formatting */
152141
struct ctl_table_poll *poll;
153142
void *extra1;
@@ -188,6 +177,17 @@ struct ctl_table_header {
188177
struct ctl_dir *parent;
189178
struct ctl_node *node;
190179
struct hlist_head inodes; /* head for proc_inode->sysctl_inodes */
180+
/**
181+
* enum type - Enumeration to differentiate between ctl target types
182+
* @SYSCTL_TABLE_TYPE_DEFAULT: ctl target with no special considerations
183+
* @SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY: Used to identify a permanently
184+
* empty directory target to serve
185+
* as mount point.
186+
*/
187+
enum {
188+
SYSCTL_TABLE_TYPE_DEFAULT,
189+
SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY,
190+
} type;
191191
};
192192

193193
struct ctl_dir {

0 commit comments

Comments
 (0)