From b4436bede2ce1c49d797a657741d0746de244a93 Mon Sep 17 00:00:00 2001 From: Leif Hedstrom Date: Wed, 1 Mar 2023 13:26:03 -0700 Subject: [PATCH] Eliminates padding from some common structs --- include/records/P_RecDefs.h | 4 +- include/ts/apidefs.h.in | 2 +- include/tscore/MatcherUtils.h | 2 +- include/tscore/ink_string++.h | 4 +- iocore/eventsystem/I_EventProcessor.h | 2 +- iocore/eventsystem/I_VIO.h | 8 +- iocore/net/I_NetVConnection.h | 4 +- proxy/InkAPIInternal.h | 2 +- proxy/PoolableSession.h | 12 +-- proxy/hdrs/HTTP.h | 13 ++- proxy/hdrs/HdrHeap.h | 9 +- proxy/http/HttpSM.h | 137 +++++++++++++------------- proxy/http/HttpTransact.h | 101 +++++++++---------- 13 files changed, 144 insertions(+), 156 deletions(-) diff --git a/include/records/P_RecDefs.h b/include/records/P_RecDefs.h index 32b4b967e82..5a3d7a1a0b3 100644 --- a/include/records/P_RecDefs.h +++ b/include/records/P_RecDefs.h @@ -93,14 +93,14 @@ struct RecConfigMeta { struct RecRecord { RecT rec_type; - const char *name; RecDataT data_type; + const char *name; RecData data; RecData data_default; RecMutex lock; unsigned char sync_required; - uint32_t version; bool registered; + uint32_t version; union { RecStatMeta stat_meta; RecConfigMeta config_meta; diff --git a/include/ts/apidefs.h.in b/include/ts/apidefs.h.in index de29b257c8b..5905e8e14f2 100644 --- a/include/ts/apidefs.h.in +++ b/include/ts/apidefs.h.in @@ -1056,8 +1056,8 @@ typedef struct { typedef struct TSFetchUrlParams { const char *request; int request_len; - struct sockaddr_storage ip; int port; + struct sockaddr_storage ip; TSCont contp; TSFetchEvent events; TSFetchWakeUpOptions options; diff --git a/include/tscore/MatcherUtils.h b/include/tscore/MatcherUtils.h index 383c77c2c3f..0c7969721e3 100644 --- a/include/tscore/MatcherUtils.h +++ b/include/tscore/MatcherUtils.h @@ -84,8 +84,8 @@ struct matcher_line { matcher_type type; // dest type int dest_entry; // entry which specifies the destination int num_el; // Number of elements - char *line[2][MATCHER_MAX_TOKENS]; // label, value pairs int line_num; // config file line number + char *line[2][MATCHER_MAX_TOKENS]; // label, value pairs matcher_line *next; // use for linked list }; diff --git a/include/tscore/ink_string++.h b/include/tscore/ink_string++.h index 69c99c1b144..553b18a7c7e 100644 --- a/include/tscore/ink_string++.h +++ b/include/tscore/ink_string++.h @@ -92,9 +92,9 @@ struct StrListOverflow; struct StrList { public: - int count; Str *head; Str *tail; + int count; public: StrList(bool do_copy_when_adding_string = true); @@ -121,11 +121,11 @@ struct StrList { void *overflow_heap_alloc(int size); void overflow_heap_clean(); + int base_heap_used; Str base_cells[STRLIST_BASE_CELLS]; char base_heap[STRLIST_BASE_HEAP_SIZE]; int cells_allocated; int base_heap_size; - int base_heap_used; StrListOverflow *overflow_current; StrListOverflow *overflow_first; bool copy_when_adding_string; diff --git a/iocore/eventsystem/I_EventProcessor.h b/iocore/eventsystem/I_EventProcessor.h index 26c1a78632a..029d3a4e533 100644 --- a/iocore/eventsystem/I_EventProcessor.h +++ b/iocore/eventsystem/I_EventProcessor.h @@ -32,7 +32,7 @@ #ifdef TS_MAX_THREADS_IN_EACH_THREAD_TYPE constexpr int MAX_THREADS_IN_EACH_TYPE = TS_MAX_THREADS_IN_EACH_THREAD_TYPE; #else -constexpr int MAX_THREADS_IN_EACH_TYPE = 3072; +constexpr int MAX_THREADS_IN_EACH_TYPE = 3071; #endif #ifdef TS_MAX_NUMBER_EVENT_THREADS diff --git a/iocore/eventsystem/I_VIO.h b/iocore/eventsystem/I_VIO.h index b06dc3b2d1a..21bb769452d 100644 --- a/iocore/eventsystem/I_VIO.h +++ b/iocore/eventsystem/I_VIO.h @@ -190,6 +190,11 @@ class VIO */ int op = VIO::NONE; + // This is a little odd location, but this saves on padding, and an entire cache line +private: + bool _disabled = false; + +public: /** Provides access to the reader or writer for this operation. @@ -215,7 +220,4 @@ class VIO */ Ptr mutex; - -private: - bool _disabled = false; }; diff --git a/iocore/net/I_NetVConnection.h b/iocore/net/I_NetVConnection.h index cded188cbe7..9eafde48c2b 100644 --- a/iocore/net/I_NetVConnection.h +++ b/iocore/net/I_NetVConnection.h @@ -154,6 +154,8 @@ struct NetVCOptions { // Use TCP Fast Open on this socket. The connect(2) call will be omitted. bool f_tcp_fastopen = false; + bool tls_upstream = false; + /// Control use of SOCKS. /// Set to @c NO_SOCKS to disable use of SOCKS. Otherwise SOCKS is /// used if available. @@ -227,8 +229,6 @@ struct NetVCOptions { */ const char *ssl_client_ca_cert_path = nullptr; - bool tls_upstream = false; - unsigned char alpn_protocols_array[MAX_ALPN_STRING]; int alpn_protocols_array_size = 0; diff --git a/proxy/InkAPIInternal.h b/proxy/InkAPIInternal.h index 572a223b124..5a87e869b13 100644 --- a/proxy/InkAPIInternal.h +++ b/proxy/InkAPIInternal.h @@ -53,8 +53,8 @@ enum CacheInfoMagic { struct CacheInfo { CryptoHash cache_key; CacheFragType frag_type = CACHE_FRAG_TYPE_NONE; - char *hostname = nullptr; int len = 0; + char *hostname = nullptr; time_t pin_in_cache = 0; CacheInfoMagic magic = CACHE_INFO_MAGIC_ALIVE; diff --git a/proxy/PoolableSession.h b/proxy/PoolableSession.h index d98f93c2540..7f6b31ac72d 100644 --- a/proxy/PoolableSession.h +++ b/proxy/PoolableSession.h @@ -86,6 +86,12 @@ class PoolableSession : public ProxySession virtual void set_netvc(NetVConnection *newvc); + // Keep track of connection limiting and a pointer to the + // singleton that keeps track of the connection counts. + OutboundConnTrack::Group *conn_track_group = nullptr; + + virtual IOBufferReader *get_remote_reader() = 0; + // Used to determine whether the session is for parent proxy // it is session to origin server // We need to determine whether a closed connection was to @@ -93,12 +99,6 @@ class PoolableSession : public ProxySession // proxy.process.http.current_parent_proxy_connections bool to_parent_proxy = false; - // Keep track of connection limiting and a pointer to the - // singleton that keeps track of the connection counts. - OutboundConnTrack::Group *conn_track_group = nullptr; - - virtual IOBufferReader *get_remote_reader() = 0; - private: // Sessions become if authentication headers // are sent over them diff --git a/proxy/hdrs/HTTP.h b/proxy/hdrs/HTTP.h index 53449ea8933..935e02b18b7 100644 --- a/proxy/hdrs/HTTP.h +++ b/proxy/hdrs/HTTP.h @@ -479,21 +479,20 @@ class HTTPHdr : public MIMEHdr { public: HTTPHdrImpl *m_http = nullptr; - // This is all cached data and so is mutable. mutable URL m_url_cached; - mutable MIMEField *m_host_mime = nullptr; - mutable int m_host_length = 0; ///< Length of hostname. - mutable int m_port = 0; ///< Target port. - mutable bool m_target_cached = false; ///< Whether host name and port are cached. - mutable bool m_target_in_url = false; ///< Whether host name and port are in the URL. mutable bool m_100_continue_required = false; ///< Whether 100_continue is in the Expect header. + mutable bool m_target_in_url = false; ///< Whether host name and port are in the URL. + mutable bool m_target_cached = false; ///< Whether host name and port are cached. + mutable bool early_data = false; /// Set if the port was effectively specified in the header. /// @c true if the target (in the URL or the HOST field) also specified /// a port. That is, @c true if whatever source had the target host /// also had a port, @c false otherwise. mutable bool m_port_in_header = false; - mutable bool early_data = false; + mutable int m_port = 0; ///< Target port. + mutable int m_host_length = 0; ///< Length of hostname. + mutable MIMEField *m_host_mime = nullptr; HTTPHdr() = default; // Force the creation of the default constructor diff --git a/proxy/hdrs/HdrHeap.h b/proxy/hdrs/HdrHeap.h index 8785265615d..48d1dcca9b1 100644 --- a/proxy/hdrs/HdrHeap.h +++ b/proxy/hdrs/HdrHeap.h @@ -258,11 +258,13 @@ class HdrHeap void dump_heap(int len = -1); uint32_t m_magic; + bool m_writeable; char *m_free_start; char *m_data_start; uint32_t m_size; - bool m_writeable; + // HdrBuf heap pointers + uint32_t m_free_size; // Overflow block ptr // Overflow blocks are necessary because we can @@ -273,9 +275,6 @@ class HdrHeap // point to string heaps HdrHeap *m_next; - // HdrBuf heap pointers - uint32_t m_free_size; - int demote_rw_str_heap(); void coalesce_str_heaps(int incoming_size = 0); void evacuate_from_str_heaps(HdrStrHeap *new_heap); @@ -315,8 +314,8 @@ class HdrHeap // String Heap access Ptr m_read_write_heap; - StrHeapDesc m_ronly_heap[HDR_BUF_RONLY_HEAPS]; int m_lost_string_space; + StrHeapDesc m_ronly_heap[HDR_BUF_RONLY_HEAPS]; }; static constexpr HdrHeapMarshalBlocks HDR_HEAP_HDR_SIZE{swoc::round_up(sizeof(HdrHeap))}; diff --git a/proxy/http/HttpSM.h b/proxy/http/HttpSM.h index 7015d67bdab..3239c19d645 100644 --- a/proxy/http/HttpSM.h +++ b/proxy/http/HttpSM.h @@ -317,6 +317,8 @@ class HttpSM : public Continuation, public PluginUserArgs int redirection_tries = 0; // To monitor number of redirections int64_t transfered_bytes = 0; // Added to calculate POST data + BackgroundFill_t background_fill = BACKGROUND_FILL_NONE; + // Tunneling request to plugin HttpPluginTunnel_t plugin_tunnel_type = HTTP_NO_PLUGIN_TUNNEL; PluginVCCore *plugin_tunnel = nullptr; @@ -327,6 +329,9 @@ class HttpSM : public Continuation, public PluginUserArgs // this, with a lot of work, but this is easier for now. UrlRewrite *m_remap = nullptr; + History history; + ProxyTransaction *ua_txn = nullptr; + // _postbuf api int64_t postbuf_reader_avail(); int64_t postbuf_buffer_avail(); @@ -343,59 +348,10 @@ class HttpSM : public Continuation, public PluginUserArgs // based on sni and host name header values void check_sni_host(); SNIRoutingType get_tunnel_type() const; - -private: - int reentrancy_count = 0; - - HttpTunnel tunnel; - - HttpVCTable vc_table; - -public: - BackgroundFill_t background_fill = BACKGROUND_FILL_NONE; void set_http_schedule(Continuation *); int get_http_schedule(int event, void *data); - History history; - - ProxyTransaction *ua_txn = nullptr; - private: - IOBufferReader *ua_raw_buffer_reader = nullptr; - - HttpVCTableEntry *ua_entry = nullptr; - HttpVCTableEntry *server_entry = nullptr; - ProxyTransaction *server_txn = nullptr; - - /* Because we don't want to take a session from a shared pool if we know that it will be private, - * but we cannot set it to private until we have an attached server session. - * So we use this variable to indicate that - * we should create a new connection and then once we attach the session we'll mark it as private. - */ - bool will_be_private_ss = false; - - HttpTransformInfo transform_info; - HttpTransformInfo post_transform_info; - /** A flag to keep track of whether there are active request plugin agents. - * - * This is used to guide plugin agent cleanup. - */ - bool has_active_request_plugin_agents = false; - - /** A flag to keep track of whether there are active response plugin agents. - * - * This is used to guide plugin agent cleanup. - */ - bool has_active_response_plugin_agents = false; - - HttpCacheSM cache_sm; - HttpCacheSM transform_cache_sm; - - HttpSMHandler default_handler = nullptr; - PendingAction pending_action; - Continuation *schedule_cont = nullptr; - - HTTPParser http_parser; void start_sub_sm(); int main_handler(int event, void *data); @@ -548,18 +504,18 @@ class HttpSM : public Continuation, public PluginUserArgs // TODO: Now that bodies can be empty, should the body counters be set to -1 ? TS-2213 // Stats & Logging Info int client_request_hdr_bytes = 0; - int64_t client_request_body_bytes = 0; int server_request_hdr_bytes = 0; - int64_t server_request_body_bytes = 0; int server_response_hdr_bytes = 0; - int64_t server_response_body_bytes = 0; int client_response_hdr_bytes = 0; - int64_t client_response_body_bytes = 0; int cache_response_hdr_bytes = 0; - int64_t cache_response_body_bytes = 0; int pushed_response_hdr_bytes = 0; - int64_t pushed_response_body_bytes = 0; int server_connection_provided_cert = 0; + int64_t client_request_body_bytes = 0; + int64_t server_request_body_bytes = 0; + int64_t server_response_body_bytes = 0; + int64_t client_response_body_bytes = 0; + int64_t cache_response_body_bytes = 0; + int64_t pushed_response_body_bytes = 0; bool client_tcp_reused = false; bool client_ssl_reused = false; bool client_connection_is_ssl = false; @@ -568,6 +524,10 @@ class HttpSM : public Continuation, public PluginUserArgs bool server_connection_is_ssl = false; bool is_waiting_for_full_body = false; bool is_using_post_buffer = false; + // hooks_set records whether there are any hooks relevant + // to this transaction. Used to avoid costly calls + // do_api_callout_internal() + bool hooks_set = false; std::optional mptcp_state; // Don't initialize, that marks it as "not defined". const char *client_protocol = "-"; const char *server_protocol = "-"; @@ -585,20 +545,37 @@ class HttpSM : public Continuation, public PluginUserArgs const char *plugin_tag = nullptr; int64_t plugin_id = 0; - // hooks_set records whether there are any hooks relevant - // to this transaction. Used to avoid costly calls - // do_api_callout_internal() - bool hooks_set = false; - private: + HttpTunnel tunnel; + + HttpVCTable vc_table; + + IOBufferReader *ua_raw_buffer_reader = nullptr; + + HttpVCTableEntry *ua_entry = nullptr; + HttpVCTableEntry *server_entry = nullptr; + ProxyTransaction *server_txn = nullptr; + + HttpTransformInfo transform_info; + HttpTransformInfo post_transform_info; + + HttpCacheSM cache_sm; + HttpCacheSM transform_cache_sm; + + HttpSMHandler default_handler = nullptr; + PendingAction pending_action; + Continuation *schedule_cont = nullptr; + + HTTPParser http_parser; + TSHttpHookID cur_hook_id = TS_HTTP_LAST_HOOK; APIHook const *cur_hook = nullptr; HttpHookState hook_state; - // // Continuation time keeper int64_t prev_hook_start_time = 0; + int reentrancy_count = 0; int cur_hooks = 0; HttpApiState_t callout_state = HTTP_API_NO_CALLOUT; @@ -613,6 +590,34 @@ class HttpSM : public Continuation, public PluginUserArgs bool terminate_sm = false; bool kill_this_async_done = false; bool parse_range_done = false; + bool _from_early_data = false; + /* Because we don't want to take a session from a shared pool if we know that it will be private, + * but we cannot set it to private until we have an attached server session. + * So we use this variable to indicate that + * we should create a new connection and then once we attach the session we'll mark it as private. + */ + bool will_be_private_ss = false; + + /** A flag to keep track of whether there are active request plugin agents. + * + * This is used to guide plugin agent cleanup. + */ + bool has_active_request_plugin_agents = false; + + /** A flag to keep track of whether there are active response plugin agents. + * + * This is used to guide plugin agent cleanup. + */ + bool has_active_response_plugin_agents = false; + + int _client_connection_id = -1; + int _client_transaction_id = -1; + int _client_transaction_priority_weight = -1; + int _client_transaction_priority_dependence = -1; + SNIRoutingType _tunnel_type = SNIRoutingType::NONE; + PreWarmSM *_prewarm_sm = nullptr; + PostDataBuffers _postbuf; + void kill_this(); void update_stats(); void transform_cleanup(TSHttpHookID hook, HttpTransformInfo *info); @@ -621,8 +626,6 @@ class HttpSM : public Continuation, public PluginUserArgs public: LINK(HttpSM, debug_link); - -public: bool set_server_session_private(bool private_session); bool is_dying() const; @@ -635,14 +638,6 @@ class HttpSM : public Continuation, public PluginUserArgs ink_hrtime get_server_active_timeout(); ink_hrtime get_server_connect_timeout(); void rewind_state_machine(); - -private: - PostDataBuffers _postbuf; - int _client_connection_id = -1, _client_transaction_id = -1; - int _client_transaction_priority_weight = -1, _client_transaction_priority_dependence = -1; - bool _from_early_data = false; - SNIRoutingType _tunnel_type = SNIRoutingType::NONE; - PreWarmSM *_prewarm_sm = nullptr; }; //// diff --git a/proxy/http/HttpTransact.h b/proxy/http/HttpTransact.h index b04a6622cf5..e5dcb96c9fa 100644 --- a/proxy/http/HttpTransact.h +++ b/proxy/http/HttpTransact.h @@ -669,20 +669,54 @@ class HttpTransact } ResponseAction; struct State { - HttpTransactMagic_t m_magic = HTTP_TRANSACT_MAGIC_ALIVE; - HttpSM *state_machine = nullptr; + HttpTransactMagic_t m_magic = HTTP_TRANSACT_MAGIC_ALIVE; + HTTPVersion updated_server_version = HTTP_INVALID; + CacheLookupResult_t cache_lookup_result = CACHE_LOOKUP_NONE; + HTTPStatus http_return_code = HTTP_STATUS_NONE; + CacheAuth_t www_auth_content = CACHE_AUTH_NONE; + Arena arena; + bool force_dns = false; + bool is_upgrade_request = false; + bool is_websocket = false; + bool did_upgrade_succeed = false; + bool client_connection_enabled = true; + bool acl_filtering_performed = false; + bool api_cleanup_cache_read = false; + bool api_server_response_no_store = false; + bool api_server_response_ignore = false; + bool api_http_sm_shutdown = false; + bool api_modifiable_cached_resp = false; + bool api_server_request_body_set = false; + bool api_req_cacheable = false; + bool api_resp_cacheable = false; + bool reverse_proxy = false; + bool url_remap_success = false; + bool api_skip_all_remapping = false; + bool already_downgraded = false; + bool transparent_passthrough = false; + bool range_in_cache = false; + + /// True if the response is cacheable because of negative caching configuration. + /// + /// This being true implies the following: + /// + /// * The response code was negative. + /// * Negative caching is enabled. + /// * The response is considered cacheable because of negative caching + /// configuration. + bool is_cacheable_due_to_negative_caching_configuration = false; + + MgmtByte cache_open_write_fail_action = 0; + HttpConfigParams *http_config_param = nullptr; CacheLookupInfo cache_info; ResolveInfo dns_info; RedirectInfo redirect_info; OutboundConnTrack::TxnState outbound_conn_track_state; - HTTPVersion updated_server_version = HTTP_INVALID; - bool force_dns = false; - MgmtByte cache_open_write_fail_action = 0; ConnectionAttributes client_info; ConnectionAttributes parent_info; ConnectionAttributes server_info; @@ -704,7 +738,6 @@ class HttpTransact std::shared_ptr next_hop_strategy = nullptr; ParentResult parent_result; CacheControlResult cache_control; - CacheLookupResult_t cache_lookup_result = CACHE_LOOKUP_NONE; StateMachineAction_t next_action = SM_ACTION_UNDEFINED; // out StateMachineAction_t api_next_action = SM_ACTION_UNDEFINED; // out @@ -713,11 +746,6 @@ class HttpTransact // We keep this so we can jump back to the upgrade handler after remap is complete void (*post_remap_upgrade_return_point)(HttpTransact::State *s) = nullptr; // out const char *upgrade_token_wks = nullptr; - bool is_upgrade_request = false; - - // Some WebSocket state - bool is_websocket = false; - bool did_upgrade_succeed = false; char *internal_msg_buffer = nullptr; // out char *internal_msg_buffer_type = nullptr; // out @@ -735,6 +763,13 @@ class HttpTransact /// response reason phrases. int cause_of_death_errno = -UNKNOWN_INTERNAL_ERROR; // in + int api_txn_active_timeout_value = -1; + int api_txn_connect_timeout_value = -1; + int api_txn_dns_timeout_value = -1; + int api_txn_no_activity_timeout_value = -1; + int congestion_control_crat = 0; // Client retry after + unsigned int filter_mask = 0; + ink_time_t client_request_time = UNDEFINED_TIME; // internal ink_time_t request_sent_time = UNDEFINED_TIME; // internal ink_time_t response_received_time = UNDEFINED_TIME; // internal @@ -742,29 +777,7 @@ class HttpTransact char via_string[MAX_VIA_INDICES + 1]; - // new ACL filtering result (calculated immediately after remap) - bool client_connection_enabled = true; - bool acl_filtering_performed = false; - - /// True if the response is cacheable because of negative caching configuration. - /// - /// This being true implies the following: - /// - /// * The response code was negative. - /// * Negative caching is enabled. - /// * The response is considered cacheable because of negative caching - /// configuration. - bool is_cacheable_due_to_negative_caching_configuration = false; - // for authenticated content caching - CacheAuth_t www_auth_content = CACHE_AUTH_NONE; - RemapPluginInst *os_response_plugin_inst = nullptr; - HTTPStatus http_return_code = HTTP_STATUS_NONE; - - int api_txn_active_timeout_value = -1; - int api_txn_connect_timeout_value = -1; - int api_txn_dns_timeout_value = -1; - int api_txn_no_activity_timeout_value = -1; // Used by INKHttpTxnCachedReqGet and INKHttpTxnCachedRespGet SDK functions // to copy part of HdrHeap (only the writable portion) for cached response headers @@ -772,14 +785,6 @@ class HttpTransact // These ptrs are deallocate when transaction is over. HdrHeapSDKHandle *cache_req_hdr_heap_handle = nullptr; HdrHeapSDKHandle *cache_resp_hdr_heap_handle = nullptr; - bool api_cleanup_cache_read = false; - bool api_server_response_no_store = false; - bool api_server_response_ignore = false; - bool api_http_sm_shutdown = false; - bool api_modifiable_cached_resp = false; - bool api_server_request_body_set = false; - bool api_req_cacheable = false; - bool api_resp_cacheable = false; UpdateCachedObject_t api_update_cached_object = UPDATE_CACHED_OBJECT_NONE; StateMachineAction_t saved_update_next_action = SM_ACTION_UNDEFINED; CacheAction_t saved_update_cache_action = CACHE_DO_UNDEFINED; @@ -788,16 +793,7 @@ class HttpTransact UrlMappingContainer url_map; host_hdr_info hh_info = {nullptr, 0, 0}; - int congestion_control_crat = 0; // Client retry after - - unsigned int filter_mask = 0; - char *remap_redirect = nullptr; - bool reverse_proxy = false; - bool url_remap_success = false; - - bool api_skip_all_remapping = false; - - bool already_downgraded = false; + char *remap_redirect = nullptr; URL unmapped_url; // unmapped url is the effective url before remap // Http Range: related variables @@ -817,9 +813,6 @@ class HttpTransact return *p; } - bool transparent_passthrough = false; - bool range_in_cache = false; - ResponseAction response_action; // Methods