diff --git a/staticmemory/memory-bucket-optimizer/generate_test_logs.sh b/staticmemory/memory-bucket-optimizer/generate_test_logs.sh index 2e9e689e..e9aa1742 100755 --- a/staticmemory/memory-bucket-optimizer/generate_test_logs.sh +++ b/staticmemory/memory-bucket-optimizer/generate_test_logs.sh @@ -1,4 +1,23 @@ #!/bin/bash +# +# Copyright (C) 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 2 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 + # Script to generate test memory logs and run the optimizer diff --git a/staticmemory/memory-bucket-optimizer/src/README.md b/staticmemory/memory-bucket-optimizer/src/README.md new file mode 100644 index 00000000..f1d8e3bb --- /dev/null +++ b/staticmemory/memory-bucket-optimizer/src/README.md @@ -0,0 +1,52 @@ +# Memory Bucket Optimizer Source Code + +This directory contains the source code for the Memory Bucket Optimizer tool. + +## Software Bill of Materials (SBOM) + +| Component | Description | License | +|-----------|-------------|---------| +| Memory Bucket Optimizer | Core optimization tool | GPLv2 | +| GCC | C compiler | GPLv3 | + +## Stack Components + +The Memory Bucket Optimizer tool analyzes memory allocation patterns in wolfSSL and recommends optimal static memory bucket configurations to minimize wasted memory. The stack components include: + +1. **Memory Bucket Optimizer**: The core optimization tool +2. **GCC**: The C compiler used to build the tool + +## Building + +To build the Memory Bucket Optimizer tool, run: + +```bash +cd ~/repos/wolfssl-examples/staticmemory/memory-bucket-optimizer +make +``` + +## Usage + +To use the Memory Bucket Optimizer tool, run: + +```bash +./src/memory_bucket_optimizer > +``` + +For example: + +```bash +./src/memory_bucket_optimizer results/tls13_google_memory.txt > results/tls13_google_buckets.txt +``` + +This will analyze the memory allocation patterns in the memory log file and generate optimized bucket configurations in the output file. + +## 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 diff --git a/staticmemory/memory-bucket-optimizer/test_operations.sh b/staticmemory/memory-bucket-optimizer/test_operations.sh index 2f8079e5..709fbea8 100755 --- a/staticmemory/memory-bucket-optimizer/test_operations.sh +++ b/staticmemory/memory-bucket-optimizer/test_operations.sh @@ -1,4 +1,23 @@ #!/bin/bash +# +# Copyright (C) 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 2 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 + # Script to test the memory bucket optimizer with different TLS operations diff --git a/staticmemory/memory-bucket-optimizer/test_optimizer.sh b/staticmemory/memory-bucket-optimizer/test_optimizer.sh index 64f417a3..3cad6642 100755 --- a/staticmemory/memory-bucket-optimizer/test_optimizer.sh +++ b/staticmemory/memory-bucket-optimizer/test_optimizer.sh @@ -1,4 +1,23 @@ #!/bin/bash +# +# Copyright (C) 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 2 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 + # Script to test the memory bucket optimizer with different TLS operations diff --git a/staticmemory/memory-bucket-optimizer/visualization/generate_data.sh b/staticmemory/memory-bucket-optimizer/visualization/generate_data.sh index 8e776798..331acd6b 100755 --- a/staticmemory/memory-bucket-optimizer/visualization/generate_data.sh +++ b/staticmemory/memory-bucket-optimizer/visualization/generate_data.sh @@ -1,4 +1,23 @@ #!/bin/bash +# +# Copyright (C) 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 2 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 + # Script to generate data files and plots for memory bucket optimization diff --git a/staticmemory/memory-bucket-optimizer/visualization/tls12_cloudflare_bucket_opt.gp b/staticmemory/memory-bucket-optimizer/visualization/tls12_cloudflare_bucket_opt.gp new file mode 100644 index 00000000..7c2379bd --- /dev/null +++ b/staticmemory/memory-bucket-optimizer/visualization/tls12_cloudflare_bucket_opt.gp @@ -0,0 +1,11 @@ +set terminal png size 800,600 +set output "tls12_cloudflare_bucket_optimization.png" +set title "Bucket Optimization for tls12_cloudflare" +set xlabel "Size (bytes)" +set ylabel "Count" +set grid +set style fill solid 0.5 +set boxwidth 0.8 +set key outside +plot "data/tls12_cloudflare_alloc_data.txt" using 2:1 with boxes title "Allocation Sizes", \ + "data/tls12_cloudflare_bucket_sizes.txt" using 1:(0.5) with impulses lw 2 title "Bucket Sizes" diff --git a/staticmemory/memory-bucket-optimizer/visualization/tls12_cloudflare_histogram.gp b/staticmemory/memory-bucket-optimizer/visualization/tls12_cloudflare_histogram.gp new file mode 100644 index 00000000..ce99bb21 --- /dev/null +++ b/staticmemory/memory-bucket-optimizer/visualization/tls12_cloudflare_histogram.gp @@ -0,0 +1,10 @@ +set terminal png size 800,600 +set output "tls12_cloudflare_allocation_histogram.png" +set title "Allocation Size Distribution for tls12_cloudflare" +set xlabel "Allocation Size (bytes)" +set ylabel "Frequency" +set style fill solid 0.5 +set boxwidth 0.8 +set grid +set logscale y +plot "data/tls12_cloudflare_alloc_data.txt" using 2:1 with boxes title "Allocation Sizes" diff --git a/staticmemory/memory-bucket-optimizer/visualization/tls13_cloudflare_bucket_opt.gp b/staticmemory/memory-bucket-optimizer/visualization/tls13_cloudflare_bucket_opt.gp new file mode 100644 index 00000000..074ee290 --- /dev/null +++ b/staticmemory/memory-bucket-optimizer/visualization/tls13_cloudflare_bucket_opt.gp @@ -0,0 +1,11 @@ +set terminal png size 800,600 +set output "tls13_cloudflare_bucket_optimization.png" +set title "Bucket Optimization for tls13_cloudflare" +set xlabel "Size (bytes)" +set ylabel "Count" +set grid +set style fill solid 0.5 +set boxwidth 0.8 +set key outside +plot "data/tls13_cloudflare_alloc_data.txt" using 2:1 with boxes title "Allocation Sizes", \ + "data/tls13_cloudflare_bucket_sizes.txt" using 1:(0.5) with impulses lw 2 title "Bucket Sizes" diff --git a/staticmemory/memory-bucket-optimizer/visualization/tls13_cloudflare_histogram.gp b/staticmemory/memory-bucket-optimizer/visualization/tls13_cloudflare_histogram.gp new file mode 100644 index 00000000..26a2070a --- /dev/null +++ b/staticmemory/memory-bucket-optimizer/visualization/tls13_cloudflare_histogram.gp @@ -0,0 +1,10 @@ +set terminal png size 800,600 +set output "tls13_cloudflare_allocation_histogram.png" +set title "Allocation Size Distribution for tls13_cloudflare" +set xlabel "Allocation Size (bytes)" +set ylabel "Frequency" +set style fill solid 0.5 +set boxwidth 0.8 +set grid +set logscale y +plot "data/tls13_cloudflare_alloc_data.txt" using 2:1 with boxes title "Allocation Sizes" diff --git a/staticmemory/memory-bucket-optimizer/visualization/tls13_google_bucket_opt.gp b/staticmemory/memory-bucket-optimizer/visualization/tls13_google_bucket_opt.gp new file mode 100644 index 00000000..e8c79f14 --- /dev/null +++ b/staticmemory/memory-bucket-optimizer/visualization/tls13_google_bucket_opt.gp @@ -0,0 +1,11 @@ +set terminal png size 800,600 +set output "tls13_google_bucket_optimization.png" +set title "Bucket Optimization for tls13_google" +set xlabel "Size (bytes)" +set ylabel "Count" +set grid +set style fill solid 0.5 +set boxwidth 0.8 +set key outside +plot "data/tls13_google_alloc_data.txt" using 2:1 with boxes title "Allocation Sizes", \ + "data/tls13_google_bucket_sizes.txt" using 1:(0.5) with impulses lw 2 title "Bucket Sizes" diff --git a/staticmemory/memory-bucket-optimizer/visualization/tls13_google_histogram.gp b/staticmemory/memory-bucket-optimizer/visualization/tls13_google_histogram.gp new file mode 100644 index 00000000..2e338216 --- /dev/null +++ b/staticmemory/memory-bucket-optimizer/visualization/tls13_google_histogram.gp @@ -0,0 +1,10 @@ +set terminal png size 800,600 +set output "tls13_google_allocation_histogram.png" +set title "Allocation Size Distribution for tls13_google" +set xlabel "Allocation Size (bytes)" +set ylabel "Frequency" +set style fill solid 0.5 +set boxwidth 0.8 +set grid +set logscale y +plot "data/tls13_google_alloc_data.txt" using 2:1 with boxes title "Allocation Sizes"