History log of /haiku/src/system/kernel/device_manager/IOCache.cpp
Revision Date Author Comments
# be808057 27-Apr-2023 Augustin Cavalier <waddlesplash@gmail.com>

IORequest: Refactor IOOperation transferred-bytes and status accounting.

Until the introduction of the nvme_disk driver, these classes were
mostly only used directly by the IO scheduler, and then a few direct
usages of IOOperation itself in the individual disk drivers; so
API confusions were easily missed.

When writing the nvme_disk driver's IORequest support, however, it
became readily apparent that there were some pretty bad confusions
around transferred-bytes accounting in IOOperation. This commit
attempts to resolve all of those.

There are two basic changes here:

1. Move transferred-bytes accounting into IOOperation::SetStatus.

The "TransferredBytes" field of IOOperation is against the *original*
range, not the actual operation's range (which will be wider, due to
bouncing, etc.), and furthermore only applies to the actual content
of the request (and not e.g. to a read half of a bounced write.)

These two facts meant that determining what value to pass to
SetTransferredBytes was not trivial, and was easy to get wrong.
I recall messing that up when working on nvme_disk multiple times
before reading the API carefully.

2. Do not pass redundant values to IORequest::OperationFinished.

All of the values here can be derived (albeit indirectly) from the
IOOperation, and all consumers of this API basically did just that.
Rather than make them do it, make the IORequest take care of
computing all of those values itself.

Change-Id: Ic9ae29e1100319e5b7647647c4db7e5aad4d125e


# c650846d 14-Mar-2023 Augustin Cavalier <waddlesplash@gmail.com>

vm: Replace the VMAreas OpenHashTable with an AVLTree.

Since we used a hash table with a fixed size (1024), collisions were
obviously inevitable, meaning that while insertions would always be
fast, lookups and deletions would take linear time to search the
linked-list for the area in question. For recently-created areas,
this would be fast; for less-recently-created areas, it would get
slower and slower and slower.

A particularly pathological case was the "mmap/24-1" test from the
Open POSIX Testsuite, which creates millions of areas until it hits
ENOMEM; it then simply exits, at which point it would run for minutes
and minutes in the kernel team deletion routines; how long I don't know,
as I rebooted before it finished.

This change fixes that problem, among others, at the cost of increased
area creation time, by using an AVL tree instead of a hash. For comparison,
mmap'ing 2 million areas with the "24-1" test before this change took
around 0m2.706s of real time, while afterwards it takes about 0m3.118s,
or around a 15% increase (1.152x).

On the other hand, the total test runtime for 2 million areas went from
around 2m11.050s to 0m4.035s, or around a 97% decrease (0.031x); in other
words, with this new code, it is *32 times faster.*

Area insertion will no longer be O(1), however, so the time increase
may go up with the number of areas present on the system; but if it's
only around 3 seconds to create 2 million areas, or about 1.56 us per area,
vs. 1.35 us before, I don't think that's worth worrying about.

My nonscientific "compile HaikuDepot with 2 cores in VM" benchmark
seems to be within the realm of "noise", anyway, with most results
both before and after this change coming in around 47s real time.

Change-Id: I230e17de4f80304d082152af83db8bd5abe7b831


# bd6434b6 22-May-2021 Máximo Castañeda <antiswen@yahoo.es>

Revert "packagefs and IOCache: don't reread pages when we have them all."

This reverts commit dfc8e52638c5e334859b8294dd41b042134b9dda.

It needs more attention to its influence on other parts of the code.

Fixes #16954

Change-Id: Ibb764d81666434a198023bc345a45ef9d270eadb
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3976
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>


# f203aee6 14-May-2021 Adrien Destugues <pulkomandy@pulkomandy.tk>

Style fixes.

Pointed out by Axel on Gerrit, I was too fast to merge the commit.


# dfc8e526 01-Apr-2019 Augustin Cavalier <waddlesplash@gmail.com>

packagefs and IOCache: don't reread pages when we have them all.

Change-Id: I56a7769e7a2fa9693db7507ffadb01a56cbf42b2
Reviewed-on: https://review.haiku-os.org/c/haiku/+/1342
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>


# 00866cc1 02-Dec-2020 Jérôme Duval <jerome.duval@gmail.com>

IOCache: adjust the last iovec when the capacity isn't multiple of B_PAGE_SIZE

Patch by mark_mcs, edited by me
this fixes #16030

