From: GOTO Masanori <gotom@debian.org>
To: Suresh Gopalakrishnan <gsuresh@cs.rutgers.edu>
Cc: linux-kernel@vger.kernel.org, marcelo@conectiva.com.br,
torvalds@transmeta.com, gotom@debian.org
Subject: Re: O_DIRECT wierd behavior..
Date: Sun, 16 Dec 2001 15:29:40 +0900 [thread overview]
Message-ID: <wtwk7vn8yp7.wl@fe.dis.titech.ac.jp> (raw)
In-Reply-To: <Pine.GSO.4.02A.10112151947010.14453-100000@aramis.rutgers.edu>
In-Reply-To: <Pine.GSO.4.02A.10112151947010.14453-100000@aramis.rutgers.edu>
Hi,
At Sat, 15 Dec 2001 19:47:46 -0500 (EST),
Suresh Gopalakrishnan wrote:
> I tried this small piece of code from an old post in the archive:
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <fcntl.h>
> #include <sys/stat.h>
> #include <sys/types.h>
> #include <unistd.h>
>
> #define O_DIRECT 040000 /* direct disk access hint */
>
> int main()
> {
> char buf[16384];
> int fd;
> char *p;
>
> p = (char *)((((unsigned long)buf) + 8191) & ~8191L);
> fd = open("/tmp/blah", O_CREAT | O_RDWR | O_DIRECT);
>
> printf("write returns %i\n", write(fd, buf, 8192));
> printf("write returns %i\n", write(fd, p, 1));
>
> return 0;
> }
>
> Output is:
>
> write returns -1
> Filesize limit exceeded (core dumped)
>
> $ ls -l /tmp/blah
> ---------- 1 gsuresh users 4294967274 Dec 15 19:15 /tmp/blah
>
> The kernel is 2.4.16 and /tmp is ext2. (It runs fine on 2.4.2).
>
> Any idea why this happens and how to fix this?
Hmm, kernel 2.4.17-rc1 also has this problem.
The reason of this problem is that written is defined as unsigned long
currently, so if generic_file_direct_IO returns -EINVAL, then written
is translated as (unsigned long)(-EINVAL) = (0x100000000-EINVAL). Thus
the file size changed such a big value!
This patch fixes it.
--- linux-2.4.17-rc1.vanilla/mm/filemap.c Sun Dec 16 14:57:42 2001
+++ linux-2.4.17-rc1/mm/filemap.c Sun Dec 16 15:02:10 2001
@@ -2854,7 +2854,7 @@
unsigned long limit = current->rlim[RLIMIT_FSIZE].rlim_cur;
loff_t pos;
struct page *page, *cached_page;
- unsigned long written;
+ ssize_t written;
long status = 0;
int err;
unsigned bytes;
This problem breaks file inode size with direct IO... we lost the
correct file inode size forever. It's serious. Linus and Marcelo,
please consider to apply this patch?
However, your program does not work yet. Try my test program. It
works well because valloc()/memalign() allocates aligned page
boundary.
But, my interest is that why we cannot access with stack memory or
malloc()-ed memory. I heard Suresh's program works fine on 2.4.2, but
it does not work on 2.4.17-rc1. Should we modify the kernel to work
well with user stack/heap memory when we use direct IO for the file ?
Or, this behavior is absolutely correct ?
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#define O_DIRECT 040000 /* direct disk access hint */
int main()
{
char *buf;
int fd;
buf = valloc(16384);
fd = open("/tmp/blah", O_CREAT | O_RDWR | O_DIRECT, 0755 );
printf("write returns %i\n", write(fd, buf, 4096));
return 0;
}
-- gotom
next prev parent reply other threads:[~2001-12-16 6:30 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-12-16 0:47 Suresh Gopalakrishnan
2001-12-16 5:59 ` Andrew Morton
2001-12-16 6:29 ` GOTO Masanori [this message]
2001-12-16 8:17 ` GOTO Masanori
2001-12-16 8:46 ` Andrew Morton
2001-12-16 9:20 ` Suresh Gopalakrishnan
2001-12-16 13:57 ` Terje Eggestad
2001-12-16 17:43 ` Suresh Gopalakrishnan
2001-12-17 9:04 ` Terje Eggestad
2001-12-17 17:18 ` Andrea Arcangeli
2001-12-17 18:07 ` Hugh Dickins
2001-12-17 18:13 ` Andrea Arcangeli
2001-12-17 18:57 ` Andrew Morton
2001-12-17 19:26 ` Linus Torvalds
2001-12-17 19:53 ` Joel Becker
2001-12-17 19:59 ` Linus Torvalds
2001-12-17 20:20 ` Joel Becker
2001-12-17 20:38 ` Andre Hedrick
2001-12-26 14:54 ` Riley Williams
2002-01-20 4:16 ` multithreaded RPC handling Suresh Gopalakrishnan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=wtwk7vn8yp7.wl@fe.dis.titech.ac.jp \
--to=gotom@debian.org \
--cc=gsuresh@cs.rutgers.edu \
--cc=linux-kernel@vger.kernel.org \
--cc=marcelo@conectiva.com.br \
--cc=torvalds@transmeta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®