Sound stuttering during package installation

Hi, whenever I install a package in the terminal using "pkg install <pkgname>", the sound stutters constantly when playing a YouTube video in Firefox. This happens when the installation starts, after the download is done, and seems related to disk activity.

However, if I transfer a large file in Thunar while listening to music, there are no sound issues, so it seems to only happen in the terminal. I'm using the Kitty terminal, but it also happens with Xfce's terminal. I added kern.sched.preempt_thresh=200 to sysctl.conf, which helped with stuttering in Chromium (Firefox never had this issue), but the problem is still present during terminal activity.

I would be grateful for any suggestions.
 
Last edited:
Installing packages are basically bus-bandwidth-intensive for both memory and filesystem (aka disk), especially for the ones with a plenty of files.

For my ThinkPad P52 with 6C12T CPU, 32GB of RAM and 2TB of NVMe SSD, installation does not affect too much, but staging/packaging on poudriere builder jail usually hurts unless it is small (both in size and number of files).
Staging and packaging are much more bus-intensive (even if CPU consumptions are quite low) than installing.
 
It might be input/output related. But it could as well be electrical. The sound chips are very prone to electric fields. Especially on some home-builds or motherboards. They are often placed beside the pci-slots. You might take a look on the cabling. And move cables a bit away from the audio chip to see if it changes anything.
 
Hi, whenever I install a package in the terminal using "pkg install <pkgname>", the sound stutters constantly when playing a YouTube video in Firefox. This happens when the installation starts, after the download is done, and seems related to disk activity.

However, if I transfer a large file in Thunar while listening to music, there are no sound issues, so it seems to only happen in the terminal. I'm using the Kitty terminal, but it also happens with Xfce's terminal. I added kern.sched.preempt_thresh=200 to sysctl.conf, which helped with stuttering in Chromium (Firefox never had this issue), but the problem is still present during terminal activity.

I'm using ZFS. The drive is an Intel 250GB SSD. It's pretty old now since it was bought back when SSDs were a new thing, but it still works great. At that time, they were mostly made for enterprises and used higher quality MLC chips.

I would be grateful for any suggestions.

You don't make it clear whether Firefox is showing the problem or "Firefox never had this issue".

What I would try next is mpg123 or mplayer playing an audio file and see whether that also shows the problem. Personally I'd also try jackd, but that is a bit annoying since jackd support is not usually compiled in by default on FreeBSD ports.
 
You don't make it clear whether Firefox is showing the problem or "Firefox never had this issue".

I apologize. With Chrome, there was another issue that I solved by adding kern.sched.preempt_thresh=200 in /etc/sysctl.conf.

This audio stuttering happens regardless of the browser. In fact, as you said, I tried it with an audio application. I played a FLAC file in mpv and the same issue occurred. What is strange is that it only happens when 'pkg' is extracting and usually with larger packages, like 0ad (the Age of Empires-like game) or something 1GB or larger.

I ran this in the terminal, which writes to a file constantly. I let it run for a minute, and it filled up a file to about 10GB, but there was no stuttering with the sound during the disk activity.

sh:
$ doas dd if=/dev/urandom of=a.tmp bs=4M count=2800; rm a.tmp

Anyway I think I can live with it. It only happens during package install. I noticed it in the first few days after I switched to FreeBSD for the first time a month ago, but I thought I'd ask anyway. I don't think it's the sound card because I have two cards, one internal and one USB. The same problem occurs with both. It might be that my Ivy Bridge CPU is already very old for a system like FreeBSD, although it runs fine with Xfce and 8GB RAM.
 
I just tried on my Thinkpad X201 AMD and can't reproduce the problem. Music from mplayer works with no stutter when uninstalling and reinstalling Firefox.

jackd and pulseaudio on top of it seem pretty screwed up, though.
 
Thank you. I appreciate your time.
I noticed this stuttering even when I move the mouse, it becomes a bit jumpy so it's not related to the sound. I tried stopping lightdm/Xfce and logged directly into pure CLI. I opened a song in mpv then switched to another TTY with CTRL+ALT+F2 and ran a pkg install, same problem. So it's not related to Xorg or the video card either. I also did a BIOS and a CPU microcode update, but they did not help. I will try to test on UFS instead of ZFS and possibly try changing the SSD with another one to see if the problem persists. I'll keep you posted.

