Modify CostModel to allocate optimal memory.

Change-Id: I7d52675d28bfc109d4e901581fc24cd36fcb79ee
Merge "Modify CostModel to allocate optimal memory."