svn commit: trunk/busybox/init
landley at busybox.net
landley at busybox.net
Tue Aug 30 18:50:39 UTC 2005
Author: landley
Date: 2005-08-30 11:50:37 -0700 (Tue, 30 Aug 2005)
New Revision: 11291
Log:
Why have a separate CONFIG_INIT_SWAPON when we already have CONFIG_SWAPONOFF?
Modified:
trunk/busybox/init/Config.in
trunk/busybox/init/init.c
Changeset:
Modified: trunk/busybox/init/Config.in
===================================================================
--- trunk/busybox/init/Config.in 2005-08-30 18:17:05 UTC (rev 11290)
+++ trunk/busybox/init/Config.in 2005-08-30 18:50:37 UTC (rev 11291)
@@ -35,14 +35,6 @@
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
Modified: trunk/busybox/init/init.c
===================================================================
--- trunk/busybox/init/init.c 2005-08-30 18:17:05 UTC (rev 11290)
+++ trunk/busybox/init/init.c 2005-08-30 18:50:37 UTC (rev 11291)
@@ -308,37 +308,6 @@
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 @@
}
}
-#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,8 +1086,21 @@
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") ||
!strcmp(argv[1], "-s") || !strcmp(argv[1], "1"))) {
More information about the busybox-cvs
mailing list