 core/includes/bootstrap.inc                        |   54 ++++++--
 core/includes/common.inc                           |  115 ++++++++++------
 core/includes/file.inc                             |   14 +-
 core/modules/color/color.module                    |   35 ++---
 core/modules/file/file.field.inc                   |   20 +--
 core/modules/file/file.module                      |    6 +-
 .../Drupal/file/Tests/FileFieldValidateTest.php    |   24 ++--
 .../lib/Drupal/file/Tests/FileTokenReplaceTest.php |    4 +-
 core/modules/image/image.field.inc                 |    2 +-
 .../Drupal/image/Tests/ImageFieldDisplayTest.php   |    4 +-
 .../lib/Drupal/simpletest/WebTestBase.php          |    2 +-
 core/modules/simpletest/simpletest.install         |    5 +-
 .../Drupal/system/Tests/Bootstrap/MiscUnitTest.php |    7 -
 .../system/Tests/Common/ByteCountUnitTest.php      |  145 ++++++++++++++++++++
 .../Drupal/system/Tests/Common/SizeUnitTest.php    |  110 ---------------
 .../lib/Drupal/system/Tests/File/ValidatorTest.php |    4 +-
 core/modules/system/system.install                 |    8 +-
 core/modules/system/system.tokens.inc              |    2 +-
 .../user/lib/Drupal/user/Tests/UserPictureTest.php |    6 +-
 core/modules/user/user.admin.inc                   |    2 +-
 core/modules/user/user.module                      |    2 +-
 .../lib/Drupal/xmlrpc/Tests/XmlRpcMessagesTest.php |    2 +-
 .../tests/modules/xmlrpc_test/xmlrpc_test.module   |    6 +-
 23 files changed, 327 insertions(+), 252 deletions(-)
 create mode 100644 core/modules/system/lib/Drupal/system/Tests/Common/ByteCountUnitTest.php
 delete mode 100644 core/modules/system/lib/Drupal/system/Tests/Common/SizeUnitTest.php

diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc
index e26cb36..f1c1809 100644
--- a/core/includes/bootstrap.inc
+++ b/core/includes/bootstrap.inc
@@ -34,7 +34,7 @@ const DRUPAL_MINIMUM_PHP = '5.3.3';
 /**
  * Minimum recommended value of PHP memory_limit.
  */
-const DRUPAL_MINIMUM_PHP_MEMORY_LIMIT = '32M';
+const DRUPAL_MINIMUM_PHP_MEMORY_LIMIT = '32 MiB';
 
 /**
  * Indicates that the item should never be removed unless explicitly selected.
@@ -160,9 +160,16 @@ const DRUPAL_AUTHENTICATED_RID = 'authenticated';
 /**
  * The number of bytes in a kilobyte.
  *
- * For more information, visit http://en.wikipedia.org/wiki/Kilobyte.
+ * See http://en.wikipedia.org/wiki/Kilobyte for more information.
  */
