Aug 122011
 

defragA volte succede che le persone che ho portato sul “lato Linux” dei sistemi operativi mi chiedano: “Quale antivirus devo usare?” oppure “devo fare defrag del disco?”
Questa è una delle risposte più complete che ho trovato per la seconda domanda, fonte Ubuntu Forum

In realtà io fortemente suggerisco la non deframmentazione … La ragione di questo? Anche su Windows i defraggers hanno 2 opzioni, 1 defrag, 2 Compact … a volte chiamato in maniera diversa, ma il risultato finale è lo stesso.

Il “deframmentare” si suppone che sposti tutti i file in blocchi contigui. L’opzione “compatta” si suppone che deframmenti e renda lo spazio libero in un blocco contiguo. Ora, mentre questo suona come buono e bello, la realtà è ben diversa:




La frammentazione causa la perdita di produttività, in quanto per ogni accesso ai file si potrebbero avere centinaia di letture/scritture sul disco. Il file system fa la differenza:

  • FAT file system salva ogni file direttamente dietro l’altro. Quindi, se poi si modifica/aggiunge a questo file, la porzione aggiunta deve essere salvata da qualche altra parte. Questo creerà un frammento (o più di uno). Un nuovo file è stato salvato a partire dal primo punto in bianco, anche se quel punto in bianco è troppo piccola per contenere l’intero file.
  • NTFS è un po’ meglio, in teoria, lascia un pò di spazio libero intorno ad ogni file. Poi se si accorge che il file diventerà frammentato, fa dei “tentativi” per salvare l’intero file in una nuova posizione. Il motivo di questo questo è “l’efficienza”: se non ci vuole voluto troppo tempo per salvare l’intero file di nuovo, questo sarà fatto, altrimenti è sarà creato un nuovo frammento. Proprio come determina “troppo tempo” è il dubbio … e come la maggior parte delle idee di M$ anche un segreto!
  • Ext3 /4 genera anchesso spazi bianchi “intorno” ad ogni file. Dove è sostanzialmente diverso da NTFS è che sarà frammento solo quando è impossibile tenere il file come un singolo frammento … che (di solito) avviene solo quando il disco diventa troppo pieno

Perché le utility di defrag non funzionano:

Deframmentare:
Tutto quello che fa è ciò che ext3/4 fa già … ma dopo il fatto. Esso controlla tutti i file sul disco fisso, poi per tutti coloro con più di un frammento “cerca” di passarlo a uno spazio vuoto che sia abbastanza grande. Dopo un po’ si finisce con un sacco di piccole parti e pezzi di spazio vuoto in tutto l’HDD. Con Linux ext3/4 questi sono in realtà progettati per evitare la frammentazione, è data una dimensione di rapporto e ogni volta che il file cresce oltre lo spazio è spostato da qualche altra parte e data una più ampia “zona cuscinetto”. Con un windows defrag gli spostamenti succedono per caso e le dimensioni possono essere qualsiasi cosa, da un’unità di allocazione (in genere 4096 byte) ad alcuni giga. Non c’è vero e proprio “piano” alle spalle, e non importa quante volte il file è cresciuto o quello che le sue dimensioni sono diventate. E’ anche possibile non avere alcun spazio tra i file, così si finisce con uno scenario come FAT.

Compattare:
Questa è la cosa peggiore che si potrebbe fare per il vostro disco rigido. A parte il fatto che si sta diminuendo la vita meccanica da superlavoro e che la compattazione determina una frammentazione in futuro. Questo perché letteralmente riorganizza i file in base a quello che abbiamo visto nei sistemi FAT. Quindi la prima modifica dopo una compattazione creerà frammenti in più (almeno uno in più). Alcuni defraggers (come Norton Speed Disc​​) permettono un riarrangiamento “intelligente” dei file. Tutto quello che in fondo fanno è spostare i file che sono cambiati molto (come i documenti) alla fine del disco e tutti i file non modificati (come programmi) alla partenza. Ma rimuovono le zone cuscinetto tra i file. L’unica volta che avevo anche considerato una cosa del genere è quando l’HDD era usato solo per l’accesso in lettura, ma anche allora ci sono a volte migliori soluzioni rispetto alle prestazioni.

