Skip to content

Commit

Permalink
module/*.ko: prune .data, global .rodata
Browse files Browse the repository at this point in the history
Evaluated every variable that lives in .data (and globals in .rodata)
in the kernel modules, and constified/eliminated/localised them
appropriately. This means that all read-only data is now actually
read-only data, and, if possible, at file scope. A lot of previously-
global-symbols became inlinable (and inlined!) constants. Probably
not in a big Wowee Performance Moment, but hey.

Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ahelenia Ziemiańska <[email protected]>
Closes openzfs#12899
  • Loading branch information
nabijaczleweli authored and tonyhutter committed Sep 15, 2022
1 parent 03fa3ef commit 23715ed
Show file tree
Hide file tree
Showing 142 changed files with 1,425 additions and 725 deletions.
13 changes: 6 additions & 7 deletions cmd/zhack/zhack.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@

extern boolean_t zfeature_checks_disable;

const char cmdname[] = "zhack";
static importargs_t g_importargs;
static char *g_pool;
static boolean_t g_readonly;
Expand All @@ -61,9 +60,9 @@ static void
usage(void)
{
(void) fprintf(stderr,
"Usage: %s [-c cachefile] [-d dir] <subcommand> <args> ...\n"
"Usage: zhack [-c cachefile] [-d dir] <subcommand> <args> ...\n"
"where <subcommand> <args> is one of the following:\n"
"\n", cmdname);
"\n");

(void) fprintf(stderr,
" feature stat <pool>\n"
Expand Down Expand Up @@ -93,10 +92,10 @@ fatal(spa_t *spa, void *tag, const char *fmt, ...)
}

va_start(ap, fmt);
(void) fprintf(stderr, "%s: ", cmdname);
(void) fputs("zhack: ", stderr);
(void) vfprintf(stderr, fmt, ap);
va_end(ap);
(void) fprintf(stderr, "\n");
(void) fputc('\n', stderr);

exit(1);
}
Expand Down Expand Up @@ -271,7 +270,7 @@ zhack_do_feature_enable(int argc, char **argv)
spa_t *spa;
objset_t *mos;
zfeature_info_t feature;
spa_feature_t nodeps[] = { SPA_FEATURE_NONE };
const spa_feature_t nodeps[] = { SPA_FEATURE_NONE };

/*
* Features are not added to the pool's label until their refcounts
Expand Down Expand Up @@ -367,7 +366,7 @@ zhack_do_feature_ref(int argc, char **argv)
spa_t *spa;
objset_t *mos;
zfeature_info_t feature;
spa_feature_t nodeps[] = { SPA_FEATURE_NONE };
const spa_feature_t nodeps[] = { SPA_FEATURE_NONE };

/*
* fi_desc does not matter here because it was written to disk
Expand Down
2 changes: 1 addition & 1 deletion cmd/ztest/ztest.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ extern uint64_t metaslab_force_ganging;
extern uint64_t metaslab_df_alloc_threshold;
extern unsigned long zfs_deadman_synctime_ms;
extern int metaslab_preload_limit;
extern boolean_t zfs_compressed_arc_enabled;
extern int zfs_compressed_arc_enabled;
extern int zfs_abd_scatter_enabled;
extern int dmu_object_alloc_chunk_shift;
extern boolean_t zfs_force_some_double_word_sm_entries;
Expand Down
2 changes: 1 addition & 1 deletion include/libzfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ extern void zpool_print_unsup_feat(nvlist_t *config);
*/
struct zfs_cmd;

extern const char *zfs_history_event_names[];
extern const char *const zfs_history_event_names[];

typedef enum {
VDEV_NAME_PATH = 1 << 0,
Expand Down
4 changes: 2 additions & 2 deletions include/os/freebsd/zfs/sys/freebsd_crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ void crypto_mac_final(struct hmac_ctx *ctx, void *out_data,
size_t out_data_size);

int freebsd_crypt_newsession(freebsd_crypt_session_t *sessp,
struct zio_crypt_info *, crypto_key_t *);
const struct zio_crypt_info *, crypto_key_t *);
void freebsd_crypt_freesession(freebsd_crypt_session_t *sessp);

