* using O_DIRECT
[not found] ` <20010903180524.Q699@athlon.random>
@ 2001-09-03 20:13 ` Bob McElrath
2001-09-03 22:09 ` Andrea Arcangeli
0 siblings, 1 reply; 4+ messages in thread
From: Bob McElrath @ 2001-09-03 20:13 UTC (permalink / raw)
To: Andrea Arcangeli; +Cc: linux-kernel
[-- Attachment #1.1: Type: text/plain, Size: 2273 bytes --]
I have written a small program to use O_DIRECT (attached), after
applying your patch o_direct-14 to kernel 2.4.9. Opening the file with
O_DIRECT is successful, but attempts to write to the fd return EINVAL.
Am I doing something wrong? Should I have to recompile glibc too?
(0)<root@draal:/usr/src/mjpeg_play> gcc -o testopen testopen.c
(0)<root@draal:/usr/src/mjpeg_play> strace ./testopen > /dev/null
execve("./testopen", ["./testopen"], [/* 54 vars */]) = 0
uname({sys="Linux", node="draal.physics.wisc.edu", ...}) = 0
brk(0) = 0x120010d90
open("/etc/ld.so.preload", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=62527, ...}) = 0
mmap(NULL, 62527, PROT_READ, MAP_PRIVATE, 3, 0) = 0x20000030000
close(3) = 0
open("/lib/libc.so.6.1", O_RDONLY) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0&\220\1\0\0\0`\201\3"..., 1024) = 1024
fstat(3, {st_mode=S_IFREG|0755, st_size=9653762, ...}) = 0
mmap(NULL, 1558648, PROT_READ|PROT_EXEC, MAP_PRIVATE, 3, 0) = 0x20000040000
mprotect(0x2000019a000, 141432, PROT_NONE) = 0
mmap(0x200001a0000, 98304, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0x150000) = 0x200001a0000
mmap(0x200001b8000, 18552, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x200001b8000
close(3) = 0
munmap(0x20000030000, 62527) = 0
getxpid() = 2387
open("testopen.txt", O_RDWR|O_CREAT|O_SYNC|0x100000, 0644) = 3
fstat(1, {st_mode=S_IFCHR|0666, st_rdev=makedev(1, 3), ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x2000001e000
ioctl(1, TCGETS, 0x11fffea50) = -1 ENOTTY (Inappropriate ioctl for device)
write(3, "Welcome to the winter of my disc"..., 40) = -1 EINVAL (Invalid argument)
close(3) = 0
write(1, "Got fd 3.\nUnable to write to fil"..., 77) = 77
munmap(0x2000001e000, 8192) = 0
exit(0) = ?
Cheers,
-- Bob
Bob McElrath (rsmcelrath@students.wisc.edu)
Univ. of Wisconsin at Madison, Department of Physics
[-- Attachment #1.2: testopen.c --]
[-- Type: text/plain, Size: 934 bytes --]
/* Test opening of a file with O_DIRECT */
#include <asm/types.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/types.h>
#include <asm/fcntl.h> /* Note: <fcntl.h> DOES NOT HAVE O_DIRECT! */
/* <fcntl.h> is a glibc header... */
#include <errno.h>
#include <stdio.h>
int main(void) {
char message[] = "Welcome to the winter of my discontent.\n";
int fd = open("testopen.txt", O_RDWR|O_CREAT|O_SYNC|O_DIRECT, S_IRUSR|S_IRGRP|S_IROTH|S_IWUSR);
int len;
if(fd < 0) {
printf("Unable to open file, errno is %d.\n", errno);
} else {
printf("Got fd %d.\n", fd);
if((len = write(fd, message, strlen(message))) < 0) {
printf("Unable to write to file, len is %d, errno is %d.\n", len, errno);
} else {
printf("%d bytes written to file.\n", len);
}
}
close(fd);
printf("End of program...\n");
return 0;
}
[-- Attachment #2: Type: application/pgp-signature, Size: 240 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: using O_DIRECT
2001-09-03 20:13 ` using O_DIRECT Bob McElrath
@ 2001-09-03 22:09 ` Andrea Arcangeli
2001-09-04 8:32 ` Bob McElrath
0 siblings, 1 reply; 4+ messages in thread
From: Andrea Arcangeli @ 2001-09-03 22:09 UTC (permalink / raw)
To: Bob McElrath; +Cc: linux-kernel
On Mon, Sep 03, 2001 at 03:13:42PM -0500, Bob McElrath wrote:
> I have written a small program to use O_DIRECT (attached), after
> applying your patch o_direct-14 to kernel 2.4.9. Opening the file with
> O_DIRECT is successful, but attempts to write to the fd return EINVAL.
>
> Am I doing something wrong? Should I have to recompile glibc too?
eh, the alignment and size of the buffer have basically the same
restrictions of running read/write on a raw device, with the only
difference that for rawio the granularity is the hardblocksize, while
for O_DIRECT the granularity is the softblocksize of the filesystem.
We'll have to relax the granularity of the I/O down to the hardblocksize
for O_DIRECT too eventually.
Andrea
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: using O_DIRECT
2001-09-04 8:32 ` Bob McElrath
@ 2001-09-03 22:37 ` Andrea Arcangeli
0 siblings, 0 replies; 4+ messages in thread
From: Andrea Arcangeli @ 2001-09-03 22:37 UTC (permalink / raw)
To: Bob McElrath; +Cc: linux-kernel
On Tue, Sep 04, 2001 at 03:32:43AM -0500, Bob McElrath wrote:
> I don't really care about the granularity. The bigger the better,
> actually, since I'm streaming data to disk quickly. ;)
Yes ;).
Andrea
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: using O_DIRECT
2001-09-03 22:09 ` Andrea Arcangeli
@ 2001-09-04 8:32 ` Bob McElrath
2001-09-03 22:37 ` Andrea Arcangeli
0 siblings, 1 reply; 4+ messages in thread
From: Bob McElrath @ 2001-09-04 8:32 UTC (permalink / raw)
To: Andrea Arcangeli; +Cc: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1143 bytes --]
Andrea Arcangeli [andrea@suse.de] wrote:
> On Mon, Sep 03, 2001 at 03:13:42PM -0500, Bob McElrath wrote:
> > I have written a small program to use O_DIRECT (attached), after
> > applying your patch o_direct-14 to kernel 2.4.9. Opening the file with
> > O_DIRECT is successful, but attempts to write to the fd return EINVAL.
> >
> > Am I doing something wrong? Should I have to recompile glibc too?
>
> eh, the alignment and size of the buffer have basically the same
> restrictions of running read/write on a raw device, with the only
> difference that for rawio the granularity is the hardblocksize, while
> for O_DIRECT the granularity is the softblocksize of the filesystem.
Ah, thanks, it's working now. Makes sense that it should use blocksize
granularity...
> We'll have to relax the granularity of the I/O down to the hardblocksize
> for O_DIRECT too eventually.
I don't really care about the granularity. The bigger the better,
actually, since I'm streaming data to disk quickly. ;)
Thanks,
-- Bob
Bob McElrath (rsmcelrath@students.wisc.edu)
Univ. of Wisconsin at Madison, Department of Physics
[-- Attachment #2: Type: application/pgp-signature, Size: 240 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2001-09-03 22:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20010903104544.X23180@draal.physics.wisc.edu>
[not found] ` <20010903175333.P699@athlon.random>
[not found] ` <20010903105714.Y23180@draal.physics.wisc.edu>
[not found] ` <20010903180524.Q699@athlon.random>
2001-09-03 20:13 ` using O_DIRECT Bob McElrath
2001-09-03 22:09 ` Andrea Arcangeli
2001-09-04 8:32 ` Bob McElrath
2001-09-03 22:37 ` Andrea Arcangeli
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox