Optimizing Linux for an AMD Xiaomi/Framework Laptop

https://jdecourval.com/ArchLinux/Xiaomi-RedmiBook-Pro-15-2023

74 points by jdecourval on 2024-05-15 | 34 comments

Automated Summary

This article discusses the author's search for a new laptop with specific features and their decision to purchase the Xiaomi Redmibook Pro 15 2023. The article then details the installation and optimization process for ArchLinux on the new laptop, including configuring disk sector size, memory usage, and compression. The author also covers various software installations and customizations for a better user experience. Additionally, the article mentions some ongoing issues with the laptop's hardware, mainly related to the Panel Self Refresh technology and the fingerprint reader.

Comments

jiehong on 2024-05-15

This is a pretty in-depth list of steps! I’m amazed!

Yet, it makes me feel like the situation is not changing that much on Linux for laptops: most of this should be more automated IMO.

An apple silicon MacBook Pro is quite a bit more expensive, but all of that has mostly been done for you and mostly “just work”, and there is value in that.

prmoustache on 2024-05-15

>Yet, it makes me feel like the situation is not changing that much on Linux for laptops: most of this should be more automated IMO.

This is an archlinux user. You cannot automate and generalize personal opinions and settings. For 1 user that wants his screen to go down to 60Hz on battery you might have 5 who will say they can't use a computer with such a low refresh rate.

A user who wants something that "just work" would have installed his computer with the latest Fedora, Mint or Ubuntu and would be using the default desktop with default sane defaults and terminal and would have been perfectly happy with it.

jdecourval on 2024-05-15

Exactly. This guide makes the computer my own. I'm always astonished when I see ArchLinux users openly praising the distro. It's great... but for people like me. I especially wouldn't recommend using it on a laptop, since skipping a few steps could mean an awful battery life, while other distro would be decent by default.

Having said that, my guide does use some advanced or very recent tricks that are not done by most distros. To which extent all of that help? Hard to say, but we are clearly in the premature, but fun, optimizations territory.

boudin on 2024-05-15

It depends of the distribution you're going for. Using Arch or Gentoo means spending more time doing fine tunings.

Installing something like Fedora is super easy.

tracker1 on 2024-05-16

I've found that using Pop tends to be more straight forward... the only things I've had to do is a grub option for proper touchpad support on a Lenovo laptop, and I've had to use a USB wireless or ethernet card to run updates and get the wifi working.

I'm mostly using it on my desktop, but have setup laptops for friends. Of course System76 that makes Pop sells hardware, so I'd expect them to do better than most in that space.

happymellon on 2024-05-15

It's in-depth because it is someone's instructions for setting up Arch, not Linux.

I don't need to do any of these things with Fedora or Suse.

Delk on 2024-05-15

I'm also not sure that lots of the stuff in the optimization part is actually needed or useful. A lot of it seems like micro-optimization. The author probably cares a lot about tweaking his laptop. If you want to do those steps just in case they might gain you a bit of battery life, you can do them. If you don't care about compiling your own kernel for potentially getting a 1% longer battery life, the vast majority of that stuff shouldn't be needed.

Of course some tweaks might actually have an effect. There are probably actual differences between different pstate driver modes or governors. (But even then it might be dubious whether you need to or should tweak them with TLP since power-profiles-daemon should supersede it in terms of energy/perf policy.)

BizarroLand on 2024-05-15

I'm not an Arch user, but I have noticed pretty poor battery life and sound volume on my Lenovo Legion laptop with every linux flavor I have tried so far.

Pop! OS, Ubuntu, Fedora, & Mint have each been tested and had similar flaws, although Fedora was the only one that automatically reconnected my bluetooth speakers on wake.

I'm going to use this post to more thoroughly examine what information I can learn about my laptop and see if I can uncover where the weaknesses are and how to resolve them.

Delk on 2024-05-15

Yeah, there could be some useful tweaks. I started getting much better battery life on light to moderate load on my ThinkPad when I switched the AMD pstate driver to passive mode. I don't know if that has performance implications but responsivity seems fine to me.

If your Legion has a discrete GPU, that might be outside of the tweaks in the post, though.

cl3misch on 2024-05-15

> By default, many modern SSDs, including the one in this laptop, report a smaller sector size than their optimal one. This is done for compatibility with Windows XP and older systems…

I had never heard of this. Of course, checking on my new NVME SSD I also get the suboptimal 512 bytes. I won't do a reinstall for this, but I wonder how large the performance impact actually is?

wtallis on 2024-05-15

Not much actually does 512-byte IOs, at least not in any performance-critical way. Your OS and filesystem are probably doing most stuff in increments of 4kB, and that's the granularity the SSD is tracking allocations with, even when it is presenting the illusion of 512-byte sectors.

The flash itself probably has a page size of at least 16kB, and erase block size of several MB, but trying to align and chunk your IO to those boundaries has marginal benefits.

As long as you don't have partitions that are misaligned relative to 4kB boundaries, you're fine.

cl3misch on 2024-05-17

Thanks, I was expecting something along those lines. I assume misaligned partitions are kinda hard to produce these days if you are using the default partitioning from your GUI Linux distro installer? Last time I heard this being really relevant was over ten years ago iirc.

