[OnePlus 9 Pro] arter97:
arter97 kernel for OnePlus 9 series running OxygenOS​

/* Features */

Supports OnePlus 9 series

Fully rebased kernel without unnecessary OnePlus code

Latest CAF msm-5.4 kernel fully merged

Latest Linux v5.4 subversion merged

Latest Google’s security fix merged

BBR as the default TCP network congestion control

Features the latest WireGuard

Modules support disabled for lighter kernel

Latest Wi-Fi drivers from Qualcomm with customized config

Built with Clang 13 and ThinLTO

Power optimizations

Memory management optimizations

Latest SELinux subsystem backported from mainline

Latest f2fs backported from mainline

Latest BFQ I/O scheduler backported from mainline

mmap/mremap backported from mainline for a major performance boost

Touchscreen optimizations for lower latency

Uses LRNG for better performance

/* Details */

- Fully rebased kernel without unnecessary OnePlus code -

This kernel is not based on the stock OxygenOS kernel source provided by OnePlus. Instead, it’s based on the latest and greatest Qualcomm has to offer. Only the necessary parts from the OnePlus kernel have been cherry-picked, such as OnePlus 9 specific device drivers.

This effectively kills all kernel modifications/optimizations from OnePlus, including the infamous app throttler.

Due to the completely different base, this kernel will behave drastically different from other kernels, in both good and bad ways.

- Power optimizations -

This kernel makes some conscious decisions for reducing power consumption.

First, the stock OnePlus configuration forces display-related processes to use the big cores exclusively.

This configuration brings a huge power regression since it makes every frame dispatch to wake up and use the power-hungry cores.