The problem doesn't happen on Debian during apt install, but of course, Linux handles things differently from BSD. I'm more interested in getting BSD to work.
 
Sure, I included the user in wheel, operator, realtime, video, and webcamd groups. I haven't looked into the pulseaudio thing yet, but as I mentioned earlier, the lag occurs even when I'm just moving the mouse. So, I'm starting to doubt it's related to audio, as I initially suspected.

To my knowledge, 'pkg install' runs under the root user, at least that's what htop indicates. During the process, CPU usage peaks at around 70-80% with significant read and write operations.
I also created a large 1GB+ tar.xz file myself and attempted to unpack it to simulate a similar read/write load, but I didn't experience any stuttering with it like I do with 'pkg install'. It's strange.

Setting kern.sched.steal_thresh to 1 or 0 doesn't seem to help either as this post suggests: https://lists.freebsd.org/pipermail/freebsd-current/2021-March/079237.html
 
I just did a clean FreeBSD reinstall and there is no stuttering when using the UFS filesystem.
I'm wondering what puts pressure when using ZFS other than ARC. I left the ARC value as-is but I also tried reducing it to 2GB but didn't help.

I have 8GB of RAM and I'm unable to upgrade my Probook 4540S to 16GB. Although I can physically add more RAM, it's not officially supported by HP, and the computer actually becomes slower with 16GB than with 8GB.

I'm using Xfce, which reports an average memory use of only 4GB. The desktop feels very responsive. My Ivy Bridge CPU peaks at 3.2GHz with Turbo Boost. Is there anything else that can be tweaked in ZFS besides ARC?
 
Do not overuse high priorities. There is only limited bandwidth and processortime to share for all processes. So it might introduce further latency. Try to lower the priority of pkg during upgrade. Or maybe just do the upgrade before or after use of the computer. It seems to be about scheduling.

Can see your problem disappeared :-)
 
This little stuttering sometimes happen during normal work or just browsing. I've noticed while moving the mouse cursor. It's like the mouse cursor jumps a little bit. I don't know how to explain this :) Also, sometimes I listen to music with mpv, then suddenly a stutter for a fraction of a section, very rare but happens and there is no pkg install involved in those situations. This only occurs on ZFS. The zfs-tools reports about 800MB of ARC use on average. I doubt it's ARC related.
 
Maybe take a look on the cabling on the motherboard. And make sure your audiocable is free from other cables nearby. Electrical Interference is a devil. I once had a lot of problems because of a cable to my speakers. Moving it away from some of the others did solve the problem.
 
Thank you. Disabling prefetch resolved the issue. Now, there is no more stuttering.

sh:
/etc/sysctl.conf

vfs.zfs.prefetch.disable=1

I tried adjusting the arc.max and arc.min values, but no matter what I set them to, it doesn't fix the issue. Only disabling prefetch helps.

cracauer@ do you have an SSD drive in your Thinkpad X201 AMD? If so, what file system are you using?

Update: Very rarely do I still experience a slight stutter, but it's not as bad as it used to be. I would say it's okay now, although I haven't completely gotten rid of it.
 
Last edited:
Same problem here with an Asus P8B75-M LX motherboard with an Intel(R) Core(TM) I5-3470 CPU and 16 Mb of RAM.
This append when extracting a tar.gz archive to the SSD or HDD with ZFS. This problem does not occurs when extracting this archive to
tmpfs(5).
I discover this problem when my old Asus M5A78L-M LX3 motherboard equipped with an AMD FX-6300 died :-(
I then moved the SSD to this Intel(R) Core(TM) i5-3470 system and the problem arise.
For information I am using the same external Nvidia GeForce GT610 graphic board on the two systems.
Code:
$ uname -v
FreeBSD 14.1-RELEASE-p3 GENERIC
$ freebsd-version -ruk
14.1-RELEASE-p3
14.1-RELEASE-p3
14.1-RELEASE-p3
 
I moved my AMD FX-6300 CPU over an even older motherboard (Asus M5A78L-M LX V2) and all is working flawlessly. No sound stuttering.
I tried the same manipulation (extracting a tar.gz archive) with another system ASRock J4105B-ITX and the result is the same, there is sound stuttering.
There is less CPU cores on J4105B and I5-3470 than on FX-6300. Is this the reason of this problem ?
Although FX-6300 is slower than I5-3470, it performs better. Is this due to his associated chipset or CPU architecture ?


 
Back
Top