Artix Linux Forum

Artix Linux => System => Topic started by: migmolrod on 09 June 2024, 18:53:07

Title: zramen-dinit flaw (possible also zramen-s6, not sure)
Post by: migmolrod on 09 June 2024, 18:53:07
Hi.

I'm using artix-dinit and wanted to use zramctl. To do so, I've found the zramen wrapper. And since I'm using dinit, I just installed zramen-dinit package. It works, but it uses always default values, so I can't define stuff like size, compression algorithm, etc.

I've taken a look at the PKGBUILD of zramen-dinit package (here in artix gitea). And also at the source code of zramen (in github) and came to the conclusion that the config is lost in the zramen-dinit package. What I mean is:


What I've tried:


Can we improve the zramen-dinit package? Or can I somehow contribute to make it use the three zramen files (config, finish, run)?

Thanks in advance.
Title: Re: zramen-dinit flaw (possible also zramen-s6, not sure)
Post by: steve_ on 10 June 2024, 11:46:08
Newb here. Just joined.

I edited the bin script, not sure if that is the right way for zramen but works.

sudo nano /usr/bin/zramen

Then change the values for constants such as below code block from script.

Code: [Select]
# constants {{{

# use this compression algorithm for zram by default
readonly COMP_ALGORITHM='lz4'
readonly ZRAM_COMP_ALGORITHM="${ZRAM_COMP_ALGORITHM:-$COMP_ALGORITHM}"

# give zram swap device highest priority
readonly PRIORITY=32767
readonly ZRAM_PRIORITY="${ZRAM_PRIORITY:-$PRIORITY}"

# allocate this percentage of memory for zram by default
readonly SIZE=25
readonly ZRAM_SIZE="${ZRAM_SIZE:-$SIZE}"

# set the maximum number of compression streams for zram
readonly STREAMS=$(nproc)
readonly ZRAM_STREAMS="${ZRAM_STREAMS:-$STREAMS}"

# zramen version number
readonly VERSION=0.2.1

# set TMPDIR to work directory for mktemp
readonly WORK_DIR='/var/run/zramen'
TMPDIR="$WORK_DIR"

# end constants }}}

Title: Re: zramen-dinit flaw (possible also zramen-s6, not sure)
Post by: migmolrod on 10 June 2024, 11:53:44
Hi steve_

It was also my first message in this forum, just joined as well haha. Welcome and thanks for your reply.

Doing that also works but the problem is what happens if there is an update for the zramen package itself. I understand it would overwrite the script and the values you entered would be lost. Right? Does it work that way or if it finds the file already present, it skips installing it again?
Title: Re: zramen-dinit flaw (possible also zramen-s6, not sure)
Post by: steve_ on 10 June 2024, 12:05:49
Hi, yeah i didnt factor in updates. That might be an issue.

But you are right, in the zramen --help, there are options to change algo and size but they dont persist over reboots.
My init is openrc and it also has the issue, so not just dinit.
Title: Re: zramen-dinit flaw (possible also zramen-s6, not sure)
Post by: migmolrod on 10 June 2024, 13:49:39
I've just opened an issue in the zramen repository (in github) to see how the developer would prefer to deal with this:
https://github.com/atweiden/zramen/issues/8

But anyways, I'll need to somehow contribute to zraman main package and zramen-xxx subpackages here in gitea.artixlinux. I tried logging in but apparently forum and gitea do not share user database (which is logical, now that I think about it). So I don't actually know how to contribute to those PKGBUILD files that will need a little tweak if zramen creator hears my suggestion.
Cloning + PR works without the ability to log in in gitea?

And now I'm realiizing this post may be in the wrong subforum. Maybe a mod can move it to the Packages subforum here https://forum.artixlinux.org/index.php/board,8.0.html
Title: Re: zramen-dinit flaw (possible also zramen-s6, not sure)
Post by: Hitman on 10 June 2024, 15:30:06
For me it complains during early boot that the log file reaches a read only file system, it starts fine manually afterwards.
Title: Re: zramen-dinit flaw (possible also zramen-s6, not sure)
Post by: migmolrod on 10 June 2024, 20:25:00
For me it complains during early boot that the log file reaches a read only file system, it starts fine manually afterwards.

What init system? Also dinit?
Title: Re: zramen-dinit flaw (possible also zramen-s6, not sure)
Post by: Hitman on 12 June 2024, 19:29:08
Yes.
Not much in the zramen.log file, it does get to "attempting to initialize...device" weirdly.
Title: Re: zramen-dinit flaw (possible also zramen-s6, not sure)
Post by: migmolrod on 13 June 2024, 16:49:47
Yes.
Not much in the zramen.log file, it does get to "attempting to initialize...device" weirdly.

