Skip to content

Commit 4df911e

Browse files
TimWollaGirgias
authored andcommitted
session: Slightly reorder the members within the module globals
The previous ordering resulted in a needlessly large number of holes and split several `zval`s across cache line boundaries. Do the bare minimum of reordering to keep related members grouped, but reducing the struct size by 32 bytes and keeping `zval`s within a single cache line. Before: struct _php_session_rfc1867_progress { size_t sname_len; /* 0 8 */ zval sid; /* 8 16 */ smart_str key; /* 24 16 */ zend_long update_step; /* 40 8 */ zend_long next_update; /* 48 8 */ double next_update_time; /* 56 8 */ /* --- cacheline 1 boundary (64 bytes) --- */ _Bool cancel_upload; /* 64 1 */ _Bool apply_trans_sid; /* 65 1 */ /* XXX 6 bytes hole, try to pack */ size_t content_length; /* 72 8 */ zval data; /* 80 16 */ zval * post_bytes_processed; /* 96 8 */ zval files; /* 104 16 */ zval current_file; /* 120 16 */ /* --- cacheline 2 boundary (128 bytes) was 8 bytes ago --- */ zval * current_file_bytes_processed; /* 136 8 */ /* size: 144, cachelines: 3, members: 14 */ /* sum members: 138, holes: 1, sum holes: 6 */ /* last cacheline: 16 bytes */ }; struct _php_ps_globals { char * save_path; /* 0 8 */ char * session_name; /* 8 8 */ zend_string * id; /* 16 8 */ char * extern_referer_chk; /* 24 8 */ char * cache_limiter; /* 32 8 */ zend_long cookie_lifetime; /* 40 8 */ char * cookie_path; /* 48 8 */ char * cookie_domain; /* 56 8 */ /* --- cacheline 1 boundary (64 bytes) --- */ _Bool cookie_secure; /* 64 1 */ _Bool cookie_httponly; /* 65 1 */ /* XXX 6 bytes hole, try to pack */ char * cookie_samesite; /* 72 8 */ const ps_module * mod; /* 80 8 */ const ps_module * default_mod; /* 88 8 */ void * mod_data; /* 96 8 */ php_session_status session_status; /* 104 4 */ /* XXX 4 bytes hole, try to pack */ zend_string * session_started_filename; /* 112 8 */ uint32_t session_started_lineno; /* 120 4 */ /* XXX 4 bytes hole, try to pack */ /* --- cacheline 2 boundary (128 bytes) --- */ zend_long gc_probability; /* 128 8 */ zend_long gc_divisor; /* 136 8 */ zend_long gc_maxlifetime; /* 144 8 */ int module_number; /* 152 4 */ /* XXX 4 bytes hole, try to pack */ zend_long cache_expire; /* 160 8 */ struct { zval ps_open; /* 168 16 */ zval ps_close; /* 184 16 */ /* --- cacheline 3 boundary (192 bytes) was 8 bytes ago --- */ zval ps_read; /* 200 16 */ zval ps_write; /* 216 16 */ zval ps_destroy; /* 232 16 */ zval ps_gc; /* 248 16 */ /* --- cacheline 4 boundary (256 bytes) was 8 bytes ago --- */ zval ps_create_sid; /* 264 16 */ zval ps_validate_sid; /* 280 16 */ zval ps_update_timestamp; /* 296 16 */ } mod_user_names; /* 168 144 */ _Bool mod_user_implemented; /* 312 1 */ _Bool mod_user_is_open; /* 313 1 */ /* XXX 6 bytes hole, try to pack */ /* --- cacheline 5 boundary (320 bytes) --- */ zend_string * mod_user_class_name; /* 320 8 */ const struct ps_serializer_struct * serializer; /* 328 8 */ zval http_session_vars; /* 336 16 */ _Bool auto_start; /* 352 1 */ _Bool use_cookies; /* 353 1 */ _Bool use_only_cookies; /* 354 1 */ _Bool use_trans_sid; /* 355 1 */ /* XXX 4 bytes hole, try to pack */ zend_long sid_length; /* 360 8 */ zend_long sid_bits_per_character; /* 368 8 */ _Bool send_cookie; /* 376 1 */ _Bool define_sid; /* 377 1 */ /* XXX 6 bytes hole, try to pack */ /* --- cacheline 6 boundary (384 bytes) --- */ php_session_rfc1867_progress * rfc1867_progress; /* 384 8 */ _Bool rfc1867_enabled; /* 392 1 */ _Bool rfc1867_cleanup; /* 393 1 */ /* XXX 6 bytes hole, try to pack */ char * rfc1867_prefix; /* 400 8 */ char * rfc1867_name; /* 408 8 */ zend_long rfc1867_freq; /* 416 8 */ double rfc1867_min_freq; /* 424 8 */ _Bool use_strict_mode; /* 432 1 */ _Bool lazy_write; /* 433 1 */ _Bool in_save_handler; /* 434 1 */ _Bool set_handler; /* 435 1 */ /* XXX 4 bytes hole, try to pack */ zend_string * session_vars; /* 440 8 */ /* size: 448, cachelines: 7, members: 48 */ /* sum members: 404, holes: 9, sum holes: 44 */ }; After: struct _php_session_rfc1867_progress { size_t sname_len; /* 0 8 */ zval sid; /* 8 16 */ smart_str key; /* 24 16 */ zend_long update_step; /* 40 8 */ zend_long next_update; /* 48 8 */ double next_update_time; /* 56 8 */ /* --- cacheline 1 boundary (64 bytes) --- */ _Bool cancel_upload; /* 64 1 */ _Bool apply_trans_sid; /* 65 1 */ /* XXX 6 bytes hole, try to pack */ size_t content_length; /* 72 8 */ zval data; /* 80 16 */ zval files; /* 96 16 */ zval * post_bytes_processed; /* 112 8 */ zval * current_file_bytes_processed; /* 120 8 */ /* --- cacheline 2 boundary (128 bytes) --- */ zval current_file; /* 128 16 */ /* size: 144, cachelines: 3, members: 14 */ /* sum members: 138, holes: 1, sum holes: 6 */ /* last cacheline: 16 bytes */ }; struct _php_ps_globals { char * save_path; /* 0 8 */ char * session_name; /* 8 8 */ zend_string * id; /* 16 8 */ char * extern_referer_chk; /* 24 8 */ char * cache_limiter; /* 32 8 */ zend_long cookie_lifetime; /* 40 8 */ char * cookie_path; /* 48 8 */ char * cookie_domain; /* 56 8 */ /* --- cacheline 1 boundary (64 bytes) --- */ char * cookie_samesite; /* 64 8 */ _Bool cookie_secure; /* 72 1 */ _Bool cookie_httponly; /* 73 1 */ /* XXX 6 bytes hole, try to pack */ const ps_module * mod; /* 80 8 */ const ps_module * default_mod; /* 88 8 */ void * mod_data; /* 96 8 */ php_session_status session_status; /* 104 4 */ /* XXX 4 bytes hole, try to pack */ zend_string * session_started_filename; /* 112 8 */ uint32_t session_started_lineno; /* 120 4 */ int module_number; /* 124 4 */ /* --- cacheline 2 boundary (128 bytes) --- */ zend_long gc_probability; /* 128 8 */ zend_long gc_divisor; /* 136 8 */ zend_long gc_maxlifetime; /* 144 8 */ zend_long cache_expire; /* 152 8 */ struct { zval ps_open; /* 160 16 */ zval ps_close; /* 176 16 */ /* --- cacheline 3 boundary (192 bytes) --- */ zval ps_read; /* 192 16 */ zval ps_write; /* 208 16 */ zval ps_destroy; /* 224 16 */ zval ps_gc; /* 240 16 */ /* --- cacheline 4 boundary (256 bytes) --- */ zval ps_create_sid; /* 256 16 */ zval ps_validate_sid; /* 272 16 */ zval ps_update_timestamp; /* 288 16 */ } mod_user_names; /* 160 144 */ zend_string * mod_user_class_name; /* 304 8 */ _Bool mod_user_implemented; /* 312 1 */ _Bool mod_user_is_open; /* 313 1 */ _Bool auto_start; /* 314 1 */ _Bool use_cookies; /* 315 1 */ _Bool use_only_cookies; /* 316 1 */ _Bool use_trans_sid; /* 317 1 */ _Bool send_cookie; /* 318 1 */ _Bool define_sid; /* 319 1 */ /* --- cacheline 5 boundary (320 bytes) --- */ const struct ps_serializer_struct * serializer; /* 320 8 */ zval http_session_vars; /* 328 16 */ zend_long sid_length; /* 344 8 */ zend_long sid_bits_per_character; /* 352 8 */ php_session_rfc1867_progress * rfc1867_progress; /* 360 8 */ char * rfc1867_prefix; /* 368 8 */ char * rfc1867_name; /* 376 8 */ /* --- cacheline 6 boundary (384 bytes) --- */ zend_long rfc1867_freq; /* 384 8 */ double rfc1867_min_freq; /* 392 8 */ _Bool rfc1867_enabled; /* 400 1 */ _Bool rfc1867_cleanup; /* 401 1 */ _Bool use_strict_mode; /* 402 1 */ _Bool lazy_write; /* 403 1 */ _Bool in_save_handler; /* 404 1 */ _Bool set_handler; /* 405 1 */ /* XXX 2 bytes hole, try to pack */ zend_string * session_vars; /* 408 8 */ /* size: 416, cachelines: 7, members: 48 */ /* sum members: 404, holes: 3, sum holes: 12 */ /* last cacheline: 32 bytes */ };
1 parent ffc6f19 commit 4df911e

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

