diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c b/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c
index 29c1bfaaeb..93502fe7d2 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmMisc.c
@@ -2,6 +2,7 @@
Misc library functions.
Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.
+(C) Copyright 2016 Hewlett Packard Enterprise Development LP
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@@ -231,7 +232,8 @@ BmSetMemoryTypeInformationVariable (
//
// Do not count the reserved memory occupied by RAM Disk.
//
- if (CurrentMemoryTypeInformation[Index1].Type == EfiReservedMemoryType) {
+ if ((CurrentMemoryTypeInformation[Index1].Type == EfiReservedMemoryType) &&
+ (CurrentMemoryTypeInformation[Index1].NumberOfPages > ((UINT32) RamDiskSizeInPages))) {
CurrentMemoryTypeInformation[Index1].NumberOfPages -= (UINT32) RamDiskSizeInPages;
}