Commit Graph

67277 Commits

Author SHA1 Message Date
Augustin Cavalier
66f51cb3b9 kernel/team: Do not inherit anything from the kernel's IO context.
We already didn't inherit FDs, which meant that the only thing we
did meaningfully inherit was the table size. That meant that basically
no applications actually had a table size of the default 256, but all
were at the kernel's 4096 (except Tracker and anything started by it,
as Tracker resets it to 512), and also that basically all applications
had FD tables allocated with the raw allocator instead of the block
allocator, which isn't very efficient.

Since this reduces the default FD table size, some applications
might encounter problems. However, build systems and other such
tools should already increase this by default as needed, and it's
easy enough to patch in calls to setrlimit() if it turns out
some applications needed a higher default after all.

Also remove a redundant call to vfs_exec_io_context. Calling
vfs_new_io_context with the second argument set to "true"
already skips cloning CLOEXEC FDs.
2025-01-03 12:26:13 -05:00
Augustin Cavalier
9479a57c4e kernel/slab: Organize block-sizes array by size increment.
This way the patterns are clearer.
No functional change.
2025-01-02 23:22:38 -05:00
Augustin Cavalier
d4a1fc648b kernel/vm: Drop VMCacheRef::ref_count.
Nothing touches it at all.
2025-01-02 21:32:44 -05:00
Augustin Cavalier
0bd8ba1b9e kernel/vm: Convert sAvailableMemoryLock into an rw_spinlock.
In most cases, we just need a read spinlock and then atomics
when updating this value, significantly reducing lock contention.
But this also paves the way for the use of these methods in
page-related hot paths, e.g. for reserving memory as well as pages
when mapping page tables.
2025-01-02 16:01:33 -05:00
Augustin Cavalier
c05dec40eb kernel/vm: Allow reserving more memory than system RAM has.
Now that we don't wait the full timeout in most cases, this "optimization"
isn't really necessary; and it was also preventing reserving amounts
of memory that would require both RAM and swap, which is suboptimal
but there's not really much reason to prevent it.
2025-01-02 15:36:52 -05:00
Augustin Cavalier
74012f55ed kernel/vm: Fail reserving memory more rapidly based on a retry count.
Previously, we would run the low resource manager continously in
a loop until reaching the timeout. This used up a lot of CPU
needlessly, because if the manager fails to release the memory
we need in the first few runs, it's unlikely to do so later.

We could add another waiting mechanism here, but ultimately
it seems to make more sense to just fail early before reaching the
timeout at all, in this case.

Improves system responsiveness under high memory pressure.
2025-01-02 15:35:33 -05:00
Augustin Cavalier
f27c94e4d3 kernel/fs: Don't hold the hot-vnodes lock too long in free_unused_vnodes.
vnode_used also acquires it, and acquiring a read-lock recursively
is illegal and can lead to deadlocks. Holding it across a vnode
lock acquisition isn't a good idea either. We only need it to hold it
before acquiring the unused-vnodes lock, and we can actually skip
acquiring that a second time altogether.

Should fix a deadlock observed by PulkoMandy.
2025-01-02 12:28:45 -05:00
Augustin Cavalier
802fa4afae kernel/arch: Add missing handling for _flags == NULL in the PAE UnmapPage.
This was missed in 7651b97c0a.
2025-01-01 17:10:01 -05:00
Humdinger
8aec27565f Rename notification sound names
Having "Notification" at the beginning of the sound names makes
sure their entries in the Sounds preferences are always next to each
other.

Change-Id: Ia47431ecd4c5e8c346f1417a4d29a151c06217cf
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8737
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Fredrik Holmqvist <fredrik.holmqvist@gmail.com>
2024-12-31 07:37:02 +00:00
Augustin Cavalier
e6a4a197e2 PowerStatus: Quit if asked to install in Deskbar when already installed.
We don't want to open a window in this case.
2024-12-30 21:33:31 -05:00
Augustin Cavalier
faf884663e kernel: Use CPUCLOCK_SPECIAL in user_timer_get_clock.
CPUCLOCK_TEAM is 0 so the last comparison was actually tautological.
Add a final branch for unrecognized flags.
2024-12-30 20:39:00 -05:00
Augustin Cavalier
b6b0fb529d kernel/stack: Fix lookup of chains for SOCK_RAW in put_domain_protocols.
If we fail to look up the chain, we won't uninitialize the protocols,
causing a memory leak (or even dangling references.) Add an ASSERT
that would have caught this problem.

Fixes a memory leak when using raw sockets.
2024-12-30 15:39:56 -05:00
Augustin Cavalier
4c29a795ad network/stack: Clean up hashing logic a bit.
No functional change intended.
2024-12-30 15:38:53 -05:00
Augustin Cavalier
f44cb411cc Package Kit & packagefs: Allocate scratch buffers for decompression further up.
Zstd wants a ~90 KB scratch buffer to decompress our 64 KB chunks.
Rather than let it allocate that itself every time, pass in a 2*64KB
"scratch" buffer and statically allocate the working memory from it.
Pass it down using iovecs, and pass down the other buffers in the same
way, to reduce parameters.

Further, rework the object_cache used for heap decompression buffers
to contain objects sized as 4x64KB, so we only need to do one allocation
and deallocation for the compression/decompression and scratch buffers.
Set the minimum reserve to 1 so that the low-memory manager doesn't
reclaim this, as we'll need it when reading back data.

Improves packagefs I/O performance (and thus boot speeds at least a bit,
it appears.)

