-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reference for nonblocking epoll on regular files #2
Comments
I tried with this code #include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char const *argv[])
{
if (argc != 2)
{
fprintf(stderr, "Usage: %s FILENAME\n", argv[0]);
exit(1);
}
const char* filename = argv[1];
int fd = open(filename, O_NONBLOCK);
if (fd == -1)
{
perror(filename);
exit(1);
}
const size_t bufsize = 1000000000;
char* buf = malloc(bufsize); // 1 GB
if (buf == NULL)
{
perror("malloc");
exit(1);
}
ssize_t n = read(fd, buf, bufsize);
if (n == -1)
{
printf("errno is EAGAIN: %d\n", errno == EAGAIN);
}
else
{
printf("read %ld bytes\n", n);
}
return 0;
} (Compiled with When run on a 15 GB file on my slow spinning disk like Am I missing something? |
Maybe I am remembering wrong, but IIRC this depends on filesystem support. Did you try on a raw block device? |
@littledan I have now tried it on a raw block device (just a primary partition on my disk) with #define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char const *argv[])
{
if (argc != 2)
{
fprintf(stderr, "Usage: %s FILENAME\n", argv[0]);
exit(1);
}
const char* filename = argv[1];
// int fd = open(filename, O_NONBLOCK | O_DIRECT);
int fd = open(filename, O_NONBLOCK);
if (fd == -1)
{
perror(filename);
exit(1);
}
const size_t bufsize = 1024LU * 1024LU * 1024LU;
char* buf = aligned_alloc(512, bufsize); // 1 GiB
if (buf == NULL)
{
perror("malloc");
exit(1);
}
while (1)
{
ssize_t n = read(fd, buf, bufsize);
if (n == -1)
{
if (errno != EAGAIN)
{
perror(filename);
break;
}
printf("errno is EAGAIN\n");
}
else
{
printf("read %ld bytes\n", n);
break;
}
}
return 0;
} But no matter whether I gave Note I had to change the So even with working on a raw block device, I couldn't manage to make an asynchronous read. |
Sorry about the misdirection. Interested in making a PR to fix the article? |
Does an body know, are there any plans to add kernel support for async files? Found out, that FreeBSD supports it :-( |
@Mart-Bogdan that is a complicated and loaded question. The Linux kernel does support async I/O via |
This article is the only one I saw which says epoll supports regular file (or limited support). So I investigated and read a lot of other blogs until I found this discussion... |
After some investigation, found that: the Like this |
Do you have a reference for that, or source code pointer?
Most locations discussing epoll on regular files (such as [1] [2] [3]) simply summarise with "epoll will always block on regular files".
It would be great to be able to extend them with this detail.
Even https://groups.google.com/forum/#!topic/comp.os.linux.development.system/K-fC-G6P4EA doesn't seem to discuss this (maybe this was written before what you stated was implemented? it would be great to know).
The text was updated successfully, but these errors were encountered: