<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dd &#8211; 良的世界</title>
	<atom:link href="https://www.lemonary.cn/tag/dd/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.lemonary.cn</link>
	<description></description>
	<lastBuildDate>Wed, 22 Jul 2026 10:00:31 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://www.lemonary.cn/wp-content/uploads/2024/12/profile-150x150.jpg</url>
	<title>dd &#8211; 良的世界</title>
	<link>https://www.lemonary.cn</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Linux下硬盘测试命令dd</title>
		<link>https://www.lemonary.cn/linux%e4%b8%8b%e7%a1%ac%e7%9b%98%e6%b5%8b%e8%af%95%e5%91%bd%e4%bb%a4dd/</link>
					<comments>https://www.lemonary.cn/linux%e4%b8%8b%e7%a1%ac%e7%9b%98%e6%b5%8b%e8%af%95%e5%91%bd%e4%bb%a4dd/#respond</comments>
		
		<dc:creator><![CDATA[shine]]></dc:creator>
		<pubDate>Thu, 12 Dec 2024 08:02:12 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[dd]]></category>
		<category><![CDATA[DM]]></category>
		<guid isPermaLink="false">https://www.lemonary.cn/?p=1012</guid>

					<description><![CDATA[一、文档目的 规范使用 dd 命令测试磁盘的真实物理读写性能，特别是针对数据库场景（模拟 Redo Log 同 [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading">一、文档目的</h2>



<p class="wp-block-paragraph">规范使用 <code>dd</code> 命令测试磁盘的<strong>真实物理读写性能</strong>，特别是针对数据库场景（模拟 Redo Log 同步写入、Data File Direct I/O），为数据库选型、性能调优和故障排查提供准确的数据基准。</p>



<h2 class="wp-block-heading">二、测试前的环境准备</h2>



<ul class="wp-block-list">
<li><strong>测试目录</strong>：务必在数据库数据目录或挂载点下执行（如 <code>/data/</code>），避免测试系统盘 <code>/root</code> 或 <code>/home</code> 产生干扰。</li>



<li><strong>预留空间</strong>：确保测试文件（通常 1~2GB）不会写满磁盘。</li>



<li><strong>清理缓存</strong>（可选，更精准）：测试前可执行 <code>sync &amp;&amp; echo 3 > /proc/sys/vm/drop_caches</code> 清空系统缓存（需 root 权限），防止脏数据干扰读取测试。</li>



<li><strong>测试文件清理</strong>：测试完成后记得 <code>rm -f ./test.sdf</code>，避免占用空间。</li>
</ul>



<h2 class="wp-block-heading">三、核心参数说明</h2>



<p class="wp-block-paragraph">oflag=direct：直接 I/O，绕过系统页缓存写入磁盘。读/写测试必备，模拟数据库 Data File 直接写入。<br>iflag=direct：直接 I/O，绕过系统页缓存从磁盘读取。读/写测试必备，模拟数据库 Data File 直接读取。<br>oflag=dsync：同步 I/O，确保每次写入完全落盘后才返回。模拟数据库 Redo Log（重做日志） 的严格持久化要求。<br>conv=fdatasync：测试结束后显式调用 fsync，确保全部落盘。模拟批量导入或表空间文件写入，比 dsync 吞吐量更高</p>



<h2 class="wp-block-heading">四、基准测试命令模板</h2>



<p class="wp-block-paragraph">以下命令均以 <code>bs=32k</code> 为例。如果您的数据库页大小不同（如 8K、16K），请相应调整 <code>bs</code> 参数，<strong>保持大小与业务实际 I/O 特征一致</strong>。</p>



<h3 class="wp-block-heading">4.1 写入性能测试</h3>



<p class="wp-block-paragraph">目标：测试极端严苛的同步写入性能。</p>



<pre class="wp-block-code"><code># 写入 1.3GB 数据（bs=32k, count=40k），强制每次 I/O 同步落盘
dd if=/dev/zero of=./test.sdf bs=32k count=40k oflag=dsync</code></pre>



<p class="wp-block-paragraph">结果解析：输出的末尾如 263 MB/s 即为写入速度。</p>



<h3 class="wp-block-heading">4.2 写入性能测试</h3>



<p class="wp-block-paragraph">目标：测试数据库 Checkpoint 或批量 ETL 场景。</p>



<pre class="wp-block-code"><code># 写入 1.3GB，最后统一调用 fsync 落盘（吞吐量通常比 dsync 高）
dd if=/dev/zero of=./test.sdf bs=32k count=40k conv=fdatasync</code></pre>



<p class="wp-block-paragraph"></p>



<p class="wp-block-paragraph">命令</p>



<pre class="wp-block-code"><code>dd if=/dev/zero of=/dmdata/test.sdf bs=32k count=40k oflag=dsync</code></pre>



<p class="wp-block-paragraph">等待测试完成即可</p>



<pre class="wp-block-code"><code>&#91;root@dameng ~]# dd if=/dev/zero of=/dmdata/test.sdf bs=32k count=40k oflag=dsync
40960+0 records in
40960+0 records out
1342177280 bytes (1.3 GB, 1.2 GiB) copied, 101.031 s, 13.3 MB/s</code></pre>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="899" height="116" src="https://www.lemonary.cn/wp-content/uploads/2024/12/image-59.png" alt="" class="wp-image-1013" srcset="https://www.lemonary.cn/wp-content/uploads/2024/12/image-59.png 899w, https://www.lemonary.cn/wp-content/uploads/2024/12/image-59-300x39.png 300w, https://www.lemonary.cn/wp-content/uploads/2024/12/image-59-768x99.png 768w" sizes="(max-width: 899px) 100vw, 899px" /></figure>



<p class="wp-block-paragraph">命令详解：</p>



<ul class="wp-block-list">
<li>dd用于复制，从if读出，写到of。</li>



<li>if=/dev/zero不产生IO，因此可以用来测试纯写速度。</li>



<li>同理of=/dev/null不产生IO，可以用来测试纯读速度。</li>



<li>bs是每次读或写的大小，即一个块的大小，count是读写块的数量。</li>
</ul>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p class="wp-block-paragraph">注意<br>bs设置的大小可以用来模拟数据库的页大小，即4K，8K，16K，32K。便可用于测试数据库服务器磁盘读写能力。</p>
</blockquote>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lemonary.cn/linux%e4%b8%8b%e7%a1%ac%e7%9b%98%e6%b5%8b%e8%af%95%e5%91%bd%e4%bb%a4dd/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Linux系统如何开启swap</title>
		<link>https://www.lemonary.cn/%e5%bc%80%e5%90%afswap/</link>
					<comments>https://www.lemonary.cn/%e5%bc%80%e5%90%afswap/#respond</comments>
		
		<dc:creator><![CDATA[shine]]></dc:creator>
		<pubDate>Mon, 09 Dec 2024 09:21:29 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[dd]]></category>
		<category><![CDATA[swap]]></category>
		<guid isPermaLink="false">https://www.lemonary.cn/?p=915</guid>

					<description><![CDATA[一、概述 由于网站添加的内容越来越多，功能越来越多，导致服务器的内存有些不足，支撑起来有些吃力，所以决定把sw [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading" id="一、概述">一、概述</h2>



<p class="wp-block-paragraph">由于网站添加的内容越来越多，功能越来越多，导致服务器的内存有些不足，支撑起来有些吃力，所以决定把swap重新开启。</p>



<p class="wp-block-paragraph">设置swap大小通常取决于你的系统内存大小和你计划运行的应用需求。以下是一些基本的指导原则：</p>



<ol class="wp-block-list">
<li>如果你有16GB以下的内存，通常建议设置与内存大小相等的swap空间。</li>



<li>对于16GB到64GB的内存，可以设置16GB的swap空间。</li>



<li>对于64GB以上的内存，通常建议至少设置16GB的swap空间。</li>
</ol>



<p class="wp-block-paragraph">以下是开启的步骤方法。</p>



<h2 class="wp-block-heading" id="二、开启方法">二、开启方法</h2>



<ul class="wp-block-list">
<li>首先利用dd命令生成/swapfile文件</li>
</ul>



<pre class="wp-block-code"><code>dd if=/dev/zero of=/swapfile bs=1G count=<strong>N</strong></code></pre>



<p class="wp-block-paragraph">其中<code>N</code>是你想设置的swap大小（以GB为单位）。</p>



<ul class="wp-block-list">
<li>然后使用以下命令使其成为swap文件</li>
</ul>



<pre class="wp-block-code"><code>mkswap /swapfile
swapon /swapfile</code></pre>



<ul class="wp-block-list">
<li>为了使swap设置在重启之后依然有效，需要将它添加到<code>/etc/fstab</code>文件中</li>
</ul>



<pre class="wp-block-code"><code>echo '/swapfile none swap sw 0 0' | tee -a /etc/fstab</code></pre>



<p class="wp-block-paragraph">配置好后重启服务器也能保持swap依然有效，验证</p>



<pre class="wp-block-code"><code>&#91;root@dameng ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           3736        3157         128           9         450         353
Swap:          4095          15        4080</code></pre>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lemonary.cn/%e5%bc%80%e5%90%afswap/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
