public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* A problem about DIRECT IO on ext3
@ 2005-08-29 12:15 colin
  2005-08-29 13:29 ` Erik Mouw
  0 siblings, 1 reply; 15+ messages in thread
From: colin @ 2005-08-29 12:15 UTC (permalink / raw)
  To: linux-kernel


Hi all,
I wrote a simple program to test direct io, and found that there are some
strange behaviors of it on "ext3".
My simple program is below. Assume that the executable file name is
"directio". If I do the following:
    1. cp directio aaa
    2. ./directio directio aaa

The size of aaa is about the same with directio. This is wrong.
It should be 3 times the size of directio because there are 2 write
operations and one lseek to the file end.

If the second file is not opened with "O_DIRECT", the result is correct.

What's the problem of direct io? I found that if I remove the instruction of
lseek, the result is correct.
Is there any problem of lseek when doing direct io on ext3?
My platform is 2.6.11.

Regards,
Colin








#define _GNU_SOURCE

#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdlib.h>


int main(int argc, char **argv) {

int fd1, fd2, count;
char *ptr1, *ptr2;

if(argc == 3) {
  fd1 = open(argv[1], O_RDONLY | O_DIRECT, S_IRWXU);
  fd2 = open(argv[2], O_RDWR | O_CREAT | O_DIRECT);
} else {
  printf("Error syntax\n");
  exit(1);
}
printf("%d\n", lseek(fd2, 0, SEEK_END));

ptr1 = malloc(4096 + 4096-1);
ptr2 = (void*)((int)ptr1 - (int)ptr1 % 4096 + 4096);

do {
  count = read(fd1, ptr2, 4096);
  if(!count)
    break;
  write(fd2, ptr2, 4096);
  write(fd2, ptr2, 4096);
} while(count > 0);

free(ptr1);
close(fd1);
close(fd2);
}






^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: A problem about DIRECT IO on ext3
@ 2005-08-29 13:21 colin
  0 siblings, 0 replies; 15+ messages in thread
From: colin @ 2005-08-29 13:21 UTC (permalink / raw)
  To: linux-kernel


Hi all,
Sorry, ignore this mail.
I found that I didn't align the block size when doing direct io...  :-(

Regards,
Colin


----- Original Message ----- 
From: "colin" <colin@realtek.com.tw>
To: <linux-kernel@vger.kernel.org>
Sent: Monday, August 29, 2005 8:15 PM
Subject: A problem about DIRECT IO on ext3


>
> Hi all,
> I wrote a simple program to test direct io, and found that there are some
> strange behaviors of it on "ext3".
> My simple program is below. Assume that the executable file name is
> "directio". If I do the following:
>     1. cp directio aaa
>     2. ./directio directio aaa
>
> The size of aaa is about the same with directio. This is wrong.
> It should be 3 times the size of directio because there are 2 write
> operations and one lseek to the file end.
>
> If the second file is not opened with "O_DIRECT", the result is correct.
>
> What's the problem of direct io? I found that if I remove the instruction
of
> lseek, the result is correct.
> Is there any problem of lseek when doing direct io on ext3?
> My platform is 2.6.11.
>
> Regards,
> Colin
>
>
>
>
>
>
>
>
> #define _GNU_SOURCE
>
> #include <stdio.h>
> #include <fcntl.h>
> #include <sys/stat.h>
> #include <sys/types.h>
> #include <stdlib.h>
>
>
> int main(int argc, char **argv) {
>
> int fd1, fd2, count;
> char *ptr1, *ptr2;
>
> if(argc == 3) {
>   fd1 = open(argv[1], O_RDONLY | O_DIRECT, S_IRWXU);
>   fd2 = open(argv[2], O_RDWR | O_CREAT | O_DIRECT);
> } else {
>   printf("Error syntax\n");
>   exit(1);
> }
> printf("%d\n", lseek(fd2, 0, SEEK_END));
>
> ptr1 = malloc(4096 + 4096-1);
> ptr2 = (void*)((int)ptr1 - (int)ptr1 % 4096 + 4096);
>
> do {
>   count = read(fd1, ptr2, 4096);
>   if(!count)
>     break;
>   write(fd2, ptr2, 4096);
>   write(fd2, ptr2, 4096);
> } while(count > 0);
>
> free(ptr1);
> close(fd1);
> close(fd2);
> }
>
>
>
>
>


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2005-10-17 17:52 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-08-29 12:15 A problem about DIRECT IO on ext3 colin
2005-08-29 13:29 ` Erik Mouw
2005-08-31  8:07   ` Jens Axboe
2005-08-31 11:12     ` Erik Mouw
2005-08-31 11:15       ` Jens Axboe
2005-10-17  8:52     ` li nux
2005-10-17  8:58       ` li nux
2005-10-17  9:03       ` Jens Axboe
2005-10-17  9:15         ` Grzegorz Kulewski
2005-10-17  9:17           ` Jens Axboe
2005-10-17  9:41             ` li nux
2005-10-17  9:51               ` Jens Axboe
2005-10-17 16:36                 ` Badari Pulavarty
2005-10-17 17:53                   ` Jens Axboe
  -- strict thread matches above, loose matches on Subject: below --
2005-08-29 13:21 colin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox