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
1diff --git a/d-i/source/partman-auto/debian/partman-auto.templates b/d-i/source/partman-auto/debian/partman-auto.templates
2index 7d7ee98..60dedd7 100644
3--- a/d-i/source/partman-auto/debian/partman-auto.templates
4+++ b/d-i/source/partman-auto/debian/partman-auto.templates
5@@ -51,11 +51,39 @@ Type: string
6 Default: 1024
7 Description: for internal use; can be preseeded
8 Cap RAM size to specified size in MB, when calculating the swap
9- partition size. Defaults to 1024, meaning 1GB, and since swap is
10- maximum 200% of RAM in the default recipes, it results in swap
11- partitions to be capped at 2GB. To revert to previous behaviour of
12- uncapped swap size with respect to available ram, pressed this key to
13- any string, e.g. partman-auto/cap-ram=false
14+ partition size. Defaults to 1024, meaning 1GB, and since swap is 200%
15+ of RAM in the default recipes, it results in swap partitions to be
16+ capped at 2GB. To revert to previous behaviour of uncapped swap size
17+ with respect to available ram, preseed this key to any string,
18+ e.g. partman-auto/cap-ram=false
19+
20+Template: partman-auto/cap-ram-percentage
21+Type: string
22+Default: 10
23+Description: for internal use; can be preseeded
24+ Cap RAM size such that resulting swap does not take up more than the
25+ given percentage of free disk space. Defaults to 10%.
26+
27+Template: partman-auto/ensure-min-mem
28+Type: string
29+Default: 8192
30+Description: for internal use; can be preseeded
31+ Ensure minimum amount of total available memory available (RAM+swap)
32+ in MB. Achieve this by reverse calculating what declared memory size
33+ needs to be, to ensure that double of that will result in enough swap
34+ in default recipes to reach minimum required memory. This will raise
35+ parman-auto/cap-ram for machines with less than 6GB of RAM to
36+ increase the amount of calculated SWAP. To revert to previous
37+ behaviour of not raising swap size with respect to low ram, preseed
38+ this key to any string, e.g. partman-auto/ensure-min-mem=false.
39+
40+Template: partman-auto/desired-swap
41+Type: string
42+Description: for internal use; automatically set
43+
44+Template: partman-auto/cap-ram-free-size
45+Type: string
46+Description: for internal use; automatically set
47
48 Template: partman-auto/automatically_partition
49 Type: select
50diff --git a/d-i/source/partman-auto/lib/recipes.sh b/d-i/source/partman-auto/lib/recipes.sh
51index 024c199..6731897 100644
52--- a/d-i/source/partman-auto/lib/recipes.sh
53+++ b/d-i/source/partman-auto/lib/recipes.sh
54@@ -40,15 +40,44 @@ find_method () {
55 }
56
57 cap_ram () {
58- local ram
59+ local ram min_ram limit
60 ram="$1"
61+ min_ram="0"
62+
63+ db_get partman-auto/ensure-min-mem
64+ # test that return string is all numbers, otherwise do not raise
65+ if [ $(expr "x$RET" : "x[0-9]*$") -gt 1 ]; then
66+ if [ "$ram" -lt "$RET" ]; then
67+ min_ram=$(expr \( "$RET" - "$ram" \) / 2)
68+ fi
69+ fi
70+
71 db_get partman-auto/cap-ram
72 # test that return string is all numbers, otherwise do not cap
73 if [ $(expr "x$RET" : "x[0-9]*$") -gt 1 ]; then
74- if [ $ram -gt "$RET" ]; then
75+ if [ "$ram" -gt "$RET" ]; then
76 ram=$RET
77 fi
78 fi
79+
80+ if [ "$min_ram" -gt "$ram" ]; then
81+ ram=$min_ram
82+ fi
83+
84+ db_get partman-auto/cap-ram-free-size
85+ limit=$((RET/100))
86+
87+ db_get partman-auto/cap-ram-percentage
88+ limit=$((limit*RET))
89+
90+ limit=$((limit/2))
91+
92+ if [ "$ram" -gt "$limit" ]; then
93+ ram=$limit
94+ fi
95+
96+ db_set partman-auto/desired-swap $((ram*2))
97+
98 echo "$ram"
99 }
100
101@@ -377,6 +406,9 @@ choose_recipe () {
102 target="$2"
103 free_size=$3
104
105+ # Export free_size for cap_ram calculation
106+ db_set partman-auto/cap-ram-free-size $free_size
107+
108 # Preseeding of recipes
109 db_get partman-auto/expert_recipe
110 if [ -n "$RET" ]; then
111diff --git a/d-i/source/partman-auto/recipes-amd64-efi/atomic b/d-i/source/partman-auto/recipes-amd64-efi/atomic
112index 0545b92..104ceeb 100644
113--- a/d-i/source/partman-auto/recipes-amd64-efi/atomic
114+++ b/d-i/source/partman-auto/recipes-amd64-efi/atomic
115@@ -23,7 +23,7 @@ partman-auto/text/atomic_scheme ::
116 $default_filesystem{ }
117 mountpoint{ / } .
118
119-100% 512 200% linux-swap
120+200% 512 200% linux-swap
121 $defaultignore{ }
122 $lvmok{ }
123 $reusemethod{ }
124diff --git a/d-i/source/partman-auto/recipes/atomic b/d-i/source/partman-auto/recipes/atomic
125index 202f8bc..3a7219b 100644
126--- a/d-i/source/partman-auto/recipes/atomic
127+++ b/d-i/source/partman-auto/recipes/atomic
128@@ -28,7 +28,7 @@ partman-auto/text/atomic_scheme ::
129 $default_filesystem{ }
130 mountpoint{ / } .
131
132-100% 512 200% linux-swap
133+200% 512 200% linux-swap
134 $defaultignore{ }
135 $lvmok{ }
136 $reusemethod{ }
137diff --git a/d-i/source/partman-swapfile/debian/partman-swapfile.templates b/d-i/source/partman-swapfile/debian/partman-swapfile.templates
138index 0954dda..a36ffbd 100644
139--- a/d-i/source/partman-swapfile/debian/partman-swapfile.templates
140+++ b/d-i/source/partman-swapfile/debian/partman-swapfile.templates
141@@ -4,14 +4,20 @@ Default: 2048
142 # :sl3:
143 _Description: Maximum size of swapfile
144 Please enter the absolute maximum size of swapfile in MiB.
145+ .
146+ Please note partman-auto/cap-ram partman-auto/cap-ram-percentage
147+ partman-auto/ensure-min-mem will take precedence over this value.
148
149 Template: partman-swapfile/percentage
150 Type: string
151-Default: 5
152+Default: 10
153 # :sl3:
154 _Description: Maximum percentage of free space to use for swapfile
155 Please enter the maximum percentage of free space on root filesystem to
156 use for swapfile.
157+ .
158+ Please note partman-auto/cap-ram partman-auto/cap-ram-percentage
159+ partman-auto/ensure-min-mem will take precedence over this value.
160
161 Template: partman-swapfile/progress_swap_formatting
162 Type: text
163diff --git a/d-i/source/partman-swapfile/finish.d/create_swapfile b/d-i/source/partman-swapfile/finish.d/create_swapfile
164index f1f97f0..5b75b63 100755
165--- a/d-i/source/partman-swapfile/finish.d/create_swapfile
166+++ b/d-i/source/partman-swapfile/finish.d/create_swapfile
167@@ -80,6 +80,12 @@ then
168 size=$limit
169 fi
170
171+# Allow partman-auto to override
172+db_get partman-auto/desired-swap
173+if [ -n "$RET" ]; then
174+ size=$(($RET * 1024))
175+fi
176+
177 # No swapfile if limits are 0MB or 0%
178 if [ $size = 0 ]
179 then

Subscribers

People subscribed via source and target branches