Reorder some class variables to fill in gaps in structure packing

The big hitters:
Dict: Fills in four 4-byte holes in the structure. This shrinks Dictionary from 136 bytes to 114 bytes.
Desc: Fills in a 6-byte hole in the structure. This shrinks ODesc from 152 bytes to 144 bytes.
Frame: Moves and combines 4 bool variables from a few places into one single 4-byte block. This resolves all of the holes at once. This shrinks Frame from 216 bytes to 192 bytes and removes one cache line.
Func: Moves one int32_t variable to fill in a 4-byte hole. This shrinks Func from 112 bytes to 104 bytes.
ID: Moves two bool variables to fill in a 3-byte hole. This leaves behind a 1-byte hole, but removes a 6-byte pad from the end of the structure. This shrinks ID from 144 bytes to 136 bytes.

Other changes:
RuleHdrTest: Fills in one 4-byte hole in the structure. This shrinks RuleHdrTest from 248 bytes to 240 bytes.
RuleEndpointState: Moves one bool variable down in the structure to reduce a 7-byte hole. This unfortunately causes a 3-byte hole later in the structure but there’s no easy way to filll it in. This does shrink RuleEndpointState from 128 bytes to 120 bytes though.
ScannedFile: Moves two bool values to reduce a 4-byte hole by 2 bytes. This shrinks ScannedFile from 64 bytes to 56 bytes.
Brofiler: Moves one char value to reduce a 4-byte hole by 1 byte. This shrinks Brofiler from 96 bytes to 88 bytes and removes one cache line.
DbgBreakpoint: Moves some values around to fill in a 4-byte hole and reduce a second. A 2-byte hole still exists, but the structure shrinks from 632 bytes to 624 bytes. It’s possible on this one that one of the int32_t values could be an int16_t and remove the last 2-byte gap.
ParseLocationRec: Moves one int to fill in a 4-byte hole. This shrinks ParseLocationRec from 32 bytes to 24 bytes.
DebugCmdInfo: Moves one bool variable to shift a few others up. This results in a 6-byte pad at the end of the structure but removes a 7-byte hole in the middle. This shrinks DebugCmdInfo from 56 bytes to 48 bytes.
FragReassembler: Moves one variable down to fill in a 4-byte hole. This shrinks FragReassembler from 272 bytes to 264 bytes.
nb_dns_result: Moves ones uint32_t variable to fill in a 4-byte hole, also removing a 4-byte pad from the end of the structure. This shrinks nb_dns_result from 32 bytes to 24 bytes.
nb_dns_entry: Moves one short value to fill in a 2-byte hole, also removing a 6-byte hole. This shrinks nb_dns_entry from 1064 bytes to 1056 bytes.
This commit is contained in:
Tim Wojtulewicz 2020-04-04 21:18:50 -04:00
parent e66148a13a
commit 2964093e5d
16 changed files with 45 additions and 43 deletions

View file