-const DRUPAL_KILOBYTE = 1024;
+const DRUPAL_KILOBYTE = 1000;
+
+/**
+ * The number of bytes in a kibibyte.
+ *
+ * See http://en.wikipedia.org/wiki/Kibibyte for more information.
+ */
+const DRUPAL_KIBIBYTE = 1024;
 
 /**
  * Special system language code (only applicable to UI language).
@@ -3522,6 +3529,26 @@ function _drupal_shutdown_function() {
 }
 
 /**
+ * Returns the maximum amount of memory in bytes that Drupal is allowed to
+ * allocate.
+ *
+ * @return
+ *   The number of bytes, or NULL if there is no limit.
+ */
+function drupal_memory_limit() {
+  $memory_limit = ini_get('memory_limit');
+
+  // If memory_limit is -1, there is no limit.
+  if ($memory_limit == -1) {
+    return NULL;
+  }
+
+  // Force parsing of PHP memory_limit as IEC, see
+  // http://php.net/manual/en/faq.using.php#faq.using.shorthandbytes
+  return parse_byte_count($memory_limit, TRUE);
+}
+
+/**
  * Compares the memory required for an operation to the available memory.
  *
  * @param $required
@@ -3539,14 +3566,19 @@ function _drupal_shutdown_function() {
  *   otherwise.
  */
 function drupal_check_memory_limit($required, $memory_limit = NULL) {
-  if (!isset($memory_limit)) {
-    $memory_limit = ini_get('memory_limit');
+  if (is_null($memory_limit)) {
+    // Get PHP's memory limit.
+    $memory_limit_bytes = drupal_memory_limit();
+    // Is it unlimited?
+    if (is_null($memory_limit_bytes)) {
+      return TRUE;
+    }
+  }
+  else {
+    $memory_limit_bytes = parse_byte_count($memory_limit);
   }
 
-  // There is sufficient memory if:
-  // - No memory limit is set.
-  // - The memory limit is set to unlimited (-1).
-  // - The memory limit is greater than or equal to the memory required for
-  //   the operation.
-  return ((!$memory_limit) || ($memory_limit == -1) || (parse_size($memory_limit) >= parse_size($required)));
+  // There is sufficient memory if the memory limit is greater than or equal to
+  // the memory required for the operation.
+  return $memory_limit_bytes >= parse_byte_count($required);
 }
diff --git a/core/includes/common.inc b/core/includes/common.inc
index 17e1363..90ea4ce 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -903,7 +903,7 @@ function drupal_http_request($url, array $options = array()) {
       break;
     }
     stream_set_timeout($fp, floor($timeout), floor(1000000 * fmod($timeout, 1)));
-    $chunk = fread($fp, 1024);
+    $chunk = fread($fp, DRUPAL_KIBIBYTE);
     $response .= $chunk;
     $info = stream_get_meta_data($fp);
     $alive = !$info['eof'] && !$info['timed_out'] && $chunk;
@@ -1752,65 +1752,90 @@ function format_plural($count, $singular, $plural, array $args = array(), array
 }
 
 /**
- * Parses a given byte count.
+ * Parses a human-readable representation of a byte count.
  *
- * @param $size
- *   A size expressed as a number of bytes with optional SI or IEC binary unit
- *   prefix (e.g. 2, 3K, 5MB, 10G, 6GiB, 8 bytes, 9mbytes).
+ * See http://en.wikipedia.org/wiki/Binary_prefix for more information.
+ *
+ * @param $count
+ *   A byte count expressed as a numeric quantity, optionally followed by a
+ *   unit:
+ *    - SI (powers of 1000), e.g. 7.4kB, 8 MB, 42.9 megabytes, 9 G, 1terabyte.
+ *    - IEC (powers of 1024), e.g. 9 Kibibytes, 0.3 MiB, 40gibibytes.
+ * @param $force_iec
+ *   Override the unit type detection to be IEC. Defaults to FALSE.
  *
  * @return
- *   An integer representation of the size in bytes.
- */
-function parse_size($size) {
-  $unit = preg_replace('/[^bkmgtpezy]/i', '', $size); // Remove the non-unit characters from the size.
-  $size = preg_replace('/[^0-9\.]/', '', $size); // Remove the non-numeric characters from the size.
-  if ($unit) {
-    // Find the position of the unit in the ordered string which is the power of magnitude to multiply a kilobyte by.
-    return round($size * pow(DRUPAL_KILOBYTE, stripos('bkmgtpezy', $unit[0])));
-  }
-  else {
-    return round($size);
+ *   An integer representation of the byte count.
+ *
+ * @see format_byte_count()
+ */
+function parse_byte_count($count, $force_iec = FALSE) {
+  // Break up the count into quantity and unit.
+  preg_match('/([0-9.]+)[ ]*([a-z]*)/', strtolower($count), $matches);
+
+  $quantity = $matches[1];
+  $unit = $matches[2];
+  $unit_length = strlen($unit);
+
+  if ($unit_length > 0) {
+    // Determine if the unit is SI or IEC. The second letter of an abbreviated
+    // IEC unit is always 'i', e.g. Mi or MiB. The forth letter of an
+    // unabbreviated IEC unit is always 'i', e.g. mebibyte.
+    if ((($unit_length == 2 || $unit_length == 3) && $unit[1] == 'i') ||
+      ($unit_length >= 4 && $unit[3] == 'i') || $force_iec)
+    {
+      $base = DRUPAL_KIBIBYTE;
+    }
+    else {
+      $base = DRUPAL_KILOBYTE;
+    }
+
+    // Multiply the quantity by the quantity of the unit. The quantity of the
+    // unit is calculated by determining its order of magnitude and raising the
+    // base of the unit to this power.
+    $quantity *= pow($base, strpos('bkmgtpezy', $unit[0]));
   }
+
+  // Make sure an integer is returned.
+  return floor($quantity);
 }
 
 /**
- * Generates a string representation for the given byte count.
+ * Formats a byte count into a human-readable representation.
  *
- * @param $size
- *   A size in bytes.
- * @param $langcode
- *   Optional language code to translate to a language other than what is used
- *   to display the page.
+ * See http://en.wikipedia.org/wiki/Binary_prefix for more information.
+ *
+ * @param $count
+ *   An integer byte count.
+ * @param $iec
+ *   Format as IEC instead of SI. Defaults to FALSE.
  *
  * @return
- *   A translated string representation of the size.
+ *   A human readable representation of the byte count, e.g.
+ *    - SI (powers of 1000) 7.4 kB, 8 MB, 42.9 MB, 9 GB, 1 TB.
+ *    - IEC (powers of 1024) 9 KiB, 0.3 MiB, 40 GiB.
+ *
+ * @see parse_byte_count()
  */
-function format_size($size, $langcode = NULL) {
-  if ($size < DRUPAL_KILOBYTE) {
-    return format_plural($size, '1 byte', '@count bytes', array(), array('langcode' => $langcode));
+function format_byte_count($count, $iec = FALSE) {
+  if ($iec) {
+    $base = DRUPAL_KIBIBYTE;
+    $units = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB');
   }
   else {
-    $size = $size / DRUPAL_KILOBYTE; // Convert bytes to kilobytes.
-    $units = array(
-      t('@size KB', array(), array('langcode' => $langcode)),
-      t('@size MB', array(), array('langcode' => $langcode)),
-      t('@size GB', array(), array('langcode' => $langcode)),
-      t('@size TB', array(), array('langcode' => $langcode)),
-      t('@size PB', array(), array('langcode' => $langcode)),
-      t('@size EB', array(), array('langcode' => $langcode)),
-      t('@size ZB', array(), array('langcode' => $langcode)),
-      t('@size YB', array(), array('langcode' => $langcode)),
-    );
-    foreach ($units as $unit) {
-      if (round($size, 2) >= DRUPAL_KILOBYTE) {
-        $size = $size / DRUPAL_KILOBYTE;
-      }
-      else {
-        break;
-      }
+    $base = DRUPAL_KILOBYTE;
+    $units = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
+  }
+
+  foreach ($units as $unit) {
+    if ($count < $base) {
+      break;
     }
-    return str_replace('@size', round($size, 2), $unit);
+
+    $count /= $base;
   }
+
+  return round($count, 2) . ' ' . $unit;
 }
 
 /**
diff --git a/core/includes/file.inc b/core/includes/file.inc
index 133d64f..aeffad7 100644
--- a/core/includes/file.inc
+++ b/core/includes/file.inc
@@ -1432,7 +1432,7 @@ function file_save_upload($source, $validators = array(), $destination = FALSE,
   switch ($_FILES['files']['error'][$source]) {
     case UPLOAD_ERR_INI_SIZE:
     case UPLOAD_ERR_FORM_SIZE:
-      drupal_set_message(t('The file %file could not be saved because it exceeds %maxsize, the maximum allowed size for uploads.', array('%file' => $_FILES['files']['name'][$source], '%maxsize' => format_size(file_upload_max_size()))), 'error');
+      drupal_set_message(t('The file %file could not be saved because it exceeds %maxsize, the maximum allowed size for uploads.', array('%file' => $_FILES['files']['name'][$source], '%maxsize' => format_byte_count(file_upload_max_size()))), 'error');
       return FALSE;
 
     case UPLOAD_ERR_PARTIAL:
@@ -1724,12 +1724,12 @@ function file_validate_size(File $file, $file_limit = 0, $user_limit = 0) {
   // Bypass validation for uid  = 1.
   if ($user->uid != 1) {
     if ($file_limit && $file->filesize > $file_limit) {
-      $errors[] = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size($file->filesize), '%maxsize' => format_size($file_limit)));
+      $errors[] = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_byte_count($file->filesize), '%maxsize' => format_byte_count($file_limit)));
     }
 
     // Save a query by only calling file_space_used() when a limit is provided.
     if ($user_limit && (file_space_used($user->uid) + $file->filesize) > $user_limit) {
-      $errors[] = t('The file is %filesize which would exceed your disk quota of %quota.', array('%filesize' => format_size($file->filesize), '%quota' => format_size($user_limit)));
+      $errors[] = t('The file is %filesize which would exceed your disk quota of %quota.', array('%filesize' => format_byte_count($file->filesize), '%quota' => format_byte_count($user_limit)));
     }
   }
   return $errors;
@@ -1927,10 +1927,10 @@ function file_unmanaged_save_data($data, $destination = NULL, $replace = FILE_EX
  */
 function file_transfer($uri, $headers) {
   return new StreamedResponse(function() use ($uri) {
-    // Transfer file in 1024 byte chunks to save memory usage.
+    // Transfer file in kibibyte chunks to save memory usage.
     if (file_exists($uri) && $fd = fopen($uri, 'rb')) {
       while (!feof($fd)) {
-        print fread($fd, 1024);
+        print fread($fd, DRUPAL_KIBIBYTE);
       }
       fclose($fd);
     }
@@ -2069,11 +2069,11 @@ function file_upload_max_size() {
 
   if ($max_size < 0) {
     // Start with post_max_size.
-    $max_size = parse_size(ini_get('post_max_size'));
+    $max_size = parse_byte_count(ini_get('post_max_size'), TRUE);
 
     // If upload_max_size is less, then reduce. Except if upload_max_size is
     // zero, which indicates no limit.
-    $upload_max = parse_size(ini_get('upload_max_filesize'));
+    $upload_max = parse_byte_count(ini_get('upload_max_filesize'), TRUE);
     if ($upload_max > 0 && $upload_max < $max_size) {
       $max_size = $upload_max;
     }
diff --git a/core/modules/color/color.module b/core/modules/color/color.module
index b2b67a7..e8cabe4 100644
--- a/core/modules/color/color.module
+++ b/core/modules/color/color.module
@@ -310,26 +310,21 @@ function color_scheme_form_submit($form, &$form_state) {
     $palette += $info['schemes']['default']['colors'];
   }
 
-  // Make sure enough memory is available, if PHP's memory limit is compiled in.
-  if (function_exists('memory_get_usage')) {
-    // Fetch source image dimensions.
-    $source = drupal_get_path('theme', $theme) . '/' . $info['base_image'];
-    list($width, $height) = getimagesize($source);
-
-    // We need at least a copy of the source and a target buffer of the same
-    // size (both at 32bpp).
-    $required = $width * $height * 8;
-    // We intend to prevent color scheme changes if there isn't enough memory
-    // available.  memory_get_usage(TRUE) returns a more accurate number than
-    // memory_get_usage(), therefore we won't inadvertently reject a color
-    // scheme change based on a faulty memory calculation.
-    $usage = memory_get_usage(TRUE);
-    $memory_limit = ini_get('memory_limit');
-    $size = parse_size($memory_limit);
-    if (!drupal_check_memory_limit($usage + $required, $memory_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 - $size), '@url' => 'http://www.php.net/manual/ini.core.php#ini.sect.resource-limits')), 'error');
-      return;
-    }
+  // Fetch source image dimensions.
+  $source = drupal_get_path('theme', $theme) . '/' . $info['base_image'];
+  list($width, $height) = getimagesize($source);
+
+  // We need at least a copy of the source and a target buffer of the same
+  // size (both at 32bpp).
+  $required = $width * $height * 8;
+  // We intend to prevent color scheme changes if there isn't enough memory
+  // available.  memory_get_usage(TRUE) returns a more accurate number than
+  // memory_get_usage(), therefore we won't inadvertently reject a color
+  // scheme change based on a faulty memory calculation.
+  $required += memory_get_usage(TRUE);
+  if (!drupal_check_memory_limit($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. Check the <a href="@url">PHP documentation</a> for more information.', array('%size' => format_byte_count($required, TRUE), '@url' => 'http://www.php.net/manual/ini.core.php#ini.sect.resource-limits')), 'error');
+    return;
   }
 
   // Delete old files.
diff --git a/core/modules/file/file.field.inc b/core/modules/file/file.field.inc
index 70314db..08136d3 100644
--- a/core/modules/file/file.field.inc
+++ b/core/modules/file/file.field.inc
@@ -106,7 +106,7 @@ function file_field_instance_settings_form($field, $instance) {
     '#type' => 'textfield',
     '#title' => t('Maximum upload size'),
     '#default_value' => $settings['max_filesize'],
-    '#description' => t('Enter a value like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes) in order to restrict the allowed file size. If left empty the file sizes will be limited only by PHP\'s maximum post and file upload sizes (current limit <strong>%limit</strong>).', array('%limit' => format_size(file_upload_max_size()))),
+    '#description' => t('Enter a value like "512" (bytes), "80 kB" (kilobytes) or "50 MB" (megabytes) in order to restrict the allowed file size. If left empty the file sizes will be limited only by PHP\'s maximum post and file upload sizes (current limit <strong>%limit</strong>).', array('%limit' => format_byte_count(file_upload_max_size()))),
     '#size' => 10,
     '#element_validate' => array('_file_generic_settings_max_filesize'),
     '#weight' => 5,
@@ -128,14 +128,14 @@ function file_field_instance_settings_form($field, $instance) {
  * Render API callback: Validates the maximum upload size field.
  *
  * Ensures that a size has been entered and that it can be parsed by
- * parse_size().
+ * parse_byte_count().
  *
  * This function is assigned as an #element_validate callback in
  * file_field_instance_settings_form().
  */
 function _file_generic_settings_max_filesize($element, &$form_state) {
-  if (!empty($element['#value']) && !is_numeric(parse_size($element['#value']))) {
-    form_error($element, t('The "!name" option must contain a valid value. You may either leave the text field empty or enter a string like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes).', array('!name' => t($element['title']))));
+  if (!empty($element['#value']) && !parse_byte_count($element['#value'])) {
+    form_error($element, t('The "!name" option must contain a valid value. You may either leave the text field empty or enter a string like "512" (bytes), "80 kB" (kilobytes) or "50 MB" (megabytes).', array('!name' => t($element['title']))));
   }
 }
 
@@ -463,9 +463,9 @@ function file_field_widget_form(&$form, &$form_state, $field, $instance, $langco
  */
 function file_field_widget_upload_validators($field, $instance) {
   // Cap the upload size according to the PHP limit.
-  $max_filesize = parse_size(file_upload_max_size());
-  if (!empty($instance['settings']['max_filesize']) && parse_size($instance['settings']['max_filesize']) < $max_filesize) {
-    $max_filesize = parse_size($instance['settings']['max_filesize']);
+  $max_filesize = file_upload_max_size();
+  if (!empty($instance['settings']['max_filesize']) && parse_byte_count($instance['settings']['max_filesize']) < $max_filesize) {
+    $max_filesize = parse_byte_count($instance['settings']['max_filesize']);
   }
 
   $validators = array();
@@ -732,7 +732,7 @@ function theme_file_widget($variables) {
   $output .= '<div class="file-widget form-managed-file clearfix">';
   if ($element['fid']['#value'] != 0) {
     // Add the file size after the file name.
-    $element['filename']['#markup'] .= ' <span class="file-size">(' . format_size($element['#file']->filesize) . ')</span> ';
+    $element['filename']['#markup'] .= ' <span class="file-size">(' . format_byte_count($element['#file']->filesize) . ')</span> ';
   }
   $output .= drupal_render_children($element);
   $output .= '</div>';
@@ -868,7 +868,7 @@ function theme_file_upload_help($variables) {
     $descriptions[] = $description;
   }
   if (isset($upload_validators['file_validate_size'])) {
-    $descriptions[] = t('Files must be less than !size.', array('!size' => '<strong>' . format_size($upload_validators['file_validate_size'][0]) . '</strong>'));
+    $descriptions[] = t('Files must be less than !size.', array('!size' => '<strong>' . format_byte_count($upload_validators['file_validate_size'][0]) . '</strong>'));
   }
   if (isset($upload_validators['file_validate_extensions'])) {
     $descriptions[] = t('Allowed file types: !extensions.', array('!extensions' => '<strong>' . check_plain($upload_validators['file_validate_extensions'][0]) . '</strong>'));
@@ -944,7 +944,7 @@ function theme_file_formatter_table($variables) {
   foreach ($variables['items'] as $delta => $item) {
     $rows[] = array(
       theme('file_link', array('file' => (object) $item)),
-      format_size($item['filesize']),
+      format_byte_count($item['filesize']),
     );
   }
 
diff --git a/core/modules/file/file.module b/core/modules/file/file.module
index 24dd94f..fa07514 100644
--- a/core/modules/file/file.module
+++ b/core/modules/file/file.module
@@ -241,7 +241,7 @@ function file_ajax_upload() {
 
   if (empty($_POST['form_build_id']) || $form_build_id != $_POST['form_build_id']) {
     // Invalid request.
-    drupal_set_message(t('An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (@size) that this server supports.', array('@size' => format_size(file_upload_max_size()))), 'error');
+    drupal_set_message(t('An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (@size) that this server supports.', array('@size' => format_byte_count(file_upload_max_size()))), 'error');
     $commands = array();
     $commands[] = ajax_command_replace(NULL, theme('status_messages'));
     return array('#type' => 'ajax', '#commands' => $commands);
@@ -306,14 +306,14 @@ function file_ajax_progress($key) {
   if ($implementation == 'uploadprogress') {
     $status = uploadprogress_get_info($key);
     if (isset($status['bytes_uploaded']) && !empty($status['bytes_total'])) {
-      $progress['message'] = t('Uploading... (@current of @total)', array('@current' => format_size($status['bytes_uploaded']), '@total' => format_size($status['bytes_total'])));
+      $progress['message'] = t('Uploading... (@current of @total)', array('@current' => format_byte_count($status['bytes_uploaded']), '@total' => format_byte_count($status['bytes_total'])));
       $progress['percentage'] = round(100 * $status['bytes_uploaded'] / $status['bytes_total']);
     }
   }
   elseif ($implementation == 'apc') {
     $status = apc_fetch('upload_' . $key);
     if (isset($status['current']) && !empty($status['total'])) {
-      $progress['message'] = t('Uploading... (@current of @total)', array('@current' => format_size($status['current']), '@total' => format_size($status['total'])));
+      $progress['message'] = t('Uploading... (@current of @total)', array('@current' => format_byte_count($status['current']), '@total' => format_byte_count($status['total'])));
       $progress['percentage'] = round(100 * $status['current'] / $status['total']);
     }
   }
diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php
index 443745f..6f5ae37 100644
--- a/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php
@@ -80,17 +80,13 @@ class FileFieldValidateTest extends FileFieldTestBase {
     $field = field_info_field($field_name);
     $instance = field_info_instance('node', $field_name, $type_name);
 
-    $small_file = $this->getTestFile('text', 131072); // 128KB.
-    $large_file = $this->getTestFile('text', 1310720); // 1.2MB
+    $small_file = $this->getTestFile('text', 131072);  // 128KiB
+    $large_file = $this->getTestFile('text', 1310720);  // 1.25MiB
 
     // Test uploading both a large and small file with different increments.
-    $sizes = array(
-      '1M' => 1048576,
-      '1024K' => 1048576,
-      '1048576' => 1048576,
-    );
+    $sizes = array('1M', '1000K', '1000000');
 
-    foreach ($sizes as $max_filesize => $file_limit) {
+    foreach ($sizes as $max_filesize) {
       // Set the max file upload size.
       $this->updateFileField($field_name, $type_name, array('max_filesize' => $max_filesize));
       $instance = field_info_instance('node', $field_name, $type_name);
@@ -99,13 +95,13 @@ class FileFieldValidateTest extends FileFieldTestBase {
       $nid = $this->uploadNodeFile($small_file, $field_name, $type_name);
       $node = node_load($nid, NULL, TRUE);
       $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
-      $this->assertFileExists($node_file, t('File exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_size($small_file->filesize), '%maxsize' => $max_filesize)));
-      $this->assertFileEntryExists($node_file, t('File entry exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_size($small_file->filesize), '%maxsize' => $max_filesize)));
+      $this->assertFileExists($node_file, t('File exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_byte_count($small_file->filesize), '%maxsize' => $max_filesize)));
+      $this->assertFileEntryExists($node_file, t('File entry exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_byte_count($small_file->filesize), '%maxsize' => $max_filesize)));
 
       // Check that uploading the large file fails (1M limit).
       $nid = $this->uploadNodeFile($large_file, $field_name, $type_name);
-      $error_message = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size($large_file->filesize), '%maxsize' => format_size($file_limit)));
-      $this->assertRaw($error_message, t('Node save failed when file (%filesize) exceeded the max upload size (%maxsize).', array('%filesize' => format_size($large_file->filesize), '%maxsize' => $max_filesize)));
+      $error_message = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_byte_count($large_file->filesize), '%maxsize' => format_byte_count(parse_byte_count($max_filesize))));
+      $this->assertRaw($error_message, t('Node save failed when file (%filesize) exceeded the max upload size (%maxsize).', array('%filesize' => format_byte_count($large_file->filesize), '%maxsize' => $max_filesize)));
     }
 
     // Turn off the max filesize.
@@ -115,8 +111,8 @@ class FileFieldValidateTest extends FileFieldTestBase {
     $nid = $this->uploadNodeFile($large_file, $field_name, $type_name);
     $node = node_load($nid, NULL, TRUE);
     $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']);
-    $this->assertFileExists($node_file, t('File exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->filesize))));
-    $this->assertFileEntryExists($node_file, t('File entry exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->filesize))));
+    $this->assertFileExists($node_file, t('File exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_byte_count($large_file->filesize))));
+    $this->assertFileEntryExists($node_file, t('File entry exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_byte_count($large_file->filesize))));
 
     // Remove our file field.
     field_delete_field($field_name);
diff --git a/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php b/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php
index 4efd9c5..401aa4f 100644
--- a/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php
@@ -54,7 +54,7 @@ class FileTokenReplaceTest extends FileFieldTestBase {
     $tests['[file:name]'] = check_plain($file->filename);
     $tests['[file:path]'] = check_plain($file->uri);
     $tests['[file:mime]'] = check_plain($file->filemime);
-    $tests['[file:size]'] = format_size($file->filesize);
+    $tests['[file:size]'] = format_byte_count($file->filesize);
     $tests['[file:url]'] = check_plain(file_create_url($file->uri));
     $tests['[file:timestamp]'] = format_date($file->timestamp, 'medium', '', NULL, $language_interface->langcode);
     $tests['[file:timestamp:short]'] = format_date($file->timestamp, 'short', '', NULL, $language_interface->langcode);
@@ -73,7 +73,7 @@ class FileTokenReplaceTest extends FileFieldTestBase {
     $tests['[file:name]'] = $file->filename;
     $tests['[file:path]'] = $file->uri;
     $tests['[file:mime]'] = $file->filemime;
-    $tests['[file:size]'] = format_size($file->filesize);
+    $tests['[file:size]'] = format_byte_count($file->filesize);
 
     foreach ($tests as $input => $expected) {
       $output = token_replace($input, array('file' => $file), array('language' => $language_interface, 'sanitize' => FALSE));
diff --git a/core/modules/image/image.field.inc b/core/modules/image/image.field.inc
index 80b8fb8..d8406b7 100644
--- a/core/modules/image/image.field.inc
+++ b/core/modules/image/image.field.inc
@@ -450,7 +450,7 @@ function theme_image_widget($variables) {
 
   $output .= '<div class="image-widget-data">';
   if ($element['fid']['#value'] != 0) {
-    $element['filename']['#markup'] .= ' <span class="file-size">(' . format_size($element['#file']->filesize) . ')</span> ';
+    $element['filename']['#markup'] .= ' <span class="file-size">(' . format_byte_count($element['#file']->filesize) . ')</span> ';
   }
   $output .= drupal_render_children($element);
   $output .= '</div>';
diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php
index 39eb53b..4978d4b 100644
--- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php
+++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php
@@ -129,7 +129,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
     $instance_settings = array(
       'alt_field' => 1,
       'file_extensions' => $test_image_extension,
-      'max_filesize' => '50 KB',
+      'max_filesize' => '50 kB',
       'max_resolution' => '100x100',
       'min_resolution' => '10x10',
       'title_field' => 1,
@@ -144,7 +144,7 @@ class ImageFieldDisplayTest extends ImageFieldTestBase {
     $instance = field_info_instance('node', $field_name, 'article');
 
     $this->drupalGet('node/add/article');
-    $this->assertText(t('Files must be less than 50 KB.'), t('Image widget max file size is displayed on article form.'));
+    $this->assertText(t('Files must be less than 50 kB.'), t('Image widget max file size is displayed on article form.'));
     $this->assertText(t('Allowed file types: ' . $test_image_extension . '.'), t('Image widget allowed file types displayed on article form.'));
     $this->assertText(t('Images must be between 10x10 and 100x100 pixels.'), t('Image widget allowed resolution displayed on article form.'));
 
diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
index bb2aef8..5a89f03 100644
--- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
+++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php
@@ -926,7 +926,7 @@ abstract class WebTestBase extends TestBase {
       '!method' => !empty($curl_options[CURLOPT_NOBODY]) ? 'HEAD' : (empty($curl_options[CURLOPT_POSTFIELDS]) ? 'GET' : 'POST'),
       '@url' => isset($original_url) ? $original_url : $url,
       '@status' => $status,
-      '!length' => format_size(strlen($this->drupalGetContent()))
+      '!length' => format_byte_count(strlen($this->drupalGetContent()))
     );
     $message = t('!method @url returned @status (!length).', $message_vars);
     $this->assertTrue($this->drupalGetContent() !== FALSE, $message, t('Browser'));
diff --git a/core/modules/simpletest/simpletest.install b/core/modules/simpletest/simpletest.install
index 23db4dc..57e51f5 100644
--- a/core/modules/simpletest/simpletest.install
+++ b/core/modules/simpletest/simpletest.install
@@ -8,7 +8,7 @@
 /**
  * Minimum value of PHP memory_limit for SimpleTest.
  */
-const SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT = '64M';
+const SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT = '64 MiB';
 
 /**
  * Implements hook_requirements().
@@ -62,8 +62,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 (!drupal_check_memory_limit(SIMPLETEST_MINIMUM_PHP_MEMORY_LIMIT, $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/system/lib/Drupal/system/Tests/Bootstrap/MiscUnitTest.php b/core/modules/system/lib/Drupal/system/Tests/Bootstrap/MiscUnitTest.php
index daa7d59..5d8af05 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Bootstrap/MiscUnitTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Bootstrap/MiscUnitTest.php
@@ -37,16 +37,9 @@ class MiscUnitTest extends UnitTestBase {
    * Tests that the drupal_check_memory_limit() function works as expected.
    */
   function testCheckMemoryLimit() {
-    $memory_limit = ini_get('memory_limit');
     // Test that a very reasonable amount of memory is available.
     $this->assertTrue(drupal_check_memory_limit('30MB'), '30MB of memory tested available.');
 
-    // Get the available memory and multiply it by two to make it unreasonably
-    // high.
-    $twice_avail_memory = ($memory_limit * 2) . 'MB';
-    // The function should always return true if the memory limit is set to -1.
-    $this->assertTrue(drupal_check_memory_limit($twice_avail_memory, -1), 'drupal_check_memory_limit() returns TRUE when a limit of -1 (none) is supplied');
-
     // Test that even though we have 30MB of memory available - the function
     // returns FALSE when given an upper limit for how much memory can be used.
     $this->assertFalse(drupal_check_memory_limit('30MB', '16MB'), 'drupal_check_memory_limit() returns FALSE with a 16MB upper limit on a 30MB requirement.');
diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/ByteCountUnitTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/ByteCountUnitTest.php
new file mode 100644
index 0000000..d1a6b30
--- /dev/null
+++ b/core/modules/system/lib/Drupal/system/Tests/Common/ByteCountUnitTest.php
@@ -0,0 +1,145 @@
+<?php
+
+/**
+ * @file
+ * Definition of Drupal\system\Tests\Common\SizeUnitTest.
+ */
+
+namespace Drupal\system\Tests\Common;
+
+use Drupal\simpletest\UnitTestBase;
+
+/**
+ * Tests byte count parsing and formatting functions.
+ */
+class ByteCountUnitTest extends UnitTestBase {
+  protected $exact_test_cases;
+  protected $rounded_test_cases;
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Byte count parsing and formatting',
+      'description' => 'Parse a predefined amount of bytes and compare the output with the expected value.',
+      'group' => 'Common',
+    );
+  }
+
+  function setUp() {
+    $this->exact_test_cases = array(
+      '1 B' => 1,
+      '1 kB' => DRUPAL_KILOBYTE,
+      '1 MB' => pow(DRUPAL_KILOBYTE, 2),
+      '1 GB' => pow(DRUPAL_KILOBYTE, 3),
+      '1 TB' => pow(DRUPAL_KILOBYTE, 4),
+      '1 PB' => pow(DRUPAL_KILOBYTE, 5),
+      '1 EB' => pow(DRUPAL_KILOBYTE, 6),
+      '1 ZB' => pow(DRUPAL_KILOBYTE, 7),
+      '1 YB' => pow(DRUPAL_KILOBYTE, 8),
+    );
+    $this->exact_iec_test_cases = array(
+      '1 KiB' => DRUPAL_KIBIBYTE,
+      '1 MiB' => pow(DRUPAL_KIBIBYTE, 2),
+      '1 GiB' => pow(DRUPAL_KIBIBYTE, 3),
+      '1 TiB' => pow(DRUPAL_KIBIBYTE, 4),
+      '1 PiB' => pow(DRUPAL_KIBIBYTE, 5),
+      '1 EiB' => pow(DRUPAL_KIBIBYTE, 6),
+      '1 ZiB' => pow(DRUPAL_KIBIBYTE, 7),
+      '1 YiB' => pow(DRUPAL_KIBIBYTE, 8),
+    );
+    $this->exact_force_iec_test_cases = array(
+      '1 kB' => DRUPAL_KIBIBYTE,
+      '1 MB' => pow(DRUPAL_KIBIBYTE, 2),
+      '1 GB' => pow(DRUPAL_KIBIBYTE, 3),
+      '1 TB' => pow(DRUPAL_KIBIBYTE, 4),
+      '1 PB' => pow(DRUPAL_KIBIBYTE, 5),
+      '1 EB' => pow(DRUPAL_KIBIBYTE, 6),
+      '1 ZB' => pow(DRUPAL_KIBIBYTE, 7),
+      '1 YB' => pow(DRUPAL_KIBIBYTE, 8),
+    );
+    $this->rounded_test_cases = array(
+      '2 B' => 2,
+      '1 MB' => DRUPAL_KILOBYTE * DRUPAL_KILOBYTE + 1, // rounded to 1 MB (not 1000 or 1024 kilobyte!)
+      round(3623651 / ($this->exact_test_cases['1 MB']), 2) . ' MB' => 3623651, // megabytes
+      round(67234178751368124 / ($this->exact_test_cases['1 PB']), 2) . ' PB' => 67234178751368124, // petabytes
+      round(235346823821125814962843827 / ($this->exact_test_cases['1 YB']), 2) . ' YB' => 235346823821125814962843827, // yottabytes
+    );
+    parent::setUp();
+  }
+
+  /**
+   * Check that format_byte_count() returns the expected string.
+   */
+  function testCommonFormatByteCount() {
+    foreach (array($this->exact_test_cases, $this->rounded_test_cases) as $test_cases) {
+      foreach ($test_cases as $expected => $input) {
+        $this->assertEqual(
+          ($result = format_byte_count($input, NULL)),
+          $expected,
+          $expected . ' == ' . $result . ' (' . $input . ' bytes)'
+        );
+      }
+    }
+  }
+
+  /**
+   * Check that parse_byte_count() returns the proper byte sizes.
+   */
+  function testCommonParseByteCount() {
+    foreach (array($this->exact_test_cases, $this->exact_iec_test_cases) as $test_cases) {
+      foreach ($test_cases as $string => $size) {
+        $this->assertEqual(
+          $parsed_size = parse_byte_count($string),
+          $size,
+          $size . ' == ' . $parsed_size . ' (' . $string . ')'
+        );
+      }
+    }
+
+    foreach ($this->exact_force_iec_test_cases as $string => $size) {
+      $this->assertEqual(
+        $parsed_size = parse_byte_count($string, TRUE),
+        $size,
+        $size . ' == ' . $parsed_size . ' (' . $string . ')'
+      );
+    }
+
+    // Some custom parsing tests
+    $string = '484302293';  // Test parsing byte count with no units.
+    $this->assertEqual(
+      ($parsed_size = parse_byte_count($string)),
+      $size = 484302293,
+      $string . ' == ' . $parsed_size . ' bytes'
+    );
+    $string = '23476892 bytes';
+    $this->assertEqual(
+      ($parsed_size = parse_byte_count($string)),
+      $size = 23476892,
+      $string . ' == ' . $parsed_size . ' bytes'
+    );
+    $string = '76MRandomStringThatShouldBeIgnoredByParseSize.'; // 76 MB
+    $this->assertEqual(
+      $parsed_size = parse_byte_count($string),
+      $size = 76000000,
+      $string . ' == ' . $parsed_size . ' bytes'
+    );
+    $string = '76.24 Gubibytes'; // Misspeld text -> 76.24 GiB
+    $this->assertEqual(
+      $parsed_size = parse_byte_count($string),
+      $size = 81862076661,
+      $string . ' == ' . $parsed_size . ' bytes'
+    );
+  }
+
+  /**
+   * Cross-test parse_byte_count() and format_byte_count().
+   */
+  function testCommonParseFormatByteCount() {
+    foreach ($this->exact_test_cases as $size) {
+      $this->assertEqual(
+        $size,
+        ($parsed_size = parse_byte_count($string = format_byte_count($size))),
+        $size . ' == ' . $parsed_size . ' (' . $string . ')'
+      );
+    }
+  }
+}
diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/SizeUnitTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/SizeUnitTest.php
deleted file mode 100644
index c804d61..0000000
--- a/core/modules/system/lib/Drupal/system/Tests/Common/SizeUnitTest.php
+++ /dev/null
@@ -1,110 +0,0 @@
-<?php
-
-/**
- * @file
- * Definition of Drupal\system\Tests\Common\SizeUnitTest.
- */
-
-namespace Drupal\system\Tests\Common;
-
-use Drupal\simpletest\UnitTestBase;
-
-/**
- * Tests file size parsing and formatting functions.
- */
-class SizeUnitTest extends UnitTestBase {
-  protected $exact_test_cases;
-  protected $rounded_test_cases;
-
-  public static function getInfo() {
-    return array(
-      'name' => 'Size parsing test',
-      'description' => 'Parse a predefined amount of bytes and compare the output with the expected value.',
-      'group' => 'Common',
-    );
-  }
-
-  function setUp() {
-    $kb = DRUPAL_KILOBYTE;
-    $this->exact_test_cases = array(
-      '1 byte' => 1,
-      '1 KB'   => $kb,
-      '1 MB'   => $kb * $kb,
-      '1 GB'   => $kb * $kb * $kb,
-      '1 TB'   => $kb * $kb * $kb * $kb,
-      '1 PB'   => $kb * $kb * $kb * $kb * $kb,
-      '1 EB'   => $kb * $kb * $kb * $kb * $kb * $kb,
-      '1 ZB'   => $kb * $kb * $kb * $kb * $kb * $kb * $kb,
-      '1 YB'   => $kb * $kb * $kb * $kb * $kb * $kb * $kb * $kb,
-    );
-    $this->rounded_test_cases = array(
-      '2 bytes' => 2,
-      '1 MB' => ($kb * $kb) - 1, // rounded to 1 MB (not 1000 or 1024 kilobyte!)
-      round(3623651 / ($this->exact_test_cases['1 MB']), 2) . ' MB' => 3623651, // megabytes
-      round(67234178751368124 / ($this->exact_test_cases['1 PB']), 2) . ' PB' => 67234178751368124, // petabytes
-      round(235346823821125814962843827 / ($this->exact_test_cases['1 YB']), 2) . ' YB' => 235346823821125814962843827, // yottabytes
-    );
-    parent::setUp();
-  }
-
-  /**
-   * Check that format_size() returns the expected string.
-   */
-  function testCommonFormatSize() {
-    foreach (array($this->exact_test_cases, $this->rounded_test_cases) as $test_cases) {
-      foreach ($test_cases as $expected => $input) {
-        $this->assertEqual(
-          ($result = format_size($input, NULL)),
-          $expected,
-          $expected . ' == ' . $result . ' (' . $input . ' bytes)'
-        );
-      }
-    }
-  }
-
-  /**
-   * Check that parse_size() returns the proper byte sizes.
-   */
-  function testCommonParseSize() {
-    foreach ($this->exact_test_cases as $string => $size) {
-      $this->assertEqual(
-        $parsed_size = parse_size($string),
-        $size,
-        $size . ' == ' . $parsed_size . ' (' . $string . ')'
-      );
-    }
-
-    // Some custom parsing tests
-    $string = '23476892 bytes';
-    $this->assertEqual(
-      ($parsed_size = parse_size($string)),
-      $size = 23476892,
-      $string . ' == ' . $parsed_size . ' bytes'
-    );
-    $string = '76MRandomStringThatShouldBeIgnoredByParseSize.'; // 76 MB
-    $this->assertEqual(
-      $parsed_size = parse_size($string),
-      $size = 79691776,
-      $string . ' == ' . $parsed_size . ' bytes'
-    );
-    $string = '76.24 Giggabyte'; // Misspeld text -> 76.24 GB
-    $this->assertEqual(
-      $parsed_size = parse_size($string),
-      $size = 81862076662,
-      $string . ' == ' . $parsed_size . ' bytes'
-    );
-  }
-
-  /**
-   * Cross-test parse_size() and format_size().
-   */
-  function testCommonParseSizeFormatSize() {
-    foreach ($this->exact_test_cases as $size) {
-      $this->assertEqual(
-        $size,
-        ($parsed_size = parse_size($string = format_size($size, NULL))),
-        $size . ' == ' . $parsed_size . ' (' . $string . ')'
-      );
-    }
-  }
-}
diff --git a/core/modules/system/lib/Drupal/system/Tests/File/ValidatorTest.php b/core/modules/system/lib/Drupal/system/Tests/File/ValidatorTest.php
index 3f8e548..880a821 100644
--- a/core/modules/system/lib/Drupal/system/Tests/File/ValidatorTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/File/ValidatorTest.php
@@ -145,8 +145,8 @@ class ValidatorTest extends WebTestBase {
     // Run these tests as a regular user.
     $user = $this->drupalCreateUser();
 
-    // Create a file with a size of 1000 bytes, and quotas of only 1 byte.
-    $file = entity_create('file', array('filesize' => 1000));
+    // Create a file with a size of 1 kB, and quotas of only 1 byte.
+    $file = entity_create('file', array('filesize' => DRUPAL_KILOBYTE));
     $errors = file_validate_size($file, 0, 0);
     $this->assertEqual(count($errors), 0, t('No limits means no errors.'), 'File');
     $errors = file_validate_size($file, 1, 0);
diff --git a/core/modules/system/system.install b/core/modules/system/system.install
index 0e42214..0277dc0 100644
--- a/core/modules/system/system.install
+++ b/core/modules/system/system.install
@@ -195,14 +195,14 @@ function system_requirements($phase) {
     );
   }
 
-  // Test PHP memory_limit
-  $memory_limit = ini_get('memory_limit');
+  // Test PHP memory_limit.
+  $memory_limit = drupal_memory_limit();
   $requirements['php_memory_limit'] = array(
     'title' => $t('PHP memory limit'),
-    'value' => $memory_limit == -1 ? t('-1 (Unlimited)') : $memory_limit,
+    'value' => $memory_limit ? format_byte_count($memory_limit, TRUE) : t('Unlimited'),
   );
 
-  if (!drupal_check_memory_limit(DRUPAL_MINIMUM_PHP_MEMORY_LIMIT, $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));
diff --git a/core/modules/system/system.tokens.inc b/core/modules/system/system.tokens.inc
index f9476fd..73b4056 100644
--- a/core/modules/system/system.tokens.inc
+++ b/core/modules/system/system.tokens.inc
@@ -236,7 +236,7 @@ function system_tokens($type, $tokens, array $data = array(), array $options = a
           break;
 
         case 'size':
-          $replacements[$original] = format_size($file->filesize);
+          $replacements[$original] = format_byte_count($file->filesize);
           break;
 
         case 'url':
diff --git a/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php b/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php
index a1ad3a6..43f8380 100644
--- a/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php
+++ b/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php
@@ -109,7 +109,7 @@ class UserPictureTest extends WebTestBase {
       $this->drupalLogin($this->user);
 
       // Images are sorted first by size then by name. We need an image
-      // bigger than 1 KB so we'll grab the last one.
+      // bigger than 1 kB so we'll grab the last one.
       $files = $this->drupalGetTestFiles('image');
       $image = end($files);
       $info = image_get_info($image->uri);
@@ -125,7 +125,7 @@ class UserPictureTest extends WebTestBase {
       // Test that the upload failed and that the correct reason was cited.
       $text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->filename));
       $this->assertRaw($text, t('Upload failed.'));
-      $text = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size(filesize($image->uri)), '%maxsize' => format_size($test_size * 1024)));
+      $text = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_byte_count(filesize($image->uri)), '%maxsize' => format_byte_count($test_size * DRUPAL_KILOBYTE)));
       $this->assertRaw($text, t('File size cited as reason for failure.'));
 
       // Check if file is not uploaded.
@@ -190,7 +190,7 @@ class UserPictureTest extends WebTestBase {
       // Test that the upload failed and that the correct reason was cited.
       $text = t('The specified file %filename could not be uploaded.', array('%filename' => $image->filename));
       $this->assertRaw($text, t('Upload failed.'));
-      $text = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_size(filesize($image->uri)), '%maxsize' => format_size($test_size * 1024)));
+      $text = t('The file is %filesize exceeding the maximum file size of %maxsize.', array('%filesize' => format_byte_count(filesize($image->uri)), '%maxsize' => format_byte_count($test_size * DRUPAL_KILOBYTE)));
       $this->assertRaw($text, t('File size cited as reason for failure.'));
 
       // Check if file is not uploaded.
diff --git a/core/modules/user/user.admin.inc b/core/modules/user/user.admin.inc
index 58b0218..2ca96b3 100644
--- a/core/modules/user/user.admin.inc
+++ b/core/modules/user/user.admin.inc
@@ -407,7 +407,7 @@ function user_admin_settings() {
     '#title' => t('Picture upload file size'),
     '#default_value' => variable_get('user_picture_file_size', '30'),
     '#min' => 0,
-    '#field_suffix' => ' ' . t('KB'),
+    '#field_suffix' => ' ' . t('kB'),
     '#description' => t('Maximum allowed file size for uploaded pictures. Upload size is normally limited only by the PHP maximum post and file upload settings, and images are automatically scaled down to the dimensions specified above.'),
   );
   $form['personalization']['pictures']['user_picture_guidelines'] = array(
diff --git a/core/modules/user/user.module b/core/modules/user/user.module
index 1f72aa6..3fd3b7f 100644
--- a/core/modules/user/user.module
+++ b/core/modules/user/user.module
@@ -406,7 +406,7 @@ function user_validate_picture(&$form, &$form_state) {
   $validators = array(
     'file_validate_is_image' => array(),
     'file_validate_image_resolution' => array(variable_get('user_picture_dimensions', '85x85')),
-    'file_validate_size' => array(variable_get('user_picture_file_size', '30') * 1024),
+    'file_validate_size' => array(variable_get('user_picture_file_size', '30') * DRUPAL_KILOBYTE),
   );
 
   // Save the file as a temporary file.
diff --git a/core/modules/xmlrpc/lib/Drupal/xmlrpc/Tests/XmlRpcMessagesTest.php b/core/modules/xmlrpc/lib/Drupal/xmlrpc/Tests/XmlRpcMessagesTest.php
index 572cd18..70d505c 100644
--- a/core/modules/xmlrpc/lib/Drupal/xmlrpc/Tests/XmlRpcMessagesTest.php
+++ b/core/modules/xmlrpc/lib/Drupal/xmlrpc/Tests/XmlRpcMessagesTest.php
@@ -39,7 +39,7 @@ class XmlRpcMessagesTest extends WebTestBase {
       $xml_message_l = xmlrpc_test_message_sized_in_kb($size);
       $xml_message_r = xmlrpc($xml_url, array('messages.messageSizedInKB' => array($size)));
 
-      $this->assertEqual($xml_message_l, $xml_message_r, t('XML-RPC messages.messageSizedInKB of %s Kb size received', array('%s' => $size)));
+      $this->assertEqual($xml_message_l, $xml_message_r, t('XML-RPC messages.messageSizedInKB of %s kB size received', array('%s' => $size)));
     }
   }
 
diff --git a/core/modules/xmlrpc/tests/modules/xmlrpc_test/xmlrpc_test.module b/core/modules/xmlrpc/tests/modules/xmlrpc_test/xmlrpc_test.module
index db8f113..9b7c363 100644
--- a/core/modules/xmlrpc/tests/modules/xmlrpc_test/xmlrpc_test.module
+++ b/core/modules/xmlrpc/tests/modules/xmlrpc_test/xmlrpc_test.module
@@ -86,10 +86,10 @@ function xmlrpc_test_xmlrpc_alter(&$services) {
 }
 
 /**
- * Created a message of the desired size in KB.
+ * Created a message of the desired size in kB.
  *
  * @param $size
- *   Message size in KB.
+ *   Message size in kB.
  * @return array
  *   Generated message structure.
  */
@@ -98,7 +98,7 @@ function xmlrpc_test_message_sized_in_kb($size) {
 
   $word = 'abcdefg';
 
-  // Create a ~1KB sized struct.
+  // Create a ~1kB sized struct.
   for ($i = 0 ; $i < 128; $i++) {
     $line['word_' . $i] = $word;
   }
