TEARING WHEN PLAYBACK VIDEO OR SCROLLING WEBPAGE (Intel Graphics)

Create file
/usr/share/X11/xorg.conf.d/20-intel.conf

or

/etc/X11/xorg.conf.d/20-intel.conf

Check folder first whether which one existed for *buntu mostly /usr/share/X11/xorg.conf.d/

Section "Device"
	Identifier "Intel Graphics"
	Driver "Intel"
		Option "AccelMethod" "sna"
		Option "TearFree" "true"
		Option "DRI" "3"
		Option "TripleBuffer" "true"
		Option "MigrationHeuristic" "greedy"
		Option "Tiling" "true"
EndSection

or

Section "Device"
	Identifier "Intel Graphics"
	Driver "Intel"
		Option "AccelMethod" "uxa"
		Option "DRI" "2"
		Option "TripleBuffer" "true"
		Option "MigrationHeuristic" "greedy"
		Option "Tiling" "true"
EndSection

for Skylake

Section "Device"
	Identifier "Intel Graphics"
	Driver "intel"
		Option "DRI" "false"
EndSection

 

Note

  1. SNA acceleration is default, change to UXA only you encounter pixelated graphics, corrupt text, etc.
  2. “TearFree” doesn’t work with UXA acceleration
  3. by default DRI is 3 change to 2 if you’re using virtual desktops and switching between desktops cause artifacts


References

https://wiki.archlinux.org/index.php/intel_graphics

https://www.x.org/archive/X11R7.5/doc/man/man4/intel.4.html

 

Force KODI to use ALSA

Force load PulseAudio and ALSA at the same time. Buggy, if you set Kodi Audio output to same device as default desktop audio output. In my case, work like charm as my default desktop audio route to HDMI while Kodi using another device.

create file /usr/share/applications/kodi-alsa.desktop and paste this into the file

 

[Desktop Entry]
Version=1.0
Name=Kodi-ALSA
GenericName=Media Center
Comment=Forced Kodi to run on ALSA instead of PulseAudio
Exec=/usr/share/applications/kodi-alsa.sh
TryExec=/usr/share/applications/kodi-alsa.sh
Icon=kodi
Terminal=false
Type=Application
Categories=AudioVideo;Video;Player;TV;

Actions=Fullscreen;Standalone;

Path=
StartupNotify=false

Create file /usr/share/applications/kodi-alsa.sh and paste this into file

#! /bin/bash

# this makes kodi start with ALSA instead of FUCKING pulse audio

# disable pulse audio
pasuspender

# start kodi with ALSA
AE_SINK=ALSA kodi

Set permission so kodi-alsa.sh could be executed.

credit : https://gist.github.com/bmaeser/1918514429e4855d5188

Config PulseAudio

To disable PulseAudio (affect every user)

in /etc/pulse/client.conf

change this line from

; autospawn = yes

to

autospawn = no

To set sample format, check sample spec first by

pacmd list-sinks

Screenshot at 2017-03-02 22:39:29.png

in /etc/pulse/daemon.conf

resample-method = speex-float-5

default-sample-format = float32ne
default-sample-rate = 88200
alternate-sample-rate = 96000
default-sample-channels = 2
default-channel-map = front-left,front-right

Credit:http://kodi.wiki/view/PulseAudio

SSD & Ram Drive Tweak

As my PC has 16GB ram and SSD. I decided to tweak it like this.

In /etc/fstab, for SSD drive I replace “errors=remount-ro” with “errors=remount-ro,noatime,nodiratime,commit=60”

and add these lines to move system tmp and log to Ramdrive

#Create Ram Disk for cache
tmpfs	/var/log	tmpfs	defaults,noatime,nodiratime,size=10M	0	0
tmpfs	/tmp	tmpfs	defaults,noatime,nodiratime,mode=1777,size=50%	0	0

In /etc/rc.local add these lines before exit 0 to create “.cache” folder in /tmp (Ramdrive) and bind its to folder “.cache” of current user. Therefore, all apps caches are moved to Ramdrive. Both Chrome and Firefox are included. Don’t forget to change my_username to your username

for u in my_username my_username1 my_username2; do

	RamDIR0=/tmp/$u/.cache
	HDDDIR0=/home/$u/.cache

	RamDIR1=/tmp/$u/.thumbnails
	HDDDIR1=/home/$u/.thumbnails

	sudo -u $u -- sh -c "mkdir -p $RamDIR0 && mkdir -p $RamDIR1 && chmod -R 700 /tmp/$u"
	mount --bind $RamDIR0 $HDDDIR0
	mount --bind $RamDIR1 $HDDDIR1

done

TCP Tweak

In file /etc/sysctl.conf

# tweak - start
net.core.wmem_max=33554432
net.core.rmem_max=33554432
net.ipv4.tcp_rmem= 10240 87380 33554432
net.ipv4.tcp_wmem= 10240 87380 33554432
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_sack = 1
net.ipv4.tcp_no_metrics_save = 1
net.core.netdev_max_backlog = 5000
# tweak - end

credit: https://www.cyberciti.biz/faq/linux-tcp-tuning/

In file /etc/rc.local

ip link set mtu 7000 dev enp4s0

Set MTU size by add this line

ip link set mtu [supported MTU] dev [NIC]

Check MTU size that your NIC supported first.

sudo ifconfig [NIC] mtu [MTU]

Fix slow network file transfer

If you’re using Linux with Windows file server on Gigabit Network, Samba max bandwidth is about 20-30MB/s. You have to install NFS and using it instead of Samba. I couldn’t find the way to make Samba able to read file from Windows share at 100+MB/s. If you could, your guide would be appreciated.

/etc/samba/smb.conf

Increase send and receive buffers size by add this line

[global]

# FORCE THE DISK SYSTEM TO ALLOCATE REAL STORAGE BLOCKS WHEN
# A FILE IS CREATED OR EXTENDED TO BE A GIVEN SIZE.
# THIS IS ONLY A GOOD OPTION FOR FILE SYSTEMS THAT SUPPORT
# UNWRITTEN EXTENTS LIKE XFS, EXT4, BTRFS, OCS2.
# IF YOU USE A FILE SYSTEM THAT DOES NOT SUPPORT UNWRITTEN
# EXTENTS, SET "strict allocate = no".
# NOTE: MAY WASTE DRIVE SPACE EVEN ON SUPPORTED FILE SYSTEMS
# SEE: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=798532

   strict allocate = Yes

# THIS IS TO COUNTERACT SPACE WASTAGE THAT CAN BE 
# CAUSED BY THE PREVIOUS OPTION 
# SEE: https://lists.samba.org/archive/samba-technical/2014-July/101304.html

   allocation roundup size = 4096

# ALLOW READS OF 65535 BYTES IN ONE PACKET.
# THIS TYPICALLY PROVIDES A MAJOR PERFORMANCE BENEFIT.

   read raw = Yes

# SUPPORT RAW WRITE SMBs WHEN TRANSFERRING DATA FROM CLIENTS.

   write raw = Yes

# WHEN "strict locking = no", THE SERVER PERFORMS FILE LOCK
# CHECKS ONLY WHEN THE CLIENT EXPLICITLY ASKS FOR THEM.
# WELL-BEHAVED CLIENTS ALWAYS ASK FOR LOCK CHECKS WHEN IT IS
# IMPORTANT, SO IN THE VAST MAJORITY OF CASES,
# "strict locking = auto" OR "strict locking = no" IS ACCEPTABLE.

   strict locking = No

# TCP_NODELAY:
#    SEND AS MANY PACKETS AS NECESSARY TO KEEP DELAY LOW
# IPTOS_LOWDELAY:
#    [Linux IPv4 Tweak] MINIMIZE DELAYS FOR INTERACTIVE TRAFFIC
# SO_RCVBUF:
#    ENLARGE SYSTEM SOCKET RECEIVE BUFFER
# SO_SNDBUF:
#    ENLARGE SYSTEM SOCKET SEND BUFFER

   socket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=131072 SO_SNDBUF=131072

# SMBWriteX CALLS GREATER THAN "min receivefile size" WILL BE
# PASSED DIRECTLY TO KERNEL recvfile/splice SYSTEM CALL.
# TO ENABLE POSIX LARGE WRITE SUPPORT (SMB/CIFS WRITES UP TO 16MB),
# THIS OPTION MUST BE NONZERO.
# THIS OPTION WILL HAVE NO EFFECT IF SET ON A SMB SIGNED CONNECTION.
# MAX VALUE = 128k

   min receivefile size = 16384

# USE THE MORE EFFICIENT sendfile() SYSTEM CALL FOR EXCLUSIVELY
# OPLOCKED FILES.
# NOTE: ONLY FOR CLIENTS HIGHER THAN WINDOWS 98/Me

   use sendfile = Yes

# READ FROM FILE ASYNCHRONOUSLY WHEN SIZE OF REQUEST IS BIGGER
# THAN THIS VALUE.
# NOTE: SAMBA MUST BE BUILT WITH ASYNCHRONOUS I/O SUPPORT

   aio read size = 16384

# WRITE TO FILE ASYNCHRONOUSLY WHEN SIZE OF REQUEST IS BIGGER
# THAN THIS VALUE
# NOTE: SAMBA MUST BE BUILT WITH ASYNCHRONOUS I/O SUPPORT

   aio write size = 16384

credit: https://eggplant.pro/blog/faster-samba-smb-cifs-share-performance/

However, in this line

socket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=131072 SO_SNDBUF=131072

Should change to

socket options = TCP_NODELAY IPTOS_LOWDELAY

In order to let Samba handle buffer size automatically. Should do TCP cache Tweak instead.

Installing Low latency kernel and DeaDBeef

As for HTPC I’m choosing Mint 18.1 XFCE. Mint coming with VLC so I don’t need to install it.

What I’m done were

1. Installing DeaDBeef as Music Player

sudo add-apt-repository ppa:starws-box/deadbeef-player

sudo apt-get update

sudo apt-get install deadbeef

2. Installing low latency kernel

You could check kernel version and type by this command

uname -a

If It’s low latency or real time kernel, you don’t need to install low-latency kernel

To install low latency kernel, use this command

sudo apt-get install linux-lowlatency

If you experience buggy or strange behavior after install low latency kernel, you should remove the kernel by this command.

sudo apt-get remove linux-lowlatency

Screenshot_2017-02-21_01-03-11.png