--- IO-AIO/AIO.pm 2010/01/10 23:10:58 1.178 +++ IO-AIO/AIO.pm 2010/11/01 22:03:43 1.184 @@ -6,7 +6,7 @@ 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: $!"; ... @@ -78,7 +78,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: $!"; @@ -170,7 +170,7 @@ use base 'Exporter'; BEGIN { - our $VERSION = '3.6'; + our $VERSION = '3.7'; our @AIO_REQ = qw(aio_sendfile aio_read aio_write aio_open aio_close aio_stat aio_lstat aio_unlink aio_rmdir aio_readdir aio_readdirx @@ -179,14 +179,16 @@ aio_rename aio_link aio_move aio_copy aio_group aio_nop aio_mknod aio_load aio_rmtree aio_mkdir aio_chown aio_chmod aio_utime aio_truncate - aio_msync aio_mtouch aio_statvfs); + aio_msync aio_mtouch aio_mlock aio_mlockall + aio_statvfs); our @EXPORT = (@AIO_REQ, qw(aioreq_pri aioreq_nice)); our @EXPORT_OK = qw(poll_fileno poll_cb poll_wait flush min_parallel max_parallel max_idle nreqs nready npending nthreads max_poll_time max_poll_reqs - sendfile fadvise); + sendfile fadvise madvise + mmap munmap munlock munlockall); push @AIO_REQ, qw(aio_busy); # not exported @@ -241,6 +243,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->() @@ -263,7 +267,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 =head2 AIO REQUEST FUNCTIONS @@ -354,7 +360,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"; ... @@ -1110,6 +1116,45 @@ C, which modifies the memory page s(by reading and writing an octet from it, which dirties the page). +=item 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 C<$length> is undefined, then the scalar will be locked till the end. + +On systems that do not implement C, this function returns C<-1> +and sets errno to C. + +Note that the corresponding C is synchronous and is +documented under L. + +Example: open a file, mmap and mlock it - both will be undone when +C<$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 + +=item aio_mlockall $flags, $callback->($status) + +Calls the C function with the given C<$flags> (a combination of +C and C). + +On systems that do not implement C, this function returns C<-1> +and sets errno to C. + +Note that the corresponding C is synchronous and is +documented under L. + +Example: asynchronously lock all current and future pages into memory. + + aio_mlockall IO::AIO::MCL_FUTURE; + =item aio_group $callback->(...) This is a very special aio request: Instead of doing something, it is a @@ -1539,7 +1584,7 @@ =item IO::AIO::fadvise $fh, $offset, $len, $advice -Simply calls the C function (see it's +Simply calls the C function (see its manpage for details). The following advice constants are avaiable: C, C, C, C, @@ -1548,6 +1593,26 @@ On systems that do not implement C, this function returns ENOSYS, otherwise the return value of C. +=item IO::AIO::madvise $scalar, $offset, $len, $advice + +Simply calls the C function (see its +manpage for details). The following advice constants are +avaiable: C, C, +C, C, C. + +On systems that do not implement C, this function returns +ENOSYS, otherwise the return value of C. + +=item IO::AIO::mprotect $scalar, $offset, $len, $protect + +Simply calls the C function on the preferably AIO::mmap'ed +$scalar (see its manpage for details). The following protect +constants are avaiable: C, C, +C, C. + +On systems that do not implement C, this function returns +ENOSYS, otherwise the return value of C. + =item IO::AIO::mmap $scalar, $length, $prot, $flags, $fh[, $offset] Memory-maps a file (or anonymous memory range) and attaches it to the @@ -1582,6 +1647,9 @@ If C<$fh> is C, then a file descriptor of C<-1> is passed. +C<$offset> is the offset from the start of the file - it generally must be +a multiple of C and defaults to C<0>. + Example: use Digest::MD5; @@ -1599,13 +1667,10 @@ Removes a previous mmap and undefines the C<$scalar>. -=item IO::AIO::mlockall $flags - -Calls the C function with the given C<$flags> (a combination of -C and C). +=item IO::AIO::munlock $scalar, $offset = 0, $length = undef -On systems that do not implement C, this function returns -ENOSYS, otherwise the return value of C. +Calls the C function, undoing the effects of a previous +C call (see its description for details). =item IO::AIO::munlockall