ext/session/php_session.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ typedef struct _php_session_rfc1867_progress {
132132
size_t content_length;
133133

134134
zval data; /* the array exported to session data */
135-
zval *post_bytes_processed; /* data["bytes_processed"] */
136135
zval files; /* data["files"] array */
137-
zval current_file; /* array of currently uploading file */
136+
zval *post_bytes_processed; /* data["bytes_processed"] */
138137
zval *current_file_bytes_processed;
138+
zval current_file; /* array of currently uploading file */
139139
} php_session_rfc1867_progress;
140140

141141
typedef struct _php_ps_globals {
@@ -147,19 +147,19 @@ typedef struct _php_ps_globals {
147147
zend_long cookie_lifetime;
148148
char *cookie_path;
149149
char *cookie_domain;
150+
char *cookie_samesite;
150151
bool cookie_secure;
151152
bool cookie_httponly;
152-
char *cookie_samesite;
153153
const ps_module *mod;
154154
const ps_module *default_mod;
155155
void *mod_data;
156156
php_session_status session_status;
157157
zend_string *session_started_filename;
158158
uint32_t session_started_lineno;
159+
int module_number;
159160
zend_long gc_probability;
160161
zend_long gc_divisor;
161162
zend_long gc_maxlifetime;
162-
int module_number;
163163
zend_long cache_expire;
164164
struct {
165165
zval ps_open;
@@ -172,28 +172,29 @@ typedef struct _php_ps_globals {
172172
zval ps_validate_sid;
173173
zval ps_update_timestamp;
174174
} mod_user_names;
175+
zend_string *mod_user_class_name;
175176
bool mod_user_implemented;
176177
bool mod_user_is_open;
177-
zend_string *mod_user_class_name;
178-
const struct ps_serializer_struct *serializer;
179-
zval http_session_vars;
180178
bool auto_start;
181179
bool use_cookies;
182180
bool use_only_cookies;
183181
bool use_trans_sid; /* contains the INI value of whether to use trans-sid */
182+
bool send_cookie;
183+
bool define_sid;
184+
185+
const struct ps_serializer_struct *serializer;
186+
zval http_session_vars;
184187

185188
zend_long sid_length;
186189
zend_long sid_bits_per_character;
187-
bool send_cookie;
188-
bool define_sid;
189190

190191
php_session_rfc1867_progress *rfc1867_progress;
191-
bool rfc1867_enabled; /* session.upload_progress.enabled */
192-
bool rfc1867_cleanup; /* session.upload_progress.cleanup */
193192
char *rfc1867_prefix; /* session.upload_progress.prefix */
194193
char *rfc1867_name; /* session.upload_progress.name */
195194
zend_long rfc1867_freq; /* session.upload_progress.freq */
196195
double rfc1867_min_freq; /* session.upload_progress.min_freq */
196+
bool rfc1867_enabled; /* session.upload_progress.enabled */
197+
bool rfc1867_cleanup; /* session.upload_progress.cleanup */
197198

198199
bool use_strict_mode; /* whether or not PHP accepts unknown session ids */
199200
bool lazy_write; /* omit session write when it is possible */

0 commit comments

Comments
 (0)