Hardware=Single CPU/core
Distro=antiX-13.2-Full-Stable
zram=copied to /etc/init.d/ from /usr/local/bin/
System=rebooted
Diagnosis
All following conducted with root privileges
Report the status of swapspace started by zram
Code: Select all
swapon -s
Filename Type Size Used Priority
/dev/zram0 partition 95500 0 100
/dev/zram1 partition 95500 0 100
The following line in /etc/init.d/zram calculates the number of CPUs
Code: Select all
...
num_cpus=$(grep -c processor /proc/cpuinfo)
...
Verifying what the line returns in a terminal
Code: Select all
grep -c processor /proc/cpuinfo
2
Explanation of value returned
Code: Select all
grep --line-number processor /proc/cpuinfo
1:processor : 0
5:model name : Intel(R) Pentium(R) M processor 1.73GHz
Later in the script a section is included to handle the incorrectly reported number of CPUs
Code: Select all
last_cpu=$((num_cpus - 1))
The adjusted value is then fed into the start and stop sections
Code: Select all
for i in $(seq 0 $last_cpu); do...
Outcome
Even though the number of CPUs has been adjusted (decreased by 1), an incorrect number of swap areas are created because the relevant section of the script starts counting from 0. A swap area is created for number 0, and a swap area is created for number 1.
Options
Workaround Fix
- Retain incorrect calculation section
- Retain section to compensate for incorrect calculation
- Adjust start and stop sections to begin counting upwards from 1 to match incorrect sections
Code: Select all
for i in $(seq 1 $last_cpu); do...
- Correctly calculate number of CPUs
- Jettison section to compensate for incorrect calculation
- Adjust start and stop sections to begin counting upwards from 1 to match correct correct calculation section
Suggestions
antiX-13.2-Full-Stable ships with two suitable apps as components of packages which Debian marks as essential
- getconf is part of libc-bin
- nproc is part of coreutils
Code: Select all
getconf _NPROCESSORS_ONLN
1
nproc
1
nproc --all
1
Code: Select all
sudo swapon -s
Filename Type Size Used Priority
/dev/zram0 partition 191004 0 100
Of the two commands my personal preference is for one of the nproc variants because its format is familiar and adaptable. Additionally the online GNU manual indicates that in use"The result is guaranteed to be greater than zero". This will enable the following additional section to be jettisoned
Code: Select all
# if something goes wrong, assume we have 1
["$num_cpus" != 0 ] || num_cpus=1
References
========= SCRAPER REMOVED AN EMBEDDED LINK HERE ===========
url was:"https://www.gnu.org/software/coreutils/manual/html_node/nproc-invocation.html"
linktext was:"https://www.gnu.org/software/coreutils/ ... ation.html"
====================================
========= SCRAPER REMOVED AN EMBEDDED LINK HERE ===========
url was:"http://www.unix.com/man-page/linux/1/getconf/"
linktext was:"http://www.unix.com/man-page/linux/1/getconf/"
====================================