Accepting request 650228 from home:malcolmlewis:openSUSE_General

New package submission. See boo#1116056 for more details. Please add me as maintainer.

OBS-URL: https://build.opensuse.org/request/show/650228
OBS-URL: https://build.opensuse.org/package/show/filesystems/systemd-zram-service?expand=0&rev=1
This commit is contained in:
David Sterba 2018-12-06 12:57:53 +00:00 committed by Git OBS Bridge
commit b5b37d1c22
8 changed files with 179 additions and 0 deletions

23
.gitattributes vendored Normal file
View File

@ -0,0 +1,23 @@
## Default LFS
*.7z filter=lfs diff=lfs merge=lfs -text
*.bsp filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.gem filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.jar filter=lfs diff=lfs merge=lfs -text
*.lz filter=lfs diff=lfs merge=lfs -text
*.lzma filter=lfs diff=lfs merge=lfs -text
*.obscpio filter=lfs diff=lfs merge=lfs -text
*.oxt filter=lfs diff=lfs merge=lfs -text
*.pdf filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.rpm filter=lfs diff=lfs merge=lfs -text
*.tbz filter=lfs diff=lfs merge=lfs -text
*.tbz2 filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -text
*.txz filter=lfs diff=lfs merge=lfs -text
*.whl filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.osc

View File

@ -0,0 +1,10 @@
-------------------------------------------------------------------
Mon Nov 19 14:31:00 UTC 2018 - malcolmlewis@opensuse.org
- Cleanup spec file for submission, (boo#1116056).
-------------------------------------------------------------------
Tue Feb 7 16:13:34 UTC 2012 - malcolmlewis@opensuse.org
- Initial build.

75
systemd-zram-service.spec Normal file
View File

@ -0,0 +1,75 @@
#
# spec file for package systemd-zram-service
#
# Copyright (c) 2012-2018 Malcolm J Lewis <malcolmlewis@opensuse.org>
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via http://bugs.opensuse.org/
#
Name: systemd-zram-service
Version: 0.2.1
Release: 0
License: GPL-2.0
Summary: Systemd service for zram
Url: https://code.launchpad.net/~elementary-os/elementaryos/zramswap-enabler
Group: System/Daemons
Source0: zramswap-enabler-0.2.1.tar.bz2
#Source0: bzr branch lp:~elementary-os/elementaryos/zramswap-enabler
Source1: zramswapon
Source2: zramswapoff
Source3: zramswap.service
Conflicts: compcache
BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildArch: noarch
%systemd_requires
%description
A successor to compcache, zram, has been already integrated in the
Linux kernel for a while now. This means that no additional compilation
nor tweaking is required to benefit from compressing memory on the fly
and massively reduced swapping.
%prep
%setup -q -n zramswap-enabler-%{version}
%build
# No building required, just a placehoder.
%install
mkdir -p %{buildroot}%{_sbindir}
install -m 0755 %{S:1} %{S:2} %{buildroot}%{_sbindir}/
mkdir -p %{buildroot}%{_unitdir}
install -m 0644 %{S:3} %{buildroot}%{_unitdir}/
pushd %{buildroot}%{_sbindir}
ln -s service rczramswap
popd
%pre
%service_add_pre zramswap.service
%post
%service_add_post zramswap.service
%preun
%service_del_preun zramswap.service
%postun
%service_del_postun zramswap.service
%files
%defattr(-,root,root,-)
%doc debian/copyright debian/changelog
%{_sbindir}/rczramswap
%{_sbindir}/zramswap*
%{_unitdir}/zramswap.service
%changelog

BIN
zramswap-enabler-0.2.1.tar.bz2 (Stored with Git LFS) Normal file

Binary file not shown.

17
zramswap.service Normal file
View File

@ -0,0 +1,17 @@
# /lib/systemd/system/zramswap.service
#
# Copyright (c) 2012-2018 Malcolm J Lewis <malcolmlewis@opensuse.org>
#
[Unit]
Description=Service enabling compressing RAM with zRam
After=multi-user.target
[Service]
Type=oneshot
ExecStart=/usr/sbin/zramswapon
ExecStop=/usr/sbin/zramswapoff
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target

16
zramswapoff Normal file
View File

@ -0,0 +1,16 @@
#!/bin/bash
# get the number of CPUs
num_cpus=$(grep -c processor /proc/cpuinfo)
# set decremented number of CPUs
decr_num_cpus=$((num_cpus - 1))
# Switching off swap
for i in $(seq 0 $decr_num_cpus); do
if [ "$(grep /dev/zram$i /proc/swaps)" != "" ]; then
swapoff /dev/zram$i
fi
done
rmmod zram

34
zramswapon Normal file
View File

@ -0,0 +1,34 @@
#!/bin/bash
# get the number of CPUs
num_cpus=$(grep -c processor /proc/cpuinfo)
# if something goes wrong, assume we have 1
[ "$num_cpus" != 0 ] || num_cpus=1
# set decremented number of CPUs
decr_num_cpus=$((num_cpus - 1))
# get the amount of memory in the machine
mem_total_kb=$(grep MemTotal /proc/meminfo | grep -E --only-matching '[[:digit:]]+')
mem_total=$((mem_total_kb * 1024))
# load dependency modules
#modprobe zram zram_num_devices=$num_cpus
# Determine module parm
mod_parm=$(modinfo zram |grep parm |tr -s " " |cut -f2 -d ":")
modprobe zram $mod_parm=$num_cpus
# initialize the devices
for i in $(seq 0 $decr_num_cpus); do
echo $((mem_total / num_cpus)) > /sys/block/zram$i/disksize
done
# Creating swap filesystems
for i in $(seq 0 $decr_num_cpus); do
mkswap /dev/zram$i
done
# Switch the swaps on
for i in $(seq 0 $decr_num_cpus); do
swapon -p 100 /dev/zram$i
done