D-FOT User Guide
Overview
Dynamic Feedback-directed Optimization Tool (D-FOT) is a dynamic feedback-directed optimization framework. It aims to enable fully automatic and non-intrusive feedback-directed optimization for applications, comprehensively improving the usability and performance of this feature. The framework is planned to support two types of dynamic optimizations: startup time optimization and runtime optimization. Currently, startup time optimization has been implemented based on the oeAware online tuning framework. Startup time optimization: During application running, sampling and feedback-directed optimization are automatically performed. Once optimization is complete, the optimized version automatically takes over the next startup. You do not need to modify the startup procedure, and the optimized version is automatically started after the application is restarted. Runtime optimization: During application running, sampling and feedback-directed optimization are automatically performed. You do not need to restart the application, and no user intervention is required throughout the process. The optimized version can be enabled after only a few interruptions.
Software Architecture Description
This framework consists of the following modules:
- libkperf-based sampling data processing
- sysboost-based startup takeover and binary optimization feature enablement
- llvm-bolt-based binary feedback-directed optimization
- Implementation of the oeAware tuning plugin dfot_tuner_sysboost
Dependency Items
OS requirements: Currently, only openEuler 22.03 LTS SP4 is supported. The following dependent components can be installed using yum.
| Component | Code Repository | Branch or Version | Description |
|---|---|---|---|
| oeAware-manager | https://atomgit.com/openeuler/oeAware-manager | openEuler-22.03-LTS-SP4 v2.0.0-3 | Online transparent service tuning framework |
| libkperf | https://atomgit.com/openeuler/libkperf | openEuler-22.03-LTS-SP4 v1.2-2 | Lightweight in-memory collection tool |
| sysboost | https://atomgit.com/openeuler/sysboost | openEuler-22.03-LTS-SP4 | Microarchitecture tuning tool |
| llvm-bolt | https://atomgit.com/src-openeuler/llvm-bolt | openEuler-22.03-LTS-SP4 17.0.6-12 | Binary optimizer |
Procedure
Prerequisites for Applications to Be Optimized
- The binary to be optimized must contain relocation information. For self-compiled software, the
-Wl,-qlinker option must be added during compilation. For example, for MySQL, addcmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DBUILD_CONFIG=mysql_release -DWITH_BOOST=../boost -DCMAKE_C_LINK_FLAGS="-Wl,-q" -DCMAKE_CXX_LINK_FLAGS="-Wl,-q". For openEuler software packages, the relocation package of the corresponding application will be provided and can be directly installed. - Check whether the target binary contains relocation information: When the
-Wl,-qlinker option is effective, the binary will include RELA sections. You can check this usingreadelf -SW /path/to/bin. For example, in MySQL, before adding the option, only the.rela.dynand.rela.pltsections exist. After option addition, more than 10 RELA sections appear, including.rela.textand.rela.eh_frame. If-Wl,-qis not effective, when manual perf sampling andperf2boltare performed orllvm-boltis used to perform optimization (with or without sysboost), the alarmBOLT-WARNING: non-relocation mode for AArch64 is not fully supportedis reported.
D-FOT Preparations
Install D-FOT using yum or build it from the source code using the following commands. (If libkperf or oeAware-manager is also built from the source code, you need to specify the library and include path when running cmake.)
# Install dependency packages.
yum install boost-devel log4cplus-devel numactl-devel libkperf-devel oeAware-manager-devel
# Download the source code and compile it.
git clone https://atomgit.com/openeuler/D-FOT.git
cd D-FOT
mkdir build && cd build
cmake ../ -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_SKIP_RPATH=TRUE
make -j`nproc`
cd ..
cp build/libdfot.so /lib64/oeAware-plugin/
chmod 440 /lib64/oeAware-plugin/libdfot.so
mkdir -p /etc/dfot/
cp configs/dfot.ini /etc/dfot/Configuration Modification
Modify /etc/dfot/dfot.ini. The configuration items can be set according to the following description. Public configuration: [general]
| Configuration Item | Value Range | Available | Description |
|---|---|---|---|
| LOG_LEVEL | <FATAL, ERROR, WARN, INFO, DEBUG> | Yes | Log level for the optimization service. Levels in the value range are listed in descending order of severity, and the default value is INFO. Note that a lower level produces more log output. |
| COLLECTOR_SAMPLING_STRATEGY | 0 | No | Sampling policy.0 indicates that low-frequency sampling is continuously performed after the plugin is enabled.1 indicates that the monitoring thread is started when the plugin is enabled. Sampling is performed only when the load reaches the threshold.Currently, the sampling process is controlled by oeAware, and only 0 is supported. |
| COLLECTOR_HIGH_LOAD_THRESHOLD | [0, cpus*100] | No | Application CPU usage threshold (HIGH_LOAD_THRESHOLD) for triggering sampling. This parameter is available only when sampling policy is set to 1. Currently, this parameter is not supported. |
| COLLECTOR_SAMPLING_PERIOD | 100 | No | Interval at which the collector runs, in milliseconds. The collector runs once every COLLECTOR_SAMPLING_PERIOD ms. Currently, this parameter is uniformly configured by oeAware. |
| COLLECTOR_SAMPLING_FREQ | 100 | No | Sampling frequency. Sampling is performed COLLECTOR_SAMPLING_FREQ times per second. Currently, this parameter is uniformly configured by oeAware. |
| COLLECTOR_DATA_AGING_TIME | Determined based on actual requirements | Yes | Aging time of sampling data, in milliseconds. When the time difference between the current data and the earliest data reaches the threshold, the accumulated sampling data is discarded. |
| TUNER_TOOL | ["sysboost"] | No | Binary optimizer. Currently, only sysboost is supported. |
| TUNER_CHECK_PERIOD | [10, max] | Yes | Interval for optimization plugin check, in milliseconds. The plugin periodically checks whether the internally collected data meets the conditions for a new round of optimization. There is no upper limit, but do not set it too large to avoid delayed optimization. The default value is 1000. |
| TUNER_PROFILE_DIR | Determined based on actual requirements | Yes | Location where the sampling data is stored. The profile file is named in format [app_name]_[full_path_hash]_[threshold].profile. |
| TUNER_OPTIMIZING_STRATEGY | [0, 1] | Yes | Optimization policy. 0 indicates that the optimization is performed only once, and 1 indicates that the optimization can be performed for multiple times as long as the sampling information is updated. |
| TUNER_OPTIMIZING_CONDITION | 0 | No | Condition for triggering optimization. 0 indicates that the optimization starts immediately after the application exits. 1 indicates that the optimization is performed when the load is low. 2 indicates that the optimization is performed when the application exits and the load is low. Currently, only 0 is supported. |
| Application configuration: [app] |
| Configuration Item | Value Range | Available | Description |
|---|---|---|---|
| FULL_PATH | Determined based on actual requirements | Yes | Absolute path of the application binary file. |
| DEFAULT_PROFILE | Determined based on actual requirements | Yes | Default profile file of the application, which is used to enable binary optimization during cold start. If there is no such file, leave it empty. |
| COLLECTOR_DUMP_DATA_THRESHOLD | [10000, max] | Yes | Row count threshold for exporting sampling data to the profile. A larger value indicates more samples to be collected before the export occurs. Determine this value based on the actual application and test scenario. For MySQL, the reference value is 65000. |
| BOLT_DIR | /usr/bin | No | BOLT tool path. If this parameter is left empty, the default value /usr/bin is used. $\{BOLT_DIR}/perf2bolt and $\{BOLT_DIR}/llvm-bolt are invoked internally.This parameter is determined by sysboost. |
| BOLT_OPTIONS | Determined based on actual requirements | Yes | BOLT optimization option. This option can be configured to override the built-in default option for specific optimization. |
| UPDATE_DEBUG_INFO | [0, 1] | Yes | Whether to update the debugging information synchronously during optimization. 1 indicates that the debugging information is updated, and 0 indicates that the debugging information is not updated. Note that updating the debugging information will take extra time. |
Plugin Usage
See https://atomgit.com/openeuler/oeAware-manager/tree/master/docs.
If D-FOT is installed using yum, you can directly run the following commands to enable plugin instances:
# Restart the oeAware service.
systemctl restart oeaware
# Enable the collection plugin.
oeawarectl -e pmu_sampling_collector
# Enable the feedback-directed optimization tuning plugin.
oeawarectl -e dfot_tuner_sysboost
# Disable the two plugins.
oeawarectl -d pmu_sampling_collector
oeawarectl -d dfot_tuner_sysboostIf D-FOT is built from the source code, copy libdfot.so to the default plugin directory /lib64/oeAware-plugin/ of oeAware, and then load and activate the plugin instance. Note that the permission of the plugin must be 440:
# Restart the oeAware service (the plugins in /lib64/oeAware-plugin/ are automatically loaded).
systemctl restart oeaware
# Alternatively, do not restart the service and manually run oeawarectl to load the plugin.
oeawarectl -l libdfot.so
# Then, perform the preceding enable operations.For other operations, see the oeAware user manual.
Example
The following uses the TPCC test scenario of mysql-8.0.25 as an example:
# 1. Prepare the environment.
yum install libkperf oeaware-manager sysboost llvm-bolt D-FOT
# 2. Build MySQL.
# -Wl,-q is mandatory for optimization. -fPIE and -Wl,-zmax-page-size=0x200000 -Wl,-zcommon-page-size=0x200000 are optional. They are mandatory if sysboost huge page preloading optimization is required.
cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DBUILD_CONFIG=mysql_release -DWITH_BOOST=../boost -DCMAKE_C_FLAGS="-fPIE" -DCMAKE_CXX_FLAGS="-fPIE" -DCMAKE_C_LINK_FLAGS="-Wl,-q -Wl,-zmax-page-size=0x200000 -Wl,-zcommon-page-size=0x200000 -pie" -DCMAKE_CXX_LINK_FLAGS="-Wl,-q -Wl,-zmax-page-size=0x200000 -Wl,-zcommon-page-size=0x200000 -pie"
# 3. Start oeAware and the optimization plugins.
# Fill in /etc/dfot/dfot.ini based on the actual application information, and then run the following commands.
systemctl start sysboost
systemctl start oeaware
oeawarectl -e pmu_sampling_collector
oeawarectl -e dfot_tuner_sysboost
# 4. Run the TPCC test.
...
# 5. Restart MySQL.
# You can check /etc/dfot/dfot.log in advance to determine whether optimization has been performed. After the application is restarted, the optimized version is used.Constraints
- Due to the limitations of the sysboost implementation, D-FOT cannot be used in virtualization scenarios (KVM virtual machines: supported but live migration is not supported; Docker containers: not supported).
- The target application to be optimized must include relocation information.
- When D-FOT is used as the oeAware tuning plugin, the fixed sampling frequency of the current oeAware collection plugin pmu_sampling_collector is 100, which may cause a long sampling time (for reference, the default sampling frequency of perf is 4000).
Future Plans
- [ ] Virtualization scenario support
- [ ] Runtime optimization support
- [ ] Enhanced binary optimization
