* Added parameter "size_t align" to file_map_translate(). If > 1, the

vector at the end of the file will be aligned to the given value.
* BFS uses an alignment of 512 bytes (should be block size of the
  underlying device or BFS block size, whatever is less), which should
  be fine, since file data are only stored in BFS blocks. This totally
  avoids any partial operations at the I/O scheduler level, thus saving
  disk operations. Not that I could measure any performance difference.
  Theoretically it should help a lot though, particularly when dealing
  with lots of small files, since we avoid using bounce buffers, which
  are (a) limited in number and (b) require copying of the data.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27246 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2008-08-30 23:06:28 +00:00
parent fd49e6b35a
commit 4612433715
7 changed files with 41 additions and 26 deletions
+16 -9
View File
@@ -63,7 +63,8 @@ public:
void SetSize(off_t size);
status_t Translate(off_t offset, size_t size,
file_io_vec* vecs, size_t* _count);
file_io_vec* vecs, size_t* _count,
size_t align);
file_extent* ExtentAt(uint32 index);
@@ -383,18 +384,26 @@ FileMap::SetMode(uint32 mode)
status_t
FileMap::Translate(off_t offset, size_t size, file_io_vec* vecs, size_t* _count)
FileMap::Translate(off_t offset, size_t size, file_io_vec* vecs, size_t* _count,
size_t align)
{
MutexLocker _(fLock);
size_t maxVecs = *_count;
size_t padLastVec = 0;
if (offset >= Size()) {
*_count = 0;
return B_OK;
}
if (offset + size > fSize)
if (offset + size > fSize) {
if (align > 1) {
off_t alignedSize = (fSize + align - 1) & ~(off_t)(align - 1);
if (offset + size >= alignedSize)
padLastVec = alignedSize - fSize;
}
size = fSize - offset;
}
// First, we need to make sure that we have already cached all file
// extents needed for this request.
@@ -414,8 +423,7 @@ FileMap::Translate(off_t offset, size_t size, file_io_vec* vecs, size_t* _count)
vecs[0].length = fileExtent->disk.length - offset;
if (vecs[0].length >= size) {
if (vecs[0].length > size)
vecs[0].length = size;
vecs[0].length = size + padLastVec;
*_count = 1;
return B_OK;
}
@@ -431,8 +439,7 @@ FileMap::Translate(off_t offset, size_t size, file_io_vec* vecs, size_t* _count)
vecs[vecIndex++] = fileExtent->disk;
if (size <= fileExtent->disk.length) {
if (size < fileExtent->disk.length)
vecs[vecIndex - 1].length = size;
vecs[vecIndex - 1].length = size + padLastVec;
break;
}
@@ -627,7 +634,7 @@ file_map_set_mode(void* _map, uint32 mode)
extern "C" status_t
file_map_translate(void* _map, off_t offset, size_t size, file_io_vec* vecs,
size_t* _count)
size_t* _count, size_t align)
{
TRACE(("file_map_translate(map %p, offset %Ld, size %ld)\n",
_map, offset, size));
@@ -636,6 +643,6 @@ file_map_translate(void* _map, off_t offset, size_t size, file_io_vec* vecs,
if (map == NULL)
return B_BAD_VALUE;
return map->Translate(offset, size, vecs, _count);
return map->Translate(offset, size, vecs, _count, align);
}