linux 下开启 trim 功能

对于 ssd 硬盘,假如长期使用, 并且已经用光磁盘 free lists 中的空间,  都会严重影响磁盘写能力 (就算磁盘空间空闲率为 90%) ,  

  注,

   但实际上是由于 ssd 使用 flash 进行数据保存, 每次数据读写过程都需要将曾经使用过的磁盘数据块抹掉后再重写, 出现重复 Io 增加了系统额外资源, 而机械硬盘不需要把数据抹掉而是直接重写,因此,对于需要进行频繁写操作,(OverWrite 操作) 或者没有 freelists 空间的情况而言, Ssd 会发现产生严重的 Io

 

1. linux 下可以通过启用 trim 功能让电脑自动重新生成 freelists

 

启用 trim 方法

1. 建议使用 ext4 格式

2. 内核必须大于 2.6.28

3.hdparm -I /dev/sda 查询是否支持

* Data Set Management TRIM supported (支持提示)

4. fstab 中加入 discard 参数

/dev/sda1 / ext4 discard,defaults

5. swap 分区启用方法

echo 1 > /proc/sys/vm/swappiness

 

2. 建议使用 noop 调度算法

Linux has several different disk schedulers, which are responsible for determining in which order read and write requests to the disk are handled.  Using thenoop scheduler means that Linux will simply handle requests in the order they are
received, without giving any consideration to where the data physically resides on the disk.  This is good for solid-state drives because they have no moving parts, and seek times are identical for all sectors on the disk.

 

The 2.6 LinuxKernel includes selectable I/O schedulers. They control the way theKernel
commits reads and writes to disks – the intention of providing different schedulers is to allow better optimisation for different classes of workload.

Without an I/O scheduler, the kernel would basically just issue each request to disk in the order that it received them. This could result in massiveHardDisk thrashing: if one
process was reading from one part of the disk, and one writing to another, the heads would have to seek back and forth across the disk for every operation. The scheduler’s main goal is to optimise disk access times.

An I/O scheduler can use the following techniques to improve performance:

Request merging
The scheduler merges adjacent requests together to reduce disk seeking
Elevator
The scheduler orders requests based on their physical location on the block device, and it basically tries to seek in one direction as much as possible.
Prioritisation
The scheduler has complete control over how it prioritises requests, and can do so in a number of ways

All I/O schedulers should also take into account resource starvation, to ensure requests eventually do get serviced!

The Schedulers

There are currently 4 available:

  • No-op Scheduler
  • Anticipatory IO Scheduler (AS)
  • Deadline Scheduler
  • Complete Fair Queueing Scheduler (CFQ)

No-op Scheduler

This scheduler only implements request merging.

Anticipatory IO Scheduler

The anticipatory scheduler is the default scheduler in older 2.6 kernels – if you've not specified one, this is the one that will be loaded. It implements request merging, a one-way elevator, read and write request batching, and attempts
some anticipatory reads by holding off a bit after a read batch if it thinks a user is going to ask for more data. It tries to optimise for physical disks by avoiding head movements if possible – one downside to this is that it probably give highly erratic
performance on database or storage systems.

Deadline Scheduler

The deadline scheduler implements request merging, a one-way elevator, and imposes a deadline on all operations to prevent resource starvation. Because writes return instantly withinLinux,
with the actual data being held in cache, the deadline scheduler will also prefer readers – as long as the deadline for a write request hasn't passed. The kernel docs suggest this is the preferred scheduler for database systems, especially if you have
TCQ aware disks, or any system with high disk performance.

Complete Fair Queueing Scheduler (CFQ)

The complete fair queueing scheduler implements both request merging and the elevator, and attempts to give all users of a particular device the same number of IO requests over a particular time interval. This should make it more efficient
for multiuser systems.  It seems that Novel SLES sets cfq as the scheduler by default, as does the latestUbuntu release. As of the 2.6.18 kernel, this is the default schedular in kernel.org releases.

Changing Schedulers

The most reliable way to change schedulers is to set the kernel option “elevator” at boot time. You can set it to one of “as”, “cfq”, “deadline” or “noop”, to set the appropriate scheduler.

It seems under more recent 2.6 kernels (2.6.11, possibly earlier), you can change the scheduler at runtime by echoing the name of the scheduler into/sys/block/$devicename/queue/scheduler, where the device name is the
basename of the block device, eg “sda” for/dev/sda.

Which one should I use?

I've not personally done any testing on this, so I can't speak from experience yet. The anticipatory scheduler will be the default one for a reason however - it is optimised for the common case. If you've only got single disk systems
(ie, no RAID - hardware or software) then this scheduler is probably the right one for you. If it's a multiuser system, you will probably find CFQ or deadline providing better performance, and the numbers seem to back deadline giving the best performance for
database systems.

The noop scheduler has minimal cpu overhead in managing the queues and may be well suited to systems with either low seek times, such as an SSD or systems using a hardware RAID controller, which often has its own IO scheduler designed
around the RAID semantics.

Tuning the I/O schedulers

The schedulers may have parameters that can be tuned at runtime. Read theLinuxKernel documentation on the schedulers listed in theReferences section below

More information

Read the documents mentioned in the References section below, especially theLinuxKernel documentation on the anticipatory and deadline schedulers.

 

