refactor ♻️: Refactor memory variables and calculations #32

Merged
Jose merged 1 commits from dev into main 2026-02-15 12:50:05 +01:00
Owner

Renamed _total_ram_mb to log2ram_host_memtotal_mb and updated the calculation accordingly. Updated variable names for memory checks in swap task.

Renamed `_total_ram_mb` to `log2ram_host_memtotal_mb` and updated the calculation accordingly. Updated variable names for memory checks in swap task.
Jose added 1 commit 2026-02-15 12:46:09 +01:00
refactor ♻️: Refactor memory variables and calculations
All checks were successful
ansible-lint / Ansible Lint (push) Successful in 12s
Gitleaks Scan / gitleaks (push) Successful in 4s
Markdown Lint / markdown-lint (push) Successful in 5s
ai-reviews / Review PR (pull_request) Successful in 4s
PR check / Gitleaks (pull_request) Successful in 5s
PR check / lint tests (pull_request) Successful in 15s
PR check / labeler (pull_request) Successful in 2s
PR check / handle_failures (pull_request) Has been skipped
PR check / handle_success (pull_request) Successful in 2s
c3327cd681
Renamed `_total_ram_mb` to `log2ram_host_memtotal_mb` and updated the calculation accordingly. Updated variable names for memory checks in swap task.
gitea-actions bot reviewed 2026-02-15 12:46:32 +01:00
gitea-actions bot left a comment

Review Summary

  • defaults/main.yml: The changes introduce a new configuration option for log2ram, log2ram_host_memtotal_mb, which defaults to the current system memory or 4086MB if not available. This allows for dynamic adjustment of the log2ram size based on the host's total memory. While this change seems mostly logical and improves maintainability, there is a potential minor issue regarding the use of host_memtotal_mb | default(4086). If the host_memtotal_mb variable does not exist or is undefined for some reason, the default value will always be 4086MB. In case of insufficient memory on the host and host_memtotal_mb is incorrectly set or missing, this may lead to excessive log2ram size allocation, which could potentially impact system performance. To mitigate this issue, you might consider adding a check for the availability of host_memtotal_mb before applying the default value.
  • tasks/ram.yml: Summary: The changes in the provided code update the calculation of total RAM and its logical usage percentage based on variables log2ram_host_memtotal_mb and log2ram_ram_percent. This should not significantly affect the logic, security, performance, or maintainability of the script. However, it's worth noting that we are now dependent on these two new variables being set properly.
  • tasks/swap.yml: Summary: The changes made in the provided YAML file seem to be refactoring certain conditions related to swap management, replacing ansible_memtotal_mb with log2ram_host_memtotal_mb. This change may improve consistency and accuracy in memory calculations, as log2ram_host_memtotal_mb might provide a more reliable value for the host's memory.
# Review Summary * **defaults/main.yml**: The changes introduce a new configuration option for log2ram, `log2ram_host_memtotal_mb`, which defaults to the current system memory or 4086MB if not available. This allows for dynamic adjustment of the log2ram size based on the host's total memory. While this change seems mostly logical and improves maintainability, there is a potential minor issue regarding the use of `host_memtotal_mb | default(4086)`. If the `host_memtotal_mb` variable does not exist or is undefined for some reason, the default value will always be 4086MB. In case of insufficient memory on the host and `host_memtotal_mb` is incorrectly set or missing, this may lead to excessive log2ram size allocation, which could potentially impact system performance. To mitigate this issue, you might consider adding a check for the availability of `host_memtotal_mb` before applying the default value. * **tasks/ram.yml**: **Summary:** The changes in the provided code update the calculation of total RAM and its logical usage percentage based on variables `log2ram_host_memtotal_mb` and `log2ram_ram_percent`. This should not significantly affect the logic, security, performance, or maintainability of the script. However, it's worth noting that we are now dependent on these two new variables being set properly. * **tasks/swap.yml**: **Summary:** The changes made in the provided YAML file seem to be refactoring certain conditions related to swap management, replacing `ansible_memtotal_mb` with `log2ram_host_memtotal_mb`. This change may improve consistency and accuracy in memory calculations, as `log2ram_host_memtotal_mb` might provide a more reliable value for the host's memory.
@@ -37,6 +37,7 @@ log2ram_ram_percent: 10
log2ram_min_size_mb: 128
log2ram_max_size_mb: 1024
log2ram_host_memtotal_mb: "{{ host_memtotal_mb | default(4086) }}"

[Score: 2] Potential performance impact if host_memtotal_mb is missing or incorrectly set and excessive log2ram size allocation occurs. Consider adding a check for the availability of host_memtotal_mb before applying the default value.

[Score: 2] Potential performance impact if `host_memtotal_mb` is missing or incorrectly set and excessive log2ram size allocation occurs. Consider adding a check for the availability of `host_memtotal_mb` before applying the default value.
gitea-actions bot added the sourceci-pass labels 2026-02-15 12:46:57 +01:00
Jose merged commit f7e31bb215 into main 2026-02-15 12:50:05 +01:00
Sign in to join this conversation.