[MOD] [A10 & Prior, Magisk 19.4+] PK's Tuning Script v33 / V34 - EOL [2020-04-30]

Search This thread

pkgnex

Senior Member
Aug 13, 2012
1,011
1,167
Michigan
Left for posterity, but no further development will occur (see 4/30/2020 post)...

Here's a script that I helped some good guys out with developing "back in the day" (Franco's Dev Team - you can look them up!). Actually, it is a trimmed, consolidated version of the set-of-scripts we came up with. If you search, you can find osm0sis still hosts the original files, and those that I have been maintaining since the Galaxy Nexus went extinct (through L, M, N, and now O), I believe. Note that those scripts will no longer on Android 10 - and probably not even on 9 - so I don't recommend actually using them.

This script has all of the original tuning scripts put into a single file, having stripped out anything that stopped working between Kit-Kat and Android 10 (which was substantial), and some very small improvements I've found over the years. I also added a few things more to my personal usage preference for this Pixel-2/XL version. It has also been trimmed to work on the Pixel 2 / Pixel 2 XL stock kernel whilst outputting no errors, on all android versions through Android 10, and now on Magisk 19.4+.

Notes:
- This script is lean and mean, but it's not rocket science.
- I didn't invent anything here. Feel free to use (or not), distribute, alter, whatever; to your satisfaction, giving credit for redistribution only to "Franco's Dev Team", and maybe me if you're feeling generous.
- Again, I have verified it works on my personal Pixel 2 XL, and is compatible with all Android versions, Kernels, and Magisk versions.
- It actually improves many benchmark scores (you know the usual culprits) without lowering any on my device. But, you know what that's worth (one device, only a few items likely significant on a statistical basis).
- It won't make your phone run any worse. It might even feel a bit "snappier", but YMMV.
- If you feel this script is good, bad, or does nothing, feel free to thank me - or hang me in effigy, as appropriate.
- I do not plan to do heavy maintenance on this, but I will keep it up to date so it at least safely runs on the Pixel 2 / 2XL as long as I own one. I will post updates with a minimal change log (it's a script, you can read it!).

Disclaimer:
I can't see how this could possibly cause irreparable harm to any android device on which it is run.
However, I suppose untested configurations may (rarely) have slow-downs, reboots, or other effects.
REGARDLESS, it is offered as-is with no warranty, and you choose to run this at your own risk.

Requirements:
Root
BusyBox installation (I recommend the Magisk module by osm0sis)
Knowledge of how to execute a linux script and/or where to place it / allow permissions to run on boot

Usage:
Download attachment to your device
Place file in /data/adb/service.d (for Magisk-rooted devices, using Magisk 18.0+)
remove ".txt" extension (leaving the .sh extension)
Ensure permissions are right (0755)
Reboot and wait 2 minutes

Credits:
Franco's Dev Team, esp. osm0sis
Google
Others as noted in the script file header
 

Attachments

  • 94pks33.sh.txt
    5 KB · Views: 789
  • 94pks33generic.sh.txt
    3.7 KB · Views: 293
  • 94pks34.sh.txt
    4.8 KB · Views: 486
Last edited:

pkgnex

Senior Member
Aug 13, 2012
1,011
1,167
Michigan
Change Log:

Version 34 (98pks34.sh):
Version added with no disabling of zram.
V33 is still active for those who don't need / want zram.
V33 generic is still active as well (V34 generic would be the same as generic version does not alter zram).

Version 33 (98pks33.sh):
- Updated with Franco Dev-Team tuned Deadline scheduler (still the fastest). Script uses this if Deadline is available in your scheduler, else it defaults to using Noop.
- Other very minor tweaks based on testing, and some code cleanup

Version 32 (98pks32.sh):
- Updated for Magisk 19.4 (primarily eliminated mounting calls on / and /system to prevent root interference or verity problems due to SAR implementation now standard)
- Backed off the schedutil governor performance tweaks just a bit, still more performance oriented then v30 and prior, just not as extreme
- Removed wakelock blocking (for now) for evaluation. Most kernels already block safe wakelocks anyway. If I find none of the benefits I'm looking for, I may add them back in the next release.
- Released corresponding device-generic version due to important Magisk / SAR compatibility updates

Version 31 (98pks31.sh):
- Simplified some VM settings / reverted to stock where no difference was noted
- Simplified some block IO parameters / reverted to stock where no difference was noted
- Increased transmission queue buffer based on latest testing (still lower than stock)
- Tuned Schedutil governor settings to bias for more performance, reduce lag
- Increase GPU min frequency to 342 MHz step (2nd from bottom) based on testing to reduce lag
- Note that these changes did not appreciably affect battery life in testing
- Simplified output file write-out
- Released official "generic device" companion script of this version for those asking

Version 30 (98pks30.sh):
! GOOD TO GO FOR Q-FINAL / A-10 !
- Re-enabled stock zram - was causing freezes after about 24-36 hours of uptime
- Re-enabled vm tweaks for increased battery life (disabled pdflush periodic writebacks, lowered potential for large data writes causing hang-ups as a result in dirty ratios, adjusted cache pressure to not favor dentry/inodes quite so hugely over pagecache)
- Blocked a few more known and safe-to-block wakelocks

Version 29 (98pks29.sh):
Reverted some changes that were causing some serious jank / freezes:
- Went back to noop
- Reintroduced periodic pdflush writeback (although less frequent than stock)

Version 28 (94pks28.sh):
Biggest changes in a while!
- Increased run delay to 2 minutes to stay out of kernel apps' way
- Reverted tcp_ecn to 2 (stock) for slight decrease in network latency
- Substantial vm tweaks for increased battery life (disabled pdflush periodic writebacks, lowered potential for large data writes causing hang-ups as a result in dirty ratios, adjusted cache pressure to not favor dentry/inodes quite so hugely over pagecache)
- Right-sized nr_requests for any scheduler (not just noop) relative to built-in Android queue-depth
- Changed scheduler to deadline* with Franco Dev Team's tuning tweaks (still fastest i/o I can manage in testing)
* Device-generic version (94pks28generic.sh) was left unchanged with noop scheduler

Version 27 (94pks27.sh):
- Fixed for Android Q while keeping backward compatibility with prior Android versions.
- Increased run delay to 90 seconds to stay out of magisk module or kernel apps' way.

Version 26 (94pks26.sh):
- Updated one minor (but hard to find), error in mount option filesystem tweaks that had been causing data connectivity issues on custom ROM's using this script or BlackenedMod.
- SPECIAL THANKS to @sublimaze for testing iterations until we found the root cause of this issue!

Version 25 - skipped, test versions for @sublimaze to help me figure out data connection issues.

Version 24 (94pks24.sh):
- Updated ext4 filesystem tweaks for even better battery life and performance
- Small reduction of entropy pool size based on other user feedback

Version 23 (94pks23.sh):
- Change header to list new Magisk 18.0+ late-start boot service folder location
- SEE ALSO OP FOR THIS LOCATION

Version 22 (94pks22.sh):
- Force read_ahead_kb to 1024 for faster I/O performance on all realistic file sizes

Version 21 (94pks21.sh):
- Increased load delay at boot back to 60s.

Version 20 (94pks20.sh):
- Added .sh extension to file to allow more flexibility for future tuning (now just delete .txt, but leave .sh in the file name before copying to run location)
- Slightly increased load time at boot to 40s to ensure script runs even for users with many magisk modules
- Reduced foreground app schedtune boost to 5% (was 10%) for battery saving when multiple apps are open with no perceived detriment to performance or app switching
- Increase dirty_expire and dirty_writeback timings for less overhead, reduced battery, and improved performance with no ill effects noted
- Reverted GPU min clock increase due to my testing finding the speed benefit was not noticeable but battery life was negatively affected

Version 19 (94pks19):
- Reduced load time at boot (enabled by re-ordering of script) to 30s
- tcp_ecn set to 1 for across-the-board network speed enhancement when handshake allows
- reduced txqueuelen to 128 for network speed enhancement on 4g/wifi (less bufferbloat)
- added wakelock blocker courtesy of @xFirefly93, but only for blocking wakelocks I have actually seen in BBS for Pixel 2 / XL.

Version 18 (94pks18):
- Increase cpu governor up-rate-time; VERY significant battery help with no performance degradation noticed.
- Reduce vm dirty ratio and dirty expires slightly to reduce potential (although unlikely) excess caching and latency from memory write-out.
- Slight code re-ordering for potential quicker boot delay in the future

Version 17 (94pks17):
- Schedtune code cleanup
- GPU min frequency set to 342 (performance boost with no adverse battery drain per @xFirefly93 testing)
- Increase cpu governor down rate limit by 25% for better performance with minimal battery life impact.

Version 16 (94pks16):
- Revert dir-notify-disable
- Fix a minor dirty-expire vm derp I made many, many releases ago
- Adjust dev/stune/schedtune parameters to ensure users won't have frequency scaling issues on any kernel, allowing cpu's to actually settle and sleep. This wasn't likely before, but is now virtually impossible, while performance improvement during app switching is still present!

Version 15 (94pks15):
- Fs dir-notify disable.
- Schedtune parameter tweaks for performance increase.
Credit: Both of the above were initiated by @xFirefly93, I only slightly modified the Schedtune parameters.

Version 14 (94pks14):
- Revert disabling service_locator, otg_wakelock, and debug kernel modules - no real battery save noted in testing; and I had some issues with apps hanging that required location services that were resolved by getting rid of this code.
- Change rq_affinity from 2 to 1 - I verified with I/O benchmark testing that this provides a slight increase in I/O performance, especially reads and sqlite operations. No battery life impact noted during days of testing.

Version 13 (94pks13): Internal test build - not released (probably would have been unlucky anyway ;))