link from http://www.wlug.org.nz/LinuxIoScheduler

 

2. 启用 wiper 工具对 SSD 进行重新清空

wiper.sh  由 hdparm 工具附带, 但 rhel5,6 都默认不带改工具, 建议重新编译安装

 

 

时间: 2024-08-31 03:22:25

linux 下开启 trim 功能的相关文章

python-如何在linux下开启守护进程

问题描述 如何在linux下开启守护进程 问题是这样的:我用python写了两个模块:Store.py,Search.py,在这两个文件中,分别会开启Store线程和Search线程.这两个线程是需要一直开启的,如果发现这两个线程挂了,需要重新开启. 我之前的做法是:在linux的begin.sh脚本中写下如下内容: #!/bin/bash python Store.py python Search.py 然后执行./begin.sh. 然后出现下面的问题: 由于Store.py中开启了线程,程

如何在源码包编译安装的 LEMP 环境下开启 OpenSSL 功能

如何在源码包编译安装的 LEMP 环境下开启 OpenSSL 功能 Hello,大家好!我是--邪恶君子! 今天,给大家分享一下解决源码包编译安装 LEMP 环境下开启 OpenSSL 功能问题的过程.前几天,在访问页面时,突然报错,要求开启 openssl 功能.那怎么办呢,首先想到的是 yum 安装,但是,安装后还是没解决,因为 LEMP 的环境是源码包编译安装的,所以,还需要编译安装 openssl. 经过邪恶不懈的努力,终于找到了解决办法,而且真的成功了,下面就给大家分享一下! 首先,要

Linux下开启关闭SeLinux

SELinux (Security-Enhanced Linux) in Fedora is an implementation of mandatory access control in the Linux kernel using the Linux Security Modules (LSM) framework. Standard Linux security is a discretionary access control model. Discretionary access c

实现linux下历史命令功能的rlwrap工具

在linux下使用Oracle的sqlplus命令时, 每次都需要重新输入命令很是烦恼,就连输错字,backspace键也不能用,只能delete 很是不习惯 现在有一个工具可以实现linux下的历史命令功能: rlwrap 下载地址是: http://utopia.knoware.nl/~hlub/uck/rlwrap/ 安装 解压缩: tar zxvf rlwrap-0.36.tar.gz ./configure make make install 用户配置文件配置 # echo 'alia

如何在Godaddy的Linux主机开启SSH功能

中介交易 http://www.aliyun.com/zixun/aggregation/6858.html">SEO诊断 淘宝客 云主机 技术大厅 Godaddy的Linux主机默认SSH功能是关闭的,需要自己去申请,其实开通也很简单,三个步骤即可完成. 一.开通前先把数据库备份好,因为可能会删除你的数据库.删除完数据库以后,接着打开godaddy的空间管理面板,选择Settings栏目下的SSH选项,如图: 二.填写Country Code: 在中国的请写"86"

Godaddy的Linux主机开启SSH功能教程

http://www.aliyun.com/zixun/aggregation/29826.html">Godaddy是世界第一大域名注册商,进军主机领域以后发展迅速,据多家监测机构显示,放置在Godaddy上的网站数量已经越居第一位.Godaddy同时提供linux主机,Windows主机,VPS以及独立主机全线主机产品,各种需求的客户在这里都可以找到适合自己的产品. Godaddy同时提供独立IP,SSL证书,帮助客户快速打造自己的电子商务网站. Godaddy优点: 价格便宜,win

Linux下HugePage内存功能配置

  在Linux环境性能优化实践中,HugePage是一个经常提到的方法.简单的说,HugePage就是Linux内核上一种是用内存块的方法.作为传统4K Page的替代,HugePage在大部分场景下可以提升Oracle实例的运行性能效率.   本篇介绍如何进行HugePage配置和Oracle环境使用.   1.HugePage介绍   HugePage广泛启用开始于Kernal 2.6,一些版本下2.4内核也可以是用.在操作系统Linux环境中,内存是以页Page的方式进行分配,默认大小为

Linux 下开启ssh服务(转)

 二.SSH     SSH 为 Secure Shell 的缩写,由 IETF 的网络工作小组(Network Working Group)所制定:SSH 为建立在应用层和传输层基础上的安全协议.SSH 是目前较可靠,专为远程登录会话和其他网络服务提供安全性的协议.利用 SSH 协议可以有效防止远程管理过程中的信息泄露问题.SSH是替代Telnet和其他远程控制台管理应用程序的行业标准.SSH命令是加密的并以几种方式进行保密.SSH有很多功能,它既可以代替 telnet,又可以为ftp.pop

Linux下针对路由功能配置iptables的方法详解

  作为公司上网的路由器需要实现的功能有nat地址转换.dhcp.dns缓存.流量控制.应用程序控制,nat地址转换通过iptables可以直 接实现,dhcp服务需要安装dhcpd,dns缓存功能需要使用bind,流量控制可以使用tc,应用程序控制:例如对qq的封锁可以使用 netfilter-layer7-v2.22+17-protocols-2009-05-28.tar.gz来实现 1.网络规划 操作系统是centos5.8 2.安装dhcpd 代码如下: yum install dhcp