Dopo aver detto tutto ciò … assolutamente niente è mai perfetto. Anche i sistemi ext4 si frammentano (ma molto raramente così tando che le prestazioni si degradano). I principali colpevoli della frammentazione su ext3/4 sono sistemi di database. Questi hanno più letture e scritture in contemporanea, così riarrangiamento per eliminare la frammentazione potrebbe realmente danneggiare le prestazioni. In questi casi di solito è una buona idea “di tanto in tanto” copiare i file frammentati su un HDD esterno, cancellare l’originale e farne una copia di nuovo. Questo metodo consente al file system ext di “decidere per sé” dove posizionare meglio il file precedentemente frammentato. E poi, naturalmente, non riempire eccessivamente il vostro disco rigido, un buon limite è di circa il 50%. Ma non è va assolutamente riempito sopra 80-90%, questo è solo andare in cerca di guai (non importa quale sistema operativo/file system avete)!

Alcuni DBMS hanno dei modi per aggirare questo. Esempio Interbase (o Firebird) crea un file per il suo database, che ha esattamente una dimensione specificata, se i dati crescono al di là di questa dimensione del file un secondo file viene creato invece di far crescere il 1°. Questo assicura che ogni file è solo un frammento – ma, ovviamente, il file può contenere un bel po’ di spazio sprecato. Questo non è il default, ma per ogni serio DB è consigliato.

Popular Posts:

Flattr this!

  7 Responses to “Linux ha bisogno di defrag ?”

  1. While delayed allocation, extents and multiblock allocation help to reduce the fragmentation, with usage filesystems can still fragment.

    http://kernelnewbies.org/Ext4#head-38e6ac2b5f58f10989d72386e6f9cc2ef7217fb0

  2. http://vleu.net/shake/ Ext2 and Ext3 best friend at times.

    “Bad advice” the link you have is not 100 percent the full story it is true but ext2 and ext3 will look for a chance to undo that. Move or Copy the file will normally trigger fix of fragmentation. This is how shake is achieving it. No need to talk directly to the filesystem just perform the operations that will allow ext2 and ext3 to fix it.

    Ext4 with online defrag in fact will wait for low load and try to fix up fragmentation issues without having to use a tool like shake. Btrfs also will include this feature as well.

    Of course in a system that is always under heavy load you still might have to run shake every now and again to fix issues up.

    Note the way shake works you don’t need to stop any operations to perform it since it just normal disk operations. I have a clone of shake for windows. Cases where you have windows defrag say the drive is too far fragmented to defrag. NTFS will in fact defrag using the same method as ext2 ext3 and ext4 with shake.

    Fat your screwed. Filesystem engine contains no natural system against fragmentation.

    General usage of ext2 and ext3 natural operations normally trigger clean up so even shake is not major-ally required.

    Yes “Bad adivce” is right the article has something badly wrong.

    ” In such cases it’s usually a good idea to “now and again” copy the fragmented file off to an external HDD, delete the original & copy it back.”

    Correct answer is run shake over the file. This will fix it up. No copying to another drive and back again.

    Also percentages are bad as well. Make sure there is more space free than the size files you normally will be writing. Lot of 1 TB drives I run near 90 percent full without any fragmentation issues. Yes 10 percent of a 1 TB drive is about 100G. Since most files I write to it are less than 1G the drive has to be quite badly fragmented not to find a fragment the right size to take the file.

    Yes shock horror Linux does have a defrag tool its not less required to be run. System may take 3 to 8 years in home usage to reach a stage of fragmentation on linux needing shake to be run.

  3. Recently, e4defrag became available in Debian as part of e2fsprogs 1.42. After running it on my root partition, I didn’t notice any performance improvement. That is on a system with daily package (un)installations and often massive dist-upgrades. I do make sure to always have enough free space on my file systems (but I have disabled root-reserved space on all of them).

    So, at least in my case, I can say that defragmentation is not a necessity. Once the tool becomes available in more distros, people will test it to determine if it has any effect on their systems.

  4. I’ve read this somewhere else, but did not remember why Linux does not need defrag, actually why EXT3/4 does not need defragmentation.

    Thanks for refreshing my mind.

  5. Many drives are used as archival or mainly read only, such as media drives, where a person my store their photos, movies, music, and other archived files. Having files contiguous can be important for performance and also in the event of a filesystem failure, to improve data carving to recover any data that has not been backed up. Contiguous data in these cases have many advantages. And on occasion these drives have the data reorganized which would then call for a possible defrag and a consolidation of free space. To say that there is no reason to have a drive defragmented is shortsighted.

  6. thanks for sharing, i was unaware of this fact.

Leave a Reply to Giorgos Cancel reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

*