wolfssl-examples/staticmemory/memory-bucket-optimizer
Devin AI 592e088800 Add memory bucket optimizer tool
This commit adds a tool to analyze memory allocation patterns from wolfSSL
operations and recommend optimal static memory bucket configurations to
minimize wasted memory. The tool includes:

- Memory bucket optimizer that analyzes allocation logs
- Example application demonstrating optimized bucket usage
- Visualization scripts using gnuplot
- Scripts to run optimization for different TLS operations

The tool helps users find optimal WOLFMEM_BUCKETS and WOLFMEM_DIST
configurations for their specific use cases.

Co-Authored-By: jacob@wolfssl.com <jacob@wolfssl.com>
2025-03-04 01:04:54 +00:00
..
examples Add memory bucket optimizer tool 2025-03-04 01:04:54 +00:00
src Add memory bucket optimizer tool 2025-03-04 01:04:54 +00:00
visualization Add memory bucket optimizer tool 2025-03-04 01:04:54 +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 memory bucket optimizer tool 2025-03-04 01:04:54 +00:00
run_multiple.sh Add memory bucket optimizer tool 2025-03-04 01:04:54 +00:00
run_optimizer.sh Add memory bucket optimizer tool 2025-03-04 01:04:54 +00:00

README.md

Memory Bucket Optimizer for wolfSSL Static Memory

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

Software Bill of Materials (SBOM)

Component Version License Purpose
wolfSSL 5.6.6 GPLv2 TLS/SSL library with static memory support
gnuplot 5.4+ gnuplot license Data visualization
gcc 9.4+ GPLv3 C compiler
GNU Make 4.2+ GPLv3 Build system

Stack Components

  1. Memory Bucket Optimizer

    • Analyzes memory allocation logs
    • Recommends optimal bucket sizes
    • Generates visualization plots
  2. wolfSSL Integration

    • Uses wolfSSL's static memory feature
    • Configures memory buckets via WOLFMEM_BUCKETS and WOLFMEM_DIST
    • Requires wolfSSL built with --enable-staticmemory
  3. Visualization Tools

    • gnuplot scripts for data visualization
    • Memory usage analysis plots
    • Bucket optimization charts

Building and Running

  1. Build wolfSSL with static memory and logging:

    cd ../../../wolfssl
    ./autogen.sh
    ./configure --enable-staticmemory --enable-memorylog
    make
    
  2. Build the memory bucket optimizer:

    cd ../wolfssl-examples/staticmemory/memory-bucket-optimizer
    make
    
  3. Run the optimizer:

    ./run_optimizer.sh
    
  4. Generate visualization plots:

    cd visualization
    ./generate_data.sh
    

Directory Structure

memory-bucket-optimizer/
├── src/                    # Source code
├── visualization/          # Visualization scripts
├── examples/              # Example applications
├── Makefile              # Build system
├── run_optimizer.sh      # Main script
└── README.md             # This file

Usage

  1. Basic Usage

    ./run_optimizer.sh
    
  2. Optimize for Multiple TLS Operations

    ./optimize_multiple.sh
    
  3. Verify Optimization Results

    ./verify_optimization.sh
    

Output

The tool generates:

  1. Optimized bucket configurations (WOLFMEM_BUCKETS and WOLFMEM_DIST)
  2. Memory usage analysis plots
  3. Comparison of different TLS operations
  4. Memory allocation pattern visualizations

Example Output

/* Optimized bucket configuration */
#define WOLFMEM_BUCKETS 16,22,30,40,86,133,184,256,344,512,864,1248,1812,3128,5518,8368
#define WOLFMEM_DIST    2,3,7,7,7,7,7,7,7,7,7,7,8,8,8,8

License

This example is part of wolfSSL examples and is licensed under the same terms as wolfSSL. See the LICENSE file in the wolfSSL root directory for details.