int freebsd_crypt_uio(boolean_t, freebsd_crypt_session_t *,
struct zio_crypt_info *, zfs_uio_t *, crypto_key_t *, uint8_t *,
const struct zio_crypt_info *, zfs_uio_t *, crypto_key_t *, uint8_t *,
size_t, size_t);

#endif /* _ZFS_FREEBSD_CRYPTO_H */
2 changes: 1 addition & 1 deletion include/os/freebsd/zfs/sys/zfs_context_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#define cond_resched() kern_yield(PRI_USER)

#define taskq_create_sysdc(a, b, d, e, p, dc, f) \
(taskq_create(a, b, maxclsyspri, d, e, f))
((void) sizeof (dc), taskq_create(a, b, maxclsyspri, d, e, f))

#define tsd_create(keyp, destructor) do { \
*(keyp) = osd_thread_register((destructor)); \
Expand Down
3 changes: 1 addition & 2 deletions include/os/freebsd/zfs/sys/zfs_znode_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ extern void zfs_tstamp_update_setup_ext(struct znode *,
uint_t, uint64_t [2], uint64_t [2], boolean_t have_tx);
extern void zfs_znode_free(struct znode *);

extern zil_replay_func_t *zfs_replay_vector[TX_MAX_TYPE];
extern int zfsfstype;
extern zil_replay_func_t *const zfs_replay_vector[TX_MAX_TYPE];

extern int zfs_znode_parent_and_name(struct znode *zp, struct znode **dzpp,
char *buf);
Expand Down
3 changes: 2 additions & 1 deletion include/os/linux/spl/rpc/xdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ enum xdr_op {
struct xdr_ops;

typedef struct {
struct xdr_ops *x_ops; /* Let caller know xdrmem_create() succeeds */
const struct xdr_ops *x_ops;
/* Let caller know xdrmem_create() succeeds */
caddr_t x_addr; /* Current buffer addr */
caddr_t x_addr_end; /* End of the buffer */
enum xdr_op x_op; /* Stream direction */
Expand Down
1 change: 0 additions & 1 deletion include/os/linux/spl/sys/sysmacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@
#endif

/* Missing globals */
extern char spl_gitrev[64];
extern unsigned long spl_hostid;

/* Missing misc functions */
Expand Down
3 changes: 2 additions & 1 deletion include/os/linux/spl/sys/taskq.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ extern taskq_t *taskq_of_curthread(void);
#define taskq_create_proc(name, nthreads, pri, min, max, proc, flags) \
taskq_create(name, nthreads, pri, min, max, flags)
#define taskq_create_sysdc(name, nthreads, min, max, proc, dc, flags) \
taskq_create(name, nthreads, maxclsyspri, min, max, flags)
((void) sizeof (dc), \
taskq_create(name, nthreads, maxclsyspri, min, max, flags))

int spl_taskq_init(void);
void spl_taskq_fini(void);
Expand Down
3 changes: 1 addition & 2 deletions include/os/linux/zfs/sys/zfs_znode_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@ extern caddr_t zfs_map_page(page_t *, enum seg_rw);
extern void zfs_unmap_page(page_t *, caddr_t);
#endif /* HAVE_UIO_RW */

extern zil_replay_func_t *zfs_replay_vector[TX_MAX_TYPE];
extern int zfsfstype;
extern zil_replay_func_t *const zfs_replay_vector[TX_MAX_TYPE];

#ifdef __cplusplus
}
Expand Down
1 change: 0 additions & 1 deletion include/os/linux/zfs/sys/zpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ extern const struct inode_operations zpl_ops_root;

extern const struct file_operations zpl_fops_snapdir;
extern const struct inode_operations zpl_ops_snapdir;
extern const struct dentry_operations zpl_dops_snapdirs;

extern const struct file_operations zpl_fops_shares;
extern const struct inode_operations zpl_ops_shares;
Expand Down
2 changes: 1 addition & 1 deletion include/sys/crypto/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ typedef struct {
*/

#define CRYPTO_MECH_INVALID ((uint64_t)-1)
extern crypto_mech_type_t crypto_mech2id(char *name);
extern crypto_mech_type_t crypto_mech2id(const char *name);

/*
* Create and destroy context templates.
Expand Down
1 change: 0 additions & 1 deletion include/sys/dmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,6 @@ int dmu_assign_arcbuf_by_dnode(dnode_t *dn, uint64_t offset,
int dmu_assign_arcbuf_by_dbuf(dmu_buf_t *handle, uint64_t offset,
struct arc_buf *buf, dmu_tx_t *tx);
#define dmu_assign_arcbuf dmu_assign_arcbuf_by_dbuf
extern int zfs_prefetch_disable;
extern int zfs_max_recordsize;

/*
Expand Down
2 changes: 1 addition & 1 deletion include/sys/dmu_recv.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include <sys/spa.h>
#include <sys/objlist.h>

extern const char *recv_clone_name;
extern const char *const recv_clone_name;

typedef struct dmu_recv_cookie {
struct dsl_dataset *drc_ds;
Expand Down
5 changes: 2 additions & 3 deletions include/sys/dsl_dataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
extern "C" {
#endif

extern int zfs_allow_redacted_dataset_mount;
struct dsl_dataset;
struct dsl_dir;
struct dsl_pool;
Expand Down Expand Up @@ -441,8 +440,8 @@ int dsl_dataset_set_compression(const char *dsname, zprop_source_t source,

boolean_t dsl_dataset_is_before(dsl_dataset_t *later, dsl_dataset_t *earlier,
uint64_t earlier_txg);
void dsl_dataset_long_hold(dsl_dataset_t *ds, void *tag);
void dsl_dataset_long_rele(dsl_dataset_t *ds, void *tag);
void dsl_dataset_long_hold(dsl_dataset_t *ds, const void *tag);
void dsl_dataset_long_rele(dsl_dataset_t *ds, const void *tag);
boolean_t dsl_dataset_long_held(dsl_dataset_t *ds);

int dsl_dataset_clone_swap_check_impl(dsl_dataset_t *clone,
Expand Down
2 changes: 1 addition & 1 deletion include/sys/fs/zfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ typedef enum {
ZFS_NUM_USERQUOTA_PROPS
} zfs_userquota_prop_t;

extern const char *zfs_userquota_prop_prefixes[ZFS_NUM_USERQUOTA_PROPS];
extern const char *const zfs_userquota_prop_prefixes[ZFS_NUM_USERQUOTA_PROPS];

/*
* Pool properties are identified by these constants and must be added to the
Expand Down
4 changes: 2 additions & 2 deletions include/sys/metaslab.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ typedef struct metaslab_ops {
} metaslab_ops_t;


extern metaslab_ops_t *zfs_metaslab_ops;
extern const metaslab_ops_t zfs_metaslab_ops;

int metaslab_init(metaslab_group_t *, uint64_t, uint64_t, uint64_t,
metaslab_t **);
Expand Down Expand Up @@ -104,7 +104,7 @@ void metaslab_stat_fini(void);
void metaslab_trace_init(zio_alloc_list_t *);
void metaslab_trace_fini(zio_alloc_list_t *);

metaslab_class_t *metaslab_class_create(spa_t *, metaslab_ops_t *);
metaslab_class_t *metaslab_class_create(spa_t *, const metaslab_ops_t *);
void metaslab_class_destroy(metaslab_class_t *);
int metaslab_class_validate(metaslab_class_t *);
void metaslab_class_histogram_verify(metaslab_class_t *);
Expand Down
2 changes: 1 addition & 1 deletion include/sys/metaslab_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ typedef struct metaslab_class_allocator {
struct metaslab_class {
kmutex_t mc_lock;
spa_t *mc_spa;
metaslab_ops_t *mc_ops;
const metaslab_ops_t *mc_ops;

/*
* Track the number of metaslab groups that have been initialized
Expand Down
8 changes: 4 additions & 4 deletions include/sys/nvpair.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ struct nv_alloc_ops {
void (*nv_ao_reset)(nv_alloc_t *);
};

extern const nv_alloc_ops_t *nv_fixed_ops;
extern nv_alloc_t *nv_alloc_nosleep;
extern const nv_alloc_ops_t *const nv_fixed_ops;
extern nv_alloc_t *const nv_alloc_nosleep;

#if defined(_KERNEL)
extern nv_alloc_t *nv_alloc_sleep;
extern nv_alloc_t *nv_alloc_pushpage;
extern nv_alloc_t *const nv_alloc_sleep;
extern nv_alloc_t *const nv_alloc_pushpage;
#endif

int nv_alloc_init(nv_alloc_t *, const nv_alloc_ops_t *, /* args */ ...);
Expand Down
3 changes: 2 additions & 1 deletion include/sys/sa.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ uint64_t sa_handle_object(sa_handle_t *);
boolean_t sa_attr_would_spill(sa_handle_t *, sa_attr_type_t, int size);
void sa_spill_rele(sa_handle_t *);
void sa_register_update_callback(objset_t *, sa_update_cb_t *);
int sa_setup(objset_t *, uint64_t, sa_attr_reg_t *, int, sa_attr_type_t **);
int sa_setup(objset_t *, uint64_t, const sa_attr_reg_t *, int,
sa_attr_type_t **);
void sa_tear_down(objset_t *);
int sa_replace_all_by_template(sa_handle_t *, sa_bulk_attr_t *,
int, dmu_tx_t *);
Expand Down
3 changes: 3 additions & 0 deletions include/sys/spa.h
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,9 @@ extern unsigned long zfs_deadman_synctime_ms;
extern unsigned long zfs_deadman_ziotime_ms;
extern unsigned long zfs_deadman_checktime_ms;

extern kmem_cache_t *zio_buf_cache[];
extern kmem_cache_t *zio_data_buf_cache[];

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion include/sys/spa_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ struct spa {
};

extern char *spa_config_path;
extern char *zfs_deadman_failmode;
extern const char *zfs_deadman_failmode;
extern int spa_slop_shift;
extern void spa_taskq_dispatch_ent(spa_t *spa, zio_type_t t, zio_taskq_type_t q,
task_func_t *func, void *arg, uint_t flags, taskq_ent_t *ent);
Expand Down
2 changes: 0 additions & 2 deletions include/sys/vdev_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,6 @@ extern uint64_t vdev_get_ndisks(vdev_t *vd);
* Global variables
*/
extern int zfs_vdev_standard_sm_blksz;
/* zdb uses this tunable, so it must be declared here to make lint happy. */
extern int zfs_vdev_cache_size;

/*
* Functions from vdev_indirect.c
Expand Down
4 changes: 2 additions & 2 deletions include/sys/vdev_raidz_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ enum raidz_rec_op {
RAIDZ_REC_NUM = 7
};

extern const char *raidz_gen_name[RAIDZ_GEN_NUM];
extern const char *raidz_rec_name[RAIDZ_REC_NUM];
extern const char *const raidz_gen_name[RAIDZ_GEN_NUM];
extern const char *const raidz_rec_name[RAIDZ_REC_NUM];

/*
* Methods used to define raidz implementation
Expand Down
2 changes: 1 addition & 1 deletion include/sys/zfs_acl.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ typedef struct zfs_acl {
uint64_t z_hints; /* ACL hints (ZFS_INHERIT_ACE ...) */
zfs_acl_node_t *z_curr_node; /* current node iterator is handling */
list_t z_acl; /* chunks of ACE data */
acl_ops_t *z_ops; /* ACL operations */
const acl_ops_t *z_ops; /* ACL operations */
} zfs_acl_t;

typedef struct acl_locator_cb {
Expand Down
2 changes: 1 addition & 1 deletion include/sys/zfs_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ extern taskq_t *taskq_create(const char *, int, pri_t, int, int, uint_t);
#define taskq_create_proc(a, b, c, d, e, p, f) \
(taskq_create(a, b, c, d, e, f))
#define taskq_create_sysdc(a, b, d, e, p, dc, f) \
(taskq_create(a, b, maxclsyspri, d, e, f))
((void) sizeof (dc), taskq_create(a, b, maxclsyspri, d, e, f))
extern taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t);
extern taskqid_t taskq_dispatch_delay(taskq_t *, task_func_t, void *, uint_t,
clock_t);
Expand Down
3 changes: 1 addition & 2 deletions include/sys/zfs_sa.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ typedef enum zpl_attr {
#define SA_FLAGS_OFFSET 48
#define SA_PROJID_OFFSET 128

extern sa_attr_reg_t zfs_attr_table[ZPL_END + 1];
extern sa_attr_reg_t zfs_legacy_attr_table[ZPL_END + 1];
extern const sa_attr_reg_t zfs_attr_table[ZPL_END + 1];

/*
* This is a deprecated data structure that only exists for
Expand Down
4 changes: 1 addition & 3 deletions include/sys/zil.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,6 @@ typedef struct zil_stats {
kstat_named_t zil_itx_metaslab_slog_bytes;
} zil_stats_t;

extern zil_stats_t zil_stats;

#define ZIL_STAT_INCR(stat, val) \
atomic_add_64(&zil_stats.stat.value.ui64, (val));
#define ZIL_STAT_BUMP(stat) \
Expand Down Expand Up @@ -494,7 +492,7 @@ extern zilog_t *zil_open(objset_t *os, zil_get_data_t *get_data);
extern void zil_close(zilog_t *zilog);

extern void zil_replay(objset_t *os, void *arg,
zil_replay_func_t *replay_func[TX_MAX_TYPE]);
zil_replay_func_t *const replay_func[TX_MAX_TYPE]);
extern boolean_t zil_replaying(zilog_t *zilog, dmu_tx_t *tx);
extern void zil_destroy(zilog_t *zilog, boolean_t keep_first);
extern void zil_destroy_sync(zilog_t *zilog, dmu_tx_t *tx);
Expand Down
2 changes: 1 addition & 1 deletion include/sys/zio.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ typedef void zio_done_func_t(zio_t *zio);

extern int zio_exclude_metadata;
extern int zio_dva_throttle_enabled;
extern const char *zio_type_name[ZIO_TYPES];
extern const char *const zio_type_name[ZIO_TYPES];

/*
* A bookmark is a four-tuple <objset, object, level, blkid> that uniquely
Expand Down
2 changes: 1 addition & 1 deletion include/sys/zio_crypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ typedef struct zio_crypt_info {
char *ci_name;
} zio_crypt_info_t;

extern zio_crypt_info_t zio_crypt_table[ZIO_CRYPT_FUNCTIONS];
extern const zio_crypt_info_t zio_crypt_table[ZIO_CRYPT_FUNCTIONS];

/* in memory representation of an unwrapped key that is loaded into memory */
typedef struct zio_crypt_key {
Expand Down
3 changes: 1 addition & 2 deletions include/sys/zvol_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,11 @@ typedef struct zvol_state {
} zvol_state_t;


extern list_t zvol_state_list;
extern krwlock_t zvol_state_lock;
#define ZVOL_HT_SIZE 1024
extern struct hlist_head *zvol_htable;
#define ZVOL_HT_HEAD(hash) (&zvol_htable[(hash) & (ZVOL_HT_SIZE-1)])
extern zil_replay_func_t *zvol_replay_vector[TX_MAX_TYPE];
extern zil_replay_func_t *const zvol_replay_vector[TX_MAX_TYPE];

extern unsigned int zvol_volmode;
extern unsigned int zvol_inhibit_dev;
Expand Down
2 changes: 1 addition & 1 deletion include/zfs_comutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extern int zfs_spa_version_map(int zpl_version);
extern boolean_t zfs_dataset_name_hidden(const char *);

#define ZFS_NUM_LEGACY_HISTORY_EVENTS 41
extern const char *zfs_history_event_names[ZFS_NUM_LEGACY_HISTORY_EVENTS];
extern const char *const zfs_history_event_names[ZFS_NUM_LEGACY_HISTORY_EVENTS];

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion include/zfs_deleg.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ typedef struct zfs_deleg_perm_tab {
zfs_deleg_note_t z_note;
} zfs_deleg_perm_tab_t;

extern zfs_deleg_perm_tab_t zfs_deleg_perm_tab[];
extern const zfs_deleg_perm_tab_t zfs_deleg_perm_tab[];

int zfs_deleg_verify_nvlist(nvlist_t *nvlist);
void zfs_deleg_whokey(char *attr, zfs_deleg_who_type_t type,
Expand Down
Loading

0 comments on commit 23715ed

Please sign in to comment.