3
* VBox frontends: Qt GUI ("VirtualBox"):
4
* VirtualBox Qt extensions: VBoxGuestRAMSlider class implementation
8
* Copyright (C) 2009 Sun Microsystems, Inc.
10
* This file is part of VirtualBox Open Source Edition (OSE), as
11
* available from http://www.virtualbox.org. This file is free software;
12
* you can redistribute it and/or modify it under the terms of the GNU
13
* General Public License (GPL) as published by the Free Software
14
* Foundation, in version 2 as it comes in the "COPYING" file of the
15
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
19
* Clara, CA 95054 USA or visit http://www.sun.com if you need
20
* additional information or have any questions.
24
#include "VBoxGuestRAMSlider.h"
25
#include "VBoxGlobal.h"
27
VBoxGuestRAMSlider::VBoxGuestRAMSlider (QWidget *aParent /* = 0 */)
28
: QIAdvancedSlider (aParent)
37
VBoxGuestRAMSlider::VBoxGuestRAMSlider (Qt::Orientation aOrientation, QWidget *aParent /* = 0 */)
38
: QIAdvancedSlider (aOrientation, aParent)
47
uint VBoxGuestRAMSlider::minRAM() const
52
uint VBoxGuestRAMSlider::maxRAMOpt() const
57
uint VBoxGuestRAMSlider::maxRAMAlw() const
62
uint VBoxGuestRAMSlider::maxRAM() const
67
void VBoxGuestRAMSlider::init()
69
ulong fullSize = vboxGlobal().virtualBox().GetHost().GetMemorySize();
70
CSystemProperties sys = vboxGlobal().virtualBox().GetSystemProperties();
71
mMinRAM = sys.GetMinGuestRAM();
72
mMaxRAM = RT_MIN (RT_ALIGN (fullSize, _1G / _1M), sys.GetMaxGuestRAM());
74
/* Come up with some nice round percent boundaries relative to
75
* the system memory. A max of 75% on a 256GB config is ridiculous,
76
* even on an 8GB rig reserving 2GB for the OS is way to conservative.
77
* The max numbers can be estimated using the following program:
79
* double calcMaxPct(uint64_t cbRam)
81
* double cbRamOverhead = cbRam * 0.0390625; // 160 bytes per page.
82
* double cbRamForTheOS = RT_MAX(RT_MIN(_512M, cbRam * 0.25), _64M);
83
* double OSPct = (cbRamOverhead + cbRamForTheOS) * 100.0 / cbRam;
84
* double MaxPct = 100 - OSPct;
90
* uint64_t cbRam = _1G;
91
* for (; !(cbRam >> 33); cbRam += _1G)
92
* printf("%8lluGB %.1f%% %8lluKB\n", cbRam >> 30, calcMaxPct(cbRam),
93
* (uint64_t)(cbRam * calcMaxPct(cbRam) / 100.0) >> 20);
94
* for (; !(cbRam >> 51); cbRam <<= 1)
95
* printf("%8lluGB %.1f%% %8lluKB\n", cbRam >> 30, calcMaxPct(cbRam),
96
* (uint64_t)(cbRam * calcMaxPct(cbRam) / 100.0) >> 20);
100
* Note. We might wanna put these calculations somewhere global later. */
102
/* System RAM amount test */
103
mMaxRAMAlw = (uint)(0.75 * fullSize);
104
mMaxRAMOpt = (uint)(0.50 * fullSize);
107
else if (fullSize < 4096) /* 3GB */
108
mMaxRAMAlw = (uint)(0.80 * fullSize);
109
else if (fullSize < 6144) /* 4-5GB */
111
mMaxRAMAlw = (uint)(0.84 * fullSize);
112
mMaxRAMOpt = (uint)(0.60 * fullSize);
114
else if (fullSize < 8192) /* 6-7GB */
116
mMaxRAMAlw = (uint)(0.88 * fullSize);
117
mMaxRAMOpt = (uint)(0.65 * fullSize);
119
else if (fullSize < 16384) /* 8-15GB */
121
mMaxRAMAlw = (uint)(0.90 * fullSize);
122
mMaxRAMOpt = (uint)(0.70 * fullSize);
124
else if (fullSize < 32768) /* 16-31GB */
126
mMaxRAMAlw = (uint)(0.93 * fullSize);
127
mMaxRAMOpt = (uint)(0.75 * fullSize);
129
else if (fullSize < 65536) /* 32-63GB */
131
mMaxRAMAlw = (uint)(0.94 * fullSize);
132
mMaxRAMOpt = (uint)(0.80 * fullSize);
134
else if (fullSize < 131072) /* 64-127GB */
136
mMaxRAMAlw = (uint)(0.95 * fullSize);
137
mMaxRAMOpt = (uint)(0.85 * fullSize);
141
mMaxRAMAlw = (uint)(0.96 * fullSize);
142
mMaxRAMOpt = (uint)(0.90 * fullSize);
144
/* Now check the calculated maximums are out of the range for the guest
145
* RAM. If so change it accordingly. */
146
mMaxRAMAlw = RT_MIN (mMaxRAMAlw, mMaxRAM);
147
mMaxRAMOpt = RT_MIN (mMaxRAMOpt, mMaxRAM);
149
setPageStep (calcPageStep (mMaxRAM));
150
setSingleStep (pageStep() / 4);
151
setTickInterval (pageStep());
152
/* Setup the scale so that ticks are at page step boundaries */
153
setMinimum ((mMinRAM / pageStep()) * pageStep());
154
setMaximum (mMaxRAM);
155
setSnappingEnabled (true);
156
setOptimalHint (mMinRAM, mMaxRAMOpt);
157
setWarningHint (mMaxRAMOpt, mMaxRAMAlw);
158
setErrorHint (mMaxRAMAlw, mMaxRAM);
162
* Calculates a suitable page step size for the given max value. The returned
163
* size is so that there will be no more than 32 pages. The minimum returned
166
int VBoxGuestRAMSlider::calcPageStep (int aMax) const
168
/* reasonable max. number of page steps is 32 */
169
uint page = ((uint) aMax + 31) / 32;
170
/* make it a power of 2 */
171
uint p = page, p2 = 0x1;