[bittorrent] Introductory/endgame algorithms
ehem at m5p.com
Thu Sep 29 04:02:45 EDT 2005
>From: Olaf van der Spek <olafvdspek at gmail.com>
> On 9/29/05, Elliott Mitchell <ehem at m5p.com> wrote:
> > >From: Olaf van der Spek <olafvdspek at gmail.com>
> > > On 9/29/05, Elliott Mitchell <ehem at m5p.com> wrote:
> > > > Bad idea to do it that way. I doubt most OSes do read-ahead on mmap()ed
> > > > files, and for what BitTorrent is doing readahead is quite important.
> > > > Your best bet is use pread()/readv() on whole pieces when the first block
> > > > is requested, and ensure your buffer is page-aligned
> > > > (sysconf(_SC_PAGESIZE)).
> > >
> > > Doesn't that also require the read offset to be aligned?
> > Yes. Given that most torrents use 256KB or larger pieces though, no
> > systems I know of have page sizes larger than that and all are some
> > factor of 256KB. Most use 4KB pages, SunOS on SPARC uses 8KB pages. No
> > problem, all pieces will be page aligned. In fact all block requests
> > should be page aligned. At least with torrents containing large single
> > files (the common case I believe?).
> I think it's the other way around, the common case being multiple files.
To tell the truth, no idea. I'm mostly after Linux CD images which tend
to be very large single files, I won't claim that is the majority. Other
things I've seen tend to be multi-hundred megabyte files. There needs to
be one more factor present to make this problematic, the file sizes need
to not be a factor of your page size.
With ISO images the block size is 2KB, so 50% chance of files being well
aligned with 4KB pages; however I doubt it is common to have multiple ISO
images in a single torrent. Do other commonly used files specify a
particular alignment? Looking at a couple handy large files, all of them
are multiples of 4KB in size. I can't guarentee other files are, but I
imagine many formats will suggest a padding for the reason of performance
(I note filesystems which actually pack the final non-blocksize element
of a file together are rare, ReiserFS is the only one I know of).
(\___(\___(\______ --=> 8-) EHM <=-- ______/)___/)___/)
\BS ( | EHeM at gremlin.m5p.com PGP 8881EF59 | ) /
\_CS\ | _____ -O #include <stddisclaimer.h> O- _____ | / _/
\___\_|_/82 04 A1 3C C7 B1 37 2A*E3 6E 84 DA 97 4C 40 E6\_|_/___/
More information about the BitTorrent