jdecourval on 2024-05-15

The truth is, I realized this too late, and now I would also need to, maybe not reinstall, but at least reformat. So I have no idea what sort of impact this has, but clearly, this is not huge.

What supposedly really kills performance is if your filesystem's blocks are unaligned with the real physical sector size (4k), but most FS correctly handles this: https://wiki.archlinux.org/title/Advanced_Format#File_system...

teo_zero on 2024-05-17

I think wrong block sizes, or, to be more precise, misaligned blocks, affect writes more than reads, so the performance impact will be limited in all common cases. But they will worsen the write amplification and thus shorten the life of your SSD.

daghamm on 2024-05-15

This looks extremly well written. I think the arch philosophy of great documentation is also spreading to its users.

This makes me want to buy a new laptop and install arch on it :) Big kudos to the author.

jdecourval on 2024-05-15

Thank you! :)

cl3misch on 2024-05-15

> There are a couple of good file system options, but I chose btrfs for a couple of reasons. Subvolumes work in practice, like more convenient partitions, snapshots are incredibly useful for backups (more on that later) and compression can save quite a bit of space on the not-so-big included SSD, which also reduces wear.

I am also running btrfs (as the default disk partitioning on Fedora 40). I used to do regular snapshots with snapper on my laptop but at some point ~20% of my SSD were reserved for metadata. From that only 10% was used (so 2% overall) without any apparent possibility to reduce the reserved space.

These days, I do snapshots only on my homeserver (which is running syncthing) but not on my laptop.

jdecourval on 2024-05-15

Yes, something similar with snapshots happened to me at a previous job. That led to the filesystem getting 100% full, and with btrfs, you can not even delete files anymore if you reach that point. This specific bug has been fixed since then, but still feel that although btrfs works much better than most are saying, it's still too easy to shoot yourself in the foot.

> These days, I do snapshots only on my homeserver (which is running syncthing) but not on my laptop.

You should try btrbk one day. I had a much better experience with it than with snapper.

JZL003 on 2024-05-17

Really great article

No buyers remorse but also look at Lenovo outlet. Unclear if certified refurbished is as good as Apple's but they have "new" labeled laptops which are way cheaper than the similar ones on main lenovo.com. Don't focus on the percent off label, if I tried to buy a Thinkpad t16 gen 2 "new" from the outlet it says it's 20% off 1k=800, but if I tried to buy it from lenovo.com it starts at 1.4k base

nbf_1995 on 2024-05-15

I used to maintain a list similar to this one when I used Void and later Arch. Now I use NixOS which lets me configure these items once and forget about them. When I swapped the ssd in my laptop for a larger one, the entire post-install configuration was as simple as applying my saved configuration and getting a cup of coffee.

Excellent article though, I've integrated the parts I found interesting into my nixos config.

dusanh on 2024-05-16

Can you share your nixos config?

kkzz99 on 2024-05-16

How is the state in regards to switching from integrated GPU to dedicated GPU? On my old laptop it was impossible to get it to work, it was either integrated or dedicated only, without an easy way to switch between the two. That was several years ago, so hopefully it is easier/better.

hddherman on 2024-05-16

Didn't expect a list this in-depth, but thanks for sharing, have a few things I'll need to check on my own setup that is really similar, except for the part where I run Fedora Linux.

Happy to see another btrbk mention, it really is great!

VTimofeenko on 2024-05-15

Running hyprland as a systemd unit is very painful to set up and prone to crashes that upstream doesn't accept. If it's just about the logs, there's systemd-cat that can pipes stdout/err into the journal.

jdecourval on 2024-05-15

Not perfect, but `systemd-cat` is indeed a very good idea. Thanks.

ssivark on 2024-05-15

What do you mean by “upstream doesn’t accept”?

VTimofeenko on 2024-05-16

Meant to say "bugreports for which the upstream doesn't accept". But maybe I was just unlucky.

Bromeo on 2024-05-16

Thanks for the nice writeup! So how many hours does your laptop get after all this?

It would also be interesting to see an "all default" install (arch or manjaro) somewhere, is someone knows a link.

jdecourval on 2024-05-17

With the computer idle, just a terminal open, screen on, but minimum brightness, I measure 4W power usage, so about 18h of autonomy. Real-world autonomy is probably closer to 8-12h which I think is really good.

JZL003 on 2024-05-17

Also since I saw jdecourval here, no pressure but if you made an rss feed for your articles I would happily subscribe. I don't see one

jdecourval on 2024-05-17

RSS should be available already from my website: https://jdecourval.com/index.xml Not sure how often I will be posting, though!

JZL003 on 2024-05-17

Cool thanks (not linked to within the website source code, so I didn't see)

notorandit on 2024-05-15

He Is totally missing the GPU stuff there!

jdecourval on 2024-05-15

Fair point! Anything to suggest?

I only confirmed that the GPU is indeed clocking correctly, and using the appropriate power profiles. The games I tried all ran flawlessly, but I had less success with ROCm or Vulkan acceleration in Lllama.cpp.