LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-05-2023, 01:10 PM   #1
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,338

Rep: Reputation: 100Reputation: 100
Can a loop thrash a disk?


Code:
#!/bin/sh

for i in `seq 1 10`
    do echo $i >> loop.txt
done
Does that code write to the loop.txt file 10 times? How about `seq 1 10000000`? Does that write to disk 10 million times?

I am specifically concerned with wearing out my SSD.
 
Old 05-05-2023, 02:02 PM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 20,224

Rep: Reputation: 6834Reputation: 6834Reputation: 6834Reputation: 6834Reputation: 6834Reputation: 6834Reputation: 6834Reputation: 6834Reputation: 6834Reputation: 6834Reputation: 6834
you need to read about disk cache. for example: https://foxutech.com/linux-memory-and-disk-caching/
 
1 members found this post helpful.
Old 05-05-2023, 02:28 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 24,368

Rep: Reputation: 5457Reputation: 5457Reputation: 5457Reputation: 5457Reputation: 5457Reputation: 5457Reputation: 5457Reputation: 5457Reputation: 5457Reputation: 5457Reputation: 5457
Look at the specifications of the SSD and post what the value of its TBW or DWPD. DWPD is the amount of drive capacity you can write per day over the warranty period. TBW is the total number of writes for the life of the drive and from there you can determine the writes per day. In most cases that far exceeds what most home users normally write to disk.
 
2 members found this post helpful.
Old 05-05-2023, 04:28 PM   #4
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,452

Rep: Reputation: 1061Reputation: 1061Reputation: 1061Reputation: 1061Reputation: 1061Reputation: 1061Reputation: 1061Reputation: 1061
In most cases there is enough free RAM, so buffering and few bundled disk writes take place.
But if you want to be safe then optimize your code
Code:
for i in `seq 1 10`
    do echo $i
done > loop.txt
 
2 members found this post helpful.
Old 05-05-2023, 05:08 PM   #5
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 10,954

Rep: Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215Reputation: 5215
Put loop.txt on tmpfs when it's being written to, and move it to the SSD after that's all done?
 
2 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows-like thrash can for Linux AdultFoundry Linux - Newbie 7 11-09-2015 01:57 PM
Pulse Audio appears to be causing HD to thrash repeatedly Toadman Mandriva 3 01-08-2010 09:48 AM
LXer: SA govt officials meet to thrash out OSS progress LXer Syndicated Linux News 0 01-21-2009 02:41 AM
which are the folders for gnome thrash bin and kde wastebasket odysseus.lost Linux - Newbie 3 08-09-2005 05:27 AM
Wht does my hard drive thrash while I'm working? glenn69 Linux - Newbie 4 05-28-2004 11:04 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:16 PM.

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