@ -56,7 +56,12 @@ private:
* Indicates whether new statments will not be considered as part of * Indicates whether new statments will not be considered as part of
* coverage statistics because it was marked with the @no-test tag. * coverage statistics because it was marked with the @no-test tag.
*/ */
unsigned int ignoring; uint32_t ignoring;
/**
* The character to use to delimit Brofiler output files. Default is '\t'.
*/
char delim;
/** /**
* This maps Stmt location-desc pairs to the total number of times that * This maps Stmt location-desc pairs to the total number of times that
@ -66,11 +71,6 @@ private:
*/ */
map<pair<string, string>, uint64_t> usage_map; map<pair<string, string>, uint64_t> usage_map;
/**
* The character to use to delimit Brofiler output files. Default is '\t'.
*/
char delim;
/** /**
* A canonicalization routine for Stmt descriptions containing characters * A canonicalization routine for Stmt descriptions containing characters
* that don't agree with the output format of Brofiler. * that don't agree with the output format of Brofiler.

View file

@ -163,11 +163,11 @@ protected:
struct AsyncRequest { struct AsyncRequest {
double time; double time;
bool is_txt;
bool processed;
IPAddr host; IPAddr host;
string name; string name;
CallbackList callbacks; CallbackList callbacks;
bool is_txt;
bool processed;
AsyncRequest() : time(0.0), is_txt(false), processed(false) { } AsyncRequest() : time(0.0), is_txt(false), processed(false) { }

View file

@ -63,21 +63,21 @@ protected:
void PrintHitMsg(); // display reason when the breakpoint hits void PrintHitMsg(); // display reason when the breakpoint hits
Kind kind; Kind kind;
bool enabled; // ### comment this and next int32_t BPID;
bool temporary;
int BPID;
char description[512]; char description[512];
string function_name; // location string function_name; // location
const char* source_filename; const char* source_filename;
int source_line; int32_t source_line;
bool enabled; // ### comment this and next
bool temporary;
Stmt* at_stmt; Stmt* at_stmt;
double at_time; // break when the virtual time is this double at_time; // break when the virtual time is this
// Support for conditional and N'th time breakpoints. // Support for conditional and N'th time breakpoints.
int repeat_count; // if positive, break after this many hits int32_t repeat_count; // if positive, break after this many hits
int hit_count; // how many times it's been hit (w/o breaking) int32_t hit_count; // how many times it's been hit (w/o breaking)
string condition; // condition to evaluate; nil for none string condition; // condition to evaluate; nil for none
}; };

View file

@ -18,9 +18,9 @@ class Stmt;
enum ParseLocationRecType { plrUnknown, plrFileAndLine, plrFunction }; enum ParseLocationRecType { plrUnknown, plrFileAndLine, plrFunction };
struct ParseLocationRec { struct ParseLocationRec {
ParseLocationRecType type; ParseLocationRecType type;
int32_t line;
Stmt* stmt; Stmt* stmt;
const char* filename; const char* filename;
int line;
}; };
class StmtLocMapping; class StmtLocMapping;

View file

@ -30,14 +30,13 @@ public:
protected: protected:
DebugCmd cmd; DebugCmd cmd;
int num_names; int32_t num_names;
std::vector<const char*> names; std::vector<const char*> names;
const char* const helpstring;
// Whether executing this should restart execution of the script. // Whether executing this should restart execution of the script.
bool resume_execution; bool resume_execution;
const char* const helpstring;
// Does entering a blank line repeat this command? // Does entering a blank line repeat this command?
bool repeatable; bool repeatable;
}; };

View file

@ -190,15 +190,17 @@ protected:
bool utf8; // whether valid utf-8 sequences may pass through unescaped bool utf8; // whether valid utf-8 sequences may pass through unescaped
bool escape; // escape unprintable characters in output? bool escape; // escape unprintable characters in output?
typedef std::set<std::string> escape_set; bool is_short;
bool want_quotes;
int indent_with_spaces;
using escape_set = std::set<std::string>;
escape_set escape_sequences; // additional sequences of chars to escape escape_set escape_sequences; // additional sequences of chars to escape
BroFile* f; // or the file we're using. BroFile* f; // or the file we're using.
int indent_level; int indent_level;
int indent_with_spaces;
bool is_short;
bool want_quotes;
bool do_flush; bool do_flush;
bool include_stats; bool include_stats;

View file

@ -162,17 +162,18 @@ private:
int num_buckets = 0; int num_buckets = 0;
int num_entries = 0; int num_entries = 0;
int max_num_entries = 0; int max_num_entries = 0;
int thresh_entries = 0;
uint64_t cumulative_entries = 0; uint64_t cumulative_entries = 0;
double den_thresh = 0.0; double den_thresh = 0.0;
int thresh_entries = 0;
// Resizing table (replicates tbl above). // Resizing table (replicates tbl above).
PList<DictEntry>** tbl2 = nullptr; PList<DictEntry>** tbl2 = nullptr;
int num_buckets2 = 0; int num_buckets2 = 0;
int num_entries2 = 0; int num_entries2 = 0;
int max_num_entries2 = 0; int max_num_entries2 = 0;
double den_thresh2 = 0;
int thresh_entries2 = 0; int thresh_entries2 = 0;
double den_thresh2 = 0;
hash_t tbl_next_ind = 0; hash_t tbl_next_ind = 0;

View file

@ -44,11 +44,11 @@ protected:
u_char* proto_hdr; u_char* proto_hdr;
IP_Hdr* reassembled_pkt; IP_Hdr* reassembled_pkt;
uint16_t proto_hdr_len;
NetSessions* s; NetSessions* s;
uint64_t frag_size; // size of fully reassembled fragment uint64_t frag_size; // size of fully reassembled fragment
uint16_t next_proto; // first IPv6 fragment header's next proto field
FragReassemblerKey key; FragReassemblerKey key;
uint16_t next_proto; // first IPv6 fragment header's next proto field
uint16_t proto_hdr_len;
FragTimer* expire_timer; FragTimer* expire_timer;
}; };

View file

@ -261,6 +261,11 @@ private:
/** The number of vals that can be stored in this frame. */ /** The number of vals that can be stored in this frame. */
int size; int size;
bool weak_closure_ref = false;
bool break_before_next_stmt;
bool break_on_return;
bool delayed;
/** Associates ID's offsets with values. */ /** Associates ID's offsets with values. */
Val** frame; Val** frame;
@ -270,7 +275,6 @@ private:
/** The enclosing frame of this frame. */ /** The enclosing frame of this frame. */
Frame* closure; Frame* closure;
bool weak_closure_ref = false;
/** ID's used in this frame from the enclosing frame. */ /** ID's used in this frame from the enclosing frame. */
id_list outer_ids; id_list outer_ids;
@ -289,12 +293,8 @@ private:
/** The next statement to be evaluted in the context of this frame. */ /** The next statement to be evaluted in the context of this frame. */
Stmt* next_stmt; Stmt* next_stmt;
bool break_before_next_stmt;
bool break_on_return;
IntrusivePtr<trigger::Trigger> trigger; IntrusivePtr<trigger::Trigger> trigger;
const CallExpr* call; const CallExpr* call;
bool delayed;
std::vector<BroFunc*> functions_with_closure_frame_reference; std::vector<BroFunc*> functions_with_closure_frame_reference;
}; };

