mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-11-08 16:11:26 +00:00
libsensors: Get rid of arbitrary limit on per-type sensor count
When gathering the attributes of each hwmon chip, libsensors uses a temporary structure in memory to order and group all the attributes into features. This temporary structure used to be a single array with room for every possible attribute/subfeature. While simple, this approach required to predefine a maximum number of per-type sensor that could be handled. In order to get rid of this arbitrary limit, which we hit and had to raise three times already, I changed the temporary structure to an array of dynamically allocated per-type subattribute arrays. This lets us not allocate any memory for types which aren't implemented by a given chip, and more importantly, this lets us reallocate room for more attributes of a given type as needed. I decided to allocate chunks of 8 attributes at a time, as this seemed a good compromise between two frequent reallocations and over-provisioning. It could be tweaked if needed. Icing on the cake, I benchmarked this change on two different systems and it results in performance gains. The total heap usage as reported by valgrind is down by 50% on average, with peak memory consumption (as reported by valgrind's massif) also down by 43% on average. The total instructions count (as reported by valgrind's callgrind) is down by 11% on average, with measured execution time also down by a few percents. Valgrind rocks, BTW. I have some ideas to optimize the memory allocations further, but I do not expect such a huge gain from them. They may not even improve peak memory consumption as massif shows the peak is somewhere else now at least in some cases.
This commit is contained in:
1 parent
18853526ec
commit
883f4e49a3
4 files changed
+84
-78
No files matched your search
@@ -6,6 +6,10 @@ over time. This document summarizes these evolutions so that application
|
||||
authors can quickly figure out how to test for the availability of a
|
||||
given new feature.
|
||||
|
||||
0x440 lm-sensors 3.4.0
|
||||
* Defined SENSORS_FEATURE_MAX
|
||||
enum sensors_feature_type SENSORS_FEATURE_MAX
|
||||
|
||||
0x432 lm-sensors 3.3.2 to 3.3.5
|
||||
* Added support for new sysfs attributes
|
||||
enum sensors_subfeature_type SENSORS_SUBFEATURE_IN_AVERAGE
|
||||
@@ -19,6 +23,7 @@ given new feature.
|
||||
enum sensors_subfeature_type SENSORS_SUBFEATURE_FAN_MAX
|
||||
enum sensors_subfeature_type SENSORS_SUBFEATURE_FAN_MIN_ALARM
|
||||
enum sensors_subfeature_type SENSORS_SUBFEATURE_FAN_MAX_ALARM
|
||||
|
||||
0x431 lm-sensors 3.3.0 to 3.3.1
|
||||
* Added support for intrusion detection
|
||||
enum sensors_feature_type SENSORS_FEATURE_INTRUSION
|
||||
|
||||
Reference in new issue
Block a user