Skip to content

Commit 5e8cf97

Browse files
initial generated optimization tool
1 parent dc36abd commit 5e8cf97

3 files changed

Lines changed: 642 additions & 0 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Memory Bucket Optimizer for wolfSSL
2+
3+
** Note that the staticmemory build of wolfSSL does not use less memory **
4+
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.
5+
6+
7+
This tool analyzes memory allocation patterns in wolfSSL and recommends optimal static memory bucket configurations to minimize wasted memory.
8+
9+
## Overview
10+
11+
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.
12+
13+
## Directory Structure
14+
15+
```
16+
memory-bucket-optimizer/
17+
├── optimizer/ # Source code for the optimizer
18+
└── README.md # This file
19+
```
20+
21+
## Prerequisites
22+
23+
- wolfSSL (built with `CPPFLAGS="-DWOLFSSL_DEBUG_MEMORY -DWOLFSSL_DEBUG_MEMORY_PRINT` and `--enable-staticmemory`)
24+
- GCC compiler
25+
- gnuplot (for visualization)
26+
27+
## Building
28+
29+
```bash
30+
make
31+
```
32+
33+
## Usage
34+
35+
### Basic Usage
36+
37+
1. Build wolfSSL with memory logging enabled:
38+
39+
```bash
40+
cd ~/wolfssl
41+
./configure CPPFLAGS="-DWOLFSSL_DEBUG_MEMORY -DWOLFSSL_DEBUG_MEMORY_PRINT" --enable-staticmemory
42+
make
43+
sudo make install
44+
```
45+
46+
2. Run the application linked to wolfssl:
47+
48+
```bash
49+
./wolfcrypt/test/testwolfcrypt &> testwolfcrypt.log
50+
```
51+
52+
This will run the application with memory log output.
53+
54+
3. Run the log through the optimizer
55+
56+
```bash
57+
cd optimizer
58+
make
59+
./memory_bucket_optimizer testwolfcrypt.log
60+
```
61+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Makefile for memory_bucket_optimizer
2+
#
3+
# Copyright (C) 2006-2025 wolfSSL Inc.
4+
#
5+
# This file is part of wolfSSL.
6+
#
7+
# wolfSSL is free software; you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation; either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# wolfSSL is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with this program; if not, write to the Free Software
19+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
20+
21+
CC = gcc
22+
LDFLAGS = -lwolfssl
23+
24+
all: memory_bucket_optimizer
25+
26+
memory_bucket_optimizer: memory_bucket_optimizer.c
27+
$(CC) $(CFLAGS) -o memory_bucket_optimizer memory_bucket_optimizer.c $(LDFLAGS)
28+
29+
clean:
30+
rm -f memory_bucket_optimizer
31+
32+
.PHONY: all clean

0 commit comments

Comments
 (0)