Commit Graph
100 Commits
Author SHA1 Message Date
Augustin Cavalier c95edc2ba1 app_server: Get rid of RenderingBuffer::IsGraphicsMemory().
It was introduced in 778706215d
for DrawingEngine's sake, but it actually isn't needed even there
and was removed in the previous commit.
2024-12-18 12:28:26 -05:00
Augustin Cavalier 87eae1e3c8 bootloader: Properly enable __PRINTFLIKE for the boot stdio.
No new warnings or errors, it appears.
2024-12-17 19:49:23 -05:00
Augustin Cavalier f836917f47 kernel/vm: Rework ordering of _RemoveConsumer and drop "unmergeable" flag.
This reverts a8877df135.

Previously, the "unmergeable" flag was necessary for the RAMFS,
because if the last vnode reference was released while there
was still a consumer (as the old ordering of _RemoveConsumer
had), then the release of the cache reference when the vnode
was removed would result in the cache trying to merge with
its now-only consumer and sole referrer.

Now, instead, we remove the consumer before releasing the store
reference, so that there's no chance the cache will be merged
inside this method.

mmap_cut_tests still pass, web browsers using ramfs shared_memory
still seem to work.
2024-12-17 19:12:40 -05:00
Augustin Cavalier 7eeb28152e kernel/vm: Commit up-front in the middle-cut case.
This way, if the Resize() is supposed to take care of the commitment,
it will (and will fail early if it can't), while if we are the ones
responsible for adjusting the commitment, map_backing_store won't
commit at all (avoiding committing far more than will be necessary),
and we can just steal the commitment from the first cache for the second.
2024-12-17 18:33:34 -05:00
Augustin Cavalier 3280d3c47d kernel/vm: Rework cutting areas with source caches.
This reverts 3a81e9446d (2022).

That commit fixed #17556 by just checking if the area had an
underlying cache that wasn't a RAM cache. But there are cases
where there will be RAM source caches that we have to take
into account, too, not just vnode caches or the like. The
most common example of that would be all areas of a team
after a fork(); the original pages will be in a read-only
source cache.

This commit fixes the real underlying problem: if the first area
has a source cache, then the new second cache needs to have that
as its source, too; and furthermore must have the correct offsets
in order to access its pages correctly.

The test for #17556 that was added in 9ed77019b6
still works as before, as do all the applications I tested that
use cut_area. Some assertion failures that the cut tests triggered
(related to commitment sizes) are fixed by this, as well.

This also seems to fix the remaining instability on fork() in the
boehm-gc's "gctest".
2024-12-17 18:32:11 -05:00
Augustin Cavalier e5b76ada08 kernel/vm: Don't re-protect pages in cut_area.
The page_protections aren't changed at all, so all pages that exist
should already have the same protections as are specified in the array.
The only thing different is what cache and area they now belong to, but
the VMTranslationMap does not care about that.

So we don't need to loop over the pages and re-protect them in this case.
We already didn't for all cases where no page_protections were involved.

(It seems this logic was introduced in bdcc293fa8
along with general page_protections support in cut_area.)
2024-12-17 18:31:05 -05:00
Augustin Cavalier c59db548ab kernel/vm: More fixes to commitment handling in cut_area.
When the area has no page_protections but isn't writable,
we also want to use a smaller-than-default commitment.
So, adjust compute_area_page_commitment to handle that case,
and then use it in cut_area where appropriate.
2024-12-17 17:53:27 -05:00
Augustin Cavalier e0854909b2 kernel/vm: Fix an area/cache offset mixup in discard_area_range.
cache->virtual_base is the cache's start address, which no pages will
be found before. area->cache_offset on the other hand is the area's
offset into the cache (i.e. offset 0 in the area will be offset
0 + area->cache_offset in the cache.) These addresses may well be
the same (even if they're not 0), and in many situations they are,
but in situations with shared or cut areas, they may not be.

The only thing that uses this method is madvise(MADV_FREE), which
probably not many things besides the guarded_heap use at present.
2024-12-17 17:39:43 -05:00
Augustin Cavalier a8adb675e6 tests/kernel/vm: Add munmap calls and fix comments in map_cut_compare_test.
Makes it easier to debug in KDL, especially.
2024-12-17 17:10:40 -05:00
Augustin Cavalier feac1ed72d kernel/vm: Add assertion in VMCache::AddConsumer that source == NULL. 2024-12-17 17:05:37 -05:00
Augustin Cavalier a6938ffd24 kernel/riscv64: Drop unimplemented ProtectPage/ProtectArea.
These are implemented in the base class instead.
2024-12-17 17:04:54 -05:00
Augustin Cavalier 0bfdddcc75 userlandfs: Sort files in the libuserlandfs_haiku_kernel Jamfile.
Alphabetical order, proper sections, etc.
No functional change intended.
2024-12-17 14:04:21 -05:00
Augustin Cavalier 0cffc2aab9 userlandfs: Add AVLTreeBase to libuserlandfs_haiku_kernel.so.
Not sure why this wasn't needed before, but it seems to be now.
2024-12-17 13:58:06 -05:00
Augustin Cavalier 94eafb3b5b kernel/vm: Commitment sizes must be rounded up to the page size.
As the virtual_base and virtual_size may not be page aligned.

Fixes #19295.
2024-12-17 13:06:46 -05:00
Augustin Cavalier 1ad6193d82 kernel/vm: Default AcquireUnreferencedStoreRef() to B_ERROR.
We shouldn't return B_OK here, because then the page writer will
assume it's acquired a store ref and can write pages from this
cache, when of course it's done nothing of the sort.
2024-12-16 23:29:46 -05:00
Augustin Cavalier f69d8200cd kernel/vm: Add assertion that a VMCache being destroyed really is empty. 2024-12-16 23:08:50 -05:00
Augustin Cavalier 74c037e938 kernel/vm: Fix problems in merging caches of differing sizes.
Previously, we'd wind up adding pages from the source to the consumer
that were potentially or actually outside the consumer's bounds.
Now we check the consumer's size and ignore any pages that we don't
want or need; they'll just be freed along with the source cache.

While at it, drop VMAnonymousCache::_MergePagesSmallerSource; it
was the same as the base class's implementation of Merge preceding
this commit; and add a comment to _MergePagesSmallerConsumer noting
that some of the pages may be busy (indeed, I manage to trigger an
assert related to copy-on-write in here at least once.)

I discovered this problem because the page commitment size ASSERT()s
triggered inside Resize() and Rebase(); but the out-of-range pages
already existed in the cache before those functions were called. So,
I've also added an ASSERT to MovePage() that would have caught this
problem more directly.
2024-12-16 22:52:59 -05:00
Augustin Cavalier d4d55c1fbb kernel/vm: Rename _FreePageRange "discarded" argument to "freedPages".
Clarifies things. No functional change.
2024-12-16 22:06:06 -05:00
Augustin Cavalier 47dbff983a iprowifi4965: Add NULL check for data->ni and data->m.
Workaround for #19289.
2024-12-16 16:35:11 -05:00
Augustin Cavalier 91bb4d0238 libroot: Implement a "partial" vfork.
The original meaning of vfork is "fork, sharing virtual memory" (until
exec). We don't implement that, and may never do so. However, since
calling any functions besides exec() in a vfork'ed child is "undefined
behavior", we can take advantage of that fact at least by not calling
any of the pre- and post-fork hooks, saving a lot of page faults from
copy-on-write.

On one run of the "compile HaikuDepot and the mime_db" benchmark with -j4,
the total waits count on the top two VMCaches by contention dropped
from 62125 and 58927, to 52034 and 41225.

musl apparently does more or less this same thing (vfork() is fork()
but without calling any of the hooks.)
2024-12-16 14:28:51 -05:00
Augustin Cavalier e534029ca0 libroot: Remove some old TODOs from fork() implementation.
The first was added in 2004 when there wasn't even a branch for
initializing the child; I think this can be considered done now.
The second was added in 2010, but it seems in the meantime we've
decided that reinitializing locks is the best way to make them
consistent after calling fork(), so it's also obsolete.
2024-12-16 14:20:11 -05:00
Augustin Cavalier 9a2e367eae kernel/vm: Enforce more area protection restrictions.
Most notably in vm_resize_area, but also a missed one in transfer_area.
Solves TODOs.
2024-12-16 14:16:58 -05:00
Augustin Cavalier e52dd571d9 bootloader: Make releasing the heap the platform loader's responsibility.
Otherwise, platform loaders couldn't make heap allocations inside
platform_start_kernel(), which some loaders (e.g. EFI) do.

Implement calling heap_release() for the BIOS loaders at least.
This gets us back the ~1.5MB of bootloader heap memory there.
2024-12-16 13:36:39 -05:00
Augustin Cavalier fc815a9c7a kernel/vm: Set sAvailableMemory from the reserved physical pages size.
Rather than setting it from the total count of pages, and then reducing
it by the size of the B_ALREADY_WIRED areas incrementally. This means
that other things allocated in the early boot period (like page tables)
will also be accounted for. The downside is that, if they don't have
a corresponding area, then any pages freed later on won't also unreserve
memory at present; but the early boot page tables likely won't be freed
at all (since they'll be in use; or should have already been freed in the
case of the 32-bit to PAE transition.)

(In the future, we should reserve memory as well as pages for the page
tables, and that will take care of that problem anyway.)

Booting x86_64 in QEMU with 1GB of RAM, the old accounting method produced
an initial (after ALREADY_WIRED accounting) sAvailableMemory of 251,368
total pages, while this new accounting method gives 250,812 instead,
a difference of 556 pages. (Some of that is probably the never-freed
bootloader memory, which I think is around ~360 pages.)

Overall this should reduce the amount of "theoretically available but
actually inaccessible" memory, which should hopefully help with the VM
getting itself into trouble thinking memory is available when it
really isn't.
2024-12-14 12:01:29 -05:00
Augustin Cavalier 2c84bc3c0e kernel/vm: Shrink commitments in discard_area_range if possible.
Confirmed by X512 to work with "mimalloc".

Change-Id: I981d6ef2d035a98f50b1b5cae1f698b9531e7dde
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8682
Tested-by: Commit checker robot <[email protected]>
Haiku-Format: Haiku-format Bot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2024-12-14 16:21:16 +00:00
Augustin Cavalier cde0531bd9 ACPI: Restore use of uncached memory for physical mappings outside ARM.
See inline comment: we can potentially wind up with conflicting mappings,
depending on what the system ACPI firmware tells ACPICA to do, so it's
best if we avoid using non-default types on architectures where they
aren't strictly necessary.

Fixes #19119 and related issues.
2024-12-13 20:14:05 -05:00
Augustin Cavalier b592ba6662 kernel/vm: Set the upper cache's commitment in vm_copy_on_write_area.
Otherwise we may fault later but have no memory to satisfy the fault.

For a compile of HaikuDepot and the mime_db in VMware with -j4, this
seems to increase the wait time on the "available memory" lock from
~0.1s to ~0.5s, and the wait count from ~500 to ~1500 (overall real time
~30s.) Probably we can mitigate that later by doing atomic updates on
sAvailableMemory, at least for releasing memory.

Change-Id: I61abc28d1fc30f7b3d5fd9a2e68e4f4ec960f88d
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8677
Reviewed-by: waddlesplash <[email protected]>
2024-12-13 23:50:35 +00:00
Augustin Cavalier 2acb67eef0 kernel/vm: Handle vm_copy_on_write_area failing properly.
Just delete the newly-created area and return the error.

Fixes #13455.
2024-12-13 18:08:22 -05:00
Augustin Cavalier 5cfac6e80f kernel/vm: Handle overcommitting areas in cut_area properly.
We shouldn't adjust their commitments directly.
2024-12-13 18:05:26 -05:00
Augustin Cavalier 038d9b44d1 kernel/listeners: Use an rw_spinlock for the gWaitObjectListenerLock.
When the system profiler is in use, this spinlock is used very often.
Internally there's another spinlock which isn't (yet) rw, though.
2024-12-13 17:17:43 -05:00
Augustin Cavalier 5a39b9f82f kernel/vm: Remove unused "no_cache_change" member from VMArea. 2024-12-13 17:14:46 -05:00
Augustin Cavalier 9774380755 kernel/vm: More fixes to commitment handling in cut_area.
* Fix a silly bug in compute_area_page_commitment that was leading to
   the cache's pages not being taken into account at all.

 * Don't let VMCache::Resize() and Rebase() alter the commitments,
   but rather let us do that. Add assertions that they did not fail.

 * Move area->cache_offset increment up so that compute_area_page_commitment
   can use it as it needs to.

Fixes assertion failures from boehm-gc tests following the previous commits.
2024-12-13 16:57:11 -05:00
Augustin Cavalier 97df206a85 kernel/vm: Accept negative (no) priority in VMCache's Resize and Rebase.
This means that we won't try and change the commitment at all, and it
will be up to the caller to do that instead.

Also move the commitment change from the beginning to the end of Rebase,
matching Resize. This way, we won't trip the new asserts added to Commit()
in the previous commits.

Add a relevant assert to vm_try_reserve_memory to make sure the
negative priority doesn't end up down that far.
2024-12-13 16:36:56 -05:00
Augustin Cavalier d00cb444a6 kernel/vm: Decommit discarded pages of overcommitted caches.
Overcommitted caches should only have commitments equal to the
number of pages they actually contain, so we should decommit
whenever pages are discarded.

This changes the API of VMCache::Discard to return an ssize_t
of the size of pages that were discarded (or a negative error on
failure.) Nothing checked the return value besides things in VMCache
itself, it appears; but it apparently never fails, so that's fine.

Also add asserts to Commit() that the new commitment at least
encompasses all pages the cache actually contains.
2024-12-13 15:08:45 -05:00
Augustin Cavalier 4e993df9e9 kernel/vm: Consider cache overcommit status in copy_area and mprotect.
In copy_on_write_area, the copied cache should have the same overcommit
status as the original area, and in set_memory_protection, we shouldn't
change the committed size at all if the cache is overcommitting (otherwise,
we'd wind up shrinking cache's commit sizes below the actual number of
pages they contained in some cases.)
2024-12-13 14:28:07 -05:00
Augustin Cavalier e7af1dd2e0 kernel/vm: Introduce VMCache::CanOvercommit().
Allows the Anonymous caches to report overcommitting status.
2024-12-13 14:25:40 -05:00
Augustin Cavalier 8308c16a5c kernel/vm: Add missing parentheses.
No functional change.
2024-12-13 14:20:48 -05:00
Augustin Cavalier 7aafc79ba4 kernel/debug: Minor style fix in the system_profiler. 2024-12-11 14:17:28 -05:00
Augustin Cavalier 12be2aa0b3 kernel/vm: Fix and reactivate VMAnonymousNoSwapCache::Merge.
It seems this method was never renamed when MergeStore was renamed
to Merge all the way back in hrev27179. However, that wound up
working out, because this method also didn't call the base class
implementation that actually merges the page trees properly, so
it wouldn't have worked anyway.
2024-12-11 14:17:14 -05:00
Augustin Cavalier f8c3cc3459 kernel/vm: Skip acquiring the available memory lock if there's nothing to unreserve.
This can happen when deleting VMCaches that were overcommitted or
never had any reservation, or caches that had their commitments
merged.
2024-12-11 14:14:30 -05:00
Augustin Cavalier be88b511d7 kernel/vm: Remove an unneeded and misplaced include.
VMArea.h is already included at the top of the file.
2024-12-11 14:13:36 -05:00
Augustin Cavalier 27e83b8be8 input: Adjust input_pointing_device_subtype enumeration and usages.
Follow input_device_type above: we don't have _TYPE or _SUBTYPE on
the end, but _POINTING in the middle, because these aren't in a global
"subtype" enumeration, but a B_POINTING_DEVICE-specific enumeration.

Also don't bother adding the UNKNOWN type to messages that have no
type; if it's not included, UNKNOWN is implied. Saves a few CPU cycles.

Change-Id: I9088b9fcee63bf001b43febbe1e3ac17eb1792b4
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8635
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2024-12-11 19:11:45 +00:00
Augustin Cavalier 254894210c LinkedLists: Rename MoveFrom method to TakeFrom.
"Move" now sounds like it has 'move' semantics (i.e. replaces this
structure's data with the other structure's data), while MoveFrom()
really had 'move+append' semantics (appends the other list's elements
to this list, and clears the other list.) To make this clearer, it's
here renamed to "TakeFrom".

This should reduce confusion with the other move-related APIs that
are starting to show up in the Haiku tree (e.g. "MoveFrom" in BRegion.)

Change-Id: Ib0a61a9c12fe8812020efd55a2a0818883883e2a
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8634
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
Reviewed-by: X512 X512 <[email protected]>
2024-12-11 19:09:25 +00:00
Augustin Cavalier 3fef105fae kernel/vm: Adjust committed sizes even for caches without sources.
This is now necessary after enabling delayed commitments for anonymous
mappings with PROT_NONE.

Change-Id: I33b76f9d9f6a1d560793e523b74e9ac9fd7a4f62
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8676
Reviewed-by: waddlesplash <[email protected]>
2024-12-11 06:25:23 +00:00
Augustin Cavalier 3cd8a6719d kernel/vm: Make privately-mapped anonymous regions avoid committing memory too.
This was already the case for non-anonymous regions (i.e. mmap'ed files),
but wasn't the case for anonymous ones (fd < 0). Now it is.
2024-12-10 22:34:16 -05:00
Augustin Cavalier c4a59a7a5f file_systems/QueryParser: Don't try to read the key size of invalid indexes.
Fixes a rare corner case.
2024-12-10 16:28:28 -05:00
Augustin Cavalier f63a4a17ea kernel/fs: Unlock the unused-vnodes lock before continue'ing.
Otherwise we'll unlock in the wrong order and trigger an "interrupts
disabled" assertion in this case.
2024-12-10 13:53:06 -05:00
Augustin Cavalier 81f187cbd9 stdlib.h: Remove *rand48_r methods.
These were declared in this header on BeOS, so we need to keep
them around for ABI compatibility, but they are nonstandard
and no other C library besides glibc appears to provide them
at all (not even musl, and none of the BSDs.)
2024-12-10 13:15:06 -05:00
Augustin Cavalier 7f7ff2884f freebsd_wlan: Enable -fvisibility=hidden.
Reduces the size of WiFi drivers by a bit (and reduces the number
of symbols the kernel has to resolve within the binaries.)

Tested with realtekwifi, still works.
2024-12-10 13:00:49 -05:00
Augustin Cavalier 4a87c95e0a kernel/fs: Handle O_RDONLY | O_TRUNC in the VFS rather than filesystems.
The POSIX specification says that the behavior of specifying O_TRUNC
with O_RDONLY is "undefined", but the Linux manpages ominously state
"On many systems the file is actually truncated." I tested this,
and indeed on Linux the file is actually truncated.

This doesn't seem like a very sensible behavior, so in this commit
it's changed to return B_NOT_ALLOWED (EPERM) if those flags are
specified together. The FAT driver already did this, but most other
filesystem drivers just checked write access permissions and
truncated the file anyway; so this is indeed a behavioral change.

Change-Id: If2e76782743ee91d934dc7e0c2f306f37b159a0f
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8625
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: Axel Dörfler <[email protected]>
2024-12-09 01:00:33 +00:00
Augustin Cavalier 6690c6cc72 kernel/vm: Don't allow mapping areas larger than the source cache's size.
And also return an error if the offset of an mmap() request isn't
page-aligned, rather than silently aligning it. libroot already
did this for mmap() itself, so this only affects things that invoke
the operation or syscall directly.

Fixes #19155.

Change-Id: I081dd1492d06f56536c1dbb5d4028345f95c4460
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8622
Reviewed-by: waddlesplash <[email protected]>
2024-12-06 22:15:03 +00:00
Augustin Cavalier ae6629023f tests/kernel/vm: Add mmap_invalid_tests.
Move one test from map_cut_tests, otherwise the other tests are new.
Includes a test for the cause of #19155.

Change-Id: I15abbf11f2c6db7385754825abbcc159414f6fd8
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8631
Reviewed-by: waddlesplash <[email protected]>
2024-12-06 22:15:03 +00:00
Augustin Cavalier 79ebd4147e BList: Slight code and parameter name cleanup.
* Clarify the fResizeThreshold logic and remove the comment.

 * Rename "count" constructor argument to "blockSize", as this is
   what it actually does.

No functional change intended.

Change-Id: I993bf0e695f47da181e9fb50b9a964edfd4a0adc
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8629
Reviewed-by: waddlesplash <[email protected]>
2024-12-06 19:52:05 +00:00
Augustin Cavalier edf7c7749c tests/kernel: Move a bunch of VM-related tests to the "vm" subdirectory.
There's still a number of tests in the root that should be moved
to other subdirectories, but this at least gets the VM-related ones
into a subdirectory (and removes a stale entry in the VM Jamfile.)
2024-12-05 23:25:36 -05:00
Augustin Cavalier 6193a477b8 realtekwifi & net80211: Synchronize with FreeBSD.
As of upstream fcb5e8d0c19ac21515ab3047d39a76b32d835cec.
2024-12-05 23:18:45 -05:00
Augustin Cavalier cd730cbd7c kernel/vm: Drop an actually obsolete comment.
This was introduced in hrev27179 to refer to the member "merge_swap",
which is now gone. The "busy_writing" field isn't used in Merge().
2024-12-05 17:13:26 -05:00
Augustin Cavalier 5cf7633a39 Revert "kernel/vm: Remove an obsolete comment."
This reverts commit 1db0961121.

It turns out the comment is not obsolete; what it refers to isn't
PAE systems but true 32-bit ones. I'm not sure we should use
64-bit cache offsets even there, but that's a decision for another
time.
2024-12-05 17:05:44 -05:00
Augustin Cavalier 319bd18c13 kernel/vm: Use KERNEL_TOP in place of (KERNEL_BASE + (KERNEL_SIZE - 1)).
No functional change.
2024-12-05 17:05:44 -05:00
Augustin Cavalier 2d6c8a8481 kernel/vm: Minor coding style cleanups. 2024-12-04 16:43:12 -05:00
Augustin Cavalier 245133b2c1 kernel/vm: Check for overflows in VMUserAddressSpace::CanResizeArea().
It can happen if a very large size is specified.
2024-12-04 16:42:57 -05:00
Augustin Cavalier 6bf630c684 tests/posix: Add symlink_create_test.
Combines the testcases from #19062 and #18355.
2024-12-04 14:09:41 -05:00
Augustin Cavalier 053116301e DebugAnalyzer: Increase the size of the buffer to print pointer values.
We need at least 19 characters on 64-bit architectures:
2 for "0x", 16 for the pointer, and 1 for the \0. So just
use a round 20.

Fixes cut-off pointer values in the display.
2024-12-04 13:38:14 -05:00
Augustin Cavalier 5434ba8dff kernel/debug: Report dummy names for THREAD_BLOCK_TYPE_OTHER_OBJECT.
So that DebugAnalyzer can display them properly.
2024-12-04 13:37:32 -05:00
Augustin Cavalier 149182f6ac kernel/fs: Don't report the leaf node in vnode_path_to_vnode unless it's last.
That is, if we have a path like "/nonexistent-1/nonexistent-2/file",
we shouldn't report "nonexistent-1" as the "leaf" node, but rather
nothing at all. Otherwise, create_vnode() that expects the result to be a
directory vnode plus a nonexistent file will get confused and try
to create a file "/nonexistent-1" rather than just bailing out.

This fixes #19062. The reproducer in that ticket caused a scenario
much like the above; and since rootfs doesn't support regular files,
it returned "EINVAL" when attempting to create the "/nonexistent" file.
After this change, we get ENOENT as expected.

Change-Id: Ifcaaa858403fb747858800afbf644051bb9913ad
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8621
Reviewed-by: Jérôme Duval <[email protected]>
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2024-12-04 17:06:59 +00:00
Augustin Cavalier 4c98a54842 kernel/fs: Minor cleanup to vnode_path_to_vnode and related methods.
No functional change intended.

Change-Id: Ie198854ef6bc434db87d362ebc31fd08ab44c176
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8620
Reviewed-by: waddlesplash <[email protected]>
2024-12-04 17:06:59 +00:00
Augustin Cavalier bef7e1c1b1 kernel/device_manager: Adjust assertion in IOBuffer::GetNextVirtualVec.
cookie->mapped_area may be < 0 but not -1 because map_physical_memory_vecs
previously failed.

Fixes #19273.
2024-12-03 15:50:37 -05:00
Augustin Cavalier 23b34b6c0e kernel/fs: Clean up code in synchronous_io.
Minor functional changes: slightly different log message,
error return of GetNextVirtualVec is actually reported properly.
2024-12-03 15:49:53 -05:00
Augustin Cavalier 20f109414c kernel/vm: Write adjacent pages in the page_writer, if possible.
This is an optimization in two ways: first, it allows us to avoid
unlocking the cache or needing the "unreferenced" store-ref acquisition
if we can write the next page in the same cache; and second, the
I/O will be much more tightly combined, as PageWriteTransfer will
be able to merge the iovecs more often and do less I/O (and on
spinning disks, we'll write adjacent regions more often, too.)

Based on some basic logging, this happens very often. I saw adjacent
writes numbers of e.g. 203, 255 (kNumPages), 139, 15, 99, etc. There
were a fair number of 0s, but that case shouldn't add too much overhead
since we bail out very rapidly.

In the case of things like "dd if=/dev/zero of=file ...", this is a
major optimization, since it massively reduces lock contention between
the dd thread and the page_writer thread.

A compile benchmark seems relatively similar, maybe slightly faster.
2024-12-03 13:59:35 -05:00
Augustin Cavalier 487d75717a kernel/disk_device_manager: Invoke base class in KFileDiskDevice::Unset().
Otherwise, the FD won't be closed, and then the underlying vnode
won't ever be released, leading to files whose space can't be reclaimed
without rebooting and running checkfs.
2024-12-03 13:18:07 -05:00
Augustin Cavalier 896f7fdb75 kernel/disk_device_manager: Cleanup code style, fix some minor TODOs. 2024-12-03 12:31:20 -05:00
Augustin Cavalier 1fd15efda9 BTimedEventQueue: Use mutex_init to appease GCC2. 2024-12-02 14:06:14 -05:00
Augustin Cavalier 0ffb72029d BTimedEventQueue: Flush events on destruction, other minor cleanup.
* The Be Book specifies that events will be flushed on destruction.
   The previous implementation of this class didn't do that, but
   we ought to. Unless the queued events have attached buffers or
   a cleanup hook, this is a no-op anyway.

 * Use a mutex rather than a BLocker for the allocation lock. This
   saves a semaphore per queue.

 * Put the queue_entry in an anonymous namespace. It shouldn't have
   any global symbols anyway, but it doesn't hurt.
2024-12-02 13:57:03 -05:00
Augustin Cavalier 4055af5143 BTimedEventQueue: Rewrite from scratch, avoiding malloc().
The previous implementation allocated and freed event objects
on every insertion and removal using malloc()/free(). It was also
licensed under a "distributions in binary form must reproduce ...
in the binary" license, which is more restrictive than the MIT license
that we prefer.

So, this is a rewrite from scratch. It uses the standard
DoublyLinkedList<> rather than rolling its own, and manages
a free list of event queue objects rather than hitting malloc()
all the time. It only frees chunks on destruction, though,
but that hopefully won't be an issue anyway.

All tests from the TimedEventQueueTest still pass, and media playback
still works as before.

Change-Id: Ia940b6176f8051ae4823b75acd305ded8783d1e0
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8594
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
2024-11-28 17:48:23 +00:00
Augustin Cavalier bb1f240594 file_systems: Invert query equation scoring values.
Previously, lower was better, and higher was worse. But really we want
the scores to be based primarily around the index sizes, which can
grow to be very large, so a maximum score is hard to determine.

Instead, start with the index size, and then divide to make it smaller
based on how "useful" the equation terms will be in searching it.

Improves the performance of queries like those in #19080; according
to humdinger's testing, the query with the most expensive term first
went from ~2.0s execution time down to ~0.7s, same as the query with
the least expensive term first.

Change-Id: Id71fa21c95cfe3d8d0019ff356bdf4935446411f
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8593
Reviewed-by: waddlesplash <[email protected]>
2024-11-26 17:13:29 +00:00
Augustin Cavalier 4da2ed4103 kernel/vm: Let TRACE_FAULTS enable logging of all faults.
This amends 0f42cf8d7d.

That commit accidentally contained an unrelated patch to the one
described in the commit message, turning a number of prints that
happened unconditionally to ones that happened only for faults
occurring in kernel context. This change re-enables those prints
when TRACE_FAULTS is set (which it isn't by default.)

The original change to reduce prints was done to cut down on syslog spam
from applications like Boehm-GC, the JVM, or emulators that trigger
many (thousands or more) faults on purpose and then catch them in
signal handlers. In the case where these faults are crashes, then
the debug_server will still log those crashes into the syslog anyway.
2024-11-25 14:02:38 -05:00
waddlesplash e4b10ec126 Revert "ps2_dev: shorter timeout for mouse reset"
This reverts commit 8a00ea4af6.

Reason for revert: #19266.

Change-Id: Ifecd8eac87eb3dd4f5f92a98bf849066db6ba8ed
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8598
Reviewed-by: waddlesplash <[email protected]>
2024-11-25 18:55:22 +00:00
Augustin Cavalier 0f42cf8d7d kernel/vm: Handle dynamically-sized commitments properly in copy_area and cut_area.
And handle another corner case in set_memory_protection.

This should fix the remaining causes of #19012.

Change-Id: I92fc184024ffb3923239da5e0bd90efc3085da28
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8589
Reviewed-by: waddlesplash <[email protected]>
2024-11-25 18:46:43 +00:00
Augustin Cavalier 3f928f8e10 kernel/vm: Correct address passed to VMCache::LookupPage.
LookupPage() takes an offset in the cache, not a global address.

Helps with #19012, but there are other causes still to be solved.
2024-11-23 13:43:57 -05:00
Augustin Cavalier 608fd0cdb9 RAMFS: More cleanup of Locker usages in kernel_interface.
No functional change intended.
2024-11-22 23:29:41 -05:00
Augustin Cavalier ce5375c0bf RAMFS: ramfs_close_attr needs a write-lock. 2024-11-22 21:30:18 -05:00
Augustin Cavalier bab3f64413 RAMFS: Lock attribute iterators separate from entry iterators.
And clean up the code style while at it.
2024-11-22 20:29:18 -05:00
Augustin Cavalier e2e7d84d21 RAMFS: Properly check that the Lockers are actually locked.
They pretty much always will be, but better to be safe. Also
de-indent one level and use an early return for this.
2024-11-22 18:07:26 -05:00
Augustin Cavalier 374d7a1eb1 RAMFS: Minor code style cleanups to Volume. 2024-11-22 17:42:00 -05:00
Augustin Cavalier fe0e833f1f fat, exfat: Add acquire_vnode/put_vnode calls in the I/O hooks.
Same as was done in BFS.
2024-11-22 16:57:27 -05:00
Augustin Cavalier 9708b08060 KPath: Use a default buffer size of B_PATH_NAME_LENGTH without + 1.
B_PATH_NAME_LENGTH == PATH_MAX, and PATH_MAX is inclusive of the final
NULL terminator, so we don't need a + 1 here.

The original KPath default was to not use + 1, but that was changed in
42e3c6f978 due to all the consumers that did.

But all those consumers are wrong, it appears; they should just be
using the default length instead. So now we do that.
2024-11-22 16:56:15 -05:00
Augustin Cavalier cc9ea55c59 file_systems/QueryParser: Coerce types up front, and handle B_TIME_TYPE better.
* If we coerce types inside the switch(), then the "type already converted"
   check at the beginning will fail every time, causing us to reconvert,
   which is surely bad for performance.

 * B_TIME_TYPE should be INT32 or INT64 depending on what its size is.

May help with #19080.
2024-11-21 23:19:09 -05:00
Augustin Cavalier 783b77b14f BFS: Fix handling of the last_modified index.
Its values must be shifted before comparing against them.
Also handle the last-modified times correctly in NodeGetLastModifiedTime.

Fixes an issue noticed in #19080 which was a regression from
the query refactor earlier this year.

Also while at it, remove a needless lock in EntryGetName;
Inode::GetName acquires this lock for us.
2024-11-21 22:38:41 -05:00
Augustin Cavalier 1abf2059a7 BFS: Adjust CachedNode::SetToWritable for consistency with SetTo.
Follow-up to an old review comment.
2024-11-21 22:38:41 -05:00
Augustin Cavalier 7de59aee29 realtekwifi: Import changes from FreeBSD HEAD.
Same source commit as the previous import of net80211 changes.

May help with USB stalls and other issues.
Tested, WiFi still works.
2024-11-21 10:43:40 -05:00
Augustin Cavalier da3ca31854 freebsd_wlan: Synchronize net80211 with FreeBSD.
From upstream commit d99eb8230eb717ab0b2eba948614d0f2f2b5dd2b.

Includes a variety of new macros that are used by drivers.
2024-11-21 10:40:37 -05:00
Augustin Cavalier 56c5e34285 freebsd_network: Use if_inc_counter and add to the "drops" counter in HANDOFF. 2024-11-20 18:46:55 -05:00
Augustin Cavalier f42bea3139 freebsd_wlan: Use vap->iv_output as on FreeBSD.
We pass a NULL destination address, so we need to keep the added
NULL check, but after the previous commit we can now use the
real hook function here.

WiFi still works (tested with realtekwifi.)
2024-11-20 18:46:32 -05:00
Augustin Cavalier 99dcbd9716 freebsd_network: Use if_transmit in ether_output.
This is what FreeBSD does. The default implementation (in this
same file) does what ether_output did before, but the FreeBSD
net80211 stack overrides the method.
2024-11-20 18:45:44 -05:00
Augustin Cavalier 551a9b9a01 BFS: Keep references to vnodes during asynchronous I/O.
IORequest notifications begin by notifying the "finished" condition,
then invoking the request callback, then invoking the parent callback.

vfs_{read|write}_pages wait on the "finished" condition and then
return at once, potentially releasing their references to the vnode
in question, before the request callback is even invoked. The request
callback is what (eventually) invokes iterative_io_finished_hook,
which meant that we were accessing the Inode object after our reference
to it had already been released.

We can't really change IORequest notification order, as any one of the
notifications could delete the request, and indeed the first one does here.
So the solution is just to acquire another reference to the vnode and
release it in the finished hook.

Fixes #19122 and #8405.
2024-11-20 18:03:09 -05:00
Augustin Cavalier 138d92635d kernel/block_cache: More 32-bit fixes. 2024-11-20 17:25:50 -05:00
Augustin Cavalier 282ff4240a kernel/block_cache: Adjust declaration of _IOFinished. 2024-11-20 16:48:07 -05:00
Augustin Cavalier f3884d7da0 kernel/block_cache: Correct callback parameter type.
Should fix x86 32-bit build.
2024-11-20 16:20:13 -05:00
Augustin Cavalier d43d69f7da kernel/block_cache: Cleanups and fixes to the prefetcher.
* Use do_fd_io and drop the unnecessary iteration callback.

 * Make the callback call a non-static function to avoid needing
   to fetch values.

 * Unlock the cache before calling the I/O function.

Should fix #19259.
2024-11-20 15:54:21 -05:00
Augustin Cavalier 5c56d775a9 kernel/fs: Fix handling of partial requests in do_synchronous_iterative_vnode_io.
If get_vecs returns 0 and no vecs, then we need to quit iterating.
Otherwise we'll just loop forever and leak memory.

Also add an assert in IOBuffer::GetNextVirtualVec that would have caught
this problem, and the memory leak it results in.
2024-11-20 15:47:56 -05:00
Augustin Cavalier e829154ffe kernel/fs: Implement do_fd_io using do_iterative_fd_io.
We need to hold a reference to the file descriptor throughout
the I/O operation, which do_iterative_fd_io already takes care of.
So just modify it to handle not having the additional callbacks.

Nothing actually uses do_fd_io at present, though it will be
in the next commits.
2024-11-20 15:47:02 -05:00