Skip to contentSkip to conversation

O_DIRECT

DISCUSSION Shesha Sreenivasamurthy 6 participants 17 messages Jul 20, 2004 – Jul 26, 2004 4 messages not in the archive

lore
Share & tools
lore
#0 lore raw

I am having trouble with O_DIRECT. Trying to read or write from a block device partition.

1. Can O_DIRECT be used on a plain block device partition say "/dev/sda11" without having a filesystem on it.

2. If no file system is created then what should be the softblock size. I am using the IOCTL "BLKBSZGET". Is this correct?

3. Can we use SEEK_END with O_DIRECT on a partition without filesystem.

Any help will be highly regarded.

-Shesha

#1 lore raw
Quoted 5 lines · Shesha Sreenivasamurthy

I am having trouble with O_DIRECT. Trying to read or write from a block device partition.

1. Can O_DIRECT be used on a plain block device partition say "/dev/sda11" without having a filesystem on it.

As fas as I know, yes, but be aware that O_DIRECT requires page aligned addresses! (an integral of 4096 on most systems).

Quoted 2 lines

2. If no file system is created then what should be the softblock size. I am using the IOCTL "BLKBSZGET". Is this correct?

No idea what you mean - but see above about the aligned addresses.

Quoted 1 line

3. Can we use SEEK_END with O_DIRECT on a partition without filesystem.

I see no reason why not. Good luck!

Signature · 2 lines
http://www.PowerDNS.com      Open source, database driven DNS Software 
http://lartc.org           Linux Advanced Routing & Traffic Control HOWTO

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
Quoted 5 lines · Shesha Sreenivasamurthy

Thank you very much Hubert.

Regarding my second question, what I mean is, to calculate the soft block size of a partition on which there is no filesystem created, I am using the IOCTL "BLKBSZGET".

Sure - but what do you need this blocksize for?

Signature · 2 lines
http://www.PowerDNS.com      Open source, database driven DNS Software 
http://lartc.org           Linux Advanced Routing & Traffic Control HOWTO
#4 lore raw
In reply to bert hubert

On Tue, 20 Jul 2004 20:48:24 +0200
bert hubert <[email protected]> wrote:

Hi Bert,

Quoted 9 lines · Shesha Sreenivasamurthy
Quoted 5 lines

I am having trouble with O_DIRECT. Trying to read or write from a block device partition.

1. Can O_DIRECT be used on a plain block device partition say "/dev/sda11" without having a filesystem on it.

As fas as I know, yes, but be aware that O_DIRECT requires page aligned addresses! (an integral of 4096 on most systems).

"soft block size" aligned. The soft block size can be smaller than a page (but not bigger). There's a requirement for:

- r/w offset
- r/w size

greetings,
Rob van Nieuwkerk

#5 lore raw
In reply to bert hubert

Hi all,
how i can write data on a partition without a filesystem??

Saluti Carlo!

Il Tue, 20 Jul 2004 20:48:24 +0200
bert hubert <[email protected]> scrisse:

Quoted 28 lines · Shesha Sreenivasamurthy
Quoted 5 lines

I am having trouble with O_DIRECT. Trying to read or write from a block device partition.

1. Can O_DIRECT be used on a plain block device partition say "/dev/sda11" without having a filesystem on it.

As fas as I know, yes, but be aware that O_DIRECT requires page aligned addresses! (an integral of 4096 on most systems).

Quoted 2 lines

2. If no file system is created then what should be the softblock size. I am using the IOCTL "BLKBSZGET". Is this correct?

No idea what you mean - but see above about the aligned addresses.

Quoted 1 line

3. Can we use SEEK_END with O_DIRECT on a partition without filesystem.

I see no reason why not. Good luck!

Signature · 7 lines
http://www.PowerDNS.com      Open source, database driven DNS Software 
http://lartc.org           Linux Advanced Routing & Traffic Control HOWTO
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw

Thanks a lot for your answare.
So if i would write information on a partition without a fs i have to write additional information to "retrive" the first one. Do you know some readable material about o project about that?

Il Wed, 21 Jul 2004 09:52:15 -0700
Shesha Sreenivasamurthy <[email protected]> scrisse:

Quoted 76 lines

Usually what you do is, partition the disk, create filesystem and read or write files.
Reading and writing is without a filesystem.
Assume you have maintained some superblock information of your own
driver say last 512 bytes you have designated as superblock. You can seek to that position and read the last 512 bytes which is meaningful only to you. Note that I am read/writing raw bytes not any file. Therefore you can read/write without a filesystem and even without any partition,

-Shesha

Quoted 60 lines · Devel

Hi all,
how i can write data on a partition without a filesystem??

Saluti Carlo!

Il Tue, 20 Jul 2004 20:48:24 +0200
bert hubert <[email protected]> scrisse:

Quoted 19 lines · Shesha Sreenivasamurthy
Quoted 9 lines

I am having trouble with O_DIRECT. Trying to read or write from a block device partition.

1. Can O_DIRECT be used on a plain block device partition say "/dev/sda11" without having a filesystem on it.

As fas as I know, yes, but be aware that O_DIRECT requires page aligned addresses! (an integral of 4096 on most systems).

Quoted 4 lines

2. If no file system is created then what should be the softblock size. I am using the IOCTL "BLKBSZGET". Is this correct?

Quoted 20 lines

No idea what you mean - but see above about the aligned addresses.

Quoted 3 lines

3. Can we use SEEK_END with O_DIRECT on a partition without filesystem.

I see no reason why not. Good luck!

Signature · 7 lines
http://www.PowerDNS.com      Open source, database driven DNS Software 
http://lartc.org           Linux Advanced Routing & Traffic Control HOWTO
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

--

Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/

.

#8 lore raw
In reply to bert hubert
Quoted 9 lines · bert hubert
Quoted 5 lines · Shesha Sreenivasamurthy

I am having trouble with O_DIRECT. Trying to read or write from a block device partition.

1. Can O_DIRECT be used on a plain block device partition say "/dev/sda11" without having a filesystem on it.

As fas as I know, yes, but be aware that O_DIRECT requires page aligned addresses! (an integral of 4096 on most systems).

Agreed, and I can tell you it works with raw disk devices. The code we use is:

  p = malloc (blocksize + PAGE_SIZE);
  buf = (void *) ((  ((long)p) + PAGE_SIZE -1 ) & ~(PAGE_SIZE-1));

Roger.

Signature · 3 lines
** [email protected] ** http://www.BitWizard.nl/ ** +31-15-2600998 **
*-- BitWizard writes Linux device drivers for any device you may have! --*
**** "Linux is like a wigwam -  no windows, no gates, apache inside!" ****
#9 lore raw
Quoted 6 lines · Rogier Wolff

The code
we use is:

   p = malloc (blocksize + PAGE_SIZE);
   buf = (void *) ((  ((long)p) + PAGE_SIZE -1 ) & ~(PAGE_SIZE-1));

memalign() and posix_memalign() will do this for you.

#10 lore raw
In reply to Shesha Sreenivasamurthy

On Tue, 20 Jul 2004 10:27:57 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

Quoted 5 lines

I am having trouble with O_DIRECT. Trying to read or write from a block device partition.

1. Can O_DIRECT be used on a plain block device partition say "/dev/sda11" without having a filesystem on it.

yes.

Quoted 2 lines

2. If no file system is created then what should be the softblock size. I am using the IOCTL "BLKBSZGET". Is this correct?

yes.

Quoted 1 line

3. Can we use SEEK_END with O_DIRECT on a partition without filesystem.

yes.

I'm using these exact things in an application.

Note that with 2.4 kernels the "granularity" you can use for offset and r/w size is the softblock size (*). For 2.6 the requirements are much more relaxed: it's the device blocksize (typically 512 byte).

(*): actually one of offset or r/w size has a smaller minimum if I remember correctly. Don't remember which one. But if you assume the softblock size as a minimum for both you're allways safe.

greetings,
Rob van Nieuwkerk

A message that is not in the archive (sent off-list or not yet received): [email protected]

#12 lore raw

On Wed, 21 Jul 2004 10:10:26 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

You don't mention what the *size* of your read()/write() is. Besides a requirement on the alignment of the read/write buffer the size of the read()/write() must also be OK.

greetings,
Rob van Nieuwkerk

Quoted 76 lines

This is what I found ....

Our driver sets the block size to be 4096. so BLKBSZGET will return 4096. So if I allin the memory at 4096 boundary, I cannot read using O_DIRECT. But, if I set the block size to 512. I can read/write successfully. It also works with 1024, but no with 4096

So the recepie what I am following is ...

BLKBSZGET -> Get original block size
BLKBSZSET -> Set the block size to 512
READ | WRITE Successfully ;)
BLKBSZSET -> Set back to the original block size

-Shesha

Quoted 57 lines · Rob van Nieuwkerk

On Tue, 20 Jul 2004 10:27:57 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

Quoted 7 lines

I am having trouble with O_DIRECT. Trying to read or write from a block device partition.

1. Can O_DIRECT be used on a plain block device partition say "/dev/sda11" without having a filesystem on it.

yes.

Quoted 4 lines

2. If no file system is created then what should be the softblock size. I am using the IOCTL "BLKBSZGET". Is this correct?

yes.

Quoted 3 lines

3. Can we use SEEK_END with O_DIRECT on a partition without filesystem.

yes.

I'm using these exact things in an application.