Change-Id: I9255fe960f73cdfc3fd2668cdaf7db19fedd70f1
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3451
Reviewed-by: Rene Gollent <rene@gollent.com>


# 03fb2d88 07-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Remove gSchedulerLock

* Thread::scheduler_lock protects thread state, priority, etc.
* sThreadCreationLock protects thread creation and removal and list of
threads in team.
* Team::signal_lock and Team::time_lock protect list of threads in team
as well.
* Scheduler uses its own internal locking.


# 4be4fc6b 15-Jun-2012 Alex Smith <alex@alex-smith.me.uk>

More 64-bit compilation/safety fixes.


# ad63c679 30-May-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Improved debug output.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41833 a95241bf-73f2-0310-859d-f6bbb57e9c96


# aa06eeb1 01-Feb-2011 Axel Dörfler <axeld@pinc-software.de>

* If retrieving the cache line failed, try again using an uncached access. That
should help with the remaining I/O errors with (older) CDs that I see only on
Haiku. Not yet tested, though.
* Added a bit of debug output to see when/if it's triggered.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40344 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3f8bbbe0 01-Feb-2011 Axel Dörfler <axeld@pinc-software.de>

* Cleanup, no functional change.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40343 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4535495d 10-Jan-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged the signals branch into trunk, with these changes:
* The team and thread kernel structures have been renamed to Team and Thread
respectively and moved into the new BKernel namespace.
* Several (kernel add-on) sources have been converted from C to C++ since
private kernel headers are included that are no longer C compatible.

Changes after merging:
* Fixed gcc 2 build (warnings mainly in the scary firewire bus manager).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40196 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 73b1cb82 30-Aug-2010 Axel Dörfler <axeld@pinc-software.de>

* The IOCache always needs a DMAResource; it was sometimes checked, and
sometimes not.
* This fixes CIDs 1755-1756, and 1505-1506.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38460 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1d578e15 02-Jun-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Fixed more address types related issues. Mostly printf() or comparison
warnings, but also some oversights from earlier changes.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37000 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 435c43f5 02-Jun-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Introduced type generic_io_vec, which is similar to iovec, but uses types
that are wide enough for both virtual and physical addresses.
* DMABuffer, IORequest, IOScheduler,... and code using them: Use
generic_io_vec and generic_{addr,size}_t where necessary.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36997 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 03768a40 31-May-2010 Axel Dörfler <axeld@pinc-software.de>

* Introduced IOScheduler::MediaChanged() - this is now called by scsi_cd instead
of having the logic be triggered by IOScheduler::SetDeviceCapacity(), as that
one might actually be called more often (for each call to update_capacity(),
ie. each B_GET_GEOMETRY/B_GET_DEVICE_SIZE will trigger it), and there is no
reason to throw away the cache every time (will make a difference during
partition/file system detection).
* In cd_init_device() just call update_capacity() instead of duplicating its
code.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36986 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c1be1e07 01-May-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* VMTranslationMap::Map()/Protect(): Added "memoryType" parameter. Not
implemented for any architecture yet.
* vm_set_area_memory_type(): Call VMTranslationMap::ProtectArea() to change the
memory type for the already mapped pages.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36574 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5060d798 26-Apr-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

IOCache implements IOScheduler, now.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36494 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f14480bc 24-Apr-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Essentially rewrote the IOCache to use a VMCache and unmapped pages for
caching (similar to the file cache) instead of contiguous areas. This is
probably a little bit slower, but integrates better with the VM -- the
caching doesn't increase memory pressure and the least recently used pages
will automatically be recycled when needed.
There are still memory allocation issues on machines with little memory. The
USB stack apparently tries to allocate a rather big chunk of contiguous
memory, which fails when all not otherwise bound memory is used for caches,
since the VM functions for allocating contiguous memory consider only free
pages ATM.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36458 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e91e4ee0 23-Apr-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Added IOCache, a simple write-through cache implementation that can be used
as a drop-in replacement for IOScheduler, processing IORequests synchronously
in FIFO order. It stores cache lines of user-defined size. Currently for each
cache line an area of contiguous memory is used, which is not optimal.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36436 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 03fb2d886830e4dd4b344c56725db59f96733216 07-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Remove gSchedulerLock

* Thread::scheduler_lock protects thread state, priority, etc.
* sThreadCreationLock protects thread creation and removal and list of
threads in team.
* Team::signal_lock and Team::time_lock protect list of threads in team
as well.
* Scheduler uses its own internal locking.


