Merge ubiquity:bump-swap into ubiquity:master

Proposed by Dimitri John Ledkov
Status: Superseded
Proposed branch: ubiquity:bump-swap
Merge into: ubiquity:master
Diff against target: 153 lines (+80/-8)
4 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-swapfile/debian/partman-swapfile.templates (+7/-1)
d-i/source/partman-swapfile/finish.d/create_swapfile (+6/-0)
Reviewer Review Type Date Requested Status
Ubuntu Installer Team Pending
Review via email: mp+425612@code.launchpad.net

This proposal has been superseded by a proposal from 2022-07-01.

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) :
Revision history for this message
Dimitri John Ledkov (xnox) :
Revision history for this message
Nick Rosbrook (enr0n) :

Unmerged commits

982dd15... by Dimitri John Ledkov

Ensure minimum available amount of memory available

Attempt to ensure that total available memory is at least 8GB
(preseedable value). Adjust partman-auto memory capping to result in
more swap, when available ram is under 6GB. Also set the calculated
value, such that partman-swapfile / zsys-setup can consume it.

Due to increased swap file size, also allow larger disk usage
percentage for swap. Small RAM machines, are likely to have less disk
space as well (2GB/128GB dual-boot scenario), and it seems reasonable
to continue to support them.

LP: #1979997

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..b47afed 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-swapfile/debian/partman-swapfile.templates b/d-i/source/partman-swapfile/debian/partman-swapfile.templates
112index 0954dda..a36ffbd 100644
113--- a/d-i/source/partman-swapfile/debian/partman-swapfile.templates
114+++ b/d-i/source/partman-swapfile/debian/partman-swapfile.templates
115@@ -4,14 +4,20 @@ Default: 2048
116 # :sl3:
117 _Description: Maximum size of swapfile
118 Please enter the absolute maximum size of swapfile in MiB.
119+ .
120+ Please note partman-auto/cap-ram partman-auto/cap-ram-percentage
121+ partman-auto/ensure-min-mem will take precedence over this value.
122
123 Template: partman-swapfile/percentage
124 Type: string
125-Default: 5
126+Default: 10
127 # :sl3:
128 _Description: Maximum percentage of free space to use for swapfile
129 Please enter the maximum percentage of free space on root filesystem to
130 use for swapfile.
131+ .
132+ Please note partman-auto/cap-ram partman-auto/cap-ram-percentage
133+ partman-auto/ensure-min-mem will take precedence over this value.
134
135 Template: partman-swapfile/progress_swap_formatting
136 Type: text
137diff --git a/d-i/source/partman-swapfile/finish.d/create_swapfile b/d-i/source/partman-swapfile/finish.d/create_swapfile
138index f1f97f0..1d31881 100755
139--- a/d-i/source/partman-swapfile/finish.d/create_swapfile
140+++ b/d-i/source/partman-swapfile/finish.d/create_swapfile
141@@ -80,6 +80,12 @@ then
142 size=$limit
143 fi
144
145+# Allow partman-auto to override
146+db_get partman-auto/desired-swap
147+if [ -n "$RET" ]; then
148+ size="$RET"
149+fi
150+
151 # No swapfile if limits are 0MB or 0%
152 if [ $size = 0 ]
153 then

Subscribers

People subscribed via source and target branches