commit b5b37d1c228fd6b090b5bcec703352a61fd34811ee4ccb677627aa817a25ac09 Author: David Sterba Date: Thu Dec 6 12:57:53 2018 +0000 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 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9b03811 --- /dev/null +++ b/.gitattributes @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57affb6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.osc diff --git a/systemd-zram-service.changes b/systemd-zram-service.changes new file mode 100644 index 0000000..897e56d --- /dev/null +++ b/systemd-zram-service.changes @@ -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. + diff --git a/systemd-zram-service.spec b/systemd-zram-service.spec new file mode 100644 index 0000000..8e8fed1 --- /dev/null +++ b/systemd-zram-service.spec @@ -0,0 +1,75 @@ +# +# spec file for package systemd-zram-service +# +# Copyright (c) 2012-2018 Malcolm J Lewis +# +# 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 diff --git a/zramswap-enabler-0.2.1.tar.bz2 b/zramswap-enabler-0.2.1.tar.bz2 new file mode 100644 index 0000000..27bc4cf --- /dev/null +++ b/zramswap-enabler-0.2.1.tar.bz2 @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fe4698084c19760592d70cc33c80064ad4e8442531d434a11ba429341b3f41f2 +size 13953 diff --git a/zramswap.service b/zramswap.service new file mode 100644 index 0000000..797e638 --- /dev/null +++ b/zramswap.service @@ -0,0 +1,17 @@ +# /lib/systemd/system/zramswap.service +# +# Copyright (c) 2012-2018 Malcolm J Lewis +# + +[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 diff --git a/zramswapoff b/zramswapoff new file mode 100644 index 0000000..552a27a --- /dev/null +++ b/zramswapoff @@ -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 diff --git a/zramswapon b/zramswapon new file mode 100644 index 0000000..399a28d --- /dev/null +++ b/zramswapon @@ -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