Skip to content

Conversation

@thunder-coding
Copy link
Member

@thunder-coding thunder-coding commented Dec 22, 2025

No description provided.

@thunder-coding
Copy link
Member Author

Seems like the zram module isn't available for azure VMs (which is internally used by GitHub action runners). Guess we will have to keep on using slower swapfiles then

@TomJo2000
Copy link
Member

We could test if Zswap is available, maybe that'll let us use a smaller swapfile.
https://wiki.archlinux.org/title/Zswap

@licy183
Copy link
Member

licy183 commented Dec 22, 2025

IIRC kernel modules on GitHub CI need to be compiled from source to run. I used to compile anbox-modules from source on GitHub CI in TUR [1]. If necessary, we can try compiling zram module from source to see if it works or not.

[1] termux-user-repository/tur@c4d183b

@TomJo2000
Copy link
Member

What's the CI time overhead on that?

Can we compile the Kernel modules ahead of time or does that need to happen on the CI every run?
Also how are the Kernel modules loaded at runtime?
Does DKMS work for that?

@licy183
Copy link
Member

licy183 commented Dec 22, 2025

What's the CI time overhead on that? Can we compile the Kernel modules ahead of time or does that need to happen on the CI every run?

I think that it can be done using Github Cache.

Also how are the Kernel modules loaded at runtime? Does DKMS work for that?

IIRC anbox-modules were loaded using dkms. The main issue is that GitHub Actions uses its own kernel, whose kernel module directory is different from the one in Ubuntu, so modules installed using apt cannot be loaded directly.

@thunder-coding
Copy link
Member Author

Let me see if I can get this thing going with zram dkms module

@thunder-coding
Copy link
Member Author

There we go. Some cleaning required. Then we can go ahead and get the builds for zram cached using GitHub Cache, and it should be pretty quick to load instead of 1m on cloning the kernel. Will probably get this in a day or two

- name: Set process id limit for 32-bit builds depending on aosp-libs
run: echo 65535 | sudo tee /proc/sys/kernel/pid_max
- name: Setup zram for packages that need more memory
run: |
Copy link
Member

@robertkirkman robertkirkman Dec 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this will be adjusted so that it is still only run conditionally when the packages requiring free-space.sh are being built, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be possible to after splitting this step into 3 steps:

  1. extraction of kernel version on the runner VM
  2. Using the kernel version as key for storing into github actions cache
  3. optionally building the module on cache miss

All these steps can be set to only run if large packages are being built

Although I would prefer to keep this to always on. zram should not negatively affect performance if it is not being used. Also it should improve performance when a process which is just hogging memory without using it is moved over to zram. We can test this on CI, and see if it is worth keeping this on by default

@TomJo2000
Copy link
Member

TomJo2000 commented Dec 23, 2025

On a procedural note since I'm seeing it in the commit log here.
You might be interested to know about the git commit --squash=<commit-ish>1 option.

That lets you mark commits in a way that they're automatically sorted to be squashed into the commit they are linked to during a git rebase -i. Provided you pass the --autoquash to git merge or set:

[rebase]
	autosquash = true

in your git config (either ~/.gitconfig or ~/.config/git/config).

This also automatically makes git rebase ignore the commit messages of the designated squash commits during the reword part of the squash.

git commit --squash= should also offer tab completions from your shell so you don't need to remember the commit hashes yourself.

Footnotes

  1. https://man.archlinux.org/man/git-commit.1#OPTIONS:~:text=1)%20for%20details.-,%2D%2Dsquash%3D%3Ccommit%3E,-Construct%20a%20commit

@thunder-coding
Copy link
Member Author

I needed the commit messages of in-between changes for rewriting the commit history once done. This PR is ready for review once I do that.

Also thanks for the git commit --squash, didn't knew of that. TIL!

@TomJo2000
Copy link
Member

I needed the commit messages of in-between changes for rewriting the commit history once done. This PR is ready for review once I do that.

Yep no worries.

Also thanks for the git commit --squash, didn't knew of that. TIL!

Found out about that one somewhat recently and it's been a really useful addition to my workflow.
Makes it way easier to do fixups to multi-commit branches.
It's kind of like a generalization of git commit --amend.
And I don't think I've managed to cause any conflicts during rebase from --squash commits alone so far, so that's a big plus as well.

@thunder-coding thunder-coding force-pushed the zswap branch 3 times, most recently from 81957a4 to 3f9033f Compare December 23, 2025 11:11
@thunder-coding
Copy link
Member Author

Thanks! git commit --squash worked pretty well (except for the mess-ups I created myself). Was able to reorder some commits as well pretty well. Not sure why stacked PRs are so much in trend in the industry nowadays than just relying on this feature which is built into git itself

Comment on lines 48 to 67
- name: Extract VM kernel version for module compilation
id: kernel-info
run: |
KERNEL_VERSION="$(uname -r | grep -o "^[0-9\\.]*")"
TAR_KERNEL_VERSION="${KERNEL_VERSION%\.0}"
echo "kernel_version=${KERNEL_VERSION}" >> "$GITHUB_OUTPUT"
echo "tar_version=${TAR_KERNEL_VERSION}" >> "$GITHUB_OUTPUT"
echo "modules_dir=/lib/modules/$(uname -r)" >> "$GITHUB_OUTPUT"
- name: Restore cached zram kernel module
id: cache-zram
uses: actions/cache/restore@v5
with:
path: scripts/zram.ko.zst
key: ${{ steps.kernel-info.outputs.kernel_version }}-${{ hashFiles('scripts/linux-kernel-signing-keys.gpg') }}-${{ hashFiles('.github/workflows/packages.yml') }}

- name: Build zram kernel module
if: steps.cache-zram.outputs.cache-hit != 'true'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How exactly does the GHA caching work anyway?
Build zram kernel module is conditioned on getting a cache miss.

But I'm guessing we need the kernel version to check the cache in the first place?

Copy link
Member Author

@thunder-coding thunder-coding Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The paths specified by path are cached by GHA. If some data is available with the specified key, then it is restored (happens above in actions/cache/restore step). The key is set to the kernel version as well as the script which is running and the files which we are using (the signing keys for the kernel)

We only need to build the module if we couldn't restore from cache.

We further save the cache just after we build the module and load it.

@thunder-coding thunder-coding marked this pull request as ready for review December 23, 2025 11:44
@thunder-coding
Copy link
Member Author

This PR should be ready for review. Some action runs:

Older runs before cleaning commits showing that caching of the built DKMS module works:

Should improve performance when compiling large packages. And zram
should be unused unless there is requirement for it's usage. Not sure
how much will it affect packages that do not need additional memory
(needs to be monitored for CI usage after getting merged)
Changes made:
- download tarball from cdn.kernel.org instead of git clone
  Also check the signature of the tarball

- Manual install module instead of using modules_install
  modules_install does do the same thing and run depmod. We are running
  depmod ourselves. Also kernel Makefile will skip running depmod since
  System.map is not available on the VM

- Also do zstd compression on the module. The kernel makefiles don't
  seem to do it by default
- Store some of the common variables as outputs for reuse

- Manually restore and save cached zram.ko.zst. This should ensure that
  the builds are cached even when building packages fails

- Additionally the built zram.ko.zst needs to be stored in scripts/ as
  GHA doesn't support caching absolute paths well:
  See issues:
  - actions/cache#1127
  - actions/cache#1540 which was worked around
    in
    oro-os/toolchain@ebcad88
    by using relative path
  Also restoring cache in /lib/modules/ would require
  actions/cache/restore to run as root, and exists no documented way to
  do that which I could find online
@thunder-coding thunder-coding changed the title ci: us zram instead of on-disk swap ci: use zram instead of on-disk swap Dec 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

4 participants