Version 12 (94pks12):
- Turn off iostats - by popular request (slight battery save)
- Increase vm stat_interval to 60 - Thx to xFirefly93 (slight battery save)
- Disable service_locator, otg_wakelock, and debug kernel modules - Thx to xFirefly93 (slight battery save)

Version 11 (94pks11):
- Delay script start by 30 seconds for users with multiple late-start scripts or other Magisk modules
- Increase timer for vm dirty writeback (saves battery from less wake-ups, cache integrity still reasonably protected by low dirty background ratio)
- Slight kernel entropy increase

Version 10 (94pks10):
- Increase min_free_kbytes - better performance based on testing
- Reduce entropy read_wakeup_threshold - to prevent blocking apps or commands if entropy drops
- Thrift ipv4 / network settings that were ineffectual - cleanup with better or same performance based on testing
- Reduce scheduler nr_requests - less overhead, subjective latency reduction
- Revert to default read_ahead_kb - better performance based on testing

Version 9 (94pks9):
- Slight change-up on kernel entropy settings to keep pool about half-full.
- tcp_max_syn_backlog and tcp_ecn parameters added (thanks @Juzman for getting me to look at these!) that seem to help network throughput slightly - they certainly don't hurt.
- Added fstrim for data, cache, and system partitions at end of script - because why not do this on every boot?

Version 8 (94pks8):
New file location noted in header: /sbin/.core/img/.core/service.d
- Need to place script in this directory for Magisk 16.3 onward
- Backward compatible for previous versions back to 14.5
Script now executes 70% faster after boot
- Only sleeps for 30 seconds; verified to still run through Magisk late start service
Added file system optimizations for /system partition
Adjusted min_free_kbytes to 7 GB from 7.5
- Should slightly raise available RAM for each node, no oom increase or other ill-effects verified through dmesg / kmesg logs
Reverted vm.vfs_cache_pressure to 20
- Less subjective latency based on testing
Script success / fail write-out file now time stamped for users local time rather than UTC/GMT

Version 7 (94pks7):
- Removed LMK (yay!) based on multiple requests, advice from @Scott, and my verifying that nothing I tried improved over stock.
- Added back in some block-level scheduler queue tweaks that are not consistent (and not optimized) on all blocks in the stock configuration as I thought they were
- Cleaned up and re-organized the code - inspiration from @Juzman
- Re-evaluated vm settings @Scott) and network tweaks @Juzman); I don't believe this resulted in any changes (except I'm trialing cache_pressure at 60 vice 20), but thanks for their advice, research, testing, and participation (which is also now credited in the script).

Version 6 (94pks6):
- Added feature: script now writes out a file "pks_script_result" to the /storage/emulated/0 (root of internal storage) directory when executed.
- If the file is present after attempting to run (or after a reboot if you have it in su.d, init.d, or service.d folders) then this indicates the script executed.
- If when you open the file in a text viewer it has a time/date stamp and the phrase "94pks6 successfully executed!", then it ran without errors.
- If when you open the file it says instead "94pks failed." then it threw some error code upon execution... but it was probably minor enough that the changes were applied (or the file wouldn't have been written ;)).

All the above is at least in theory. It seems to be working that way on my device. Thanks to @Scott for the suggestion!

Version 5 (94pks5):
- Lowered last lmk slot (empty apps) much further - no appreciable loss of available RAM during my testing, less redraws in chrome tabs and reloading of recent apps.

Version 4 (94pks4):
- Fixed aggressive Lowmemorykiller / memory over-commit interaction issue (only last LMK slot now much more aggressive than stock, vm.overcommit_memory reverted to "1" (stock). The interaction with previous settings could cause an issue where no additional apps could be opened (they were immediately killed).
- Very minor tweaks to some vm caching parameters

Version 3 (94pks3):
Corrected swap off command to not throw error flag on execution
Altered tx_queue_len replacement command to skip non-linked file and not flag error on execution
Thanks @Lessaj and @veetoe for helping

Version 2 (94pks2):
1). Increased LMK levels
---- I tested for weeks, we have gobs of RAM, it should really only affect empty apps
2). Turned off swap and de-allocated zram space
---- With 4GB of RAM, do we need zram? I don't think so. I found benchmarks and day-to-day performance to be slightly better without it, plus this is further enabled by increased LMK levels (in theory).
3). Reduced the vm dirty expire / writeback by a factor of 10 (still far more aggressive than stock)
---- No real effect here, just walking back to stock since I see no real effect with these parameters on Pixel 2.
4). Enabled Schedutil governor IO_wait_boost flag for both little and big clusters.
---- Should boost performance / reduce latency during high I/O events, found it to marginally increase some benchmarks and subjective performance feel without affecting battery (YMMV).
 