View file

@ -111,9 +111,9 @@ protected:
vector<Body> bodies; vector<Body> bodies;
IntrusivePtr<Scope> scope; IntrusivePtr<Scope> scope;
Kind kind; Kind kind;
uint32_t unique_id;
IntrusivePtr<BroType> type; IntrusivePtr<BroType> type;
string name; string name;
uint32_t unique_id;
static vector<Func*> unique_ids; static vector<Func*> unique_ids;
}; };

View file

@ -122,6 +122,8 @@ protected:
const char* name; const char* name;
IDScope scope; IDScope scope;
bool is_export; bool is_export;
bool infer_return_type;
bool weak_ref;
IntrusivePtr<BroType> type; IntrusivePtr<BroType> type;
bool is_const, is_enum_const, is_type, is_option; bool is_const, is_enum_const, is_type, is_option;
int offset; int offset;
@ -130,6 +132,4 @@ protected:
// contains list of functions that are called when an option changes // contains list of functions that are called when an option changes
std::multimap<int, IntrusivePtr<Func>> option_handlers; std::multimap<int, IntrusivePtr<Func>> option_handlers;
bool infer_return_type;
bool weak_ref;
}; };

View file

@ -93,17 +93,18 @@ struct ScannedFile {
dev_t dev; dev_t dev;
ino_t inode; ino_t inode;
int include_level; int include_level;
string name;
bool skipped; // This ScannedFile was @unload'd. bool skipped; // This ScannedFile was @unload'd.
bool prefixes_checked; // If loading prefixes for this file has been tried. bool prefixes_checked; // If loading prefixes for this file has been tried.
string name;
ScannedFile(dev_t arg_dev, ino_t arg_inode, int arg_include_level, ScannedFile(dev_t arg_dev, ino_t arg_inode, int arg_include_level,
const string& arg_name, bool arg_skipped = false, const string& arg_name, bool arg_skipped = false,
bool arg_prefixes_checked = false) bool arg_prefixes_checked = false)
: dev(arg_dev), inode(arg_inode), : dev(arg_dev), inode(arg_inode),
include_level(arg_include_level), include_level(arg_include_level),
name(arg_name), skipped(arg_skipped), skipped(arg_skipped),
prefixes_checked(arg_prefixes_checked) prefixes_checked(arg_prefixes_checked),
name(arg_name)
{ } { }
}; };

