created_date: 2020-01-02T11:29:24+08:00

update_date: 2020-05-07T08:17:10+08:00

comment_url: https://github.com/ferstar/blog/issues/11

1. 关闭错误报告

可以选择直接卸载apport这个软件包, 但最好还是改配置

# 看说明
sudo vi /etc/default/apport

贴个图

DeepinScreenshot_select-area_20200102193713

2.关于根分区文件系统的选择

ext4老当益壮,选他没错

btrfs真香, subvolume很赞!

拿了个64GB的U盘(因为我想搞个Ubuntu2GO的东东)跑了下分:

跑分代码如下,哪抄的忘了,就是随机建大量小文件,然后再写&读,看耗时多少

#!/usr/bin/python
# -*- coding: utf-8 -*-

filecount = 30000
filesize = 1024


import random, time
from os import system
flush = "sudo su -c 'sync ; echo 3 > /proc/sys/vm/drop_caches'"

randfile = open("/dev/urandom", "r")

print "\ncreate test folder:"
starttime = time.time()
system("rm -rf test && mkdir test")
print time.time() - starttime
system(flush)

print "\ncreate files:"
starttime = time.time()
for i in xrange(filecount):
    rand = randfile.read(int(filesize * 0.5 + filesize * random.random()))
    outfile = open("test/" + unicode(i), "w")
    outfile.write(rand)
print time.time() - starttime
system(flush)

print "\nrewrite files:"
starttime = time.time()
for i in xrange(int(filecount / 10)):
    rand = randfile.read(int(filesize * 0.5 + filesize * random.random()))
    outfile = open("test/" + unicode(int(random.random() * filecount)), "w")
    outfile.write(rand)
print time.time() - starttime
system(flush)

print "\nread linear:"
starttime = time.time()
for i in xrange(int(filecount / 10)):
    infile = open("test/" + unicode(i), "r")
    outfile.write(infile.read());
print time.time() - starttime
system(flush)

print "\nread random:"
starttime = time.time()
outfile = open("/dev/null", "w")
for i in xrange(int(filecount / 10)):
    infile = open("test/" + unicode(int(random.random() * filecount)), "r")
    outfile.write(infile.read());
print time.time() - starttime
system(flush)

print "\ndelete all files:"
starttime = time.time()
system("rm -rf test")
print time.time() - starttime
system(flush)

U盘被我格成这样:

# sudo gdisk -l /dev/sda
Disk /dev/sda: 124822487 sectors, 59.5 GiB
Model: ROS2GO          
Sector size (logical/physical): 512/512 bytes
Disk identifier (GUID): B3D0C73A-433D-44C1-8F80-FA90167AAADC
Partition table holds up to 128 entries
Main partition table begins at sector 2 and ends at sector 33
First usable sector is 34, last usable sector is 124822453
Partitions will be aligned on 2048-sector boundaries
Total free space is 1942420 sectors (948.4 MiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048        20482047   9.8 GiB     8300  ext4
   2        20482048        40962047   9.8 GiB     8300  btrfs
   3        40962048        61442047   9.8 GiB     8300  f2fs
   4        61442048        81922047   9.8 GiB     8300  xfs
   5        81922048       102402047   9.8 GiB     8300  reiserfs

各分区挂载参数均是Ubuntu系统默认参数

f2fs (rw,nosuid,nodev,relatime,lazytime,background_gc=on,discard,no_heap,user_xattr,inline_xattr,acl,inline_data,inline_dentry,flush_merge,extent_cache,mode=adaptive,active_logs=6,alloc_mode=reuse,fsync_mode=posix,uhelper=udisks2)
btrfs (rw,nosuid,nodev,relatime,space_cache,subvolid=5,subvol=/,uhelper=udisks2)
ext4 (rw,nosuid,nodev,relatime,uhelper=udisks2)
xfs (rw,nosuid,nodev,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota,uhelper=udisks2)
reiserfs (rw,nosuid,nodev,relatime,uhelper=udisks2)

测试机系统:

DeepinScreenshot_select-area_20200110101815

内核版本:

Linux xiaoxinpro 5.3.0-24-generic #26-Ubuntu SMP Thu Nov 14 01:33:18 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

跑分结果:

create filesrewrite filesread linearread randomdelete all files
ext40.5933940413.6460258960.9608368872.2868559360.646140814
btrfs5.7079169752.01583910.4468250272.0395538812.933115005
f2fs0.7372770312.2162010670.8415830142.21618604717.70262408
xfs0.7814130785.9080522061.2127680783.1982340814.744434118
reiserfs1.7357139591.8663630490.234380961.5599799162.575639963

bench

对于系统性能影响最大的应该是随机读写,这么看来还是reiserfs牛逼,几乎全面领先,可惜这货作者杀老婆,进局子了,但并不妨碍我用脚投票,reiserfs做根分区文件系统,然并卵,Ubuntu用这货做根分区丢资料,放弃。剩下的,ext4还是老当益壮,btrfs也可以,xfs则并没有如网传那样犀利,f2fs删除文件居然那么慢。

3. TLP - Linux电源优化利器

via: https://linrunner.de/en/tlp/docs/tlp-linux-advanced-power-management.html

有人说跟powertop搭配可能效果更好,然而我不觉得,这两货一起用卡的要死,所以只留一个就好

btrfs 文件系统的话, 需要改个东西

# AHCI link power management (ALPM) for disk devices:
#   min_power, med_power_with_dipm(*), medium_power, max_performance.
# (*) Kernel >= 4.15 required, then recommended.
# Multiple values separated with spaces are tried sequentially until success.
# Default:
#  - "med_power_with_dipm max_performance" (AC)
#  - "med_power_with_dipm min_power" (BAT)

SATA_LINKPWR_ON_AC="med_power_with_dipm max_performance"
SATA_LINKPWR_ON_BAT="med_power_with_dipm max_performance"

4. 要不要swap分区

我倾向于不要,万一想要swap了完全可以用swapfile的形式随用随开

Archlinux Wiki的文档真是优秀

摘抄几个命令

Swap file creation

For copy-on-write file systems like Btrfs, first create a zero length file, set the No_COW attribute on it with chattr, and make sure compression is disabled:

# truncate -s 0 /swapfile
# chattr +C /swapfile
# btrfs property set /swapfile compression none

See Btrfs#Swap file for more information.

Use fallocate to create a swap file the size of your choosing (M = Mebibytes, G = Gibibytes). For example, creating a 512 MiB swap file:

# fallocate -l 512M /swapfile

Note: fallocate may cause problems with some file systems such as F2FS.[1] As an alternative, using dd is more reliable, but slower:

# dd if=/dev/zero of=/swapfile bs=1M count=512 status=progress

Set the right permissions (a world-readable swap file is a huge local vulnerability):

# chmod 600 /swapfile

After creating the correctly sized file, format it to swap:

# mkswap /swapfile

Activate the swap file:

# swapon /swapfile

Finally, edit the fstab configuration to add an entry for the swap file:

/etc/fstab
/swapfile none swap defaults 0 0

For additional information, see fstab#Usage.

Note: The swap file must be specified by its location on the file system not by its UUID or LABEL.

Remove swap file

To remove a swap file, it must be turned off first and then can be removed:

# swapoff /swapfile
# rm -f /swapfile

关于性能也抄几句,我给vm.swappiness配了1

Performance

Swap operations are usually significantly slower than directly accessing data in RAM. Disabling swap entirely to improve performance can sometimes lead to a degradation, since it decreases the memory available for VFS caches, causing more frequent and costly disk I/O.

Swap values can be adjusted to help performance:

Swappiness

The swappiness sysctl parameter represents the kernel’s preference (or avoidance) of swap space. Swappiness can have a value between 0 and 100, the default value is 60. A low value causes the kernel to avoid swapping, a higher value causes the kernel to try to use swap space. Using a low value on sufficient memory is known to improve responsiveness on many systems.

To check the current swappiness value:

$ sysctl vm.swappiness

Alternatively, the files /sys/fs/cgroup/memory/memory.swappiness or /proc/sys/vm/swappiness can be read in order to obtain the raw integer value.

Note: As /proc is a lot less organized and is kept only for compatibility purposes, you are encouraged to use /sys instead.

To temporarily set the swappiness value:

# sysctl -w vm.swappiness=10

To set the swappiness value permanently, create a sysctl.d(5) configuration file. For example:

/etc/sysctl.d/99-swappiness.conf
vm.swappiness=10

To test and more on why this may work, take a look at this article.

5. 常用软件

  • Google Chrome/Chromium

支持的一些启动参数如下所示,我一般用的是--disk-cache-dir=/tmp/chrome_cache --process-per-site,即缓存扔到/tmp分区,每个站点使用一个进程

对于Chromium,可以在/etc/chromium-browser/default添加自己想要的配置参数,而对于Google Chrome,貌似只能从这里/usr/share/applications/chromium-browser.desktop

--user-data-dir="[PATH]"  自定义用户数据目录
--start-maximized                启动就最大化
--no-sandbox                         取消沙盒模式
--single-process                    单进程运行
--process-per-tab                 每个标签使用单独进程
--process-per-site                每个站点使用单独进程
--in-process-plugins            插件不启用单独进程
--disable-popup-blocking 禁用弹出拦截
--disable-javascript             禁用JavaScript
--disable-java                         禁用Java
--disable-plugins                   禁用插件
--disable-images                   禁用图像
-incognito                               启动进入隐身模式
--enable-udd-profiles        启用账户切换菜单
--proxy-pac-url                   使用pac代理 [via 1/2]
--lang=zh-CN                        设置语言为简体中文
--disk-cache-dir="[PATH]" 自定义缓存目录
--disk-cache-size=              自定义缓存最大值(单位byte)
--media-cache-size=         自定义多媒体缓存最大值(单位byte)
--bookmark-menu              在工具栏增加一个书签按钮
--enable-sync                       启用书签同步
  • Foxit Reader

安装方法见:https://websiteforstudents.com/how-to-install-foxit-reader-on-ubuntu-16-04-17-10-18-04-desktop/

  • Barrier 在Linux和其他设备之间共享键盘和鼠标

我是从snap安装的,挺方便,务必带好梯子

https://snapcraft.io/barrier

  • FlameShot - 火焰截图

  • DeepinTerminal - 深度终端

  • CopyQ - 剪贴板增强

  • Qv2ray - 梯子客户端

  • Typora - MarkDown编辑器