summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley2005-08-30 18:50:37 +0000
committerRob Landley2005-08-30 18:50:37 +0000
commitc3386a43048907fb07fb28f2723c1efbacf4bd79 (patch)
treee16eabe2df3ef6680f7d2f41a72b883b19f8e2dd
parent7a8f6792f3a360756efccd6fbdb1f72db0108118 (diff)
downloadbusybox-c3386a43048907fb07fb28f2723c1efbacf4bd79.zip
busybox-c3386a43048907fb07fb28f2723c1efbacf4bd79.tar.gz
Why have a separate CONFIG_INIT_SWAPON when we already have CONFIG_SWAPONOFF?
-rw-r--r--init/Config.in8
-rw-r--r--init/init.c78
2 files changed, 14 insertions, 72 deletions
diff --git a/init/Config.in b/init/Config.in
index a3584aa..91d990c 100644
--- a/init/Config.in
+++ b/init/Config.in
@@ -35,14 +35,6 @@ config CONFIG_FEATURE_INIT_COREDUMPS
core file sizes. If this option is disabled, processes
will not generate any core files.
-config CONFIG_FEATURE_INIT_SWAPON
- bool " Should init run swapon if short on memory?"
- default y
- depends on CONFIG_INIT
- help
- If the system has less than one megabyte of total memory, init
- will run '/sbin/swapon -a' to add swap memory.
-
config CONFIG_FEATURE_INIT_SCTTY
bool " Support running commands with a controlling-tty?"
default n
diff --git a/init/init.c b/init/init.c
index 7656bf3..058a47a 100644
--- a/init/init.c
+++ b/init/init.c
@@ -308,37 +308,6 @@ static void set_term(int fd)
tcsetattr(fd, TCSANOW, &tty);
}
-#ifdef CONFIG_FEATURE_INIT_SWAPON
-/* How much memory does this machine have?
- Units are kBytes to avoid overflow on 4GB machines */
-static unsigned int check_free_memory(void)
-{
- struct sysinfo info;
- unsigned int result, u, s = 10;
-
- if (sysinfo(&info) != 0) {
- bb_perror_msg("Error checking free memory");
- return -1;
- }
-
- /* Kernels 2.0.x and 2.2.x return info.mem_unit==0 with values in bytes.
- * Kernels 2.4.0 return info.mem_unit in bytes. */
- u = info.mem_unit;
- if (u == 0)
- u = 1;
- while ((u & 1) == 0 && s > 0) {
- u >>= 1;
- s--;
- }
- result = (info.totalram >> s) + (info.totalswap >> s);
- if (((unsigned long long)result * (unsigned long long)u) > UINT_MAX) {
- return(UINT_MAX);
- } else {
- return(result * u);
- }
-}
-#endif /* CONFIG_FEATURE_INIT_SWAPON */
-
static void console_init(void)
{
int fd;
@@ -918,38 +887,6 @@ static void delete_init_action(struct init_action *action)
}
}
-#ifdef CONFIG_FEATURE_INIT_SWAPON
-/* Make sure there is enough memory to do something useful. *
- * Calls "swapon -a" if needed so be sure /etc/fstab is present... */
-static void check_memory(void)
-{
- struct stat statBuf;
-
- if (check_free_memory() > 1000)
- return;
-
-#if !defined(__UCLIBC__) || defined(__ARCH_HAS_MMU__)
- if (stat("/etc/fstab", &statBuf) == 0) {
- /* swapon -a requires /proc typically */
- new_init_action(SYSINIT, "/bin/mount -t proc proc /proc", "");
- /* Try to turn on swap */
- new_init_action(SYSINIT, "/sbin/swapon -a", "");
- run_actions(SYSINIT); /* wait and removing */
- if (check_free_memory() < 1000)
- goto goodnight;
- } else
- goto goodnight;
- return;
-#endif
-
- goodnight:
- message(CONSOLE, "Sorry, your computer does not have enough memory.");
- loop_forever();
-}
-#else
-# define check_memory()
-#endif /* CONFIG_FEATURE_INIT_SWAPON */
-
/* NOTE that if CONFIG_FEATURE_USE_INITTAB is NOT defined,
* then parse_inittab() simply adds in some default
* actions(i.e., runs INIT_SCRIPT and then starts a pair
@@ -1149,7 +1086,20 @@ extern int init_main(int argc, char **argv)
message(MAYBE_CONSOLE | LOG, "init started: %s", bb_msg_full_version);
/* Make sure there is enough memory to do something useful. */
- check_memory();
+ if (ENABLE_SWAPONOFF) {
+ struct sysinfo info;
+
+ if (!sysinfo(&info) &&
+ (info.mem_unit ? : 1) * (long long)info.totalram < MEGABYTE)
+ {
+ message(CONSOLE,"Low memory: forcing swapon.");
+ /* swapon -a requires /proc typically */
+ new_init_action(SYSINIT, "/bin/mount -t proc proc /proc", "");
+ /* Try to turn on swap */
+ new_init_action(SYSINIT, "/sbin/swapon -a", "");
+ run_actions(SYSINIT); /* wait and removing */
+ }
+ }
/* Check if we are supposed to be in single user mode */
if (argc > 1 && (!strcmp(argv[1], "single") ||