Last edited:

TheGeekyNimrod

Senior Member
Jun 18, 2013
1,181
1,696
Virginia
thisisjohnnyt.com

Attachments

  • Screenshot_20171109-211446.png
    Screenshot_20171109-211446.png
    133 KB · Views: 2,719
  • Like
Reactions: pkgnex

bryantjopplin

Senior Member
Sep 15, 2010
1,635
724
It wasn't there, just added it. Picture confirmed it was a folder

Sent from my Pixel 2 XL using Tapatalk
 

pkgnex

Senior Member
Aug 13, 2012
1,011
1,167
Michigan
I might give this a go in the morning. Add it and reboot in a full charge before I go to work. Using Flash kernel with my 2 XL, but hey, I'm always down for tweaking and tuning. I'll report back.
Should work fine with custom kernels... I'm just not sure if any of the tweaks might not already be in Flash - I know a couple aren't. Thanks for giving it a try and reporting back.

You won't see it in the app. Use a root browser of some kind.

Root Partition/Magisk/.core/service.d

That would be the file path.
Thanks for helping others out while I was away!

It wasn't there, just added it. Picture confirmed it was a folder

Sent from my Pixel 2 XL using Tapatalk
That's truly odd - I've had 3 different devices with Magisk and they always had that folder. Could be that it was hidden to your file explorer of choice, especially since some of the folder names start with, or have "." in them? I dunno. Hopefully adding the folder manually like you did just works.
 
  • Like
Reactions: bryantjopplin

bryantjopplin

Senior Member
Sep 15, 2010
1,635
724
Should work fine with custom kernels... I'm just not sure if any of the tweaks might not already be in Flash - I know a couple aren't. Thanks for giving it a try and reporting back.


Thanks for helping others out while I was away!


That's truly odd - I've had 3 different devices with Magisk and they always had that folder. Could be that it was hidden to your file explorer of choice, especially since some of the folder names start with, or have "." in them? I dunno. Hopefully adding the folder manually like you did just works.
Using root explorer since OG Droid. Others are inferior imo. Thanks for checking up.

Sent from my Pixel 2 XL using Tapatalk
 
  • Like
Reactions: pkgnex

pkgnex

Senior Member
Aug 13, 2012
1,011
1,167
Michigan
Easy way to tell if the script is working? Or pretty much seeing this here is enough?

Which kernel are you running? If it's stock, the easiest way to tell for sure is to install a kernel editor (EX by FLAR2 is a good one, but there are others if you have to pay for that one, I forget) and see if some of the parameters in the script "took" like low memory killer values, vm parameters, entropy values, read-ahead kb, io-scheduler being noop instead of CFQ, etc. I know Flash uses cfq as the default sceduler, so if you're returning noop, that would indicate the script ran. I'm not sure what the default scheduler is on Despair's Snoke.

One thing - I don't think the folder you have it in is right. I think the path should be (root)/Magisk/.core/service.d NOT (root)/DEV/Magisk/IMG/.core/service.d

Just remembered, another way to see if it ran is to open Magisk manager, go into settings, click "log" and select the "Magisk" tab. You should see a bunch of stuff, but near the bottom you should see:
: ** late_start service mode running
: * Running service.d scripts
service.d: exec [94pks]
 
  • Like
Reactions: mnrivera210

henderjr

Senior Member
Dec 21, 2007
880
277
LaCrosse, WI
Google Pixel 6 Pro
Which kernel are you running? If it's stock, the easiest way to tell for sure is to install a kernel editor (EX by FLAR2 is a good one, but there are others if you have to pay for that one, I forget) and see if some of the parameters in the script "took" like low memory killer values, vm parameters, entropy values, read-ahead kb, io-scheduler being noop instead of CFQ, etc. I know Flash uses cfq as the default sceduler, so if you're returning noop, that would indicate the script ran. I'm not sure what the default scheduler is on Despair's Snoke.

One thing - I don't think the folder you have it in is right. I think the path should be (root)/Magisk/.core/service.d NOT (root)/DEV/Magisk/IMG/.core/service.d

