Re: performance implications of releasing resources and context switches



Ambrose Silk <silky@xxxxxxxxxxxxxx> writes:

[...]

Files are mapped rather than fopen-ed because that costs exactly 4
system calls per file (open, mmap, munmap, close) as opposed to
fopen/fread/fclose which might do any number of read calls.

Unless you know the filesize, there must be a (f)stat missing in this
list. And you can save one (two) system call(s) by not using mmap:
open, fstat, read, close (as opposed to open, fstat, mmap, (madvise),
munap, close). Assuming your file accesses are read-only, there should
be a filesize up to which copying the data is faster than having the
kernel make it accessible after a page fault[*]. If your checksumming
operation can work on blocks of data not larger than the size of the
L1 cache, using read would have the additional benefit that the
contents of the cache would already be loaded during the copy
operation.

[*] This is claimed in 'The Design and ... FreeBSD Operating
System' somewhere and the size is IIRC 16K.
.



Relevant Pages

  • Re: New libc malloc patch
    ... Your decision to switch to using mmap as the exclusive source of malloc ... bounding from cpu to cpu and thrashing each CPU cache ...
    (freebsd-current)
  • Re: New libc malloc patch
    ... the best one might be to permit mmap to actually consume space below ... than the size of one cache line. ... >> be allocated with brk. ... > we already have systems running with enough CPUs that this is an issue. ...
    (freebsd-current)
  • Re: Cyrus mmap vs lseek/write usage - (WAS: BUG: mmapfile/writev spurious zero bytes (x86_64/not
    ... shared writable mmap() doesn't work well on unix-lookalikes (ie "not real ... The cache alias issue can actually be really thorny, ... is known not to work on some systems, ie HP-UX). ... but apparently Cyrus already has such strategies at least for HP-UX. ...
    (Linux-Kernel)
  • Re: mmap() sendfile()
    ... > the file in memory until munmapis called. ... I do not understand why mmap() is called with MAP_PRIVATE ... > for use by sendfile(). ... > sendfilehas the same cache effect ?! ...
    (freebsd-hackers)
  • Re: read vs. mmap (or io vs. page faults)
    ... using mmap() is considerably ... so the fault overhead is very high for the data rate. ... It's because your buffer is smaller then the L1 cache, ...
    (freebsd-current)