Skip to content

Commit

Permalink
fix: clean up blocksize implementation
Browse files Browse the repository at this point in the history
It helps to RTFM. `st_blocks` and `st_blksize` are *not* related.
`st_blksize` *really is* the optimal I/O block size. `st_blocks`
is *always* given in multiples of 512 bytes.
  • Loading branch information
mhx committed Feb 12, 2024
1 parent 089f073 commit 3d17b2c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 14 deletions.
3 changes: 1 addition & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

- (feature) Added `blocksize` option to the FUSE driver, which allows
the `st_blksize` value to be configured for the mounted file system.
This is necessary on macOS as macFUSE derives the optimum read size
from this value. Use along with macFUSE's `iosize` for best effect.
Increasing this value can improve throughput for large files.

- (feature) Added experimental `readahead` option to the FUSE driver.
This can potentially increase throughput when performing sequential
Expand Down
7 changes: 2 additions & 5 deletions doc/dwarfs.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ options:
memory. For more details, see mkdwarfs(1).

- `-o blocksize=`*value*:
Size reported for files in `st_blksize`. This is 512 bytes
by default on Linux/Windows. On macOS, the value is 256 kiB,
as macFUSE uses this to derive the maximum size of a read
request. Use this along with macFUSE's `iosize` option to
tune throughput.
Size reported for files in `st_blksize`. You can use this to
optimize throughput in certain situations.

- `-o readahead=`*value*:
How much data to read ahead when receiving a read request.
Expand Down
2 changes: 1 addition & 1 deletion src/dwarfs/metadata_v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1554,7 +1554,7 @@ int metadata_<LoggerPolicy>::getattr(inode_view iv, file_stat* stbuf) const {
: file_size(iv, mode);
stbuf->ino = inode + inode_offset_;
stbuf->blksize = options_.block_size;
stbuf->blocks = (stbuf->size + options_.block_size - 1) / options_.block_size;
stbuf->blocks = (stbuf->size + 511) / 512;
stbuf->uid = iv.getuid();
stbuf->gid = iv.getgid();
stbuf->mtime = resolution * (timebase + iv.mtime_offset());
Expand Down
8 changes: 2 additions & 6 deletions src/dwarfs_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,7 @@ namespace dwarfs {

namespace {

#ifdef __APPLE__
constexpr size_t const kDefaultBlockSize{static_cast<size_t>(256) << 10};
#else
constexpr size_t const kDefaultBlockSize{512};
#endif
constexpr size_t const kDefaultBlockSize{static_cast<size_t>(512) << 10};

struct options {
// std::string isn't standard-layout on MSVC
Expand Down Expand Up @@ -1021,7 +1017,7 @@ void usage(std::ostream& os, std::filesystem::path const& progname) {
<< " <image> <mountpoint> [options]\n\n"
<< "DWARFS options:\n"
<< " -o cachesize=SIZE set size of block cache (512M)\n"
<< " -o blocksize=SIZE set file block size\n"
<< " -o blocksize=SIZE set file I/O block size (512K)\n"
<< " -o readahead=SIZE set readahead size (0)\n"
<< " -o workers=NUM number of worker threads (2)\n"
<< " -o mlock=NAME mlock mode: (none), try, must\n"
Expand Down

0 comments on commit 3d17b2c

Please sign in to comment.