Just remembered, another way to see if it ran is to open Magisk manager, go into settings, click "log" and select the "Magisk" tab. You should see a bunch of stuff, but near the bottom you should see:
: ** late_start service mode running
: * Running service.d scripts
service.d: exec [94pks]

I'm stock 8.1 right now besides Magisk with Adaway.

The script is is in both places though I only remember putting it in one. Wonder if one is a copy of the other.

Anyway I see it in the logs so we should be good. Thanks again!
 

Attachments

  • screenshot_2017_11_10_12_21_02.png
    screenshot_2017_11_10_12_21_02.png
    67.1 KB · Views: 1,108
  • screenshot_2017_11_10_12_22_38.jpg
    screenshot_2017_11_10_12_22_38.jpg
    270.2 KB · Views: 1,122
Last edited:
  • Like
Reactions: pkgnex

pkgnex

Senior Member
Aug 13, 2012
1,011
1,167
Michigan
I'm stock 8.1 right now besides Magisk with Adaway.

The script is is in both places though I only remember putting it in one. Wonder if one is a copy of the other.

Anyway I see it in the logs so we should be good. Thanks again!

One location is probably a sym-link to the other, then. Good to know!

I'm still running 8.0, so at least I now know it works on 8.1 as well.
 
  • Like
Reactions: henderjr

TheGeekyNimrod

Senior Member
Jun 18, 2013
1,181
1,696
Virginia
thisisjohnnyt.com
So I've used the script alongside Flash Kernel beta and a few tweaks of my own. Can't really say I've noticed a battery difference as I also use Disable service and others. But I do feel there is a slight increase in response time whether it's touch, transition, fingerprint, etc.
 
  • Like
Reactions: pkgnex

skinza

Senior Member
Which kernel are you running? If it's stock, the easiest way to tell for sure is to install a kernel editor (EX by FLAR2 is a good one, but there are others if you have to pay for that one, I forget) and see if some of the parameters in the script "took" like low memory killer values, vm parameters, entropy values, read-ahead kb, io-scheduler being noop instead of CFQ, etc. I know Flash uses cfq as the default sceduler, so if you're returning noop, that would indicate the script ran. I'm not sure what the default scheduler is on Despair's Snoke.

One thing - I don't think the folder you have it in is right. I think the path should be (root)/Magisk/.core/service.d NOT (root)/DEV/Magisk/IMG/.core/service.d

Just remembered, another way to see if it ran is to open Magisk manager, go into settings, click "log" and select the "Magisk" tab. You should see a bunch of stuff, but near the bottom you should see:
: ** late_start service mode running
: * Running service.d scripts
service.d: exec [94pks]
Followed the above instructions
Ran no problem
 
  • Like
Reactions: pkgnex

