Merge ubiquity:bump-swap into ubiquity:main

Proposed by Dimitri John Ledkov
Status: Merged
Merged at revision: 28ae0794734a4bc2d2420b882c99181483b0dd0d
Proposed branch: ubiquity:bump-swap
Merge into: ubiquity:main
Diff against target: 179 lines (+82/-10)
6 files modified
d-i/source/partman-auto/debian/partman-auto.templates (+33/-5)
d-i/source/partman-auto/lib/recipes.sh (+34/-2)
d-i/source/partman-auto/recipes-amd64-efi/atomic (+1/-1)
d-i/source/partman-auto/recipes/atomic (+1/-1)
d-i/source/partman-swapfile/debian/partman-swapfile.templates (+7/-1)
d-i/source/partman-swapfile/finish.d/create_swapfile (+6/-0)
Reviewer Review Type Date Requested Status
Nick Rosbrook (community) Approve
Ubuntu Installer Team Pending
Review via email: mp+426012@code.launchpad.net

This proposal supersedes a proposal from 2022-06-27.

Commit message

Implement dynamic swap support

This is just a draft, did not test-build nor test install yet. This is a draft that at least hopes to cover all install cases and scenarios that need to work correctly.

To post a comment you must log in.
Revision history for this message
Dan Bungert (dbungert) : Posted in a previous version of this proposal
Revision history for this message
Dimitri John Ledkov (xnox) : Posted in a previous version of this proposal
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

All install methods are now consistent.

Still need to test fs capping.

Revision history for this message
Dimitri John Ledkov (xnox) wrote :

And need to test large RAM system

Revision history for this message
Dimitri John Ledkov (xnox) wrote :

tested fs capping and large ram systems. all is good.

This is ready for review and uploading into kinetic.

Revision history for this message
Nick Rosbrook (enr0n) : Posted in a previous version of this proposal
Revision history for this message
Nick Rosbrook (enr0n) wrote :

In the LP, you say that "Higher RAM machines should not experience any changes". But, for a machine with e.g. 16GB RAM, these changes would result in a 2GB swap file, right? Or have I misread the code? (It looks like my understanding is also supported by your test plan on the LP).

Based on my understanding of the desired changes, I think that 2GB swap for a 16GB RAM machine is correct, so I am just looking for clarification.

Revision history for this message
Dimitri John Ledkov (xnox) wrote :

given enough disk space, existing installer produced 2GB swapfile on unencrypted machines, and between 1 and 2GB swap on lvm/luks machines. As di partman recipe scales things based on priority, between min-max values.

Revision history for this message
Nick Rosbrook (enr0n) wrote :

I see, thanks for the correction. Based on my understanding of the changes we outlined before, this commit LGTM.

There is one small typo that should be corrected on merge.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/d-i/source/partman-auto/debian/partman-auto.templates b/d-i/source/partman-auto/debian/partman-auto.templates
index 7d7ee98..60dedd7 100644
--- a/d-i/source/partman-auto/debian/partman-auto.templates
+++ b/d-i/source/partman-auto/debian/partman-auto.templates
@@ -51,11 +51,39 @@ Type: string
51Default: 102451Default: 1024
52Description: for internal use; can be preseeded52Description: for internal use; can be preseeded
53 Cap RAM size to specified size in MB, when calculating the swap53 Cap RAM size to specified size in MB, when calculating the swap
54 partition size. Defaults to 1024, meaning 1GB, and since swap is54 partition size. Defaults to 1024, meaning 1GB, and since swap is 200%
55 maximum 200% of RAM in the default recipes, it results in swap55 of RAM in the default recipes, it results in swap partitions to be
56 partitions to be capped at 2GB. To revert to previous behaviour of56 capped at 2GB. To revert to previous behaviour of uncapped swap size
57 uncapped swap size with respect to available ram, pressed this key to57 with respect to available ram, preseed this key to any string,
58 any string, e.g. partman-auto/cap-ram=false58 e.g. partman-auto/cap-ram=false
59
60Template: partman-auto/cap-ram-percentage
61Type: string
62Default: 10
63Description: for internal use; can be preseeded
64 Cap RAM size such that resulting swap does not take up more than the
65 given percentage of free disk space. Defaults to 10%.
66
67Template: partman-auto/ensure-min-mem
68Type: string
69Default: 8192
70Description: for internal use; can be preseeded
71 Ensure minimum amount of total available memory available (RAM+swap)
72 in MB. Achieve this by reverse calculating what declared memory size
73 needs to be, to ensure that double of that will result in enough swap
74 in default recipes to reach minimum required memory. This will raise
75 parman-auto/cap-ram for machines with less than 6GB of RAM to
76 increase the amount of calculated SWAP. To revert to previous
77 behaviour of not raising swap size with respect to low ram, preseed
78 this key to any string, e.g. partman-auto/ensure-min-mem=false.
79
80Template: partman-auto/desired-swap
81Type: string
82Description: for internal use; automatically set
83
84Template: partman-auto/cap-ram-free-size
85Type: string
86Description: for internal use; automatically set
5987
60Template: partman-auto/automatically_partition88Template: partman-auto/automatically_partition
61Type: select89Type: select
diff --git a/d-i/source/partman-auto/lib/recipes.sh b/d-i/source/partman-auto/lib/recipes.sh
index 024c199..6731897 100644
--- a/d-i/source/partman-auto/lib/recipes.sh
+++ b/d-i/source/partman-auto/lib/recipes.sh
@@ -40,15 +40,44 @@ find_method () {
40}40}
4141
42cap_ram () {42cap_ram () {
43 local ram43 local ram min_ram limit
44 ram="$1"44 ram="$1"
45 min_ram="0"
46
47 db_get partman-auto/ensure-min-mem
48 # test that return string is all numbers, otherwise do not raise
49 if [ $(expr "x$RET" : "x[0-9]*$") -gt 1 ]; then
50 if [ "$ram" -lt "$RET" ]; then
51 min_ram=$(expr \( "$RET" - "$ram" \) / 2)
52 fi
53 fi
54
45 db_get partman-auto/cap-ram55 db_get partman-auto/cap-ram
46 # test that return string is all numbers, otherwise do not cap56 # test that return string is all numbers, otherwise do not cap
47 if [ $(expr "x$RET" : "x[0-9]*$") -gt 1 ]; then57 if [ $(expr "x$RET" : "x[0-9]*$") -gt 1 ]; then
48 if [ $ram -gt "$RET" ]; then58 if [ "$ram" -gt "$RET" ]; then
49 ram=$RET59 ram=$RET
50 fi60 fi
51 fi61 fi
62
63 if [ "$min_ram" -gt "$ram" ]; then
64 ram=$min_ram
65 fi
66
67 db_get partman-auto/cap-ram-free-size
68 limit=$((RET/100))
69
70 db_get partman-auto/cap-ram-percentage
71 limit=$((limit*RET))
72
73 limit=$((limit/2))
74
75 if [ "$ram" -gt "$limit" ]; then
76 ram=$limit
77 fi
78
79 db_set partman-auto/desired-swap $((ram*2))
80
52 echo "$ram"81 echo "$ram"
53}82}
5483
@@ -377,6 +406,9 @@ choose_recipe () {
377 target="$2"406 target="$2"
378 free_size=$3407 free_size=$3
379408
409 # Export free_size for cap_ram calculation
410 db_set partman-auto/cap-ram-free-size $free_size
411
380 # Preseeding of recipes412 # Preseeding of recipes
381 db_get partman-auto/expert_recipe413 db_get partman-auto/expert_recipe
382 if [ -n "$RET" ]; then414 if [ -n "$RET" ]; then
diff --git a/d-i/source/partman-auto/recipes-amd64-efi/atomic b/d-i/source/partman-auto/recipes-amd64-efi/atomic
index 0545b92..104ceeb 100644
--- a/d-i/source/partman-auto/recipes-amd64-efi/atomic
+++ b/d-i/source/partman-auto/recipes-amd64-efi/atomic
@@ -23,7 +23,7 @@ partman-auto/text/atomic_scheme ::
23 $default_filesystem{ }23 $default_filesystem{ }
24 mountpoint{ / } .24 mountpoint{ / } .
2525
26100% 512 200% linux-swap26200% 512 200% linux-swap
27 $defaultignore{ }27 $defaultignore{ }
28 $lvmok{ }28 $lvmok{ }
29 $reusemethod{ }29 $reusemethod{ }
diff --git a/d-i/source/partman-auto/recipes/atomic b/d-i/source/partman-auto/recipes/atomic
index 202f8bc..3a7219b 100644
--- a/d-i/source/partman-auto/recipes/atomic
+++ b/d-i/source/partman-auto/recipes/atomic
@@ -28,7 +28,7 @@ partman-auto/text/atomic_scheme ::
28 $default_filesystem{ }28 $default_filesystem{ }
29 mountpoint{ / } .29 mountpoint{ / } .
3030
31100% 512 200% linux-swap31200% 512 200% linux-swap
32 $defaultignore{ }32 $defaultignore{ }
33 $lvmok{ }33 $lvmok{ }
34 $reusemethod{ }34 $reusemethod{ }
diff --git a/d-i/source/partman-swapfile/debian/partman-swapfile.templates b/d-i/source/partman-swapfile/debian/partman-swapfile.templates
index 0954dda..a36ffbd 100644
--- a/d-i/source/partman-swapfile/debian/partman-swapfile.templates
+++ b/d-i/source/partman-swapfile/debian/partman-swapfile.templates
@@ -4,14 +4,20 @@ Default: 2048
4# :sl3:4# :sl3:
5_Description: Maximum size of swapfile5_Description: Maximum size of swapfile
6 Please enter the absolute maximum size of swapfile in MiB.6 Please enter the absolute maximum size of swapfile in MiB.
7 .
8 Please note partman-auto/cap-ram partman-auto/cap-ram-percentage
9 partman-auto/ensure-min-mem will take precedence over this value.
710
8Template: partman-swapfile/percentage11Template: partman-swapfile/percentage
9Type: string12Type: string
10Default: 513Default: 10
11# :sl3:14# :sl3:
12_Description: Maximum percentage of free space to use for swapfile15_Description: Maximum percentage of free space to use for swapfile
13 Please enter the maximum percentage of free space on root filesystem to16 Please enter the maximum percentage of free space on root filesystem to
14 use for swapfile.17 use for swapfile.
18 .
19 Please note partman-auto/cap-ram partman-auto/cap-ram-percentage
20 partman-auto/ensure-min-mem will take precedence over this value.
1521
16Template: partman-swapfile/progress_swap_formatting22Template: partman-swapfile/progress_swap_formatting
17Type: text23Type: text
diff --git a/d-i/source/partman-swapfile/finish.d/create_swapfile b/d-i/source/partman-swapfile/finish.d/create_swapfile
index f1f97f0..5b75b63 100755
--- a/d-i/source/partman-swapfile/finish.d/create_swapfile
+++ b/d-i/source/partman-swapfile/finish.d/create_swapfile
@@ -80,6 +80,12 @@ then
80 size=$limit80 size=$limit
81fi81fi
8282
83# Allow partman-auto to override
84db_get partman-auto/desired-swap
85if [ -n "$RET" ]; then
86 size=$(($RET * 1024))
87fi
88
83# No swapfile if limits are 0MB or 0%89# No swapfile if limits are 0MB or 0%
84if [ $size = 0 ]90if [ $size = 0 ]
85then91then

Subscribers

People subscribed via source and target branches