SHOW:
|
|
- or go back to the newest paste.
| 1 | if (!resources.mem().isSome()) {
| |
| 2 | // No memory specified so probe OS or resort to DEFAULT_MEM. | |
| 3 | Bytes mem; | |
| 4 | Try<os::Memory> mem_ = os::memory(); | |
| 5 | if (mem_.isError()) {
| |
| 6 | LOG(WARNING) << "Failed to auto-detect the size of main memory: '" | |
| 7 | << mem_.error() | |
| 8 | << "' ; defaulting to DEFAULT_MEM"; | |
| 9 | mem = DEFAULT_MEM; | |
| 10 | } else {
| |
| 11 | mem = mem_.get().total; | |
| 12 | ||
| 13 | // Leave 1 GB free if we have more than 1 GB, otherwise, use all! | |
| 14 | // TODO(benh): Have better default scheme (e.g., % of mem not greater | |
| 15 | // than 1 GB?) | |
| 16 | if (mem > Gigabytes(1)) {
| |
| 17 | mem = mem - Gigabytes(1); | |
| 18 | } | |
| 19 | } | |
| 20 | ||
| 21 | resources += Resources::parse( | |
| 22 | "mem", | |
| 23 | stringify(mem.megabytes()), | |
| 24 | flags.default_role).get(); | |
| 25 | } else {
| |
| 26 | // If memory specified | |
| 27 | Bytes mem ; | |
| 28 | // value of memory provided by user | |
| 29 | mem = resources.mem().get(); | |
| 30 | Try<os::Memory> mem_ = os::memory(); | |
| 31 | if (mem_.isError()) {
| |
| 32 | //Error in main memory detection so using the default memory | |
| 33 | //check if the user specified memory is more than the Default memory | |
| 34 | if (mem > DEFAULT_MEM ) {
| |
| 35 | LOG(WARNING) << "Failed to auto-detect the size of main memory: '" | |
| 36 | << mem_.error() | |
| 37 | << "' ; defaulting to DEFAULT_MEM" | |
| 38 | << "Resources specifies more than the default memory '" | |
| 39 | << DEFAULT_MEM | |
| 40 | << "' Defaulting to DEFAULT_MEM"; | |
| 41 | mem = DEFAULT_MEM ; | |
| 42 | } | |
| 43 | ||
| 44 | } else {
| |
| 45 | if (mem > mem_.get().total ) {
| |
| 46 | LOG(WARNING) << "Resources specifies more than the main memory '" | |
| 47 | << mem_.get().total.megabytes() | |
| 48 | << "' Defaulting to main memory"; | |
| 49 | mem = mem_.get().total ; | |
| 50 | } | |
| 51 | } | |
| 52 | //subtract the already parsed resources( memory ) and then | |
| 53 | resources -= Resources::parse( | |
| 54 | "mem", | |
| 55 | stringify(resources.mem().get().megabytes()), | |
| 56 | flags.default_role).get(); | |
| 57 | ||
| 58 | //add the new value of resources | |
| 59 | resources += Resources::parse( | |
| 60 | "mem", | |
| 61 | stringify(mem.megabytes()), | |
| 62 | flags.default_role).get(); | |
| 63 | ||
| 64 | } |