ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/AIO.pm
(Generate patch)

Comparing IO-AIO/AIO.pm (file contents):
Revision 1.310 by root, Wed Dec 30 07:45:32 2020 UTC vs.
Revision 1.314 by root, Sat Apr 9 19:34:05 2022 UTC

171use common::sense; 171use common::sense;
172 172
173use base 'Exporter'; 173use base 'Exporter';
174 174
175BEGIN { 175BEGIN {
176 our $VERSION = 4.75; 176 our $VERSION = 4.76;
177 177
178 our @AIO_REQ = qw(aio_sendfile aio_seek aio_read aio_write aio_open aio_close 178 our @AIO_REQ = qw(aio_sendfile aio_seek aio_read aio_write aio_open aio_close
179 aio_stat aio_lstat aio_unlink aio_rmdir aio_readdir aio_readdirx 179 aio_stat aio_lstat aio_unlink aio_rmdir aio_readdir aio_readdirx
180 aio_scandir aio_symlink aio_readlink aio_realpath aio_fcntl aio_ioctl 180 aio_scandir aio_symlink aio_readlink aio_realpath aio_fcntl aio_ioctl
181 aio_sync aio_fsync aio_syncfs aio_fdatasync aio_sync_file_range 181 aio_sync aio_fsync aio_syncfs aio_fdatasync aio_sync_file_range
2061longer exceeded. 2061longer exceeded.
2062 2062
2063In other words, this setting does not enforce a queue limit, but can be 2063In other words, this setting does not enforce a queue limit, but can be
2064used to make poll functions block if the limit is exceeded. 2064used to make poll functions block if the limit is exceeded.
2065 2065
2066This is a very bad function to use in interactive programs because it 2066This is a bad function to use in interactive programs because it blocks,
2067blocks, and a bad way to reduce concurrency because it is inexact: Better 2067and a bad way to reduce concurrency because it is inexact. If you need to
2068issue many requests without being able to call a poll function on demand,
2068use an C<aio_group> together with a feed callback. 2069it is better to use an C<aio_group> together with a feed callback.
2069 2070
2070Its main use is in scripts without an event loop - when you want to stat 2071Its main use is in scripts without an event loop - when you want to stat a
2071a lot of files, you can write something like this: 2072lot of files, you can write something like this:
2072 2073
2073 IO::AIO::max_outstanding 32; 2074 IO::AIO::max_outstanding 32;
2074 2075
2075 for my $path (...) { 2076 for my $path (...) {
2076 aio_stat $path , ...; 2077 aio_stat $path , ...;
2077 IO::AIO::poll_cb; 2078 IO::AIO::poll_cb;
2078 } 2079 }
2079 2080
2080 IO::AIO::flush; 2081 IO::AIO::flush;
2081 2082
2082The call to C<poll_cb> inside the loop will normally return instantly, but 2083The call to C<poll_cb> inside the loop will normally return instantly,
2083as soon as more thna C<32> reqeusts are in-flight, it will block until 2084allowing the loop to progress, but as soon as more than C<32> requests
2084some requests have been handled. This keeps the loop from pushing a large 2085are in-flight, it will block until some requests have been handled. This
2085number of C<aio_stat> requests onto the queue. 2086keeps the loop from pushing a large number of C<aio_stat> requests onto
2087the queue (which, with many paths to stat, can use up a lot of memory).
2086 2088
2087The default value for C<max_outstanding> is very large, so there is no 2089The default value for C<max_outstanding> is very large, so there is no
2088practical limit on the number of outstanding requests. 2090practical limit on the number of outstanding requests.
2089 2091
2090=back 2092=back
2329C<IO::AIO::MAP_POPULATE>, 2331C<IO::AIO::MAP_POPULATE>,
2330C<IO::AIO::MAP_NONBLOCK>, 2332C<IO::AIO::MAP_NONBLOCK>,
2331C<IO::AIO::MAP_FIXED>, 2333C<IO::AIO::MAP_FIXED>,
2332C<IO::AIO::MAP_GROWSDOWN>, 2334C<IO::AIO::MAP_GROWSDOWN>,
2333C<IO::AIO::MAP_32BIT>, 2335C<IO::AIO::MAP_32BIT>,
2334C<IO::AIO::MAP_HUGETLB> or 2336C<IO::AIO::MAP_HUGETLB>,
2335C<IO::AIO::MAP_STACK>. 2337C<IO::AIO::MAP_STACK>,
2338C<IO::AIO::MAP_FIXED_NOREPLACE>,
2339C<IO::AIO::MAP_SHARED_VALIDATE>,
2340C<IO::AIO::MAP_SYNC> or
2341C<IO::AIO::MAP_UNINITIALIZED>.
2336 2342
2337If C<$fh> is C<undef>, then a file descriptor of C<-1> is passed. 2343If C<$fh> is C<undef>, then a file descriptor of C<-1> is passed.
2338 2344
2339C<$offset> is the offset from the start of the file - it generally must be 2345C<$offset> is the offset from the start of the file - it generally must be
2340a multiple of C<IO::AIO::PAGESIZE> and defaults to C<0>. 2346a multiple of C<IO::AIO::PAGESIZE> and defaults to C<0>.
2479C<undef>. If the memfd_create syscall is missing, fails with C<ENOSYS>. 2485C<undef>. If the memfd_create syscall is missing, fails with C<ENOSYS>.
2480 2486
2481Please refer to L<memfd_create(2)> for more info on this call. 2487Please refer to L<memfd_create(2)> for more info on this call.
2482 2488
2483The following C<$flags> values are available: C<IO::AIO::MFD_CLOEXEC>, 2489The following C<$flags> values are available: C<IO::AIO::MFD_CLOEXEC>,
2484C<IO::AIO::MFD_ALLOW_SEALING> and C<IO::AIO::MFD_HUGETLB>. 2490C<IO::AIO::MFD_ALLOW_SEALING>, C<IO::AIO::MFD_HUGETLB>,
2491C<IO::AIO::MFD_HUGETLB_2MB> and C<IO::AIO::MFD_HUGETLB_1GB>.
2485 2492
2486Example: create a new memfd. 2493Example: create a new memfd.
2487 2494
2488 my $fh = IO::AIO::memfd_create "somenameforprocfd", IO::AIO::MFD_CLOEXEC 2495 my $fh = IO::AIO::memfd_create "somenameforprocfd", IO::AIO::MFD_CLOEXEC
2489 or die "memfd_create: $!\n"; 2496 or die "memfd_create: $!\n";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines