Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Perl reads minimum 8KB from files. Can this be lowered?

by sectokia (Pilgrim)
on Apr 11, 2022 at 12:11 UTC ( [id://11142912]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl reads minimum 8KB from files. Can this be lowered?
in thread Perl reads minimum 8KB from files. Can this be lowered?

It appears on windows reguardless of the file system cluster size, you can fetch 512b with sysread. At least on my system this is the minimum it ends up being. Clusters really only matter to the file system for its allocation of clusters to a file, where as the devices only care about blocks.

Replies are listed 'Best First'.
Re^3: Perl reads minimum 8KB from files. Can this be lowered?
by harangzsolt33 (Chaplain) on Apr 12, 2022 at 00:48 UTC
    Well, what I was saying is that you can fetch any number of bytes using sysread(). You can fetch just one byte or you can read the entire file with one call. But behind the scenes, Windows does a lot of buffering. So, instead of just reading 512 bytes of a file, it reads an entire cluster. That may be 4KB or 32KB...whatever the size of the cluster. Sysread() will give you 512 or 513 bytes, if that's what you requested, but the OS will read more, because that's how the system is designed.
      Sysread() will give you 512 or 513 bytes, if that's what you requested, but the OS will read more, because that's how the system is designed.

      That continues to below the operating system. In the PC world, both hard disks and floppy disks have had sector sizes of 512 bytes from day 1, and there was and is simply no way to read less than a single sector. CDROMs introduced a sector size of 2048 bytes, with the same restriction, you have to read whole sectors. Modern large capacity hard disks have sector sizes of 4096 bytes. Only those can emulate hard disk with 512 byte sector size, i.e. you can read and write less than a sector. Of course, the performance penalty for writing an emulated 512 byte sector means that the hard disk has to read the whole 4096 bytes of the physical sector to its internal memory, then modify one of the eight emulated sectors, and write back the physical sector. That needs at least one full rotation of the spindle. Compare to writing a full physical sector, needing no read and just a single write at the right time.

      The real implementationis much more complex, involving caching, relocation of sectors, and things get really crazy with Shingled magnetic recording, where the hard disk has to rewrite a bunch of sectors because the sectors overlap each other. In that regard, SMR is compareable to flash memory (SD-Cards, USB-Sticks, SSDs, etc), where erase blocks are typically much larger than write blocks, and so you have to shuffle data around before writing used blocks.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11142912]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-03-28 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found