SSD以Page为单位做读写,以Block为单位做垃圾回收,Page一般有16KB大小,Block一般有几十MB大小,SSD写数据的逻辑是:

1)将该块数据所在的Page读出

2)修改该Page中该块数据的内容

3)找出一个新的空闲Block将2)中的Page写入,并将1)中提到的Page所在的Block中的Page标志为脏

理解了写原理,也就明白了为什么顺序写比随机写好了。四个字:垃圾回收!写相同数据量的情况下,顺序写制造更少的垃圾Block,所以比随机写有更高的性能。

这篇文章有详细的描述:

... the need for garbage collection affects an SSD’s performance, because any write operation to a “full” disk (one whose initial free space or capacity has been filled at least once) needs to await the availability of new free space created through the garbage collection process. Because garbage collection occurs at the block level, there is also a significant performance difference, depending on whether sequential or random data is involved. Sequential files fill entire blocks, which dramatically simplifies garbage collection. The situation is very different for random data.

As random data is written, often by multiple applications, the pages are written sequentially throughout the blocks of the flash memory.
The problem is: This new data is replacing old data distributed randomly in other blocks. This causes a potentially large number of small “holes” of invalid pages to become scattered among the pages still containing valid data. During garbage collection of these blocks, all valid data must be moved (i.e. read and re-written) to a different block.
By contrast, when sequential files are replaced, entire blocks are often invalid, so no data needs to be moved. Sometimes a portion of a sequential file might share a block with another file, but on average only about half of such blocks will need to be moved, making it much faster than garbage collection for randomly-written blocks. ...

 原文来源:http://serverfault.com/questions/843628/why-does-sequential-writes-have-better-performance-than-random-writes-in-ssds

当然,如果每次读写都以Block为单位读写,那么顺序写和随机写的性能相当。

SSD 为什么顺序写比随机写性能更好?的更多相关文章

  1. 深入理解 linux磁盘顺序写、随机写

    一.前言 ● 随机写会导致磁头不停地换道,造成效率的极大降低:顺序写磁头几乎不用换道,或者换道的时间很短 ● 本文来讨论一下两者具体的差别以及相应的内核调用 二.环境准备 组件 版本 OS Ubunt ...

  2. JavaScript写的随机选人真实案例

    JavaScript写的随机选人真实案例 因工作需要,写了一个随机选人的小网页,先看效果图. 背景也是动态的,只不过在写的时候碰到个问题,就是如果把生成动态流星雨的画布放到上生成随机数的操作界面之上的 ...

  3. #写一个随机产生138开头手机号的程序 1.输入一个数量,产生xx条手机号 2.产生的这些手机号不能重复

    import randomcount=int(input('请输入你所想要手机号数量:'))prefix='138'for i in range(count): num=random.sample(r ...

  4. 面试官:如何写出让 CPU 跑得更快的代码?

    前言 代码都是由 CPU 跑起来的,我们代码写的好与坏就决定了 CPU 的执行效率,特别是在编写计算密集型的程序,更要注重 CPU 的执行效率,否则将会大大影响系统性能. CPU 内部嵌入了 CPU ...

  5. OS: 读者写者问题(写者优先+LINUX+多线程+互斥量+代码)(转)

    一. 引子 最近想自己写个简单的 WEB SERVER ,为了先练练手,熟悉下在LINUX系统使用基本的进程.线程.互斥等,就拿以前学过的 OS 问题开开刀啦.记得当年学读者写者问题,尤其是写者优先的 ...

  6. mnesia的脏写和事物写的测试

    在之前的文章中,测试了脏读和事物读之间性能差别,下面测试下脏写和事物写之间的性能差别: 代码如下: -module(mnesia_text). -compile(export_all). -recor ...

  7. 象写程序一样写博客:搭建基于github的博客

    象写程序一样写博客:搭建基于github的博客   前言 github 真是无所不能.其 Pages 功能 支持上传 html,并且在页面中显示.于是有好事者做了一个基于 github 的博客管理工具 ...

  8. 《自己动手写CPU》写书评获赠书活动结果

    <自己动手写CPU>写书评获赠图书的读者有: 京东:8***2.16号哨兵.magicyu.kk6803.jddickyd.杰出的胡兵 亚马逊:徐贺.马先童.jaychen.farmfar ...

  9. 通过hive向写elasticsearch的写如数据

    通过hive向写elasticsearch的写如数据 hive 和 elasticsearch 的整合可以参考官方的文档: ES-hadoop的hive整合 : https://www.elastic ...

随机推荐

  1. [leetcode]Candy @ Python

    原题地址:https://oj.leetcode.com/problems/candy/ 题意: There are N children standing in a line. Each child ...

  2. GDB 程序调试简单实践

    用了好久的GCC/G++ 却一直都没用过GDB调试过程序,有时程序不是非常大,一般有错,直接看编译器编译结果就几乎相同知道错在哪儿了,或者使用codeblocks单步调试,甚至回到windows以下调 ...

  3. tcp socket/ unix socket

    A UNIX socket is an inter-process communication mechanism that allows bidirectional data exchange be ...

  4. 3D打印机切片与控制软件

    3D模型必须经由两个软件的处理来完成打印程序:切片与传送.切片软件会将模型细分成可以打印的薄度,然后计算其打印路径.3d打印机客户端软件再把这系列动作传送到硬件,并提供控制其他功能的控制介面.了解您的 ...

  5. 逻辑回归应用之Kaggle泰坦尼克之灾

    机器学习系列(3)_逻辑回归应用之Kaggle泰坦尼克之灾 标签: 机器学习应用 2015-11-12 13:52 3688人阅读 评论(15) 收藏 举报 本文章已收录于:  机器学习知识库  分类 ...

  6. 如何拷贝一个wchar_t类型的字符串

    Do this, wchar_t clone[260]; wcscpy(clone,szPath); Or, if you want to allocate memory yourself, wcha ...

  7. 小议IE10下的DrawToBitmap方法

    在完成博文“PS网页设计教程XXIV——从头设计一个漂亮的网站”后. 出于习惯,打开之前“利用Webbrowser类实现超长网页的截屏的实现(解决报错不能截取的难题)”中的代码的程序,截取博文作为资料 ...

  8. Web UI 技术发展历程

    本文内容 纯文本和静态 HTML 页面 服务器端技术 插件技术--ActiveX.Applet 和 Flash Ajax 异步时代和基于 JavaScript 的 UI 技术 RIA--Adobe F ...

  9. 在线创建springboot项目

    在线创建srpingboot项目的网址:https://start.spring.io/ 我只选了一个web,然后开始生成:

  10. KindEditor-编辑器配置参数属性

    KindEditor-源码分析 通过使用KE.show(config)方法即可将编辑器添加到文档中.下面是一段源码: KE.show = function(args) {     KE.init(ar ...