Skip to content

Commit

Permalink
Use RAMdisk based on available memory instead of free memory (#1463)
Browse files Browse the repository at this point in the history
Resolves #1461

Based on `man free` it is more appropriate to use the metric for
available memory instead of free memory, when deciding whether to use
the RAMdisk for TinyPilot installation/update.

>   free   Unused memory (MemFree and SwapFree in /proc/meminfo)
> ...
> available: Estimation of how much memory is available for starting new
applications, without swapping. Unlike the data provided by the cache or
free fields, this field takes into account page cache and also that not
all reclaimable memory slabs will be reclaimed due to items being in use
(MemAvailable in /proc/meminfo, available on kernels 3.14, emulated on
kernels 2.6.27+, otherwise the same as free)

<a data-ca-tag
href="https://codeapprove.com/pr/tiny-pilot/tinypilot/1463"><img
src="https://codeapprove.com/external/github-tag-allbg.png" alt="Review
on CodeApprove" /></a>
  • Loading branch information
jdeanwallace authored Jun 23, 2023
1 parent 5ccb481 commit 7498b9a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions get-tinypilot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ readonly LEGACY_INSTALLER_DIR='/opt/tinypilot-updater'
# du --summarize --total --bytes "${INSTALLER_DIR}" "${BUNDLE_FILE}"
readonly RAMDISK_SIZE_MIB=500

FREE_MEMORY_MIB="$(free --mebi |
AVAILABLE_MEMORY_MIB="$(free --mebi |
grep --fixed-strings 'Mem:' |
tr --squeeze-repeats ' ' |
cut --delimiter ' ' --fields 4)"
readonly FREE_MEMORY_MIB
cut --delimiter ' ' --fields 7)"
readonly AVAILABLE_MEMORY_MIB

# Assign a provisional installation directory for our `clean_up` function.
INSTALLER_DIR='/mnt/tinypilot-installer'
Expand All @@ -93,7 +93,7 @@ trap 'clean_up' EXIT

# Determine the installation directory. Use RAMdisk if there is enough memory,
# otherwise, fall back to regular disk.
if (( "${FREE_MEMORY_MIB}" >= "${RAMDISK_SIZE_MIB}" )); then
if (( "${AVAILABLE_MEMORY_MIB}" >= "${RAMDISK_SIZE_MIB}" )); then
# Mount volatile RAMdisk.
# Note: `tmpfs` can use swap space when the device's physical memory is under
# pressure. Alternatively, we could use `ramfs` which doesn't use swap space,
Expand Down
8 changes: 4 additions & 4 deletions scripts/install-bundle
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ readonly LEGACY_INSTALLER_DIR='/opt/tinypilot-updater'
# du --summarize --total --bytes "${INSTALLER_DIR}" "${BUNDLE_FILE}"
readonly RAMDISK_SIZE_MIB=500

FREE_MEMORY_MIB="$(free --mebi |
AVAILABLE_MEMORY_MIB="$(free --mebi |
grep --fixed-strings 'Mem:' |
tr --squeeze-repeats ' ' |
cut --delimiter ' ' --fields 4)"
readonly FREE_MEMORY_MIB
cut --delimiter ' ' --fields 7)"
readonly AVAILABLE_MEMORY_MIB

# Assign a provisional installation directory for our `clean_up` function.
INSTALLER_DIR='/mnt/tinypilot-installer'
Expand All @@ -108,7 +108,7 @@ trap 'clean_up' EXIT

# Determine the installation directory. Use RAMdisk if there is enough memory,
# otherwise, fall back to regular disk.
if (( "${FREE_MEMORY_MIB}" >= "${RAMDISK_SIZE_MIB}" )); then
if (( "${AVAILABLE_MEMORY_MIB}" >= "${RAMDISK_SIZE_MIB}" )); then
# Mount volatile RAMdisk.
# Note: `tmpfs` can use swap space when the device's physical memory is under
# pressure. Alternatively, we could use `ramfs` which doesn't use swap space,
Expand Down

0 comments on commit 7498b9a

Please sign in to comment.