Note that with 2.4 kernels the "granularity" you can use for offset and r/w size is the softblock size (*). For 2.6 the requirements are much more relaxed: it's the device blocksize (typically 512 byte).

(*): actually one of offset or r/w size has a smaller minimum if I remember correctly. Don't remember which one. But if you assume the softblock size as a minimum for both you're allways safe.

greetings,
Rob van Nieuwkerk

--

Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/

.

A message that is not in the archive (sent off-list or not yet received): [email protected]

#14 lore raw

On Wed, 21 Jul 2004 11:01:20 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

Quoted 3 lines

ohhh OK, if the block size is 4096, then the read/write size must be integer multiple of 4096 ??? is it ???
In general should the read/write length be a multiple of block size?

Yes, see my previous emails.

greetings,
Rob van Nieuwkerk

Quoted 116 lines
Quoted 113 lines · Rob van Nieuwkerk

On Wed, 21 Jul 2004 10:10:26 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

You don't mention what the *size* of your read()/write() is. Besides a requirement on the alignment of the read/write buffer the size of the read()/write() must also be OK.

greetings,
Rob van Nieuwkerk

Quoted 9 lines

This is what I found ....

Our driver sets the block size to be 4096. so BLKBSZGET will return 4096. So if I allin the memory at 4096 boundary, I cannot read using O_DIRECT. But, if I set the block size to 512. I can read/write successfully. It also works with 1024, but no with 4096

So the recepie what I am following is ...

Quoted 79 lines

BLKBSZGET -> Get original block size
BLKBSZSET -> Set the block size to 512
READ | WRITE Successfully ;)
BLKBSZSET -> Set back to the original block size

-Shesha

Quoted 68 lines · Rob van Nieuwkerk

On Tue, 20 Jul 2004 10:27:57 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

Quoted 9 lines

I am having trouble with O_DIRECT. Trying to read or write from a block device partition.

1. Can O_DIRECT be used on a plain block device partition say "/dev/sda11" without having a filesystem on it.

yes.

Quoted 6 lines

2. If no file system is created then what should be the softblock size. I am using the IOCTL "BLKBSZGET". Is this correct?

yes.

Quoted 5 lines

3. Can we use SEEK_END with O_DIRECT on a partition without filesystem.

yes.

I'm using these exact things in an application.

Note that with 2.4 kernels the "granularity" you can use for offset and r/w size is the softblock size (*). For 2.6 the requirements are much more relaxed: it's the device blocksize (typically 512 byte).

(*): actually one of offset or r/w size has a smaller minimum if I remember correctly. Don't remember which one. But if you assume the softblock size as a minimum for both you're allways safe.

greetings,
Rob van Nieuwkerk

--

Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/

.

--

Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/

.

#15 lore raw

Thank you very much ....
-Shesha

Quoted 160 lines · Rob van Nieuwkerk

On Wed, 21 Jul 2004 11:01:20 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

Quoted 4 lines

ohhh OK, if the block size is 4096, then the read/write size must be integer multiple of 4096 ??? is it ??? In general should the read/write length be a multiple of block size?

Yes, see my previous emails.

greetings,
Rob van Nieuwkerk

Quoted 124 lines
Quoted 120 lines · Rob van Nieuwkerk

On Wed, 21 Jul 2004 10:10:26 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

You don't mention what the *size* of your read()/write() is. Besides a requirement on the alignment of the read/write buffer the size of the read()/write() must also be OK.

greetings,
Rob van Nieuwkerk

Quoted 6 lines

This is what I found ....

Our driver sets the block size to be 4096. so BLKBSZGET will return 4096. So if I allin the memory at 4096 boundary, I cannot read using O_DIRECT. But, if I set the block size to 512. I can read/write successfully. It also works with 1024, but no with 4096

So the recepie what I am following is ...

Quoted 92 lines

BLKBSZGET -> Get original block size BLKBSZSET -> Set the block size to 512 READ | WRITE Successfully ;)
BLKBSZSET -> Set back to the original block size

-Shesha

Quoted 79 lines · Rob van Nieuwkerk

On Tue, 20 Jul 2004 10:27:57 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

Quoted 9 lines

I am having trouble with O_DIRECT. Trying to read or write from a block device partition.

1. Can O_DIRECT be used on a plain block device partition say "/dev/sda11" without having a filesystem on it.

yes.

Quoted 7 lines

2. If no file system is created then what should be the softblock size. I am using the IOCTL "BLKBSZGET". Is this correct?

yes.

Quoted 7 lines

3. Can we use SEEK_END with O_DIRECT on a partition without filesystem.

yes.

I'm using these exact things in an application.

Note that with 2.4 kernels the "granularity" you can use for offset and r/w size is the softblock size (*). For 2.6 the requirements are much more relaxed: it's the device blocksize (typically 512 byte).

(*): actually one of offset or r/w size has a smaller minimum if I remember correctly. Don't remember which one. But if you assume the softblock size as a minimum for both you're allways safe.

greetings,
Rob van Nieuwkerk

--

Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/

.

--

Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/
Quoted 6 lines
Quoted 6 lines

.

--

Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/

.

#16 lore raw
In reply to Rob van Nieuwkerk

I could never get it working with 4096 block size.

I created an EXT3 with blockize=4096 (mkfs.ext3 -b 4096 /dev/sda11). Alligned memory to 4096 boundary. Read 8192 Bytes. -> UNSUCCESSFUL :( I created an XFS with blockize=4096 (mkfs.xfs -f -b size=4096 /dev/sda11). Alligned memory to 4096 boundary. Read 8192 Bytes. -> UNSUCCESSFUL :(

SUCCESS HAPPEND ONLY WHEN ....

1. I created an XFS with blockize=4096 (mkfs.xfs -f -b size=4096 /dev/sda11). OR
I created an EXT3 with blockize=4096 (mkfs.ext3 -b 4096 /dev/sda11).

2. Changed blocksizeto 1024
3. Alligned memory to 1024 boundary.
4 Read 8192 Bytes. -> SUCCESSFUL :)

-Shesha

Quoted 160 lines · Rob van Nieuwkerk

On Wed, 21 Jul 2004 11:01:20 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

Quoted 4 lines

ohhh OK, if the block size is 4096, then the read/write size must be integer multiple of 4096 ??? is it ??? In general should the read/write length be a multiple of block size?

Yes, see my previous emails.

greetings,
Rob van Nieuwkerk

Quoted 124 lines
Quoted 120 lines · Rob van Nieuwkerk

On Wed, 21 Jul 2004 10:10:26 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

You don't mention what the *size* of your read()/write() is. Besides a requirement on the alignment of the read/write buffer the size of the read()/write() must also be OK.

greetings,
Rob van Nieuwkerk

Quoted 6 lines

This is what I found ....

Our driver sets the block size to be 4096. so BLKBSZGET will return 4096. So if I allin the memory at 4096 boundary, I cannot read using O_DIRECT. But, if I set the block size to 512. I can read/write successfully. It also works with 1024, but no with 4096

So the recepie what I am following is ...

Quoted 92 lines

BLKBSZGET -> Get original block size BLKBSZSET -> Set the block size to 512 READ | WRITE Successfully ;)
BLKBSZSET -> Set back to the original block size

-Shesha

Quoted 79 lines · Rob van Nieuwkerk

On Tue, 20 Jul 2004 10:27:57 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

Quoted 9 lines

I am having trouble with O_DIRECT. Trying to read or write from a block device partition.

1. Can O_DIRECT be used on a plain block device partition say "/dev/sda11" without having a filesystem on it.

yes.

Quoted 7 lines

2. If no file system is created then what should be the softblock size. I am using the IOCTL "BLKBSZGET". Is this correct?

yes.

Quoted 7 lines

3. Can we use SEEK_END with O_DIRECT on a partition without filesystem.

yes.

I'm using these exact things in an application.

Note that with 2.4 kernels the "granularity" you can use for offset and r/w size is the softblock size (*). For 2.6 the requirements are much more relaxed: it's the device blocksize (typically 512 byte).

(*): actually one of offset or r/w size has a smaller minimum if I remember correctly. Don't remember which one. But if you assume the softblock size as a minimum for both you're allways safe.

greetings,
Rob van Nieuwkerk

--

Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/

.

--

Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/
Quoted 6 lines
Quoted 6 lines

.

--

Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/

.

#17 lore raw

On Wed, 21 Jul 2004 16:18:37 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

Your original question (and my answer) was about a different situation:

- partition with no filesystem
- access on this raw partition

Now you start talking about various file-systems and I get the impression that you access the device through the file-system (although that is not very clear in your text) on a mounted fs.

What I told you applied to straight partitions (without mounted a mounted fs).

I don't know the exact rules for the various file-systems.
They might be different (and some might not support O_DIRECT at all). I expect the same "soft block size rules" to apply for the filesystems that *do* support O_DIRECT. Note that mounting a partition might change the softblock size of that partition used by the kernel from thereon.

greetings,
Rob van Nieuwkerk

PS1: what kernel are you using ?

PS2: what are you trying to do ?

PS3: you mention "our driver ..". What is this driver ?

Quoted 192 lines

I could never get it working with 4096 block size.

I created an EXT3 with blockize=4096 (mkfs.ext3 -b 4096 /dev/sda11). Alligned memory to 4096 boundary. Read 8192 Bytes. -> UNSUCCESSFUL :( I created an XFS with blockize=4096 (mkfs.xfs -f -b size=4096 /dev/sda11). Alligned memory to 4096 boundary. Read 8192 Bytes. -> UNSUCCESSFUL :(

SUCCESS HAPPEND ONLY WHEN ....

1. I created an XFS with blockize=4096 (mkfs.xfs -f -b size=4096 /dev/sda11).

                                                       OR
    I created an EXT3 with blockize=4096 (mkfs.ext3 -b 4096 /dev/sda11).

2. Changed blocksizeto 1024
3. Alligned memory to 1024 boundary.
4 Read 8192 Bytes. -> SUCCESSFUL :)

-Shesha

Quoted 167 lines · Rob van Nieuwkerk

On Wed, 21 Jul 2004 11:01:20 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

Quoted 5 lines

ohhh OK, if the block size is 4096, then the read/write size must be integer multiple of 4096 ??? is it ???
In general should the read/write length be a multiple of block size?

Yes, see my previous emails.

greetings,
Rob van Nieuwkerk

Quoted 130 lines
Quoted 126 lines · Rob van Nieuwkerk

On Wed, 21 Jul 2004 10:10:26 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

You don't mention what the *size* of your read()/write() is. Besides a requirement on the alignment of the read/write buffer the size of the read()/write() must also be OK.

greetings,
Rob van Nieuwkerk

Quoted 9 lines

This is what I found ....

Our driver sets the block size to be 4096. so BLKBSZGET will return 4096. So if I allin the memory at 4096 boundary, I cannot read using O_DIRECT. But, if I set the block size to 512. I can read/write successfully. It also works with 1024, but no with 4096

So the recepie what I am following is ...

Quoted 95 lines

BLKBSZGET -> Get original block size
BLKBSZSET -> Set the block size to 512
READ | WRITE Successfully ;)
BLKBSZSET -> Set back to the original block size

-Shesha

Quoted 82 lines · Rob van Nieuwkerk

On Tue, 20 Jul 2004 10:27:57 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

Quoted 11 lines

I am having trouble with O_DIRECT. Trying to read or write from a block device partition.

1. Can O_DIRECT be used on a plain block device partition say "/dev/sda11" without having a filesystem on it.

yes.

Quoted 8 lines

2. If no file system is created then what should be the softblock size. I am using the IOCTL "BLKBSZGET". Is this correct?

yes.

Quoted 7 lines

3. Can we use SEEK_END with O_DIRECT on a partition without filesystem.

yes.

I'm using these exact things in an application.

Note that with 2.4 kernels the "granularity" you can use for offset and r/w size is the softblock size (*). For 2.6 the requirements are much more relaxed: it's the device blocksize (typically 512 byte).

(*): actually one of offset or r/w size has a smaller minimum if I remember correctly. Don't remember which one. But if you assume the softblock size as a minimum for both you're allways safe.

greetings,
Rob van Nieuwkerk

--

Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/

.

--

Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/
Quoted 6 lines
Quoted 6 lines

.

--

Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/

.

#18 lore raw

You are right I am not using any file system. Just did that experiment by creating FS too. That also did not help. I shared that information. You are absolutely right I am dealing with straight partitions.

(1) With staraight partition even if I explicitly set the block size to 4096 and adher to the rules of O_DIRECT i cannot read/write

(2) With staraight partition if I set the block size to 1024 and adher to the rules of O_DIRECT i can read/write

Ruls include : Alligning the buffer & read/write multiple of block size.

-Shesha

Quoted 251 lines · Rob van Nieuwkerk

On Wed, 21 Jul 2004 16:18:37 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

Your original question (and my answer) was about a different situation:

- partition with no filesystem
- access on this raw partition

Now you start talking about various file-systems and I get the impression that you access the device through the file-system (although that is not very clear in your text) on a mounted fs.

What I told you applied to straight partitions (without mounted a mounted fs).

I don't know the exact rules for the various file-systems.
They might be different (and some might not support O_DIRECT at all). I expect the same "soft block size rules" to apply for the filesystems that *do* support O_DIRECT. Note that mounting a partition might change the softblock size of that partition used by the kernel from thereon.

greetings,
Rob van Nieuwkerk

PS1: what kernel are you using ?

PS2: what are you trying to do ?

PS3: you mention "our driver ..". What is this driver ?

Quoted 11 lines

I could never get it working with 4096 block size.

