--- IO-AIO/README 2010/01/10 23:44:02 1.43 +++ IO-AIO/README 2010/11/01 22:03:43 1.44 @@ -4,7 +4,7 @@ SYNOPSIS use IO::AIO; - aio_open "/etc/passwd", O_RDONLY, 0, sub { + aio_open "/etc/passwd", IO::AIO::O_RDONLY, 0, sub { my $fh = shift or die "/etc/passwd: $!"; ... @@ -74,7 +74,7 @@ my $aio_w = EV::io IO::AIO::poll_fileno, EV::READ, \&IO::AIO::poll_cb; # queue the request to open /etc/passwd - aio_open "/etc/passwd", O_RDONLY, 0, sub { + aio_open "/etc/passwd", IO::AIO::O_RDONLY, 0, sub { my $fh = shift or die "error while opening: $!"; @@ -189,6 +189,8 @@ aio_pathsync $path, $callback->($status) aio_msync $scalar, $offset = 0, $length = undef, flags = 0, $callback->($status) aio_mtouch $scalar, $offset = 0, $length = undef, flags = 0, $callback->($status) + aio_mlock $scalar, $offset = 0, $length = undef, $callback->($status) + aio_mlockall $flags, $callback->($status) aio_group $callback->(...) aio_nop $callback->() @@ -211,7 +213,9 @@ IO::AIO::sendfile $ofh, $ifh, $offset, $count IO::AIO::fadvise $fh, $offset, $len, $advice - IO::AIO::mlockall $flags + IO::AIO::madvise $scalar, $offset, $length, $advice + IO::AIO::mprotect $scalar, $offset, $length, $protect + IO::AIO::munlock $scalar, $offset = 0, $length = undef IO::AIO::munlockall AIO REQUEST FUNCTIONS @@ -294,7 +298,7 @@ Example: - aio_open "/etc/passwd", O_RDONLY, 0, sub { + aio_open "/etc/passwd", IO::AIO::O_RDONLY, 0, sub { if ($_[0]) { print "open successful, fh is $_[0]\n"; ... @@ -753,6 +757,46 @@ "IO::AIO::MT_MODIFY", which modifies the memory page s(by reading and writing an octet from it, which dirties the page). + aio_mlock $scalar, $offset = 0, $length = undef, $callback->($status) + This is a rather advanced IO::AIO call, which works best on + mmap(2)ed scalars. + + It reads in all the pages of the underlying storage into memory (if + any) and locks them, so they are not getting swapped/paged out or + removed. + + If $length is undefined, then the scalar will be locked till the + end. + + On systems that do not implement "mlock", this function returns -1 + and sets errno to "ENOSYS". + + Note that the corresponding "munlock" is synchronous and is + documented under "MISCELLANEOUS FUNCTIONS". + + Example: open a file, mmap and mlock it - both will be undone when + $data gets destroyed. + + open my $fh, "<", $path or die "$path: $!"; + my $data; + IO::AIO::mmap $data, -s $fh, IO::AIO::PROT_READ, IO::AIO::MAP_SHARED, $fh; + aio_mlock $data; # mlock in background + + aio_mlockall $flags, $callback->($status) + Calls the "mlockall" function with the given $flags (a combination + of "IO::AIO::MCL_CURRENT" and "IO::AIO::MCL_FUTURE"). + + On systems that do not implement "mlockall", this function returns + -1 and sets errno to "ENOSYS". + + Note that the corresponding "munlockall" is synchronous and is + documented under "MISCELLANEOUS FUNCTIONS". + + Example: asynchronously lock all current and future pages into + memory. + + aio_mlockall IO::AIO::MCL_FUTURE; + aio_group $callback->(...) This is a very special aio request: Instead of doing something, it is a container for other aio requests, which is useful if you want @@ -1132,7 +1176,7 @@ Returns the number of bytes copied, or -1 on error. IO::AIO::fadvise $fh, $offset, $len, $advice - Simply calls the "posix_fadvise" function (see it's manpage for + Simply calls the "posix_fadvise" function (see its manpage for details). The following advice constants are avaiable: "IO::AIO::FADV_NORMAL", "IO::AIO::FADV_SEQUENTIAL", "IO::AIO::FADV_RANDOM", "IO::AIO::FADV_NOREUSE", @@ -1141,6 +1185,25 @@ On systems that do not implement "posix_fadvise", this function returns ENOSYS, otherwise the return value of "posix_fadvise". + IO::AIO::madvise $scalar, $offset, $len, $advice + Simply calls the "posix_madvise" function (see its manpage for + details). The following advice constants are avaiable: + "IO::AIO::MADV_NORMAL", "IO::AIO::MADV_SEQUENTIAL", + "IO::AIO::MADV_RANDOM", "IO::AIO::MADV_WILLNEED", + "IO::AIO::MADV_DONTNEED". + + On systems that do not implement "posix_madvise", this function + returns ENOSYS, otherwise the return value of "posix_madvise". + + IO::AIO::mprotect $scalar, $offset, $len, $protect + Simply calls the "mprotect" function on the preferably AIO::mmap'ed + $scalar (see its manpage for details). The following protect + constants are avaiable: "IO::AIO::PROT_NONE", "IO::AIO::PROT_READ", + "IO::AIO::PROT_WRITE", "IO::AIO::PROT_EXEC". + + On systems that do not implement "mprotect", this function returns + ENOSYS, otherwise the return value of "mprotect". + IO::AIO::mmap $scalar, $length, $prot, $flags, $fh[, $offset] Memory-maps a file (or anonymous memory range) and attaches it to the given $scalar, which will act like a string scalar. @@ -1194,12 +1257,9 @@ IO::AIO::munmap $scalar Removes a previous mmap and undefines the $scalar. - IO::AIO::mlockall $flags - Calls the "mlockall" function with the given $flags (a combination - of "IO::AIO::MCL_CURRENT" and "IO::AIO::MCL__FUTURE"). - - On systems that do not implement "mlockall", this function returns - ENOSYS, otherwise the return value of "mlockall". + IO::AIO::munlock $scalar, $offset = 0, $length = undef + Calls the "munlock" function, undoing the effects of a previous + "aio_mlock" call (see its description for details). IO::AIO::munlockall Calls the "munlockall" function.