diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index 027e070..d01f4e9 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -3468,3 +3468,30 @@ function _drupal_shutdown_function() {
     }
   }
 }
+
+/**
+ * Compares the memory required for an operation to the available memory.
+ *
+ * @param $required
+ *   The memory required for the operation, expressed as a number of bytes with
+ *   optional SI or IEC binary unit prefix (e.g. 2, 3K, 5MB, 10G, 6GiB, 8bytes,
+ *   9mbytes).
+ * @param $memory_limit
+ *   (optional) The memory limit for the operation, expressed as a number of
+ *   bytes with optional SI or IEC binary unit prefix (e.g. 2, 3K, 5MB, 10G,
+ *   6GiB, 8bytes, 9mbytes). If no value is passed, the current PHP
+ *   memory_limit will be used. Defaults to NULL.
+ *
+ * @return
+ *   TRUE if there is sufficient memory to allow the operation, or FALSE
+ *   otherwise.
+ */
+function drupal_check_memory_limit($required, $memory_limit = NULL) {
+  if (!isset($memory_limit)) {
+    $memory_limit = ini_get('memory_limit');
+  }
+  if ($memory_limit && $memory_limit != -1 && parse_size($memory_limit) < parse_size($required)) {
+    return FALSE;
+  }
+  return TRUE;
+}
diff --git a/core/modules/color/color.module b/core/modules/color/color.module
index 4a61b62..2f531f3 100644
--- a/core/modules/color/color.module
+++ b/core/modules/color/color.module
@@ -324,9 +324,9 @@ function color_scheme_form_submit($form, &$form_state) {
     // memory_get_usage(), therefore we won't inadvertently reject a color
     // scheme change based on a faulty memory calculation.
     $usage = memory_get_usage(TRUE);
-    $limit = parse_size(ini_get('memory_limit'));
-    if ($usage + $required > $limit) {
-      drupal_set_message(t('There is not enough memory available to PHP to change this theme\'s color scheme. You need at least %size more. Check the <a href="@url">PHP documentation</a> for more information.', array('%size' => format_size($usage + $required - $limit), '@url' => 'http://www.php.net/manual/ini.core.php#ini.sect.resource-limits')), 'error');
+    $memory_limit = ini_get('memory_limit');
+    if (!drupal_check_memory_limit($usage + $required)) {
+      drupal_set_message(t('There is not enough memory available to PHP to change this theme\'s color scheme. You need at least %size more. Check the <a href="@url">PHP documentation</a> for more information.', array('%size' => format_size($usage + $required - $memory_limit), '@url' => 'http://www.php.net/manual/ini.core.php#ini.sect.resource-limits')), 'error');
       return;
     }
   }
diff --git a/core/modules/simpletest/simpletest.install b/core/modules/simpletest/simpletest.install
index 96cc011..30ecc14 100644
--- a/core/modules/simpletest/simpletest.install
+++ b/core/modules/simpletest/simpletest.install
@@ -63,7 +63,7 @@ function simpletest_requirements($phase) {
   // Check the current memory limit. If it is set too low, SimpleTest will fail
   // to load all tests and throw a fatal error.
   $memory_limit = ini_get('memory_limit');
-  if ($memory_limit && $memory_limit != -1 && parse_size($memory_limit) < parse_size(SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT)) {
+  if (!drupal_check_memory_limit(SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT)) {
     $requirements['php_memory_limit']['severity'] = REQUIREMENT_ERROR;
     $requirements['php_memory_limit']['description'] = $t('The testing framework requires the PHP memory limit to be at least %memory_minimum_limit. The current value is %memory_limit. <a href="@url">Follow these steps to continue</a>.', array('%memory_limit' => $memory_limit, '%memory_minimum_limit' => SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT, '@url' => 'http://drupal.org/node/207036'));
   }
diff --git a/core/modules/simpletest/tests/bootstrap.test b/core/modules/simpletest/tests/bootstrap.test
index 13fdf07..ac608e4 100644
--- a/core/modules/simpletest/tests/bootstrap.test
+++ b/core/modules/simpletest/tests/bootstrap.test
@@ -459,6 +459,22 @@ class BootstrapMiscTestCase extends DrupalUnitTestCase {
     $expected = array('fragment' => 'y', 'attributes' => array('title' => 'Y', 'class' => array('a', 'b', 'c', 'd')), 'language' => 'en', 'html' => TRUE);
     $this->assertIdentical(drupal_array_merge_deep($link_options_1, $link_options_2), $expected, t('drupal_array_merge_deep() returned a properly merged array.'));
   }
+
+  /**
+   * Tests that the memory limit checker works as expected.
+   */
+  function testMemoryLimitCheck() {
+    // Test that a very reasonable amount of memory is available.
+    $this->assertTrue(drupal_check_memory_limit('30MB'), t('30MB of memory tested available.'));
+    // Get the available memory and multiply it by two to make it unreasonably
+    // high.
+    $unreasonable_mem = (ini_get('memory_limit') * 2) . 'MB';
+    $this->assertFalse(drupal_check_memory_limit($unreasonable_mem), t('Unreasonable of memory tested unavailable.'));
+    // Test that even though we have 30MB of memory available - the function
+    // returns FALSE when given an upper limit for how much memory to allow
+    // being used.
+    $this->assertFalse(drupal_check_memory_limit('30MB', '16MB'), t('30MB of memory tested unavailable with a 16MB upper limit.'));
+  }
 }
 
 /**
@@ -506,4 +522,3 @@ class BootstrapOverrideServerVariablesTestCase extends DrupalUnitTestCase {
     }
   }
 }
-
diff --git a/core/modules/system/system.install b/core/modules/system/system.install
index d8112e6..d5d6912 100644
--- a/core/modules/system/system.install
+++ b/core/modules/system/system.install
@@ -199,7 +199,7 @@ function system_requirements($phase) {
     'value' => $memory_limit == -1 ? t('-1 (Unlimited)') : $memory_limit,
   );
 
-  if ($memory_limit && $memory_limit != -1 && parse_size($memory_limit) < parse_size(DRUPAL_MINIMUM_PHP_MEMORY_LIMIT)) {
+  if (!drupal_check_memory_limit(DRUPAL_MINIMUM_PHP_MEMORY_LIMIT)) {
     $description = '';
     if ($phase == 'install') {
       $description = $t('Consider increasing your PHP memory limit to %memory_minimum_limit to help prevent errors in the installation process.', array('%memory_minimum_limit' => DRUPAL_MINIMUM_PHP_MEMORY_LIMIT));