I created an EXT3 with blockize=4096 (mkfs.ext3 -b 4096 /dev/sda11). Alligned memory to 4096 boundary. Read 8192 Bytes. -> UNSUCCESSFUL :( I created an XFS with blockize=4096 (mkfs.xfs -f -b size=4096 /dev/sda11). Alligned memory to 4096 boundary. Read 8192 Bytes. -> UNSUCCESSFUL :(

SUCCESS HAPPEND ONLY WHEN ....

1. I created an XFS with blockize=4096 (mkfs.xfs -f -b size=4096 /dev/sda11). OR
I created an EXT3 with blockize=4096 (mkfs.ext3 -b 4096 /dev/sda11).

Quoted 199 lines

2. Changed blocksizeto 1024
3. Alligned memory to 1024 boundary.
4 Read 8192 Bytes. -> SUCCESSFUL :)

-Shesha

Quoted 188 lines · Rob van Nieuwkerk

On Wed, 21 Jul 2004 11:01:20 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

Quoted 6 lines

ohhh OK, if the block size is 4096, then the read/write size must be integer multiple of 4096 ??? is it ??? In general should the read/write length be a multiple of block size?

Yes, see my previous emails.

greetings,
Rob van Nieuwkerk

Quoted 144 lines
Quoted 138 lines · Rob van Nieuwkerk

On Wed, 21 Jul 2004 10:10:26 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

You don't mention what the *size* of your read()/write() is. Besides a requirement on the alignment of the read/write buffer the size of the read()/write() must also be OK.

greetings,
Rob van Nieuwkerk

Quoted 6 lines

This is what I found ....

Our driver sets the block size to be 4096. so BLKBSZGET will return 4096. So if I allin the memory at 4096 boundary, I cannot read using O_DIRECT. But, if I set the block size to 512. I can read/write successfully. It also works with 1024, but no with 4096

So the recepie what I am following is ...

Quoted 108 lines

BLKBSZGET -> Get original block size BLKBSZSET -> Set the block size to 512 READ | WRITE Successfully ;)
BLKBSZSET -> Set back to the original block size

-Shesha

Quoted 93 lines · Rob van Nieuwkerk

On Tue, 20 Jul 2004 10:27:57 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

Quoted 11 lines

I am having trouble with O_DIRECT. Trying to read or write from a block device partition.

1. Can O_DIRECT be used on a plain block device partition say "/dev/sda11" without having a filesystem on it.

yes.

Quoted 9 lines

2. If no file system is created then what should be the softblock size. I am using the IOCTL "BLKBSZGET". Is this correct?

yes.

Quoted 9 lines

3. Can we use SEEK_END with O_DIRECT on a partition without filesystem.

yes.

I'm using these exact things in an application.

Note that with 2.4 kernels the "granularity" you can use for offset and r/w size is the softblock size (*). For 2.6 the requirements are much more relaxed: it's the device blocksize (typically 512 byte).

(*): actually one of offset or r/w size has a smaller minimum if I remember correctly. Don't remember which one. But if you assume the softblock size as a minimum for both you're allways safe.

greetings,
Rob van Nieuwkerk

--

Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/

.

--

Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/
Quoted 8 lines
Quoted 8 lines

.

--

Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/

.

.

#19 lore raw

On Wed, 21 Jul 2004 17:00:07 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

I've always used the default softblock sizes (eg. did not alter it) on the devices I've dealt with (which was 1024).

Did you check what this default softblock size is for your device (with BLKBSZGET) ?

Reading my old code I noticed that I use 3 (instead of the 2 I already mentioned) alignment requirements:

	1.  read size 1024 byte aligned          (= softblock size)
	2.  read buffer page aligned (4096)
	3.  read/write offset 1024 byte aligned  (= softblock size)

Rule 3. is important too for O_DIRECT ! It may be that rule 2. can be softblock aligned too, but page alignment certainly won't harm

greetings,
Rob van Nieuwkerk

Quoted 279 lines

You are right I am not using any file system. Just did that experiment by creating FS too. That also did not help. I shared that information. You are absolutely right I am dealing with straight partitions.

(1) With staraight partition even if I explicitly set the block size to 4096 and adher to the rules of O_DIRECT i cannot read/write

(2) With staraight partition if I set the block size to 1024 and adher to the rules of O_DIRECT i can read/write

Ruls include : Alligning the buffer & read/write multiple of block size.

-Shesha

Quoted 262 lines · Rob van Nieuwkerk

On Wed, 21 Jul 2004 16:18:37 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

Your original question (and my answer) was about a different situation:

- partition with no filesystem
- access on this raw partition

Now you start talking about various file-systems and I get the impression that you access the device through the file-system (although that is not very clear in your text) on a mounted fs.

What I told you applied to straight partitions (without mounted a mounted fs).

I don't know the exact rules for the various file-systems.
They might be different (and some might not support O_DIRECT at all). I expect the same "soft block size rules" to apply for the filesystems that *do* support O_DIRECT. Note that mounting a partition might change the softblock size of that partition used by the kernel from thereon.

greetings,
Rob van Nieuwkerk

PS1: what kernel are you using ?

PS2: what are you trying to do ?

PS3: you mention "our driver ..". What is this driver ?