Top Liked Posts

  • There are no posts matching your filters.
  • 42
    Left for posterity, but no further development will occur (see 4/30/2020 post)...

    Here's a script that I helped some good guys out with developing "back in the day" (Franco's Dev Team - you can look them up!). Actually, it is a trimmed, consolidated version of the set-of-scripts we came up with. If you search, you can find osm0sis still hosts the original files, and those that I have been maintaining since the Galaxy Nexus went extinct (through L, M, N, and now O), I believe. Note that those scripts will no longer on Android 10 - and probably not even on 9 - so I don't recommend actually using them.

    This script has all of the original tuning scripts put into a single file, having stripped out anything that stopped working between Kit-Kat and Android 10 (which was substantial), and some very small improvements I've found over the years. I also added a few things more to my personal usage preference for this Pixel-2/XL version. It has also been trimmed to work on the Pixel 2 / Pixel 2 XL stock kernel whilst outputting no errors, on all android versions through Android 10, and now on Magisk 19.4+.

    Notes:
    - This script is lean and mean, but it's not rocket science.
    - I didn't invent anything here. Feel free to use (or not), distribute, alter, whatever; to your satisfaction, giving credit for redistribution only to "Franco's Dev Team", and maybe me if you're feeling generous.
    - Again, I have verified it works on my personal Pixel 2 XL, and is compatible with all Android versions, Kernels, and Magisk versions.
    - It actually improves many benchmark scores (you know the usual culprits) without lowering any on my device. But, you know what that's worth (one device, only a few items likely significant on a statistical basis).
    - It won't make your phone run any worse. It might even feel a bit "snappier", but YMMV.
    - If you feel this script is good, bad, or does nothing, feel free to thank me - or hang me in effigy, as appropriate.
    - I do not plan to do heavy maintenance on this, but I will keep it up to date so it at least safely runs on the Pixel 2 / 2XL as long as I own one. I will post updates with a minimal change log (it's a script, you can read it!).

    Disclaimer:
    I can't see how this could possibly cause irreparable harm to any android device on which it is run.
    However, I suppose untested configurations may (rarely) have slow-downs, reboots, or other effects.
    REGARDLESS, it is offered as-is with no warranty, and you choose to run this at your own risk.

    Requirements:
    Root
    BusyBox installation (I recommend the Magisk module by osm0sis)
    Knowledge of how to execute a linux script and/or where to place it / allow permissions to run on boot

    Usage:
    Download attachment to your device
    Place file in /data/adb/service.d (for Magisk-rooted devices, using Magisk 18.0+)
    remove ".txt" extension (leaving the .sh extension)
    Ensure permissions are right (0755)
    Reboot and wait 2 minutes

    Credits:
    Franco's Dev Team, esp. osm0sis
    Google
    Others as noted in the script file header
    12
    Change Log:

    Version 34 (98pks34.sh):
    Version added with no disabling of zram.
    V33 is still active for those who don't need / want zram.
    V33 generic is still active as well (V34 generic would be the same as generic version does not alter zram).

    Version 33 (98pks33.sh):
    - Updated with Franco Dev-Team tuned Deadline scheduler (still the fastest). Script uses this if Deadline is available in your scheduler, else it defaults to using Noop.
    - Other very minor tweaks based on testing, and some code cleanup

    Version 32 (98pks32.sh):
    - Updated for Magisk 19.4 (primarily eliminated mounting calls on / and /system to prevent root interference or verity problems due to SAR implementation now standard)
    - Backed off the schedutil governor performance tweaks just a bit, still more performance oriented then v30 and prior, just not as extreme
    - Removed wakelock blocking (for now) for evaluation. Most kernels already block safe wakelocks anyway. If I find none of the benefits I'm looking for, I may add them back in the next release.
    - Released corresponding device-generic version due to important Magisk / SAR compatibility updates

    Version 31 (98pks31.sh):
    - Simplified some VM settings / reverted to stock where no difference was noted
    - Simplified some block IO parameters / reverted to stock where no difference was noted
    - Increased transmission queue buffer based on latest testing (still lower than stock)
    - Tuned Schedutil governor settings to bias for more performance, reduce lag
    - Increase GPU min frequency to 342 MHz step (2nd from bottom) based on testing to reduce lag
    - Note that these changes did not appreciably affect battery life in testing
    - Simplified output file write-out
    - Released official "generic device" companion script of this version for those asking

    Version 30 (98pks30.sh):
    ! GOOD TO GO FOR Q-FINAL / A-10 !
    - Re-enabled stock zram - was causing freezes after about 24-36 hours of uptime
    - Re-enabled vm tweaks for increased battery life (disabled pdflush periodic writebacks, lowered potential for large data writes causing hang-ups as a result in dirty ratios, adjusted cache pressure to not favor dentry/inodes quite so hugely over pagecache)
    - Blocked a few more known and safe-to-block wakelocks

    Version 29 (98pks29.sh):
    Reverted some changes that were causing some serious jank / freezes:
    - Went back to noop
    - Reintroduced periodic pdflush writeback (although less frequent than stock)

    Version 28 (94pks28.sh):
    Biggest changes in a while!
    - Increased run delay to 2 minutes to stay out of kernel apps' way
    - Reverted tcp_ecn to 2 (stock) for slight decrease in network latency
    - Substantial vm tweaks for increased battery life (disabled pdflush periodic writebacks, lowered potential for large data writes causing hang-ups as a result in dirty ratios, adjusted cache pressure to not favor dentry/inodes quite so hugely over pagecache)
    - Right-sized nr_requests for any scheduler (not just noop) relative to built-in Android queue-depth
    - Changed scheduler to deadline* with Franco Dev Team's tuning tweaks (still fastest i/o I can manage in testing)
    * Device-generic version (94pks28generic.sh) was left unchanged with noop scheduler

    Version 27 (94pks27.sh):
    - Fixed for Android Q while keeping backward compatibility with prior Android versions.
    - Increased run delay to 90 seconds to stay out of magisk module or kernel apps' way.

    Version 26 (94pks26.sh):
    - Updated one minor (but hard to find), error in mount option filesystem tweaks that had been causing data connectivity issues on custom ROM's using this script or BlackenedMod.
    - SPECIAL THANKS to @sublimaze for testing iterations until we found the root cause of this issue!

    Version 25 - skipped, test versions for @sublimaze to help me figure out data connection issues.

    Version 24 (94pks24.sh):
    - Updated ext4 filesystem tweaks for even better battery life and performance
    - Small reduction of entropy pool size based on other user feedback

    Version 23 (94pks23.sh):
    - Change header to list new Magisk 18.0+ late-start boot service folder location
    - SEE ALSO OP FOR THIS LOCATION

    Version 22 (94pks22.sh):
    - Force read_ahead_kb to 1024 for faster I/O performance on all realistic file sizes

    Version 21 (94pks21.sh):
    - Increased load delay at boot back to 60s.

    Version 20 (94pks20.sh):
    - Added .sh extension to file to allow more flexibility for future tuning (now just delete .txt, but leave .sh in the file name before copying to run location)
    - Slightly increased load time at boot to 40s to ensure script runs even for users with many magisk modules
    - Reduced foreground app schedtune boost to 5% (was 10%) for battery saving when multiple apps are open with no perceived detriment to performance or app switching
    - Increase dirty_expire and dirty_writeback timings for less overhead, reduced battery, and improved performance with no ill effects noted
    - Reverted GPU min clock increase due to my testing finding the speed benefit was not noticeable but battery life was negatively affected

    Version 19 (94pks19):
    - Reduced load time at boot (enabled by re-ordering of script) to 30s
    - tcp_ecn set to 1 for across-the-board network speed enhancement when handshake allows
    - reduced txqueuelen to 128 for network speed enhancement on 4g/wifi (less bufferbloat)
    - added wakelock blocker courtesy of @xFirefly93, but only for blocking wakelocks I have actually seen in BBS for Pixel 2 / XL.

    Version 18 (94pks18):
    - Increase cpu governor up-rate-time; VERY significant battery help with no performance degradation noticed.
    - Reduce vm dirty ratio and dirty expires slightly to reduce potential (although unlikely) excess caching and latency from memory write-out.
    - Slight code re-ordering for potential quicker boot delay in the future

    Version 17 (94pks17):
    - Schedtune code cleanup
    - GPU min frequency set to 342 (performance boost with no adverse battery drain per @xFirefly93 testing)
    - Increase cpu governor down rate limit by 25% for better performance with minimal battery life impact.

    Version 16 (94pks16):
    - Revert dir-notify-disable
    - Fix a minor dirty-expire vm derp I made many, many releases ago
    - Adjust dev/stune/schedtune parameters to ensure users won't have frequency scaling issues on any kernel, allowing cpu's to actually settle and sleep. This wasn't likely before, but is now virtually impossible, while performance improvement during app switching is still present!

    Version 15 (94pks15):
    - Fs dir-notify disable.
    - Schedtune parameter tweaks for performance increase.
    Credit: Both of the above were initiated by @xFirefly93, I only slightly modified the Schedtune parameters.

    Version 14 (94pks14):
    - Revert disabling service_locator, otg_wakelock, and debug kernel modules - no real battery save noted in testing; and I had some issues with apps hanging that required location services that were resolved by getting rid of this code.
    - Change rq_affinity from 2 to 1 - I verified with I/O benchmark testing that this provides a slight increase in I/O performance, especially reads and sqlite operations. No battery life impact noted during days of testing.

    Version 13 (94pks13): Internal test build - not released (probably would have been unlucky anyway ;))

    Version 12 (94pks12):
    - Turn off iostats - by popular request (slight battery save)
    - Increase vm stat_interval to 60 - Thx to xFirefly93 (slight battery save)
    - Disable service_locator, otg_wakelock, and debug kernel modules - Thx to xFirefly93 (slight battery save)

    Version 11 (94pks11):
    - Delay script start by 30 seconds for users with multiple late-start scripts or other Magisk modules
    - Increase timer for vm dirty writeback (saves battery from less wake-ups, cache integrity still reasonably protected by low dirty background ratio)
    - Slight kernel entropy increase

    Version 10 (94pks10):
    - Increase min_free_kbytes - better performance based on testing
    - Reduce entropy read_wakeup_threshold - to prevent blocking apps or commands if entropy drops
    - Thrift ipv4 / network settings that were ineffectual - cleanup with better or same performance based on testing
    - Reduce scheduler nr_requests - less overhead, subjective latency reduction
    - Revert to default read_ahead_kb - better performance based on testing

    Version 9 (94pks9):
    - Slight change-up on kernel entropy settings to keep pool about half-full.
    - tcp_max_syn_backlog and tcp_ecn parameters added (thanks @Juzman for getting me to look at these!) that seem to help network throughput slightly - they certainly don't hurt.
    - Added fstrim for data, cache, and system partitions at end of script - because why not do this on every boot?

    Version 8 (94pks8):
    New file location noted in header: /sbin/.core/img/.core/service.d
    - Need to place script in this directory for Magisk 16.3 onward
    - Backward compatible for previous versions back to 14.5
    Script now executes 70% faster after boot
    - Only sleeps for 30 seconds; verified to still run through Magisk late start service
    Added file system optimizations for /system partition
    Adjusted min_free_kbytes to 7 GB from 7.5
    - Should slightly raise available RAM for each node, no oom increase or other ill-effects verified through dmesg / kmesg logs
    Reverted vm.vfs_cache_pressure to 20
    - Less subjective latency based on testing
    Script success / fail write-out file now time stamped for users local time rather than UTC/GMT

    Version 7 (94pks7):
    - Removed LMK (yay!) based on multiple requests, advice from @Scott, and my verifying that nothing I tried improved over stock.
    - Added back in some block-level scheduler queue tweaks that are not consistent (and not optimized) on all blocks in the stock configuration as I thought they were
    - Cleaned up and re-organized the code - inspiration from @Juzman
    - Re-evaluated vm settings @Scott) and network tweaks @Juzman); I don't believe this resulted in any changes (except I'm trialing cache_pressure at 60 vice 20), but thanks for their advice, research, testing, and participation (which is also now credited in the script).

    Version 6 (94pks6):
    - Added feature: script now writes out a file "pks_script_result" to the /storage/emulated/0 (root of internal storage) directory when executed.
    - If the file is present after attempting to run (or after a reboot if you have it in su.d, init.d, or service.d folders) then this indicates the script executed.
    - If when you open the file in a text viewer it has a time/date stamp and the phrase "94pks6 successfully executed!", then it ran without errors.
    - If when you open the file it says instead "94pks failed." then it threw some error code upon execution... but it was probably minor enough that the changes were applied (or the file wouldn't have been written ;)).

    All the above is at least in theory. It seems to be working that way on my device. Thanks to @Scott for the suggestion!

    Version 5 (94pks5):
    - Lowered last lmk slot (empty apps) much further - no appreciable loss of available RAM during my testing, less redraws in chrome tabs and reloading of recent apps.

    Version 4 (94pks4):
    - Fixed aggressive Lowmemorykiller / memory over-commit interaction issue (only last LMK slot now much more aggressive than stock, vm.overcommit_memory reverted to "1" (stock). The interaction with previous settings could cause an issue where no additional apps could be opened (they were immediately killed).
    - Very minor tweaks to some vm caching parameters

    Version 3 (94pks3):
    Corrected swap off command to not throw error flag on execution
    Altered tx_queue_len replacement command to skip non-linked file and not flag error on execution
    Thanks @Lessaj and @veetoe for helping

    Version 2 (94pks2):
    1). Increased LMK levels
    ---- I tested for weeks, we have gobs of RAM, it should really only affect empty apps
    2). Turned off swap and de-allocated zram space
    ---- With 4GB of RAM, do we need zram? I don't think so. I found benchmarks and day-to-day performance to be slightly better without it, plus this is further enabled by increased LMK levels (in theory).
    3). Reduced the vm dirty expire / writeback by a factor of 10 (still far more aggressive than stock)
    ---- No real effect here, just walking back to stock since I see no real effect with these parameters on Pixel 2.
    4). Enabled Schedutil governor IO_wait_boost flag for both little and big clusters.
    ---- Should boost performance / reduce latency during high I/O events, found it to marginally increase some benchmarks and subjective performance feel without affecting battery (YMMV).
    11
    New Version!

    Updated!

    94pks17 is released with further performance increases.

    File in OP, change log in 2nd post.

    Enjoy!
    10
    Notes on Compatibility

    Since some have asked in this thread, via PM, or in @xFirefly93's thread, here are some notes on kernel and script compatibility:

    1. The PK script is the same for all Pixel 2 / Pixel 2 XL kernels. I do not turn knobs that are specific to any given kernel. It works on all of them!

    2. The PK script is slightly more performance oriented than xFirefly93's, but we do share some things - he's taken some things from me that help one aspect without harming the other, and I have done the same from his excellent work.

    3. The PK script and xFirefly93's are compatible! Due to the way they are named, if you place both scripts in service.d, his will run first, then mine will. This actually works quite well because you get all of the kernel module, GPU, and wakelock stuff he has done mostly for battery saving, and then you get a slightly more performance-oriented tune from my script for the things the two scripts have in common or that I have added.

    Note also that I have no immediate plans to disable all the kernel modules and wakelocks that xFirefly93 has, so running both of our scripts in conjunction will be the only way to take advantage of both of our efforts should you desire to do so.
    9
    New Version!

    Updated!

    94pks18 is released with a substantial battery life improvement with no perceptible performance hit.

    File in OP, change log in 2nd post.

    Enjoy!

    P.S. Stay tuned... I'm planning to ask some users to do some beta testing on an item or two in the near future!