# 4be4fc6b1faddbd037146214a0011d320842b4f3 15-Jun-2012 Alex Smith <alex@alex-smith.me.uk>

More 64-bit compilation/safety fixes.


# ad63c6796c6e37059a332647b42ea0b244aaa3b4 30-May-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Improved debug output.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@41833 a95241bf-73f2-0310-859d-f6bbb57e9c96


# aa06eeb1b9efd779485e025e9292ae548d7d26f1 01-Feb-2011 Axel Dörfler <axeld@pinc-software.de>

* If retrieving the cache line failed, try again using an uncached access. That
should help with the remaining I/O errors with (older) CDs that I see only on
Haiku. Not yet tested, though.
* Added a bit of debug output to see when/if it's triggered.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40344 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3f8bbbe05a989d756551c00cf684c101cb6c034c 01-Feb-2011 Axel Dörfler <axeld@pinc-software.de>

* Cleanup, no functional change.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40343 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4535495d80c86e19e2610e7444a4fcefe3e0f8e6 10-Jan-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged the signals branch into trunk, with these changes:
* The team and thread kernel structures have been renamed to Team and Thread
respectively and moved into the new BKernel namespace.
* Several (kernel add-on) sources have been converted from C to C++ since
private kernel headers are included that are no longer C compatible.

Changes after merging:
* Fixed gcc 2 build (warnings mainly in the scary firewire bus manager).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40196 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 73b1cb824029f8957d7e60c7ad3828f3eea1aca2 30-Aug-2010 Axel Dörfler <axeld@pinc-software.de>

* The IOCache always needs a DMAResource; it was sometimes checked, and
sometimes not.
* This fixes CIDs 1755-1756, and 1505-1506.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38460 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1d578e15fe5b5c3ff62866ae81aef529d00d7762 02-Jun-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Fixed more address types related issues. Mostly printf() or comparison
warnings, but also some oversights from earlier changes.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37000 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 435c43f5912b109e7d5cf682865d2061e62fad8c 02-Jun-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Introduced type generic_io_vec, which is similar to iovec, but uses types
that are wide enough for both virtual and physical addresses.
* DMABuffer, IORequest, IOScheduler,... and code using them: Use
generic_io_vec and generic_{addr,size}_t where necessary.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36997 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 03768a405289a006f256465ea93a87faed5ea339 31-May-2010 Axel Dörfler <axeld@pinc-software.de>

* Introduced IOScheduler::MediaChanged() - this is now called by scsi_cd instead
of having the logic be triggered by IOScheduler::SetDeviceCapacity(), as that
one might actually be called more often (for each call to update_capacity(),
ie. each B_GET_GEOMETRY/B_GET_DEVICE_SIZE will trigger it), and there is no
reason to throw away the cache every time (will make a difference during
partition/file system detection).
* In cd_init_device() just call update_capacity() instead of duplicating its
code.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36986 a95241bf-73f2-0310-859d-f6bbb57e9c96


# c1be1e0761d0904d99dabd3d1638d94802b4b600 01-May-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* VMTranslationMap::Map()/Protect(): Added "memoryType" parameter. Not
implemented for any architecture yet.
* vm_set_area_memory_type(): Call VMTranslationMap::ProtectArea() to change the
memory type for the already mapped pages.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36574 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5060d7980f7ca574e6b23d96e49dd78d9fd74210 26-Apr-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

IOCache implements IOScheduler, now.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36494 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f14480bc2c86a3af8f802c7478bc7a54ae445339 24-Apr-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Essentially rewrote the IOCache to use a VMCache and unmapped pages for
caching (similar to the file cache) instead of contiguous areas. This is
probably a little bit slower, but integrates better with the VM -- the
caching doesn't increase memory pressure and the least recently used pages
will automatically be recycled when needed.
There are still memory allocation issues on machines with little memory. The
USB stack apparently tries to allocate a rather big chunk of contiguous
memory, which fails when all not otherwise bound memory is used for caches,
since the VM functions for allocating contiguous memory consider only free
pages ATM.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36458 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e91e4ee0a6787d04bfac0fef11e5e3cffe9b9f6b 23-Apr-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Added IOCache, a simple write-through cache implementation that can be used
as a drop-in replacement for IOScheduler, processing IORequests synchronously
in FIFO order. It stores cache lines of user-defined size. Currently for each
cache line an area of contiguous memory is used, which is not optimal.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36436 a95241bf-73f2-0310-859d-f6bbb57e9c96