Quoted 15 lines

I could never get it working with 4096 block size.

I created an EXT3 with blockize=4096 (mkfs.ext3 -b 4096 /dev/sda11). Alligned memory to 4096 boundary. Read 8192 Bytes. -> UNSUCCESSFUL :( I created an XFS with blockize=4096 (mkfs.xfs -f -b size=4096 /dev/sda11). Alligned memory to 4096 boundary. Read 8192 Bytes. -> UNSUCCESSFUL :(

SUCCESS HAPPEND ONLY WHEN ....

1. I created an XFS with blockize=4096 (mkfs.xfs -f -b size=4096 /dev/sda11).
OR
I created an EXT3 with blockize=4096 (mkfs.ext3 -b 4096 /dev/sda11).

Quoted 206 lines

2. Changed blocksizeto 1024
3. Alligned memory to 1024 boundary.
4 Read 8192 Bytes. -> SUCCESSFUL :)

-Shesha

Quoted 195 lines · Rob van Nieuwkerk

On Wed, 21 Jul 2004 11:01:20 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

Quoted 7 lines

ohhh OK, if the block size is 4096, then the read/write size must be integer multiple of 4096 ??? is it ???
In general should the read/write length be a multiple of block size?

Yes, see my previous emails.

greetings,
Rob van Nieuwkerk

Quoted 150 lines
Quoted 144 lines · Rob van Nieuwkerk

On Wed, 21 Jul 2004 10:10:26 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

You don't mention what the *size* of your read()/write() is. Besides a requirement on the alignment of the read/write buffer the size of the read()/write() must also be OK.

greetings,
Rob van Nieuwkerk

Quoted 9 lines

This is what I found ....

Our driver sets the block size to be 4096. so BLKBSZGET will return 4096. So if I allin the memory at 4096 boundary, I cannot read using O_DIRECT. But, if I set the block size to 512. I can read/write successfully. It also works with 1024, but no with 4096

So the recepie what I am following is ...

Quoted 111 lines

BLKBSZGET -> Get original block size
BLKBSZSET -> Set the block size to 512
READ | WRITE Successfully ;)
BLKBSZSET -> Set back to the original block size

-Shesha

Quoted 96 lines · Rob van Nieuwkerk

On Tue, 20 Jul 2004 10:27:57 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

Quoted 13 lines

I am having trouble with O_DIRECT. Trying to read or write from a block device partition.

1. Can O_DIRECT be used on a plain block device partition say "/dev/sda11" without having a filesystem on it.

yes.

Quoted 10 lines

2. If no file system is created then what should be the softblock size. I am using the IOCTL "BLKBSZGET". Is this correct?

yes.

Quoted 9 lines

3. Can we use SEEK_END with O_DIRECT on a partition without filesystem.

yes.

I'm using these exact things in an application.

Note that with 2.4 kernels the "granularity" you can use for offset and r/w size is the softblock size (*). For 2.6 the requirements are much more relaxed: it's the device blocksize (typically 512 byte).

(*): actually one of offset or r/w size has a smaller minimum if I remember correctly. Don't remember which one. But if you assume the softblock size as a minimum for both you're allways safe.

greetings,
Rob van Nieuwkerk

--

Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/

.

--

Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/
Quoted 8 lines
Quoted 8 lines

.

--

Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/

.

.

#20 lore raw

Ok, I got to know what exactly is the problem ,,

Basically on my partition total sectors is not a muliple of 8 (Each sector = 512, 4096/512=8). That is the end of the disk is not alligned with 4096, What I am doing is, reading/writing from/to the last 8192 bytes by seeking (Negetive 8192) from the end. So this may not be 4096 byte alligned. Now the start of my read/write point WILL always be 1024 byte alligned in case of odd and even # of sectors becasue, Even number of sectors is trivial/obvious, but in case of odd # of sectors, when we do a SEEK_END it will always seek to the last EVEN sector of the disk. Therefore I am always successful with 1024 byte alligned. Actually the last sector in my case is 490223474 :)

Thank you all, special thanks to Rob van Nieuwkerk .. Shesha

Quoted 331 lines · Rob van Nieuwkerk

On Wed, 21 Jul 2004 17:00:07 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

I've always used the default softblock sizes (eg. did not alter it) on the devices I've dealt with (which was 1024).

Did you check what this default softblock size is for your device (with BLKBSZGET) ?

Reading my old code I noticed that I use 3 (instead of the 2 I already mentioned) alignment requirements:

	1.  read size 1024 byte aligned          (= softblock size)
	2.  read buffer page aligned (4096)
	3.  read/write offset 1024 byte aligned  (= softblock size)

Rule 3. is important too for O_DIRECT ! It may be that rule 2. can be softblock aligned too, but page alignment certainly won't harm

