Comments (4)
so if this package can not support small size direct write, is there any other solution?
from directio.
You can write less than a block but you need to do it from an aligned buffer.
when buf size less than blockSize, it reports error when write after calling AlignedBlock(). It should be noted down if not support this case.
Can you give a code example please?
from directio.
This is not just for smaller sizes.
When the buffer is not even to BlockSize, it will generate an error:
package main
import (
"github.com/ncw/directio"
"log"
"os"
)
func main() {
block1 := directio.AlignedBlock(directio.BlockSize + 1)
for i := 0; i < len(block1); i++ {
block1[i] = 'A'
}
// Write the file
out, err := directio.OpenFile("O_DIRECT.test", os.O_CREATE|os.O_WRONLY, 0666)
defer out.Close()
if err != nil {
log.Fatal("Failed to directio.OpenFile for write: ", err)
}
_, err = out.Write(block1)
if err != nil {
log.Fatal("Failed to write: ", err)
}
}
from directio.
I think the alignment rules depend on the file system and the kernel.
From man 2 open
O_DIRECT
The O_DIRECT flag may impose alignment restrictions on the length and
address of user-space buffers and the file offset of I/Os. In Linux
alignment restrictions vary by filesystem and kernel version and might
be absent entirely. However there is currently no filesystem-indepen‐
dent interface for an application to discover these restrictions for a
given file or filesystem. Some filesystems provide their own inter‐
faces for doing so, for example the XFS_IOC_DIOINFO operation in xf‐
sctl(3).
So I think getting an error on writing a non block sized chunk is normal.
from directio.
Related Issues (11)
- confuse about the alignment HOT 6
- Confused about usage with bufio.Scanner HOT 1
- enable/disable O_DIRECT HOT 1
- Extremely slow O_DIRECT HOT 3
- Panic on 0 sized `AlignedBlock` HOT 2
- Alignment HOT 2
- windows dda to physical drive HOT 2
- Link to docs broken HOT 1
- TestDirectIO fail on Fedora 26, Go version 1.7 HOT 2
- OpenFile return error 'invalid argument' when path is under tmpfs HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from directio.