Maybe you can try to manually run the zramctl command (at the end of the day, that's what zramen is, I think: a wrapper around zramctl)

In this line of code you can see what command is run:
https://github.com/atweiden/zramen/blob/master/zramen#L245
Title: Re: zramen-dinit flaw (possible also zramen-s6, not sure)
Post by: burein-ita on 15 June 2024, 05:02:28
For me it complains during early boot that the log file reaches a read only file system, it starts fine manually afterwards.

Same here. It seems zramen is starting too early.

I don't think this is the best way to do it but it works.
Changing the following line in the service file seems to do the trick:
Code: [Select]
- waits-for = pseudofs
+ waits-for = fsck

Is there a way to make the changes to a dinit service file persist after updates?
Title: Re: zramen-dinit flaw (possible also zramen-s6, not sure)
Post by: konimex on 15 June 2024, 07:07:52
I initially wanted to ignore this since zramen is not an Arch package (and I didn't add it initially), however since the alternative is systemd-zram-generator, I took a second look at this and rewritten the dinit service itself (I don't know why a script file is needed when we can invoke the binary script itself).

Code: (/etc/dinit.d/zramen) [Select]
type         = scripted
command      = /usr/bin/zramen make
stop-command = /usr/bin/zramen toss
env-file     = /etc/dinit.d/config/zramen.conf
logfile      = /var/log/dinit/zramen.log
depends-on   = early-devices.target
after        = early-fs-local.target # can be removed if logfile is removed/log-type is buffer

Code: (/etc/dinit.d/config/zramen.conf) [Select]
ZRAM_COMP_ALGORITHM=zstd # for testing purposes
#ZRAM_PRIORITY=32767
#ZRAM_SIZE=25
#ZRAM_MAX_SIZE=4096
#ZRAM_STREAMS=1

It works for me.

Though from this PR (https://github.com/atweiden/zramen/pull/4) I found the zramen author's response odd. Why doesn't zramen just read the config file (https://github.com/atweiden/zramen/blob/master/sv/zramen/conf) directly from the bash script (just put it in /etc and name it /etc/zramen.conf)? Why isn’t it (I quote) "designed to be sourced outside of a runit service context"?

Also, zramen can be a POSIX sh script instead of bash script, but that's outside this topic and can be discussed another day.

As for packaging, I'll need to contact whoever last packaged zramen (and its scripts).
Title: Re: zramen-dinit flaw (possible also zramen-s6, not sure)
Post by: migmolrod on 15 June 2024, 21:08:06
Thanks for your reply.

Yeah, I also added an "issue" to the zramen repo in github, promising a PR that I never did  ::)

Maybe I can take a look now. But my idea was to convince the zramen developer to just add a simple line:

Code: [Select]
config_file_path="/etc/zramen.conf"
[ -r "${config_file_path}" ] && . "${config_file_path}"

near the top of the script, so default values can always be provided with a config file, instead of the miriad of parameters zramctl has (algo, size, streams, etc).


But I like your approach a lot more since it's specific for dinit. I just wanted to help the guy with s6 also in that PR you mentioned hahaha
Title: Re: zramen-dinit flaw (possible also zramen-s6, not sure)
Post by: capezotte on 16 June 2024, 01:39:19
@konimex I think the author means "./conf isn't designed to be sourced from outside of a shell script". Since we can get the same effect of sourcing ./conf by prepending envfile /etc/s6/config/zramen.conf to the s6 command, or using env-file = in dinit, I don't think this needs zramen's maintainer to step in and say "this is the canonical config file everywhere".
Title: Re: zramen-dinit flaw (possible also zramen-s6, not sure)
Post by: konimex on 16 June 2024, 05:24:41
@konimex I think the author means "./conf isn't designed to be sourced from outside of a shell script". Since we can get the same effect of sourcing ./conf by prepending envfile /etc/s6/config/zramen.conf to the s6 command, or using env-file = in dinit, I don't think this needs zramen's maintainer to step in and say "this is the canonical config file everywhere".

Yeah, but why shouldn't it be the "canonical config file everywhere"? I honestly prefer @migmolrod's solution of that simple line instead of making an init-specific solution of using envfile for s6, env-file for dinit, different conf location for every single init. I don't really mind (and frankly, it's just one line ultimately). But the reasoning is odd to me. That's all.