greetings,
Rob van Nieuwkerk

Quoted 4 lines

You are right I am not using any file system. Just did that experiment by creating FS too. That also did not help. I shared that information. You are absolutely right I am dealing with straight partitions.

(1) With staraight partition even if I explicitly set the block size to 4096 and adher to the rules of O_DIRECT i cannot read/write

Quoted 296 lines

(2) With staraight partition if I set the block size to 1024 and adher to the rules of O_DIRECT i can read/write

Ruls include : Alligning the buffer & read/write multiple of block size.

-Shesha

Quoted 286 lines · Rob van Nieuwkerk

On Wed, 21 Jul 2004 16:18:37 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

Your original question (and my answer) was about a different situation:

- partition with no filesystem
- access on this raw partition

Now you start talking about various file-systems and I get the impression that you access the device through the file-system (although that is not very clear in your text) on a mounted fs.

What I told you applied to straight partitions (without mounted a mounted fs).

I don't know the exact rules for the various file-systems.
They might be different (and some might not support O_DIRECT at all). I expect the same "soft block size rules" to apply for the filesystems that *do* support O_DIRECT. Note that mounting a partition might change the softblock size of that partition used by the kernel from thereon.

greetings,
Rob van Nieuwkerk

PS1: what kernel are you using ?

PS2: what are you trying to do ?

PS3: you mention "our driver ..". What is this driver ?

Quoted 11 lines

I could never get it working with 4096 block size.

I created an EXT3 with blockize=4096 (mkfs.ext3 -b 4096 /dev/sda11). Alligned memory to 4096 boundary. Read 8192 Bytes. -> UNSUCCESSFUL :( I created an XFS with blockize=4096 (mkfs.xfs -f -b size=4096 /dev/sda11). Alligned memory to 4096 boundary. Read 8192 Bytes. -> UNSUCCESSFUL :(

SUCCESS HAPPEND ONLY WHEN ....

1. I created an XFS with blockize=4096 (mkfs.xfs -f -b size=4096 /dev/sda11). OR
I created an EXT3 with blockize=4096 (mkfs.ext3 -b 4096 /dev/sda11).

Quoted 231 lines

2. Changed blocksizeto 1024
3. Alligned memory to 1024 boundary.
4 Read 8192 Bytes. -> SUCCESSFUL :)

-Shesha

Quoted 218 lines · Rob van Nieuwkerk

On Wed, 21 Jul 2004 11:01:20 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

Quoted 8 lines

ohhh OK, if the block size is 4096, then the read/write size must be integer multiple of 4096 ??? is it ??? In general should the read/write length be a multiple of block size?

Yes, see my previous emails.

greetings,
Rob van Nieuwkerk

Quoted 164 lines
Quoted 156 lines · Rob van Nieuwkerk

On Wed, 21 Jul 2004 10:10:26 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

You don't mention what the *size* of your read()/write() is. Besides a requirement on the alignment of the read/write buffer the size of the read()/write() must also be OK.

greetings,
Rob van Nieuwkerk

Quoted 6 lines

This is what I found ....

Our driver sets the block size to be 4096. so BLKBSZGET will return 4096. So if I allin the memory at 4096 boundary, I cannot read using O_DIRECT. But, if I set the block size to 512. I can read/write successfully. It also works with 1024, but no with 4096

So the recepie what I am following is ...

Quoted 124 lines

BLKBSZGET -> Get original block size BLKBSZSET -> Set the block size to 512 READ | WRITE Successfully ;)
BLKBSZSET -> Set back to the original block size

-Shesha

Quoted 107 lines · Rob van Nieuwkerk

On Tue, 20 Jul 2004 10:27:57 -0700
Shesha Sreenivasamurthy <[email protected]> wrote:

Hi Shesha,

Quoted 13 lines

I am having trouble with O_DIRECT. Trying to read or write from a block device partition.

1. Can O_DIRECT be used on a plain block device partition say "/dev/sda11" without having a filesystem on it.

yes.

Quoted 11 lines

2. If no file system is created then what should be the softblock size. I am using the IOCTL "BLKBSZGET". Is this correct?

yes.

Quoted 11 lines

3. Can we use SEEK_END with O_DIRECT on a partition without filesystem.

yes.

I'm using these exact things in an application.

Note that with 2.4 kernels the "granularity" you can use for offset and r/w size is the softblock size (*). For 2.6 the requirements are much more relaxed: it's the device blocksize (typically 512 byte).

(*): actually one of offset or r/w size has a smaller minimum if I remember correctly. Don't remember which one. But if you assume the softblock size as a minimum for both you're allways safe.

greetings,
Rob van Nieuwkerk

--

Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/

.

--

Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/
Quoted 10 lines
Quoted 10 lines

.

--

Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/

.

.

.