LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > *BSD
User Name
Password
*BSD This forum is for the discussion of all BSD variants.
FreeBSD, OpenBSD, NetBSD, etc.

Notices


Reply
  Search this Thread
Old 04-25-2008, 06:26 AM   #1
noir911
Member
 
Registered: Apr 2004
Posts: 682

Rep: Reputation: Disabled
Understanding blocksize


I am trying to understand what block size is at a system level. The only reference I get is "unix filesystems are allocated a blocksize upon creation." The points I am trying to understand are:

what is a block size? does an individual file or directory has a block size? how does it affect anything when creating a new file.

I can see the block size of ext3 filesystem on OpenSuSe as 1024. Also, Block count: 409601 and Blocks per group: 8192. But they don't make much sense to me.

Any explanation on this would be much appreciated. Thanks.
 
Old 04-25-2008, 07:30 AM   #2
keratos
Member
 
Registered: May 2007
Location: London, UK.
Distribution: Major:FC8. Others:Debian;Zenwalk; Arch; Slack; RHEL.
Posts: 544

Rep: Reputation: 30
A block in linux is analagous to a cluster in windows. It is the smallest unit of physical allocation storage that is exposed through an operating system, to a client.

The allocation unit is typically configurable but usually starts at 512bytes upto, well anything ... 32MB is the unit allocation on one of my video streaming disks and yet 512bytes on a temporary filesystem.

Becuase it is the smallest unit of physical allocation, this has a clear implication. It means that any file created will AT LEAST be of equal or greater than size of the allocation unit. This is critical consideration because ...

a) Lots of small files will each consume at least the allocation unit. Thus, what is perceived to be a large capacity hard disk can quickly become consumed and yield limited or no free space if a signficiant number of small files are written to a disk with a large block/cluster size.

b) Large files could possibly be fragmented in the form of tens/hundreds/thousands of small blocks spread all over the disk thus yielding slow access times because the disk heads need to constantly move to access all the blocks of the large file. Disk head movement slows down disk access.

Therefore, to maximise disk performance, one needs to carefully consider disk storage allocation. In Windows and linux this can be achieved through basic partitioning of the disk and selecting a block size for that partition that reflects the intended use of the partition.

For example, in linux, I use the following:

/tmp 200MB partition of blocks at 512bytes.
Rationale: lots of small temporary files. However because the files are small in size, I can limit the total to a minimal 200MB rather. I could have allocated 8192 block size but then I might well consider a partition size of 3200MB (3.2GB), because the block size is now 16 times bigger and consumes 16x more disk space ... 16*512bytes = my new 8192 block size, and 16*200MB = 3200MB. Get it!!? They are both exactly the same geometry in terms of allocatable units, but one uses 200MB , the other 3200MB. Extrapolte this up on disks of 200, 400 or 800MB disks and you see what can happen!!

/home 50GB at block size of 2048bytes
Rationale: A mix of small and medium files. This time I'm using slightly larger 2048 bytes blocks because I dont want a 512byte block to slow things down (remember that disk head move) but also I dont want too large a block size because I'll quickly consume disk free space. This is a trade-off I find acceptable. Others may have different setups. It works for me.

/stream/video 200GB partition of blocks at 16MB.
Rationale: All AVI videos, my disk internal buffer and throughput works best at accessing 16MB chunks at a time, hence I align the disk allocation to 16MB. There are various utilities out there than can propose an efficient block size for your disk depending on application. So here my block size is a whopping 16384 bytes, lets hope I dont write lots of 1MB files to the disk because each such file would consume a minimum of 16MB (16384bytes) this being the minimum allocation size. Phew!!!


Now, to caveat all this, linux filesystem management far exceeds Windows for technical reasons that are beyond the scope of this post - NTFS isn't too bad but still not a performer when marked against a good linux fs such as XFS, JFS or Reiser. Again there are many many technical documents and materials on the net relating to this topic.


To answer your other questions,

A directory in linux is a special file, but nevertheless a file in the sense of what the O/S understands and thus can be treated in the context of this discussion, as a file - taking space.

The block size is the fundemental building block. You will see this when referenced in higher level terms such as Sectors & Cylinders. Google is your friend!!

Hope this helps.

Last edited by keratos; 04-25-2008 at 07:37 AM.
 
  


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
Need help understanding this PostCode Linux - Newbie 3 11-09-2007 04:12 PM
What is blocksize? binarybob0001 Linux - Software 6 04-21-2006 07:27 PM
A better understanding! nny0000 Slackware 1 04-14-2004 12:01 PM
Understanding X?? nny0000 Linux - General 2 02-25-2004 02:07 AM
Understanding df -k itsjustme Linux - General 6 10-28-2003 12:08 PM

LinuxQuestions.org > Forums > Other *NIX Forums > *BSD

All times are GMT -5. The time now is 08:21 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