LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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,441

Rep: Reputation: 110Reputation: 110
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: 22,092

Rep: Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365Reputation: 7365
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: 25,812

Rep: Reputation: 5957Reputation: 5957Reputation: 5957Reputation: 5957Reputation: 5957Reputation: 5957Reputation: 5957Reputation: 5957Reputation: 5957Reputation: 5957Reputation: 5957
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,840

Rep: Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221Reputation: 1221
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: 11,261

Rep: Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338Reputation: 5338
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.
Old 06-19-2023, 08:53 AM   #6
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 448Reputation: 448Reputation: 448Reputation: 448Reputation: 448
Hi

Doing a lot of file open, write, close, is slightly slower, but not that much.

The kernel has a buffer and will not write to disk as long as there is free memory, or a "commit interval" setting is reached. I think it's 5 seconds by default on ext4.

I have a Rasperry PI (used as server), and added "noatime,commit=10800" in fstab. Then it will take up to 3 hours to get written disk. Of course I lose more on power failure, but it's ok for me.

It's useful for sd-cards and when it's written to /var/log or other places.

You can use the command "sync" when you want it to actually write to disk.
 
1 members found this post helpful.
Old 06-19-2023, 09:13 AM   #7
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
mod your fstab to put /tmp into ram
tmpfs /tmp tmpfs defaults,noatime,size=3G 0 0

size part is not actually necessary size=3G not needed unless you want to limit it to whatever size you want manually ( i just copy pasted that off my fstab)
then write to /tmp to cut down/off writes to the ssd
Code:
 #!/bin/sh

for i in `seq 1 10`
    do   echo $i >> /tmp/loop.txt

done
cp /tmp/loop.txt ~/
something like that, and stuff in /tmp is lost every time the PC looses electricity

Last edited by BW-userx; 06-19-2023 at 09:31 AM.
 
1 members found this post helpful.
Old 06-19-2023, 10:15 AM   #8
Jan K.
Member
 
Registered: Apr 2019
Location: Esbjerg
Distribution: Windows 7...
Posts: 773

Rep: Reputation: 489Reputation: 489Reputation: 489Reputation: 489Reputation: 489
I doubt you are able to wear out the SSD no matter the number...

https://www.howtogeek.com/806926/wha...mean-for-ssds/
 
1 members found this post helpful.
Old 06-21-2023, 05:27 AM   #9
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
I should think it's Ok as it's appending >> not overwriting.
 
Old 06-21-2023, 06:45 AM   #10
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Quote:
Originally Posted by Jan K. View Post
I doubt you are able to wear out the SSD no matter the number...

https://www.howtogeek.com/806926/wha...mean-for-ssds/
putting it into RAM still cuts down on read writes to a disk (SDD) nonetheless thus prolonging its life cycle
 
1 members found this post helpful.
Old 06-21-2023, 11:36 AM   #11
Jan K.
Member
 
Registered: Apr 2019
Location: Esbjerg
Distribution: Windows 7...
Posts: 773

Rep: Reputation: 489Reputation: 489Reputation: 489Reputation: 489Reputation: 489
The write process in op means you'll run out of disc space years before disc is worn out...

It's easy to calculate disc's life by looking at the number of bytes writes per day divided in TBW... we're talking decades. The disc will be replaced by other reasons than worn out.

I have an SSD you may try to wear out!
 
1 members found this post helpful.
  


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 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 06:37 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