LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-31-2016, 08:18 PM   #1
designator
Member
 
Registered: Jun 2003
Location: California, USA
Distribution: OpenSUSE Tumbleweed
Posts: 219

Rep: Reputation: 37
Question Disable caching writes when using dd to erase disk


I'm trying to use the following command to erase an externally attached (USB 3) drive:
Code:
dd if=/dev/zero of=/dev/sdc
Depending on the block size I use, this command quickly eats the RAM buffer and eventually crashes my laptop. 1GB block size will freeze the laptop within a few minutes. Default, 512b block size freezes it within 15 minutes or so.

I also tried the following command to try and disable caching with similar results:
Code:
dd if=/dev/zero of=/dev/sdc bs=1G conv=sync
Relevant details:
Code:
$ uname -a
Linux laptop 4.1.21-14-default #1 SMP PREEMPT Sun Apr 17 07:27:45 UTC 2016 (fc187c1) x86_64 x86_64 x86_64 GNU/Linux
$ free -m
             total       used       free     shared    buffers     cached
Mem:         11894       2776       9117        421         13        929
-/+ buffers/cache:       1833      10060
Swap:            0          0          0
This is what free reports right before my laptop freezes when (I think) it runs out of RAM:
Code:
$ free -m
             total       used       free     shared    buffers     cached
Mem:         11894      11824         69        411       7849       1131
-/+ buffers/cache:       2843       9050
Swap:            0          0          0
What's the correct way to prevent dd from using buffer?
Thanks!

Last edited by designator; 05-31-2016 at 08:22 PM.
 
Old 05-31-2016, 09:22 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by designator View Post
What's the correct way to prevent dd from using buffer?
Thanks!
That would be, "oflag=direct".
 
1 members found this post helpful.
Old 05-31-2016, 10:21 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,120

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Read this.
 
2 members found this post helpful.
Old 06-01-2016, 08:40 AM   #4
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by syg00 View Post
Read this.
Very interesting. Now I'm wondering why I've never experienced the problem. I see the writing process stall for a long time while a few gigabytes of buffer get flushed to a slow USB flash drive at around 10 MB/s, but the rest of the 64-bit system continues to run just fine.
 
Old 06-02-2016, 11:54 AM   #5
designator
Member
 
Registered: Jun 2003
Location: California, USA
Distribution: OpenSUSE Tumbleweed
Posts: 219

Original Poster
Rep: Reputation: 37
Quote:
Originally Posted by rknichols View Post
That would be, "oflag=direct".
Worked perfectly. Thank you.
Speed went from ~50MB/s to ~4MB/s, but buffer stays unused.

Quote:
Originally Posted by syg00 View Post
Read this.
Thanks for the explanation. Unless I misunderstood that article though it seems like there is no fix. You can only delay the inevitable which wouldn't really help in this case anyway since the entire buffer fills up.
 
Old 06-02-2016, 01:45 PM   #6
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,776

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Quote:
Originally Posted by designator View Post
Worked perfectly. Thank you.
Speed went from ~50MB/s to ~4MB/s, but buffer stays unused.
Choosing a block size more compatible with the device might alleviate the performance hit.
 
Old 06-02-2016, 02:12 PM   #7
designator
Member
 
Registered: Jun 2003
Location: California, USA
Distribution: OpenSUSE Tumbleweed
Posts: 219

Original Poster
Rep: Reputation: 37
Quote:
Originally Posted by rknichols View Post
Choosing a block size more compatible with the device might alleviate the performance hit.
I discovered that as well. I set the block size to 32mb suggested by fdisk as optimal I/O size and was able to dd the entire drive @ ~70MB/s.
Code:
I/O size (minimum/optimal): 512 bytes / 33553920 bytes
Thanks again.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Polipo cache to disk, cannot activate disk caching, different browsers redownload con Trauma Linux - Software 8 12-07-2013 11:13 AM
How Do I Disable But Not Erase Panel Toolbar? jimwg Linux - Desktop 2 12-02-2012 06:29 AM
How do I disable multipath route caching? SouthPawn Linux - Networking 0 04-26-2010 10:52 AM
Disable caching in HTML sharathkv Programming 4 04-24-2007 09:16 PM
Disable Route Caching RSalameh Linux - Networking 1 02-01-2005 08:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration