Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions staticmemory/memory-bucket-optimizer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Memory Bucket Optimizer for wolfSSL

** Note that the staticmemory build of wolfSSL does not use less memory **
The staticmemory feature ends up using a bit more memory and is a simple sectioning up of a static buffer used dynamically instead of malloc/free. wolfSSL has the option for users to define custom XMALLOC/XFREE if wanting to use a different allocater.


The exact optimized configuration is a difficult problem (think traveling salesman problem), but this optimizer gives a good starting point. It uses a simple algorithm in that it fill the first half of bucket sizes with largest allocations and the second half based on max concurrent uses.

## Directory Structure

```
memory-bucket-optimizer/
├── optimizer/ # Source code for the optimizer
├── tester/ # Source code for testing configuration
└── README.md # This file
```

## Prerequisites

- wolfSSL (built with `CPPFLAGS="-DWOLFSSL_DEBUG_MEMORY -DWOLFSSL_DEBUG_MEMORY_PRINT` and `--enable-staticmemory`)
- GCC compiler
- gnuplot (for visualization)

## Building

```bash
make
```

## Usage

### Basic Usage

1. Build wolfSSL with memory logging enabled:

```bash
cd ~/wolfssl
./configure CPPFLAGS="-DWOLFSSL_DEBUG_MEMORY -DWOLFSSL_DEBUG_MEMORY_PRINT" --enable-staticmemory
make
sudo make install
```

2. Run the application linked to wolfssl:

```bash
./wolfcrypt/test/testwolfcrypt &> testwolfcrypt.log
```

This will run the application with memory log output.

3. Run the log through the optimizer

```bash
cd optimizer
make
./memory_bucket_optimizer testwolfcrypt.log
```

4. Build and run tester (optional)

```
cd ~/wolfssl
./configure CPPFLAGS="-DWOLFSSL_NO_MALLOC -DWOLFSSL_DEBUG_MEMORY -DWOLFSSL_DEBUG_MEMORY_PRINT" --enable-staticmemory
make && sudo make install
cd tester && make
./memory_bucket_tester ../testwolfcrypt.log --buckets "289,832,1056,1072,1152,1616,1632,3160,4240" --dist "2,1,2,1,1,1,1,19,1" --buffer-size 74298
```

32 changes: 32 additions & 0 deletions staticmemory/memory-bucket-optimizer/optimizer/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Makefile for memory_bucket_optimizer
#
# Copyright (C) 2006-2025 wolfSSL Inc.
#
# This file is part of wolfSSL.
#
# wolfSSL is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# wolfSSL is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA

CC = gcc
LDFLAGS = -lwolfssl

all: memory_bucket_optimizer

memory_bucket_optimizer: memory_bucket_optimizer.c
$(CC) $(CFLAGS) -o memory_bucket_optimizer memory_bucket_optimizer.c $(LDFLAGS)

clean:
rm -f memory_bucket_optimizer

.PHONY: all clean
Loading
Loading