wolfssl-examples/staticmemory/memory-bucket-optimizer
Devin AI abb76a4089 Add copyright notices and comprehensive documentation
Co-Authored-By: jacob@wolfssl.com <jacob@wolfssl.com>
2025-03-04 02:03:21 +00:00
..
examples Update TLS example to better handle missing static memory support 2025-03-04 01:07:30 +00:00
src Add copyright notices and comprehensive documentation 2025-03-04 02:03:21 +00:00
visualization Add copyright notices and comprehensive documentation 2025-03-04 02:03:21 +00:00
.gitignore Add memory bucket optimizer tool 2025-03-04 01:04:54 +00:00
Makefile Add memory bucket optimizer tool 2025-03-04 01:04:54 +00:00
README.md Add visualization scripts and update documentation 2025-03-04 01:52:38 +00:00
compare_memory.sh Add memory usage comparison script 2025-03-04 01:19:36 +00:00
generate_test_logs.sh Add copyright notices and comprehensive documentation 2025-03-04 02:03:21 +00:00
run_multiple.sh Add visualization scripts and update documentation 2025-03-04 01:52:38 +00:00
run_optimizer.sh Add memory bucket optimizer tool 2025-03-04 01:04:54 +00:00
test_operations.sh Add copyright notices and comprehensive documentation 2025-03-04 02:03:21 +00:00
test_optimizer.sh Add copyright notices and comprehensive documentation 2025-03-04 02:03:21 +00:00

README.md

Memory Bucket Optimizer for wolfSSL

This tool analyzes memory allocation patterns in wolfSSL and recommends optimal static memory bucket configurations to minimize wasted memory.

Overview

When wolfSSL is built with the --enable-staticmemory option, it uses a static memory management system with memory buckets. The size and distribution of these buckets can significantly impact memory usage efficiency. This tool helps optimize these bucket configurations for specific TLS operations.

Software Bill of Materials (SBOM)

Component Description License
Memory Bucket Optimizer Core optimization tool GPLv2
wolfSSL TLS/SSL library GPLv2
gnuplot Plotting utility GPLv2
Bash Scripts Automation scripts GPLv2
Example Applications Demo applications GPLv2

Directory Structure

memory-bucket-optimizer/
├── src/                    # Source code for the optimizer
├── results/                # Results of optimization runs
├── examples/               # Example applications using optimized buckets
├── visualization/          # Visualization scripts and plots
├── run_multiple.sh         # Script to run tests for multiple TLS operations
├── compare_memory.sh       # Script to compare memory usage
└── README.md               # This file

Prerequisites

  • wolfSSL (built with --enable-memorylog and --enable-staticmemory)
  • GCC compiler
  • gnuplot (for visualization)

Building

make

Usage

Basic Usage

  1. Build wolfSSL with memory logging enabled:
cd ~/repos/wolfssl
./configure --enable-memorylog --enable-staticmemory && make
  1. Run the optimizer:
./run_multiple.sh

This will:

  • Run the example client with different TLS operations
  • Collect memory allocation logs
  • Generate optimized bucket configurations for each operation
  • Create visualization plots

Advanced Usage

To optimize for a specific TLS operation:

./src/memory_bucket_optimizer results/tls13_google_memory.txt > results/tls13_google_buckets.txt

To compare memory usage between default and optimized configurations:

./compare_memory.sh

Visualization

The visualization directory contains scripts to generate plots:

  • Allocation size histograms
  • Bucket optimization plots
  • TLS operation comparisons

To generate plots:

cd visualization
./generate_data.sh

Example Applications

The examples directory contains example applications that demonstrate how to use the optimized bucket configurations in your wolfSSL applications.

Algorithm

The memory bucket optimizer uses the following algorithm:

  1. Parse memory allocation logs to identify allocation sizes and frequencies
  2. Sort allocation sizes from smallest to largest
  3. Select the most frequent allocation sizes as bucket sizes
  4. Assign distribution values based on allocation frequency
  5. Calculate memory waste and optimize for minimal overhead

License

This project is licensed under the GPL v2.0 License - see the LICENSE file for details.