Skip to content

Commit 05b3b76

Browse files
authored
Merge pull request #513 from JacobBarthelmeh/static_memory_tool
initial generated optimization tool
2 parents e9632df + 8adc6ad commit 05b3b76

File tree

5 files changed

+1236
-0
lines changed

5 files changed

+1236
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
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.
8+
9+
## Directory Structure
10+
11+
```
12+
memory-bucket-optimizer/
13+
├── optimizer/ # Source code for the optimizer
14+
├── tester/ # Source code for testing configuration
15+
└── README.md # This file
16+
```
17+
18+
## Prerequisites
19+
20+
- wolfSSL (built with `CPPFLAGS="-DWOLFSSL_DEBUG_MEMORY -DWOLFSSL_DEBUG_MEMORY_PRINT` and `--enable-staticmemory`)
21+
- GCC compiler
22+
- gnuplot (for visualization)
23+
24+
## Building
25+
26+
```bash
27+
make
28+
```
29+
30+
## Usage
31+
32+
### Basic Usage
33+
34+
1. Build wolfSSL with memory logging enabled:
35+
36+
```bash
37+
cd ~/wolfssl
38+
./configure CPPFLAGS="-DWOLFSSL_DEBUG_MEMORY -DWOLFSSL_DEBUG_MEMORY_PRINT" --enable-staticmemory
39+
make
40+
sudo make install
41+
```
42+
43+
2. Run the application linked to wolfssl:
44+
45+
```bash
46+
./wolfcrypt/test/testwolfcrypt &> testwolfcrypt.log
47+
```
48+
49+
This will run the application with memory log output.
50+
51+
3. Run the log through the optimizer
52+
53+
```bash
54+
cd optimizer
55+
make
56+
./memory_bucket_optimizer testwolfcrypt.log
57+
```
58+
59+
4. Build and run tester (optional)
60+
61+
```
62+
cd ~/wolfssl
63+
./configure CPPFLAGS="-DWOLFSSL_NO_MALLOC -DWOLFSSL_DEBUG_MEMORY -DWOLFSSL_DEBUG_MEMORY_PRINT" --enable-staticmemory
64+
make && sudo make install
65+
cd tester && make
66+
./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
67+
```
68+
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)