View file

@ -102,6 +102,7 @@ private:
uint32_t id; // For debugging, each HdrTest gets an unique ID uint32_t id; // For debugging, each HdrTest gets an unique ID
static uint32_t idcounter; static uint32_t idcounter;
int32_t level; // level within the tree
// The following are all set by RuleMatcher::BuildRulesTree(). // The following are all set by RuleMatcher::BuildRulesTree().
friend class RuleMatcher; friend class RuleMatcher;
@ -132,8 +133,6 @@ private:
RuleHdrTest* sibling; // linkage within HdrTest tree RuleHdrTest* sibling; // linkage within HdrTest tree
RuleHdrTest* child; RuleHdrTest* child;
int level; // level within the tree
}; };
typedef PList<RuleHdrTest> rule_hdr_test_list; typedef PList<RuleHdrTest> rule_hdr_test_list;
@ -173,7 +172,6 @@ private:
typedef PList<Matcher> matcher_list; typedef PList<Matcher> matcher_list;
bool is_orig;
analyzer::Analyzer* analyzer; analyzer::Analyzer* analyzer;
RuleEndpointState* opposite; RuleEndpointState* opposite;
analyzer::pia::PIA* pia; analyzer::pia::PIA* pia;
@ -188,6 +186,7 @@ private:
bstr_list matched_text; bstr_list matched_text;
int payload_size; int payload_size;
bool is_orig;
int_list matched_rules; // Rules for which all conditions have matched int_list matched_rules; // Rules for which all conditions have matched
}; };

View file

@ -691,7 +691,7 @@ class CompositeHash;
class HashKey; class HashKey;
class Frame; class Frame;
class TableVal : public Val, public notifier::Modifiable { class TableVal final : public Val, public notifier::Modifiable {
public: public:
explicit TableVal(IntrusivePtr<TableType> t, IntrusivePtr<Attributes> attrs = nullptr); explicit TableVal(IntrusivePtr<TableType> t, IntrusivePtr<Attributes> attrs = nullptr);
~TableVal() override; ~TableVal() override;

View file

@ -61,10 +61,10 @@ extern int recvfrom(int, void *, int, int, struct sockaddr *, int *);
struct nb_dns_entry { struct nb_dns_entry {
struct nb_dns_entry *next; struct nb_dns_entry *next;
char name[NS_MAXDNAME + 1]; char name[NS_MAXDNAME + 1];
u_short id;
int qtype; /* query type */ int qtype; /* query type */
int atype; /* address family */ int atype; /* address family */
int asize; /* address size */ int asize; /* address size */
u_short id;
void *cookie; void *cookie;
}; };

View file

@ -11,8 +11,8 @@ struct nb_dns_info;
struct nb_dns_result { struct nb_dns_result {
void *cookie; void *cookie;
int host_errno; int host_errno;
struct hostent *hostent;
uint32_t ttl; uint32_t ttl;
struct hostent *hostent;
}; };
typedef unsigned int nb_uint32_t; typedef unsigned int nb_uint32_t;