This kernel resets this profile to use the configuration Google recommends, which is to use the LITTLE cores exclusively instead. (Reverted in r2 as it seems like that little cores aren't enough to drive 120 Hz fluidly.)

This kernel allows these processes to use little and middle cores (0-6), depending on the load.

Second, this kernel disables wakelocks upon Wi-Fi’s RX unicast packet transmissions. qcom_rx_wakelock is one of the major culprits to increased idle power consumption. Although its total wakelock time is quite low, it's catched very frequently and prevents the system from entering suspend repeatedly.

As dropping unicast or local ARP packets doesn’t pose practical issues on Android, this kernel disables qcom_rx_wakelock.

Third, this kernel reduces the duration of the Bluetooth ISR wakelock from 2 seconds to 100ms. This was done from an observation that the average userspace response time from ISR is less than 10ms.

My kernels have been doing this for years and no Bluetooth-related issues were reported.

Fourth, the vibrator driver used in this kernel no longer controls the cpuidle driver. The stock kernel disables the cpuidle whenever the vibrator is used. This kernel disables it as the vibrator is not that sensitive to deadline misses.

There are other small improvements throughout the kernel tree as well.

- Memory management optimizations -

This kernel marks the first Linux v5.4 based Android kernel to have MGLRU backported.

MGLRU is a big deal in everything Linux related, especially for Android.

Esper have a great article on what is MGLRU in a nutshell: https://blog.esper.io/android-dessert-bites-22-linux-memory-management-38419756/

TL;DR:

This kernel also disables LMKD and uses an in-kernel solution called SimpleLMK, made by kerneltoast. You can track how often SimpleLMK kicks in by monitoring:

/sys/module/lowmemorykiller/parameters/lmk_count

This kernel also changes a lot related to swap and zram.

The swap-related code has been backported from Linux v5.9 (link1, link2) to efficiently support fast swap device and allow swappiness over 100. This kernel currently sets swappiness to 160 on < 6GB of RAM, 120 on 8GB and 90 on 12GB.

zram has been also backported from mainline Linux and further tweaked to use block device writeback. This is equivalent to the recent “RAM Plus” feature that companies have been marketing that uses the internal storage to extend RAM.

This kernel uses zram writeback to offload idle pages (i.e., really, really unused RAM) to the internal storage. As it's extremely slow to bring pages back from UFS, writeback code works quite conservatively. It'll start to writeback pages that haven't been used for a day or two. It makes use of the hidden 2GB “last_parti” partition from the UFS storage.

Along with zram writeback, this kernel also enables deduplication with xxHash. Each page stored in zram is checked for deduplication to further save memory. With these 2 features combined, RAM reaching 1GB is additionally saved, but your mileage may vary.

zram writeback is temporarily disabled to avoid lags on long uptime with r20.

The post boot script used in the stock ROM is also overridden and it sets the readahead to 128KB. As I/O workload under Android is mostly random, high readahead doesn’t help and only increases memory thrashing.

This kernel also incorporates a lot of patches to reduce/optimize memory allocations used throughout the entire kernel.

mmap/mremap code was also backported from Linux v5.10 to optimize ART (see here for more info).

- Latest subsystems -

This kernel backports the SELinux subsystem from mainline Linux. This includes caching improvements that drastically reduces time spent on lookups. 10K lines of code has been changed.

This kernel also backports f2fs (Flash-Friendly File System) from mainline Linux. This includes bug fixes and performance improvements such as shorter discard latency, more optimized GC logic for Android, and checkpoint merging.

BFQ I/O scheduler has also been backported from mainline Linux for better I/O performance.

- LRNG -

This kernel ditches the traditional RNG driver from the Linux kernel in favor of LRNG. See here and here for more info.

A rudimentary throughput benchmark shows an improvement of 10.5% (keep in mind that this is only one aspect of an RNG metric).

- Battery charging management -

- Battery charging code has been backported from OxygenOS 12. There are numerous fixes there.

- A case where the charger negotiation doesn't go smoothly, the stock kernel will have the charging current limited for prolonged time instead of retrying. This kernel retries AICL right after re-negotiation, so the charging speed will be fixed for this particular case.

- Users can now unlock 27W (9V 3A) charging through USB-PD. From my testing, the battery charges 2% per minute.

Most decent USB-PD chargers should be capable of 27W (including all PD chargers that I personally own), but do note that this is dangerous if you connect to a non-27W capable charger (i.e., 3A unsupported on the 9V voltage profile) when this is enabled.

Write 0 to /sys/modules/oplus_chg/parameters/limit_pd enable this new behavior.

- OnePlus lowers the temperature limit when the screen is on for cooler user experience. Users can now also change this behavior and allow the device to get a little hotter by forcing the kernel to behave the same during screen-on and screen-off.

This is not dangerous but it'll obviously mean the device will be hotter when you use it and charge it simultaneously.

Write 1 to /sys/modules/oplus_chg/parameters/ignore_screen_state to do this.

- This build now disables surface temperature monitoring in the charging code for non-SuperWarp chargings. This mechanism is a separate one from what's described above, and I've personally ran into multiple charging annoyances due to this, resulting in a super slow 3W charging when I need to charge urgently.

OnePlus have set the threshold too low, resulting in real charging issues in practice. This behavior is somewhat lifted with OxygenOS 12, and my kernel takes it further and removes it entirely for non-SuperWarp charges as other perfectly fine safety mechanisms exist.

See the commit for more details:

oplus_chg: disable non-swarp strategy policies · arter97/android_kernel_oneplus_sm8350@cc9fcc1

This mechanism serves to limit the charging current (not input current) depending on the surface temperature, but it fails in practice for so many different reasons. First, the input current is st...

github.com

/* Notice */

OxygenOS 12 is unsupported.

Non-OxygenOS custom ROMs are supported, but your mileage may vary wildly. Most notably, gesture orientations on some ROMs may be inverted.

Custom ROMs that uses OxygenOS 12 kernel, including LineageOS 19.1, are not supported.

This kernel touches vendor_boot and dtbo partitions, meaning you'd need to restore said partitions whenever you're switching to another kernel or stock.

Please make a back-up of these partitions. The installer doesn’t do this automatically for you. Installing the stock ROM with a full OTA restores said partitions as well.

/* Disclaimer */

Your warranty is now void.

I am not responsible for bricked devices, dead SD cards,

thermonuclear war, or you getting fired because the alarm app failed. Please

do some research if you have any concerns about features included in this kernel

before flashing it! YOU are choosing to make these modifications, and if

you point the finger at me for messing up your device, I will laugh at you. Hard. A lot.

/* Thanks to */

Vishalcj17

kristofpetho

kdrag0n

kerneltoast (SultanXDA)

/* Instructions */

1. Read the above. Please.

2. Flash the zip file from FK Kernel Manager. Any other installation methods are untested.

/* Downloads and links */

arter97.com

Kernel source

Telegram chat link