Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
7
rated 0 times [  7] [ 0]  / answers: 1 / hits: 11113  / 2 Years ago, fri, august 26, 2022, 9:07:55

How does the installer calculate what size of swap partition to create? Presumably it's based on installed RAM size, but does that depend on how much RAM?


More From » default

 Answers
6

Actually there is no dphys-swapfile program on a default Ubuntu installation CD and it is not used to calculate the swap size.



What happens is that the ubiquity installer uses the partman-auto scripts and configuration files (called recipes) to determine the sizes of all partitions. It works like this:




  • Partman finds the right recipe file according to the type of the computer and the option the user has chosen.

  • There it finds the minimum and maximum size of the partition and its priority. For swap it can be 96 (min - in MB) 512 (priority) 300% (max).

  • Then it gets the RAM size (via /proc/meminfo).

  • It uses its own algorithm to calculate the sizes.



Details:



A recipe file can look like this:



1 1 1 free
$iflabel{ gpt }
method{ biosgrub } .

500 10000 -1 $default_filesystem
$lvmok{ }
method{ format }
format{ }
mountpoint{ / } .

96 512 300% linux-swap
$lvmok{ }
method{ swap }
format{ } .


The algorithm to calculate the sizes:



for(i=1;i<=N;i++) {
factor[i] = priority[i] - min[i];
}
ready = FALSE;
while (! ready) {
minsum = min[1] + min[2] + ... + min[N];
factsum = factor[1] + factor[2] + ... + factor[N];
ready = TRUE;
for(i=1;i<=N;i++) {
x = min[i] + (free_space - minsum) * factor[i] / factsum;
if (x > max[i])
x = max[i];
if (x != min[i]) {
ready = FALSE;
min[i] = x;
}
}
}


For more see:




[#44470] Sunday, August 28, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
taigysel

Total Points: 33
Total Questions: 136
Total Answers: 114

Location: Singapore
Member since Wed, Jan 13, 2021
3 Years ago
taigysel questions
;