public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: Ulrich Mueller <ulm@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: qa@gentoo.org
Subject: [gentoo-dev] [PATCH] check-reqs.eclass: check-reqs_memory(): Check for available swap.
Date: Fri, 16 Aug 2019 12:51:22 +0200	[thread overview]
Message-ID: <w6g36i1l6xh.fsf@kph.uni-mainz.de> (raw)

[-- Attachment #1: Type: text/plain, Size: 2393 bytes --]

From: Arfrever Frehtes Taifersar Arahesis <Arfrever@Apache.Org>
Date: Mon, 13 May 2019 16:30:15 +0200

Print warning if usage of swap appears to be needed.

Closes: https://bugs.gentoo.org/569966
Signed-off-by: Arfrever Frehtes Taifersar Arahesis <Arfrever@Apache.Org>
Signed-off-by: Ulrich Müller <ulm@gentoo.org>
---
 eclass/check-reqs.eclass | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/eclass/check-reqs.eclass b/eclass/check-reqs.eclass
index 689944c8770..feb0b2fdbfd 100644
--- a/eclass/check-reqs.eclass
+++ b/eclass/check-reqs.eclass
@@ -1,3 +1,3 @@
-# Copyright 1999-2018 Gentoo Foundation
+# Copyright 2004-2019 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
@@ -241,33 +241,43 @@
 check-reqs_memory() {
 	debug-print-function ${FUNCNAME} "$@"
 
 	[[ -z ${1} ]] && die "Usage: ${FUNCNAME} [size]"
 
 	local size=${1}
 	local actual_memory
+	local actual_swap
 
 	check-reqs_start_phase \
 		${size} \
 		"RAM"
 
 	if [[ -r /proc/meminfo ]] ; then
 		actual_memory=$(awk '/MemTotal/ { print $2 }' /proc/meminfo)
+		actual_swap=$(awk '/SwapTotal/ { print $2 }' /proc/meminfo)
 	else
-		actual_memory=$(sysctl hw.physmem 2>/dev/null )
+		actual_memory=$(sysctl hw.physmem 2>/dev/null)
 		[[ "$?" == "0" ]] &&
-			actual_memory=$(echo $actual_memory | sed -e 's/^[^:=]*[:=]//' )
+			actual_memory=$(echo "${actual_memory}" | sed -e 's/^[^:=]*[:=][[:space:]]*//')
+		actual_swap=$(sysctl vm.swap_total 2>/dev/null)
+		[[ "$?" == "0" ]] &&
+			actual_swap=$(echo "${actual_swap}" | sed -e 's/^[^:=]*[:=][[:space:]]*//')
 	fi
 	if [[ -n ${actual_memory} ]] ; then
-		if [[ ${actual_memory} -lt $(check-reqs_get_kibibytes ${size}) ]] ; then
+		if [[ ${actual_memory} -ge $(check-reqs_get_kibibytes ${size}) ]] ; then
+			eend 0
+		elif [[ -n ${actual_swap} && $((${actual_memory} + ${actual_swap})) -ge $(check-reqs_get_kibibytes ${size}) ]] ; then
+			ewarn "Amount of main memory is insufficient, but amount"
+			ewarn "of main memory combined with swap is sufficient."
+			ewarn "Build process may make computer very slow!"
+			eend 0
+		else
 			eend 1
 			check-reqs_unsatisfied \
 				${size} \
 				"RAM"
-		else
-			eend 0
 		fi
 	else
 		eend 1
 		ewarn "Couldn't determine amount of memory, skipping..."
 	fi
 }
-- 
2.22.1

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

                 reply	other threads:[~2019-08-16 10:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=w6g36i1l6xh.fsf@kph.uni-mainz.de \
    --to=ulm@gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    --cc=qa@gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox