如何加快ubuntu16.04的启动速度和打开软件应用的速度

启动讨论 grub/grub2/syslinux/grub4dos/Lilo
头像
Archer123
帖子: 146
注册时间: 2008-05-18 10:16

如何加快ubuntu16.04的启动速度和打开软件应用的速度

#1

帖子 Archer123 » 2016-10-12 9:03

目前我有两大问题:
ubuntu16.04
我的机器配置并不低,i7 cpu 16GB 内存 虽然ubuntu是装在了sda上不是固态上.但是
1 启动速度太慢了 我计算了下要1分30秒到2分之间.启动期间明显看到硬盘灯狂闪
2 进入系统后,首次打开软件应用也是十分慢 开个firefox也要30秒.但是唯一好处是,启动后的使用速度都是非常快的.就是首次打开应用太慢,同样硬盘也狂闪.

参考网上的一些做法已经做了如下优化.

sudo gedit /etc/sysctl.conf

#当值为0时最大限度的使用物理内存,物理内存使用完后再使用swap内存。为100时,最大限度的使用swap.默认的参数是60,根据这里将其改为10较优


vm.swappiness=10

===================================================================


1.打开/etc/security/limits.conf,里面有很详细的注释,找到如下设置(如果没有就插入)

#最大文件打开数限制

* soft nofile 51200

* hard nofile 51200

#最大进程打开数限制

* soft noproc 11000

* hard noproc 11000

2.编辑/etc/pam.d/common-session,加入一行

session required pam_limits.so

3.编辑/etc/profile,加入

ulimit -SHn 51200 -S 软限制 -H硬限制 -n 可打开最大文件数

重启服务器,再次登陆,查看句柄数,已经正确设置为51200。

================================================================
实际只需第三步16.04就生效的,我最后只是改了软限制 ulimit -Sn 32768
编辑/etc/profile,加入ulimit -Sn 32768

调整最大文件打开数soft限制 32768后

cmd@TR:~$ ulimit -n

32768

cmd@TR:~$ ulimit -a

core file size (blocks, -c) 0

data seg size (kbytes, -d) unlimited

scheduling priority (-e) 0

file size (blocks, -f) unlimited

pending signals (-i) 63711

max locked memory (kbytes, -l) 64

max memory size (kbytes, -m) unlimited

open files (-n) 32768

pipe size (512 bytes, -p) 8

POSIX message queues (bytes, -q) 819200

real-time priority (-r) 0

stack size (kbytes, -s) 8192

cpu time (seconds, -t) unlimited

max user processes (-u) 63711

virtual memory (kbytes, -v) unlimited

file locks (-x) unlimited

cmd@TR:~$ ulimit -Ha

core file size (blocks, -c) unlimited

data seg size (kbytes, -d) unlimited

scheduling priority (-e) 0

file size (blocks, -f) unlimited

pending signals (-i) 63711

max locked memory (kbytes, -l) 64

max memory size (kbytes, -m) unlimited

open files (-n) 65536

pipe size (512 bytes, -p) 8

POSIX message queues (bytes, -q) 819200

real-time priority (-r) 0

stack size (kbytes, -s) unlimited

cpu time (seconds, -t) unlimited

max user processes (-u) 63711

virtual memory (kbytes, -v) unlimited

file locks (-x) unlimited



剩下的是一些检查ulimit限制

cmd@TR:~$ cat /proc/sys/kernel/pid_max

32768

cmd@TR:~$ ulimit -s

8192

cmd@TR:~$ cat /proc/sys/fs/file-max

1627130

cmd@TR:~$ cat /proc/sys/fs/nr_open

1048576

cmd@TR:~$ ulimit -Hn

65536

cmd@TR:~$ ulimit -n

32768

===========================================

http://www.jianshu.com/p/11491ee15344



cmd@TR:~$ systemd-analyze blame

16.961s teamviewerd.sysv.service

16.841s docker.service

8.795s NetworkManager-wait-online.service

6.771s dev-sda3.device

6.469s ModemManager.service

6.045s grub-common.service

4.697s irqbalance.service

4.447s networking.service

4.206s NetworkManager.service

3.953s sysfsutils.service

3.929s accounts-daemon.service

3.785s apport.service

3.482s systemd-logind.service

3.399s cgroupfs-mount.service

3.399s iio-sensor-proxy.service

3.398s gpu-manager.service

3.398s vboxdrv.service

3.394s lm-sensors.service

3.390s rsyslog.service

3.267s lightdm.service

3.231s bluetooth.service

3.222s thermald.service

3.187s snapd.firstboot.service

3.021s apparmor.service

2.387s wpa_supplicant.service

2.370s systemd-tmpfiles-setup.service

2.166s media-DataE.mount

1.964s media-DataD.mount

1.850s systemd-udevd.service

1.780s systemd-fsck@dev-disk-by\x2duuid-f25c448f\x2d3c9e\x2d4723\x2db1b4\x2d00b9d91ece04.service

1.629s polkitd.service

1.585s systemd-rfkill.service

1.488s systemd-tmpfiles-setup-dev.service

1.387s keyboard-setup.service

1.170s binfmt-support.service

然后用rcconf 关掉了头两个的自启动

===========================================================

多核启动
默认情况下,即便你的电脑是双核甚至多核的CPU,LinuxMint/Ubuntu启动时仍旧是以单核在执行系统启动任务。可以通过如下修改,使其充分利用多核CPU进行系统启动,从而加快速度。
以管理员身份编辑:
sudo gedit /etc/init.d/rc
找到CONCURRENCY=none行,并修改为CONCURRENCY=makefile



下边是从/etc/init.d/rc 粘贴出来的 检查了insserv是安装了的


#

# Check if we are able to use make like booting. It require the

# insserv package to be enabled. Boot concurrency also requires

# startpar to be installed.

#

#CONCURRENCY=makefile

# disable startpar, incompatible with "task" upstart jobs



cmd@TR:~$ sudo apt-get install insserv

[sudo] cmd 的密码:

正在读取软件包列表... 完成

正在分析软件包的依赖关系树

正在读取状态信息... 完成

insserv 已经是最新版 (1.14.0-5ubuntu3)。

升级了 0 个软件包,新安装了 0 个软件包,要卸载 0 个软件包,有 1 个软件包未被升级。

cmd@TR:~$ sudo apt-get install startpar

正在读取软件包列表... 完成

正在分析软件包的依赖关系树

正在读取状态信息... 完成

没有可用的软件包 startpar,但是它被其它的软件包引用了。

这可能意味着这个缺失的软件包可能已被废弃,

或者只能在其他发布源中找到

E: 软件包 startpar 没有可安装候选

但这个startpar 是这样

有谁了解16.04的 这块 多核启动要如何配置?


谁还有加速应用启动速度的方法?
头像
vickycq
帖子: 4507
注册时间: 2011-03-20 13:12
系统: Debian
来自: 山东省寿光县
联系:

Re: 如何加快ubuntu16.04的启动速度和打开软件应用的速度

#2

帖子 vickycq » 2016-10-12 10:50

Archer123 写了:ubuntu16.04 ubuntu是装在了sda上不是固态
找到CONCURRENCY=none行,并修改为CONCURRENCY=makefile
systemd 默认即为并行启动。是否利用多核心处理器或关系不大,猜测最大瓶颈在于磁盘性能。
Archer123 写了:E: 软件包 startpar 没有可安装候选
startpar 用于 sysvinit。Ubuntu 6.10 引入 upstart,15.04 引入 systemd
故猜测对于 Ubuntu 此方法已过期十年了
Debian 中文论坛 - forums.debiancn.org
欢迎所有 Debian GNU/Linux 用户
头像
Archer123
帖子: 146
注册时间: 2008-05-18 10:16

Re: 如何加快ubuntu16.04的启动速度和打开软件应用的速度

#3

帖子 Archer123 » 2016-10-12 12:08

vickycq 写了:
Archer123 写了:ubuntu16.04 ubuntu是装在了sda上不是固态
找到CONCURRENCY=none行,并修改为CONCURRENCY=makefile
systemd 默认即为并行启动。是否利用多核心处理器或关系不大,猜测最大瓶颈在于磁盘性能。
Archer123 写了:E: 软件包 startpar 没有可安装候选
startpar 用于 sysvinit。Ubuntu 6.10 引入 upstart,15.04 引入 systemd
故猜测对于 Ubuntu 此方法已过期十年了

我觉的也是 磁盘性能 优化sda硬盘 有什么成熟的建议吗?
头像
Archer123
帖子: 146
注册时间: 2008-05-18 10:16

Re: 如何加快ubuntu16.04的启动速度和打开软件应用的速度

#4

帖子 Archer123 » 2016-10-12 13:15

cmd@TR:~$ sudo hdparm /dev/sda

/dev/sda:
multcount = 16 (on)
IO_support = 1 (32-bit)
readonly = 0 (off)
readahead = 256 (on)
geometry = 121601/255/63, sectors = 1953525168, start = 0
cmd@TR:~$ sudo hdparm -tT /dev/sda

/dev/sda:
Timing cached reads: 20388 MB in 1.99 seconds = 10230.67 MB/sec
Timing buffered disk reads: 312 MB in 3.01 seconds = 103.50 MB/sec


指点下 怎么优化
头像
Archer123
帖子: 146
注册时间: 2008-05-18 10:16

Re: 如何加快ubuntu16.04的启动速度和打开软件应用的速度

#5

帖子 Archer123 » 2016-10-12 13:17

cmd@TR:~$ sudo hdparm /dev/sda

/dev/sda:
multcount = 16 (on)
IO_support = 1 (32-bit)
readonly = 0 (off)
readahead = 256 (on)
geometry = 121601/255/63, sectors = 1953525168, start = 0
cmd@TR:~$ sudo hdparm -tT /dev/sda

/dev/sda:
Timing cached reads: 20388 MB in 1.99 seconds = 10230.67 MB/sec
Timing buffered disk reads: 312 MB in 3.01 seconds = 103.50 MB/sec

cmd@TR:~$ sudo hdparm -i /dev/sda

/dev/sda:

Model=ST1000LM024 HN-M101MBB, FwRev=2BA30001, SerialNo=S30YJ9AF304695
Config={ Fixed }
RawCHS=16383/15/63, TrkSize=0, SectSize=0, ECCbytes=4
BuffType=unknown, BuffSize=16384kB, MaxMultSect=16, MultSect=16
(maybe): CurCHS=16383/16/63, CurSects=16514064, LBA=yes, LBAsects=1953525168
IORDY=on/off, tPIO={min:120,w/IORDY:120}, tDMA={min:120,rec:120}
PIO modes: pio0 pio1 pio2 pio3 pio4
DMA modes: mdma0 mdma1 mdma2
UDMA modes: udma0 udma1 udma2 udma3 udma4 *udma5
AdvancedPM=yes: unknown setting WriteCache=enabled
Drive conforms to: unknown: ATA/ATAPI-0,1,2,3,4,5,6,7

* signifies the current active mode


指点下 怎么优化
cao627
帖子: 992
注册时间: 2007-12-05 10:57
系统: ubuntu14.04
来自: 金山

Re: 如何加快ubuntu16.04的启动速度和打开软件应用的速度

#6

帖子 cao627 » 2016-10-12 17:21

systemd-analyze plot > aa
然后看看图片aa

我的也是sda硬盘,显示时间如下
Startup finished in 4.769s (kernel) + 13.234s (userspace) = 18.004s
科学之子
帖子: 2284
注册时间: 2013-05-26 6:58
系统: Debian 9

Re: 如何加快ubuntu16.04的启动速度和打开软件应用的速度

#7

帖子 科学之子 » 2016-10-12 17:56

传说preload可以改善楼主的情况
楼主试试?
我不确定
preload不是改善系统启动速度,而是在系统启动后自动预读用户即将访问的文件到内存中,以此加快对用户的相应速度
https://wiki.archlinux.org/index.php/Preload
头像
Archer123
帖子: 146
注册时间: 2008-05-18 10:16

Re: 如何加快ubuntu16.04的启动速度和打开软件应用的速度

#8

帖子 Archer123 » 2016-10-13 9:58

https://www.linuxbabe.com/ubuntu/4-tips ... untu-16-04

这个帖子蛮靠谱 国内的翻译过来的都有错

已经做了如下,慢慢体验下有用没用

cmd@TR:~$ sudo apt install preload

[sudo] cmd 的密码:

正在读取软件包列表... 完成

正在分析软件包的依赖关系树

正在读取状态信息... 完成

下列【新】软件包将被安装:

preload

升级了 0 个软件包,新安装了 1 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。

需要下载 36.3 kB 的归档。

解压缩后会消耗 139 kB 的额外空间。

获取:1 http://archive.ubuntu.com/ubuntu xenial/universe amd64 preload amd64 0.6.4-2 [36.3 kB]

已下载 36.3 kB,耗时 2秒 (15.5 kB/s)

正在选中未选择的软件包 preload。

(正在读取数据库 ... 系统当前共安装有 267867 个文件和目录。)

正准备解包 .../preload_0.6.4-2_amd64.deb ...

正在解包 preload (0.6.4-2) ...

正在处理用于 man-db (2.7.5-1) 的触发器 ...

正在处理用于 systemd (229-4ubuntu11) 的触发器 ...

正在处理用于 ureadahead (0.100.0-19) 的触发器 ...

ureadahead will be reprofiled on next reboot

正在设置 preload (0.6.4-2) ...

正在处理用于 systemd (229-4ubuntu11) 的触发器 ...

正在处理用于 ureadahead (0.100.0-19) 的触发器 ...

cmd@TR:~$ systemctl status preload

● preload.service - LSB: Adaptive readahead daemon

Loaded: loaded (/etc/init.d/preload; bad; vendor preset: enabled)

Active: active (running) since 四 2016-10-13 09:17:36 CST; 18s ago

Docs: man:systemd-sysv-generator(8)

CGroup: /system.slice/preload.service

└─23146 /usr/sbin/preload -s /var/lib/preload/preload.state



10月 13 09:17:36 TR systemd[1]: Starting LSB: Adaptive readahead daemon...

10月 13 09:17:36 TR preload[23140]: * Starting Adaptive readahead daemon preload

10月 13 09:17:36 TR preload[23140]: ...done.

10月 13 09:17:36 TR systemd[1]: Started LSB: Adaptive readahead daemon.



sudo systemctl start preload



这句国内的都是错的这句是对的 可以打开 启动应用程序 来关闭文章内提到的不必要的隐藏启动程序了.
sudo sed -i 's/NoDisplay=true/NoDisplay=false/g' /etc/xdg/autostart/*.desktop


cmd@TR:~$ systemd-analyze time

Startup finished in 5.503s (kernel) + 30.127s (userspace) = 35.631s


谢谢这句命令 挺有用的
systemd-analyze plot > aa
然后看看图片aa

我的目前安装完首次启动是这样的图
头像
Archer123
帖子: 146
注册时间: 2008-05-18 10:16

Re: 如何加快ubuntu16.04的启动速度和打开软件应用的速度

#9

帖子 Archer123 » 2016-10-13 11:02

谁懂preload.conf 调优啊... 已经改了一些 不知道会有毛病不
[model]

# cycle:
#
# This is the quantum of time for preload. Preload performs
# data gathering and predictions every cycle. Use an even
# number.
#
# Note: Setting this parameter too low may reduce system performance
# and stability.
#
# unit: seconds
# default: 20
#
cycle = 20

# usecorrelation:
#
# Whether correlation coefficient should be used in the prediction
# algorithm. There are arguments both for and against using it.
# Currently it's believed that using it results in more accurate
# prediction. The option may be removed in the future.
#
# default: true
usecorrelation = true

# minsize:
#
# Minimum sum of the length of maps of the process for
# preload to consider tracking the application.
#
# Note: Setting this parameter too high will make preload less
# effective, while setting it too low will make it eat
# quadratically more resources, as it tracks more processes.
#
# unit: bytes
# default: 2000000
#
minsize = 2000000

#
# The following control how much memory preload is allowed to use
# for preloading in each cycle. All values are percentages and are
# clamped to -100 to 100.
#
# The total memory preload uses for prefetching is then computed using
# the following formulae:
#
# max (0, TOTAL * memtotal + FREE * memfree) + CACHED * memcached
# where TOTAL, FREE, and CACHED are the respective values read at
# runtime from /proc/meminfo.
#

# memtotal: precentage of total memory
#
# unit: signed_integer_percent
# default: -10
#
#memtotal = -10
memtotal = 20

# memfree: precentage of free memory
#
# unit: signed_integer_percent
# default: 50
#
#memfree = 50
memfree = 20

# memcached: precentage of cached memory
#
# unit: signed_integer_percent
# default: 0
#
#memcached = 0
memcached = 0

###########################################################################

[system]

# doscan:
#
# Whether preload should monitor running processes and update its
# model state. Normally you do want that, that's all preload is
# about, but you may want to temporarily turn it off for various
# reasons like testing and only make predictions. Note that if
# scanning is off, predictions are made based on whatever processes
# have been running when preload started and the list of running
# processes is not updated at all.
#
# default: true
doscan = true

# dopredict:
#
# Whether preload should make prediction and prefetch anything off
# the disk. Quite like doscan, you normally want that, that's the
# other half of what preload is about, but you may want to temporarily
# turn it off, to only train the model for example. Note that
# this allows you to turn scan/predict or or off on the fly, by
# modifying the config file and signalling the daemon.
#
# default: true
dopredict = true

# autosave:
#
# Preload will automatically save the state to disk every
# autosave period. This is only relevant if doscan is set to true.
# Note that some janitory work on the model, like removing entries
# for files that no longer exist happen at state save time. So,
# turning off autosave completely is not advised.
#
# unit: seconds
# default: 3600
#
autosave = 3600

# mapprefix:
#
# A list of path prefixes that controll which mapped file are to
# be considered by preload and which not. The list items are
# separated by semicolons. Matching will be stopped as soon as
# the first item is matched. For each item, if item appears at
# the beginning of the path of the file, then a match occurs, and
# the file is accepted. If on the other hand, the item has a
# exclamation mark as its first character, then the rest of the
# item is considered, and if a match happens, the file is rejected.
# For example a value of !/lib/modules;/ means that every file other
# than those in /lib/modules should be accepted. In this case, the
# trailing item can be removed, since if no match occurs, the file is
# accepted. It's advised to make sure /dev is rejected, since
# preload doesn't special-handle device files internally.
#
# Note that /lib matches all of /lib, /lib64, and even /libexec if
# there was one. If one really meant /lib only, they should use
# /lib/ instead.
#
# default: (empty list, accept all)
#mapprefix = /usr/;/lib;/var/cache/;!/
mapprefix = /usr/;/lib;/var/cache/;/opt/;!/

# exeprefix:
#
# The syntax for this is exactly the same as for mapprefix. The only
# difference is that this is used to accept or reject binary exectuable
# files instead of maps.
#
# default: (empty list, accept all)
#exeprefix = !/usr/sbin/;!/usr/local/sbin/;/usr/;!/
exeprefix = !/usr/sbin/;!/usr/local/sbin/;/usr/;/opt/;!/

# maxprocs
#
# Maximum number of processes to use to do parallel readahead. If
# equal to 0, no parallel processing is done and all readahead is
# done in-process. Parallel readahead supposedly gives a better I/O
# performance as it allows the kernel to batch several I/O requests
# of nearby blocks.
#
# default: 30
processes = 30

# sortstrategy
#
# The I/O sorting strategy. Ideally this should be automatically
# decided, but it's not currently. One of:
#
# 0 -- SORT_NONE: No I/O sorting.
# Useful on Flash memory for example.
# 1 -- SORT_PATH: Sort based on file path only.
# Useful for network filesystems.
# 2 -- SORT_INODE: Sort based on inode number.
# Does less house-keeping I/O than the next option.
# 3 -- SORT_BLOCK: Sort I/O based on disk block. Most sophisticated.
# And useful for most Linux filesystems.
#
# default: 3
sortstrategy = 3
头像
Archer123
帖子: 146
注册时间: 2008-05-18 10:16

Re: 如何加快ubuntu16.04的启动速度和打开软件应用的速度

#10

帖子 Archer123 » 2016-10-13 11:49

If you want to check up on what resources Preload is using, you can monitor logfile with following commands:

sudo tail -f /var/log/preload.log

To check more information about the specific files that Preload is caching for you, run the command below:

sudo less /var/lib/preload/preload.state
头像
astolia
论坛版主
帖子: 6445
注册时间: 2008-09-18 13:11

Re: 如何加快ubuntu16.04的启动速度和打开软件应用的速度

#11

帖子 astolia » 2016-10-13 14:55

通过预加载进缓存来加快启动,ubuntu不是默认已经装了ureadahead了?如果你用的是原装内核它应该是有效的
头像
Archer123
帖子: 146
注册时间: 2008-05-18 10:16

Re: 如何加快ubuntu16.04的启动速度和打开软件应用的速度

#12

帖子 Archer123 » 2016-10-13 15:16

astolia 写了:通过预加载进缓存来加快启动,ubuntu不是默认已经装了ureadahead了?如果你用的是原装内核它应该是有效的
ureadahead 求指教 怎么配置啊 配置文件在哪啊 常用技巧啊
头像
Archer123
帖子: 146
注册时间: 2008-05-18 10:16

Re: 如何加快ubuntu16.04的启动速度和打开软件应用的速度

#13

帖子 Archer123 » 2016-10-14 8:19

可是當我更新及安裝一些程式之後,覺的有點變慢
登入速度慢了一些
我查的結果是 ureadahead的關係

ureadahead 會預先把要載入的東西弄成一個檔
在開機的時候直接載入,減少硬碟搜尋資料的時間
http://ubuntuforums.org/showthread.php?t=1434502
這是開發者的說明,還蠻詳細的

但是當系統有變更時,ureadahead似乎不會更新,不會載入真正需要的東西
使的開機速度慢了一些

這裡要跟大家分享怎樣讓 ureadahead 正確運作:

首先 ureadahead 會把要載入的東西放在 /var/lib/ureadahead 裡
我的有 pack sys.kernel.debug.pack tmp.pack 三個檔案及一個資料夾
不同人可能有不同的東西
把檔案砍掉後,下次開機 ureadahead 會重新建立檔案
再次開機後就會變得很快了



不過 ureadahead 也可以把平常常用的一些程式也順便載入
ureadahead 預設建立檔案的範圍為
ureadahead啟動後到 display manager 開始後的45秒
也就是你登入後沒多久就結束了

那我們把時間給延長一點,在這段時間所載入的東西也會被ureadahead給寫成檔案
之後開機後程式就有先預讀過了,開啟速度會很快,改法就是
1.先開起設定檔 /etc/init/ureadahead.conf
修改
kill timeout 180
180 改成 600 也就是10分鐘
pre-stop exec sleep 45
45 改成 300 也就是5分鐘
存檔
2.刪除 /var/lib/ureadahead 下的檔案
重開機
3.重開機之後你在前5分鐘所執行的程式都會被 ureadahead 紀錄起來
我開了 gimp chrome 終端機 OOo 還有一些其他程式
把一些你常用的程式都開過一次
不常用的就不用開了,不然會使得開機時載入過多的東西
要看時間到了沒的話可以看一下 /var/lib/ureadahead 裡有沒有檔案
有的話就是時間到了
然後把 /etc/init/ureadahead.conf 裡的時間改回去
重開機
4.這次重開機因為 ureadahead 要載入較多的東西,所以可能會稍微久一點
但是當你登入之後,你之前有預載過的程式,幾乎是一點就開了
不用再讀取了

就是這樣了

另外 ureadahead 這個指令有個參數 --force-trace
應該就是讓人可以重新建立要預載的東西的,不過我試不太出來怎麼用
不然用起來會方便一些


ureadahead --help
Usage: ureadahead [OPTION]... [PATH]
预读需要的文件

Options:
--daemon detach and run in the background
--force-trace ignore existing pack and force retracing
--timeout=SECONDS maximum time to trace [default: until terminated]
--dump dump the current pack file
--sort=SORT how to sort the pack file when dumping [default: open]
-q, --quiet reduce output to errors only
-v, --verbose increase output to include informational messages
--help display this help and exit
--version output version information and exit

PATH should be the location of a mounted filesystem for which files should be read. If not given, the
root filesystem is assumed.

If PATH is not given, and no readahead information exists for the root filesystem (or it is old),
tracing is performed instead to generate the information for the next boot.

Report bugs to <ubuntu-devel@lists.ubuntu.com>



cmd@TR:~$ sudo ureadahead --force-trace

开着这个命令行,再开一个命令行cmd@TR:/var/lib/ureadahead$ ls -al

如果有老的文件的话,你ctrl+c 关掉sudo ureadahead --force-trace 命令 你就会发现/var/lib/ureadahead 就会重新生成了.
上次由 Archer123 在 2016-10-14 15:23,总共编辑 1 次。
头像
Archer123
帖子: 146
注册时间: 2008-05-18 10:16

Re: 如何加快ubuntu16.04的启动速度和打开软件应用的速度

#14

帖子 Archer123 » 2016-10-14 8:57

Archer123 写了:可是當我更新及安裝一些程式之後,覺的有點變慢
登入速度慢了一些
我查的結果是 ureadahead的關係

ureadahead 會預先把要載入的東西弄成一個檔
在開機的時候直接載入,減少硬碟搜尋資料的時間
http://ubuntuforums.org/showthread.php?t=1434502
這是開發者的說明,還蠻詳細的

但是當系統有變更時,ureadahead似乎不會更新,不會載入真正需要的東西
使的開機速度慢了一些

這裡要跟大家分享怎樣讓 ureadahead 正確運作:

首先 ureadahead 會把要載入的東西放在 /var/lib/ureadahead 裡
我的有 pack sys.kernel.debug.pack tmp.pack 三個檔案及一個資料夾
不同人可能有不同的東西
把檔案砍掉後,下次開機 ureadahead 會重新建立檔案
再次開機後就會變得很快了



不過 ureadahead 也可以把平常常用的一些程式也順便載入
ureadahead 預設建立檔案的範圍為
ureadahead啟動後到 display manager 開始後的45秒
也就是你登入後沒多久就結束了

那我們把時間給延長一點,在這段時間所載入的東西也會被ureadahead給寫成檔案
之後開機後程式就有先預讀過了,開啟速度會很快,改法就是
1.先開起設定檔 /etc/init/ureadahead.conf
修改
kill timeout 180
180 改成 600 也就是10分鐘
pre-stop exec sleep 45
45 改成 300 也就是5分鐘
存檔
2.刪除 /var/lib/ureadahead 下的檔案
重開機
3.重開機之後你在前5分鐘所執行的程式都會被 ureadahead 紀錄起來
我開了 gimp chrome 終端機 OOo 還有一些其他程式
把一些你常用的程式都開過一次
不常用的就不用開了,不然會使得開機時載入過多的東西
要看時間到了沒的話可以看一下 /var/lib/ureadahead 裡有沒有檔案
有的話就是時間到了
然後把 /etc/init/ureadahead.conf 裡的時間改回去
重開機
4.這次重開機因為 ureadahead 要載入較多的東西,所以可能會稍微久一點
但是當你登入之後,你之前有預載過的程式,幾乎是一點就開了
不用再讀取了

就是這樣了

另外 ureadahead 這個指令有個參數 --force-trace
應該就是讓人可以重新建立要預載的東西的,不過我試不太出來怎麼用
不然用起來會方便一些
我删除掉了preload 尝试了这个

修改了/etc/init/ureadahead.conf 里的两个时间都为600s 10分钟 但多次反复尝试 发现实际
/var/lib/ureadahead 文件的生成时间不受这个控制 比实际的10分钟少很多 大概也就3分钟的样子
而且好像一旦unity界面加载完毕 看到整个系统界面好像就停的样子
谁知道为什么 还要咋么改?



弄完后重启 你会发现 这个 3ms ureadahead-stop.service 在启动时候就已经调用 ureadahead-stop.service 被停掉了 说明 /etc/init/ureadahead.conf 里的两个时间都为600s 10分钟 改了没起作用
sudo systemd-analyze blame
[sudo] cmd 的密码:
28.573s networking.service
9.013s NetworkManager-wait-online.service
8.180s dev-sda3.device
7.399s ModemManager.service
5.915s accounts-daemon.service
5.004s NetworkManager.service
3.290s apparmor.service
3.184s wpa_supplicant.service
3.082s systemd-logind.service
3.028s snapd.firstboot.service
2.994s teamviewerd.service
2.956s alsa-restore.service
2.951s vboxdrv.service
2.889s gpu-manager.service
2.815s polkitd.service
2.600s grub-common.service
2.456s media-DataD.mount
2.401s avahi-daemon.service
2.204s systemd-udevd.service
2.073s media-DataE.mount
2.044s systemd-tmpfiles-setup.service
2.020s lightdm.service
1.757s thermald.service
1.710s systemd-journal-flush.service
1.584s systemd-fsck@dev-disk-by\x2duuid-f25c448f\x2d3c9e\x2d4723\x2db1b4\x2d00b9d91ece04.s
1.575s plymouth-start.service
1.349s binfmt-support.service
1.230s keyboard-setup.service
1.207s apport.service
1.161s atop.service
1.154s systemd-modules-load.service
1.152s rsyslog.service
1.137s iio-sensor-proxy.service
979ms sysfsutils.service
941ms console-setup.service
928ms systemd-tmpfiles-setup-dev.service
878ms systemd-journald.service
858ms systemd-random-seed.service
844ms lm-sensors.service
687ms upower.service
658ms ondemand.service
609ms systemd-rfkill.service
567ms sysstat.service
565ms speech-dispatcher.service
536ms irqbalance.service
531ms systemd-user-sessions.service
530ms cgroupfs-mount.service
472ms udisks2.service
472ms dev-hugepages.mount
462ms dev-disk-by\x2duuid-7d9dcef9\x2d4a62\x2d478f\x2daf92\x2da5559f926b0c.swap
442ms systemd-sysctl.service
435ms systemd-backlight@backlight:intel_backlight.service
427ms pppd-dns.service
400ms colord.service
338ms sys-kernel-debug.mount
337ms dev-mqueue.mount
272ms systemd-update-utmp.service
251ms bluetooth.service
209ms systemd-remount-fs.service
202ms systemd-hostnamed.service
199ms ufw.service
197ms vboxballoonctrl-service.service
196ms vboxautostart-service.service
176ms vboxweb-service.service
164ms kmod-static-nodes.service
163ms dns-clean.service
145ms plymouth-read-write.service
141ms home.mount
130ms systemd-udev-trigger.service
122ms snapd.socket
84ms proc-sys-fs-binfmt_misc.mount
71ms resolvconf.service
49ms setvtrgb.service
48ms user@108.service
41ms docker.socket
31ms user@1000.service
11ms hddtemp.service
5ms snapd.boot-ok.service
3ms systemd-update-utmp-runlevel.service
3ms rtkit-daemon.service
3ms ureadahead-stop.service
3ms sslh.service
2ms rc-local.service
1ms plymouth-quit-wait.service
1ms sys-fs-fuse-connections.mount
上次由 Archer123 在 2016-10-14 15:27,总共编辑 1 次。
科学之子
帖子: 2284
注册时间: 2013-05-26 6:58
系统: Debian 9

Re: 如何加快ubuntu16.04的启动速度和打开软件应用的速度

#15

帖子 科学之子 » 2016-10-14 12:06

ureadahead不知是什么,貌似和preload类似甚至相同功能的东西
https://fedorahosted.org/readahead/
貌似是已经过时的东西,被systemd的组建替代了
但我这里debian 8没有找到

https://wiki.archlinux.org/index.php/e4rat
https://wiki.archlinux.org/index.php?ti ... edirect=no
https://en.wikipedia.org/wiki/Readahead
(维基百科里好像(我英文很烂)说Readahead已经被(包括systemd)废弃,理由是缺乏维护又不能达到预期效果)
找到一些参考资料,看是否有所帮助

关于preload,貌似这种东西一般默认设置就可以了
如果调优的话,可以自己仔细看看相关文档
我英文水平太烂,就懒得看了... :em03
回复