Index: wp-includes/default-constants.php
===================================================================
--- wp-includes/default-constants.php (revision 18061)
+++ wp-includes/default-constants.php (working copy)
@@ -39,8 +39,31 @@
 		$blog_id = 1;
 
 	// set memory limits.
-	if ( function_exists('memory_get_usage') && ( (int) @ini_get('memory_limit') < abs(intval(WP_MEMORY_LIMIT)) ) )
-		@ini_set('memory_limit', WP_MEMORY_LIMIT);
+	$memory_limit = @ini_get( 'memory_limit' );
+
+	if ( $memory_limit > -1 ) { // Any value of -1 or below is unlimited memory
+		$unit = strtolower( substr( $memory_limit, -1 ) );
+
+		$wp_memory_limit = WP_MEMORY_LIMIT;
+		$wp_unit = strtolower( substr( $wp_memory_limit, -1 ) );
+
+		if ( 'm' == $unit )
+			$memory_limit *= 1048576;
+		else if ( 'g' == $unit )
+			$memory_limit *= 1073741824;
+		else if ( 'k' == $unit )
+			$memory_limit *= 1024;
+
+		if ( 'm' == $wp_unit )
+			$wp_memory_limit *= 1048576;
+		else if ( 'g' == $wp_unit )
+			$wp_memory_limit *= 1073741824;
+		else if ( 'k' == $wp_unit )
+			$wp_memory_limit *= 1024;
+
+		if ( (int) $memory_limit < (int) $wp_memory_limit )
+			@ini_set( 'memory_limit', WP_MEMORY_LIMIT );
+	}
 
 	if ( !defined('WP_CONTENT_DIR') )
 		define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' ); // no trailing slash, full paths only - WP_CONTENT_URL is defined further down