Change-Id: Id51f6f598b33b9d757a283184c533bb97049529f
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8717
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
2024-12-30 19:04:10 +00:00
Augustin Cavalier
7651b97c0a kernel/vm: Consolidate implementations of VMTranslationMap::UnmapArea.
This adds some new parameters to UnmapPage and UnmapPages. The important
one is a "_flags" pointer to UnmapPage, which if specified will be
filled with the page flags instead of PageUnmapped() being called
(and Flush() won't be invoked, either.)

This removes the remaining PAGE_STATE_* changes from VM architecture code.

Change-Id: Iacbc424dd8a75a79986edcd7f04d15a10f773c87
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8728
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2024-12-30 18:50:10 +00:00
Humdinger
783347df2b Sounds prefs: "pre-hear" button in file panel
* Using "SndFilePanel" from Be Sample Code by Todd Thomas with only
  small changes.

* Removed check for audio file in B_REFS_RECEIVED, because the file
  panel uses a BRefsFilter.

* Reset file panel location in case the panel was canceled.

* Use entry.IsDirectory() instead of entry.GetStat() for simplicity.

Change-Id: Ibb4a4cb8e3c4b60c85a9ba0b2e5287416bbc4b44
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8736
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
2024-12-30 18:01:18 +00:00
Devin Gillman
6a9e72b0d3 BuildSetup: Added HomeBrew Apple Silicon paths.
Addresses issue here: https://discuss.haiku-os.org/t/building-on-macos-cannot-find-zstd-h/14489/4

And the differences are called out on the install page here: https://docs.brew.sh/Installation

Cleanups by waddlesplash: put the new paths in their own 'block'
and adjust comments.

Change-Id: Ie00fbc07abae141d8ac0580dd661a2fc3cf7a216
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8732
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2024-12-30 17:06:31 +00:00
Jim906
7020e10ab8 userlandfs: Fix file_cache_read
* Prevent the userlandfs server from calling clone_area on an area
  that might have already been deleted.
* _HandleRequest(FileCacheReadRequest*) waits for a reply from the
  server when bytesRead > 0.  This ensures that the server has time to
  use the area holding the returned data, before that area is deleted
  when the RequestAllocator goes out of scope in the kernel add-on.
  However, if bytesRead is 0, the server will still call clone_area,
  even though by that time the area has probably been deleted.  This
  leads to a B_BAD_VALUE error when the FS tries to use the emulated
  file_cache_read at the end of a file, which differs from the
  normal behavior of file_cache_read.
* _HandleRequest(ReadFromIORequestRequest*) has similar logic in that
  it waits for a server reply, but not if size == 0.  It's possible
  that a similar problem could occur here. This test can be
  dropped if no requests with size 0 are ever sent from the server to
  begin with.
* For other _HandleRequest overrides, the kernel never waits for a
  server reply, and this causes no problems.  This could be because the
  size of data returned fits in the port buffer, so no external area
  needs to be created by RequestAllocator::AllocateAddress.

Change-Id: If070901c25d446e00e67a74a7883808d8a38dae2
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8721
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2024-12-30 17:00:48 +00:00
Augustin Cavalier
fccefbf347 kernel/vm: Use allocate_early instead of passing a get_free_page method to early_map.
Simplifies things significantly.
No functional change intended.

Change-Id: Ia14c2ec72038ad6f8b56a14974dca78e1877063c
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8725
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2024-12-28 14:47:32 +00:00
Augustin Cavalier
0c2ad1411f kernel/vm: Unreserve memory as well as unreserving pages.
In a basic test, I only saw one page of memory unreserved this way,
though.

Change-Id: I153bea280e26bee0d5b3159b24719f549b7b5178
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8724
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Haiku-Format: Haiku-format Bot <no-reply+haikuformatbot@haiku-os.org>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
2024-12-28 14:47:32 +00:00
Augustin Cavalier
b1a913c3aa kernel/vm: Free pages via vm_page_free only, not vm_page_set_state.
All consumers of this API should be adjusted here.

This partially paves the way for use of committed pages for page tables.

Change-Id: Id6fc2edc86fbd80e929c413e23cf8de1509a8215
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8723
Reviewed-by: X512 X512 <danger_mail@list.ru>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
2024-12-28 14:47:32 +00:00
Autocomitter
bd0f4983c8 Update translations from Pootle 2024-12-28 08:08:56 +00:00
Augustin Cavalier
c5874ee428 kernel/vm: Make use of VMTranslationMap::PageUnmapped in UnmapPages.
An extra argument is added to allow the VMAreaMappings objects to
be added to a queue instead of freed directly (and the lock unlocked,
and so on.)

All architectures adjusted.

This means there is now only one place in each TranslationMap that
the page state and other data is directly adjusted (in UnmapArea).

Change-Id: I3ed2d6d969d1b1e235144a1035c90c750779af27
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8716
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: X512 X512 <danger_mail@list.ru>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2024-12-27 22:07:34 +00:00
Augustin Cavalier
6f786da5f7 kernel/slab: Unreserve pages just before unreserving memory.
This makes the tails of _MapChunk and _UnmapChunk look more similar to
each other.
2024-12-27 16:21:00 -05:00
Augustin Cavalier
597097ae03 SCSI: Do not wait for memory in the critical path.
As swap can be written out this way.
2024-12-27 16:20:28 -05:00
Augustin Cavalier
2bc6f2846e kernel/vm: Increment missing before returning reservations.
Otherwise the next loop won't reserve all the pages we actually need.

Fixes "PANIC: Had reserved page, but there is none!" after yesterday's
changes.
2024-12-27 15:36:51 -05:00
Augustin Cavalier
0e898f694f kernel/vm: Decrement missing after stealing pages from the next waiter.
This isn't that important, as the only thing we do with "missing" in
this case is to report it to the low_resource manager.
2024-12-27 15:36:51 -05:00
Augustin Cavalier
0e63914d02 kernel/vm: Add an assert that we got as many pages as requested.
This is a cheap test to ensure we weren't woken up spuriously.
2024-12-27 15:36:51 -05:00
Augustin Cavalier
054ecb9759 kernel/vm: Minor cleanups to vm_page code.
* Add some parentheses for clarity.

 * Remove a comment about unreserving pages. In fact this method is
   always called with pages already reserved, and in the path the comment
   was in, we wouldn't want to unreserve anyway, because we've
   successfully allocated.

 * Use a boolean rather than an int for "useCached".

No functional change intended.
2024-12-27 15:36:51 -05:00
Humdinger
05c63cc0fe Sounds prefs: don't show folders in Sounds menu
Besides the already set sound files, the Sounds popup menu shows
the files of all the B_*_SOUNDS_DIRECTORY.
As people/packages may sort sound themes in sub-folders there, only
add files from there to the menu, no folders.

Change-Id: I79cda5d547fc1a0ec0234384e3b76f2c455b2881
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8722
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2024-12-27 16:15:24 +00:00
Humdinger
ae08ea6750 Sound prefs: save path for file dialog
* Default to B_SYSTEM_SOUNDS_DIRECTORY (if it doen't exist, the
  home folder gets set automatically).

* Save the last used path in the Sounds_Settings file.

* If the last used path isn't valid any more, default to
  B_SYSTEM_SOUNDS_DIRECTORY.

Change-Id: I90bf7e640e648e6e7dfc2941440550cb074c18f0
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8704
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
Haiku-Format: Haiku-format Bot <no-reply+haikuformatbot@haiku-os.org>
2024-12-27 16:04:33 +00:00
Alexander von Gluck
33beece770 jam/BuildSetup: Gracefully handle arm64, riscv HOST_CPU
* HOST_CPU was getting set to "" on arm64 host builds of
  Haiku which resulted in varying host tool directories
  objects/linux/x86_64/release vs objects/linux/release
* This captures the changes in buildtools abcf50c2 which
  adds proper arm 64, and riscv 32/64 OSPLAT definitions

Change-Id: Ife768fe3e4b1f90748b8f09afd632d4cd9c87d2d
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8720
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2024-12-27 15:29:12 +00:00
Augustin Cavalier
38210e8510 kernel/team: Minor code cleanup in LockTeamAndParent and LockTeamAndProcessGroup.
Make them look a bit more similar to each other.
No functional change intended.
2024-12-26 22:52:51 -05:00
Augustin Cavalier
da880bc23d kernel/vm: Correct check for other waiters.
Since in the case where we're being inserted last, otherWaiter == NULL.
2024-12-26 22:32:42 -05:00
Augustin Cavalier
36dfbcad11 kernel/fs: Set a minimum reserve in the path-name cache.
This cache is used for allocating typically ephemeral KPath buffers
for syscall handlers and the like. Letting it be drained to 0 by
the low resource system will just make future VFS syscalls needlessly
slower, so make sure that doesn't happen.
2024-12-26 21:41:27 -05:00
Augustin Cavalier
84ba9f198e packagefs: Use VM_PRIORITY_USER for reserving cache pages.
If it fails, we just fall back to uncached reading, so it's not
that important.
2024-12-26 21:40:10 -05:00
Augustin Cavalier
ef386dfe75 kernel/vm: Fix a race in reserve_pages.
See inline comment: it's possible to race with other threads
and wind up with pages if there are a lot of waiters or lock
contention. Just bail out and retry in that case.

The only other potential way to fix this I can think of would be to add a
read-write locking strategy; however this would still be prone to races,
since we acquire and release the lock in a loop in reserve_pages,
and keep whatever pages we managed to reserve from the last iteration.
2024-12-26 20:34:27 -05:00
Augustin Cavalier
f33f17f18e kernel/vm: Cleanups to reserve_pages.
* Rename "count" to "missing", makes clearer what it is and does.

 * Move a comment for clarity.

 * Remove an unnecessary Lock().
2024-12-26 20:34:27 -05:00
Augustin Cavalier
0008c79e56 kernel/vm: Implement AcquireUnreferencedStoreRef in VMAnonymousCache.
This is needed for the page writer to be sure it can do its job.
Fixes swap support after hrev58420 broke it.
2024-12-26 20:34:27 -05:00
Augustin Cavalier
593cb3a54d kernel/vm: Let higher-priority waiters steal lower-priority waiters' reservations.
This way, we don't wind up in a situation where there are dozens of
waiters, each needing a handful of pages, but each also having a
handful of pages already reserved, and everything deadlocks.

Significantly improves system responsiveness under high memory usage.
There's still more to be done, however.
2024-12-26 20:34:27 -05:00
Augustin Cavalier
c9fe6a1441 kernel/user_debugger: Remove declaration for _user_get_stack_trace.
The method itself was removed in 8f9d4cad45.
2024-12-26 20:34:27 -05:00
Augustin Cavalier
2d246d1be0 kernel/vm: Assert in reserve_memory that the amount is a multiple of B_PAGE_SIZE.
It doesn't make sense to reserve memory in other increments.

This would have caught #19295 earlier.

Also use PAGE_ALIGN in VMCache::SetMinimalCommitment.
2024-12-26 20:34:27 -05:00
Augustin Cavalier
8bb382decf kernel/vm: Drop vm_page_num_available_pages.
Nothing uses it, and it isn't correct anyway: vm_page_num_free_pages()
now includes cached pages, too, while vm_available_memory() includes
not just available memory pages but also swap.
2024-12-26 20:34:27 -05:00
Augustin Cavalier
a26220df71 kernel/vm: Use the correct PAGE_STATE for the queue count.
Avoids reserving data in the static area that we won't be using.
Also tweak one bit of coding style.
2024-12-26 20:34:27 -05:00
Augustin Cavalier
ec2f7c257b kernel/vm: Unreserve pages in bulk in VMCache::Delete and the MemoryManager.
Avoids extra wakeups when there are page reservation waiters.
Inspired by a patch from Jarek Pelczar, see #19034.
2024-12-26 20:34:26 -05:00
Augustin Cavalier
548202a11e kernel/vm: Actually increment the reservation count in page_free_etc.
The documentation comment claimed this was done but it actually wasn't,
potentially leading to leaks of pages. However, this method appears
to be passed reservation objects only in one rare case in vm_soft_fault
at present. In brief testing, I didn't manage to get that case to
happen.

This method will be used in more cases in future refactors, so it's
important it work correctly.
2024-12-26 20:34:26 -05:00
John Scipione
3c18c3d5c6 Tracker: Restore IsFiltering() to IsRefFiltering() or IsTypeAheadFiltering()
Add IsRefFiltering() and IsFiltering() is once again either kind
of filtering: ref or type-ahead.

Use IsRefFiltering() in a few places, otherwise use IsFiltering()
to restore filtering code so that it gets triggered on either kind
of filter.

Make the filtering methods inline to avoid function call overhead.

Fixes #19317

Change-Id: I27407ca33e8f2b967975c8a8ef8de83105442bd4
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8715
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Haiku-Format: Haiku-format Bot <no-reply+haikuformatbot@haiku-os.org>
2024-12-26 22:10:31 +00:00
John Scipione
ffed6d0bff Tracker: 100 char style fixes to PoseView
Change-Id: Ife469064cd2e92e23da80849d4ba9f07936bf210
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8714
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2024-12-26 22:10:31 +00:00
JackBurton79
e4420b24eb Terminal: fixed possible memory leak on error.
Also add const to some methods

Change-Id: I6355a1f2f49ac6b819ff4c53983fce76119ed258
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8713
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2024-12-26 10:21:11 +00:00
JackBurton79
06fdc2e30f Terminal: Initialize fore and back color to sane defaults.
Fixes missing / random colors when using Terminal as replicant and does not have side effects

Change-Id: I839098cf95298c729eac9f68c4d6de9308a47d39
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8710
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
2024-12-24 16:30:52 +00:00