I've written a C program that creates a 20GB file using O_DIRECT and O_ASYNC correctly. The trick to write to a file using O_DIRECT is that I have to align the buffer with respect to the memory block size.
When I write a similar program using Perl, I receive the expected "System write error: Invalid argument" as the buffer is not aligned.
So, my question is: Is it possible, in Perl, to align the buffer?
#!/usr/bin/perl use strict; use warnings; $|++; use Fcntl qw(:DEFAULT O_ASYNC O_DIRECT); my $FH; sysopen($FH, "./test.dat", O_WRONLY | O_TRUNC | O_CREAT | O_ASYNC | O_ +DIRECT, 0666); my $BUFFER = "0"x1048576; my $BUFSIZE = 1048576; for (my $i = 0; $i < 20480; $i++) { my $written = syswrite($FH, $BUFFER, $BUFSIZE); die "System write error: $!\n" unless defined $written; }
In reply to O_DIRECT & O_ASYNC, Linux & Perl by jfroebe
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |