Commit b8a97e4f authored by intrigeri's avatar intrigeri

Upgrader wrapper: make the check for free memory smarter.

Quoting anonym (#8263#note-1):

In our Live system context, where a lot of stuff is in tmpfs:es, looking
at the values of free or /proc/meminfo alone isn't accurate for
determining how much memory "really" is free, since the tmpfs usage is
included in the buffers. Hence, MemFree is the lower (and safe) bound of
how much "really" free memory we have, and MemFree + Buffers + Cache is
the upper (and unsafe) bound. The true value should be (at least closer
to) MemFree + Buffers + Cache - (sum of usage by tmpfs:es). We should
check once against that value instead.

The 300 MB magic number (minimum "real memory" available) was found
after bisecting with an ISO built from current feature/jessie:

 * with 278000 kB of "real memory" available, Tails Upgrader could
   successfully tell me that no upgrade was available (which is indeed
   the case), or that I should manually upgrade (after tweaking
   /etc/os-release; because I started from DVD);
 * with 255000 kB of "real memory" available, the check for upgrades
   failed and the desktop session froze;

=> so 300x1024 kB should give us a small safety margin.

For the record, a VM with 1GB of RAM allocated (891 MB visible due to
the QXL video adapter stealing some) on current feature/jessie has
336MB (137MB free + 39MB buffers + 212MB cache - 52MB tmpfs) of "real
memory" available once Tor is ready and Tor Browser is started, so in
practice any system that's beefy enough to use Tails 2.0 can check
for upgrades.

Closes: #10540, #8263
parent 220c9ce7
......@@ -9,8 +9,7 @@ export TEXTDOMAIN
TORDATE_DIR=/var/run/tordate
TORDATE_DONE_FILE="${TORDATE_DIR}/done"
INOTIFY_TIMEOUT=60
MIN_MEMFREE=$((125 * 1024))
MIN_TOTAL_MEMFREE=$((500 * 1024))
MIN_REAL_MEMFREE=$((300 * 1024))
RUN_AS_USER=tails-upgrade-frontend
### Functions
......@@ -26,16 +25,16 @@ ${@}"
}
check_free_memory () {
local min_memfree min_total_memfree memfree buffers cached total_memfree
local min_real_memfree memfree buffers cached real_memfree
local errormsg
min_memfree="$1"
min_total_memfree="$2"
min_real_memfree="$1"
memfree=$(awk '/^MemFree:/{print $2}' /proc/meminfo)
buffers=$(awk '/^Buffers:/{print $2}' /proc/meminfo)
cached=$(awk '/^Cached:/{print $2}' /proc/meminfo)
total_memfree=$(($memfree + $buffers + $cached))
tmpfs=$(df --type=tmpfs --local --output=used --total | tail -n1)
real_memfree=$(($memfree + $buffers + $cached - $tmpfs))
errormsg="`gettext \"<b>Not enough memory available to check for upgrades.</b>
......@@ -47,13 +46,8 @@ Try to restart Tails to check for upgrades again.
Or do a manual upgrade.
See https://tails.boum.org/doc/first_steps/upgrade#manual\"`"
if [ "$memfree" -lt "$MIN_MEMFREE" ] ; then
echo "Only $memfree MemFree, while $MIN_MEMFREE is needed." >&2
error "$errormsg"
fi
if [ "$total_memfree" -lt "$MIN_TOTAL_MEMFREE" ] ; then
echo "Only $total_memfree MemFree + Buffers + Cached, while $MIN_TOTAL_MEMFREE is needed." >&2
if [ "$real_memfree" -lt "$MIN_REAL_MEMFREE" ] ; then
echo "Only $real_memfree MemFree + Buffers + Cached - usage of tmpfs, while $MIN_REAL_MEMFREE is needed." >&2
error "$errormsg"
fi
}
......@@ -62,7 +56,7 @@ See https://tails.boum.org/doc/first_steps/upgrade#manual\"`"
sleep 30
check_free_memory "$MIN_MEMFREE" "$MIN_TOTAL_MEMFREE"
check_free_memory "$MIN_REAL_MEMFREE"
# Go to a place where everyone, especially Archive::Tar::Wrapper called by
# tails-install-iuk, can chdir back after it has chdir'd elsewhere to do
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment