@@ -401,33 +401,49 @@ func (s *Start) isServiceSupported(service string, services []provision.Service)
401401 return false
402402}
403403
404- func (s * Start ) allocateMemory (isoConfig iso.Metadata , memoryArg int ) (int , error ) {
405- memoryToAllocate := defaultMemory
404+ func (s * Start ) allocateMemory (isoConfig iso.Metadata , requestedMem int ) (int , error ) {
405+ baseMem := defaultMemory
406406 if isoConfig .DefaultMemory > 0 {
407- fmt .Printf ("isoConfig.DefaultMemory %v \n " , isoConfig .DefaultMemory )
408- memoryToAllocate = isoConfig .DefaultMemory
407+ baseMem = isoConfig .DefaultMemory
409408 }
410409
411410 availableMem , err := s .Profiler .GetAvailableMemory ()
412411 if err != nil {
413412 return 0 , errors .SafeWrap (err , "error retrieving available system memory" )
414413 }
415414
416- customMemProvided := memoryArg > 0
415+ customMemProvided := requestedMem > 0
417416 if customMemProvided {
418- memoryToAllocate = memoryArg
419- }
417+ if requestedMem >= baseMem {
418+ if availableMem >= uint64 (requestedMem ) {
419+ return requestedMem , nil
420+ }
421+
422+ if availableMem < uint64 (requestedMem ) {
423+ s .UI .Say ("WARNING: This machine does not have enough available RAM to run with what is specified." )
424+ return requestedMem , nil
425+ }
426+ }
427+
428+ if requestedMem < baseMem {
429+ s .UI .Say (fmt .Sprintf ("WARNING: It is recommended that you run %s Dev with at least %v MB of RAM" , strings .ToUpper (isoConfig .DeploymentName ), baseMem ))
430+ if availableMem >= uint64 (requestedMem ) {
431+ return requestedMem , nil
432+ }
420433
421- if ! customMemProvided {
422- if availableMem < uint64 ( memoryToAllocate ) {
423- s . UI . Say ( fmt . Sprintf ( "WARNING : It is recommended that you run (P) CF Dev with at least %v" , memoryToAllocate ))
424- return memoryToAllocate , errors . SafeWrap ( err , "not enough system memory" )
434+ if availableMem < uint64 ( requestedMem ) {
435+ s . UI . Say ( "WARNING: This machine does not have enough available RAM to run with what is specified." )
436+ return requestedMem , nil
437+ }
425438 }
426439 } else {
427- if availableMem < uint64 (memoryToAllocate ) {
428- s .UI .Say (fmt .Sprintf ("This machine does not have the enough available RAM to run with what is specified." ))
440+ if availableMem >= uint64 (baseMem ) {
441+ return baseMem , nil
442+ } else {
443+ s .UI .Say ("WARNING: This machine does not have enough available RAM to run with what is specified." )
444+ return baseMem , nil
429445 }
430446 }
431447
432- return memoryToAllocate , nil
448+ return 0 , nil
433449}
0 commit comments