Commit Graph

2130 Commits

Author SHA1 Message Date
ad
ba90a6ba38 Counter tweaks:
- Don't need to count anonpages+filepages any more; clean+unknown+dirty for
  each kind of page can be summed to get the totals.

- Track the number of free pages with a counter so that it's one less thing
  for the allocator to do, which opens up further options there.

- Remove cpu_count_sync_one().  It has no users and doesn't save a whole lot.
  For the cheap option, give cpu_count_sync() a boolean parameter indicating
  that a cached value is okay, and rate limit the updates for cached values
  to hz.
2020-06-11 22:21:05 +00:00
ad
4b8a875ae2 uvm_availmem(): give it a boolean argument to specify whether a recent
cached value will do, or if the very latest total must be fetched.  It can
be called thousands of times a second and fetching the totals impacts not
only the calling LWP but other CPUs doing unrelated activity in the VM
system.
2020-06-11 19:20:42 +00:00
maxv
10b7bc9101 Avoid passing file paths in panic strings, this results in extra long
output that is annoying and that syzbot classifies as independent reports
due to the instances having different build paths.
2020-05-30 08:50:31 +00:00
ad
a88d45a181 uvm_page_array_fill(): return ENOENT in all cases when nothing's left. 2020-05-26 21:52:12 +00:00
kamil
9f15ed54af Catch up with the usage of struct vmspace::vm_refcnt
Use the dedicated reference counting routines.

Change the type of struct vmspace::vm_refcnt and struct vm_map::ref_count
to volatile.

Remove the unnecessary vm->vm_map.misc_lock locking in process_domem().

Reviewed by <ad>
2020-05-26 00:50:53 +00:00
ad
a6b947c515 uao_get(): in the PGO_SYNCIO case use uvm_page_array and simplify control
flow a little bit.
2020-05-25 22:04:51 +00:00
ad
7fa42e33fe Make previous work as intended. Bad programmer. 2020-05-25 22:01:26 +00:00
ad
88d4be8106 Minor correction to previous. 2020-05-25 21:22:40 +00:00
ad
4bfe043955 - Alter the convention for uvm_page_array slightly, so the basic search
parameters can't change part way through a search: move the "uobj" and
  "flags" arguments over to uvm_page_array_init() and store those with the
  array.

- With that, detect when it's not possible to find any more pages in the
  tree with the given search parameters, and avoid repeated tree lookups if
  the caller loops over uvm_page_array_fill_and_peek().
2020-05-25 21:15:10 +00:00
ad
48081d9a3b PR kern/55300: ubciomove triggers page not dirty assertion
If overwriting an existing page, mark it dirty since there may be no
managed mapping to track the modification.
2020-05-25 20:13:00 +00:00
ad
3d8601a9ec uvm_pageout_done(): do nothing when npages is zero. 2020-05-25 19:46:20 +00:00
ad
704e68575e ubc_uiomove_direct(): if UBC_FAULTBUSY, the left-over portion of the final
page needs to be zeroed.
2020-05-25 19:29:08 +00:00
ad
504f478a85 - ubc_uiomove(): Always use direct access in the UBC_FAULTBUSY case, since
it works basically the same way as !direct minus temporary mappings, and
  there are no concurrency issues.

- ubc_alloc_direct(): In the PGO_OVERWRITE case blocks are allocated
  beforehand.  Avoid waking or activating pages unless needed.
2020-05-24 20:05:53 +00:00
ad
232803aa39 Add uvm_pagewanted_p(): return true if someone is waiting on the page and
assert caller has correct lock to observe that.
2020-05-24 19:46:59 +00:00
jdolecek
86cd877033 fix KASAN PoolUseAfterFree for async write - can't read bp after VOP_STRATEGY()
problem found and fix provided by Paul Ripke
2020-05-24 14:11:49 +00:00
ad
0eaaa024ea Move proc_lock into the data segment. It was dynamically allocated because
at the time we had mutex_obj_alloc() but not __cacheline_aligned.
2020-05-23 23:42:41 +00:00
ad
a5899d2545 uvm_pglistfree(): just use uvm_pagefree(). 2020-05-23 20:22:42 +00:00
ad
5959644557 - In ubc_alloc() take initial offset into account in the UBC_FAULTBUSY case
or one too few pages can be mapped.

- In ubc_release() with UBC_FAULTBUSY, chances are that pages are newly
  allocated and freshly enqueued, so avoid uvm_pageactivate() if possible

- Keep track of the pages mapped in ubc_alloc() in an array on the stack,
  and use this to avoid calling pmap_extract() in ubc_release().
2020-05-23 11:59:03 +00:00
ad
7ca862d114 Remove the ubc_direct hack. 2020-05-22 19:46:29 +00:00
ad
0fd3595baf uao_get(): handle PGO_OVERWRITE. 2020-05-22 19:02:59 +00:00
jdolecek
f5a755e60c DRY code in uvm_swap_io() for the write loop 2020-05-22 11:54:05 +00:00
riastradh
fe1ee0bb64 Let's not waste time decrypting garbage, shall we?
Skip to the end if the transfer failed.
2020-05-21 16:50:25 +00:00
ad
7d8a7e3546 uvm_loanuobjpages():
- there are no pages to unbusy in the error case
- always clear the caller's page array
2020-05-20 18:37:50 +00:00
riastradh
3c117f034d Make swap encryption MP-safe.
Not entirely sure the rest of the swap system is MP-safe, but let's
not make it worse!

XXX Why is swap_syscall_lock an rwlock?  We don't seem to take the
reader lock ever.
2020-05-20 17:48:34 +00:00
hannken
b616d2aaa2 Suppress GCC warnings and fix a UVMHIST_LOG() statement.
Kernels ALL/amd64 and ALL/i386 and port sparc64 build again.
2020-05-20 12:47:36 +00:00
ad
812b46df75 PR kern/32166: pgo_get protocol is ambiguous
Also problems with tmpfs+nfs noted by hannken@.

Don't pass PGO_ALLPAGES to pgo_get, and ignore PGO_DONTCARE in the
!PGO_LOCKED case.  In uao_get() have uvm_pagealloc() take care of page
zeroing and release busy pages on error.
2020-05-19 22:22:15 +00:00
ad
14c8aaf800 uvm_loanuobjpages():
- vmobjlock is shared between tmpfs vnodes and UAOs now
- split into two routines, to simplify
- fix error recovery
2020-05-19 21:52:04 +00:00
ad
6e318774b6 Don't try to do readahead on tmpfs. 2020-05-19 21:45:57 +00:00
ad
5ba8a0826b Drop & re-acquire vmobjlock less often. 2020-05-19 21:45:35 +00:00
ad
103c607c83 UVM_PAGE_TRKOWN: print the LID too 2020-05-19 20:46:39 +00:00
ad
ff872804dc Start trying to reduce cache misses on vm_page during fault processing.
- Make PGO_LOCKED getpages imply PGO_NOBUSY and remove the latter.  Mark
  pages busy only when there's actually I/O to do.

- When doing COW on a uvm_object, don't mess with neighbouring pages.  In
  all likelyhood they're already entered.

- Don't mess with neighbouring VAs that have existing mappings as replacing
  those mappings with same can be quite costly.

- Don't enqueue pages for neighbour faults unless not enqueued already, and
  don't activate centre pages unless uvmpdpol says its useful.

Also:

- Make PGO_LOCKED getpages on UAOs work more like vnodes: do gang lookup in
  the radix tree, and don't allocate new pages.

- Fix many assertion failures around faults/loans with tmpfs.
2020-05-17 19:38:16 +00:00
ad
c28f10c162 Don't set PG_AOBJ on a page unless UVM_OBJ_IS_AOBJ(), otherwise it can
catch pages from e.g. uvm_loanzero_object.
2020-05-17 17:12:28 +00:00
ad
8545b637a5 - If the hardware provided NUMA info, then use it to decide how to set up
the allocator's buckets, instead of doing round robin distribution.  There
  are open questions here but this is better than doing nothing.

- Kernel reserve pages are for the kernel not realtime threads.
2020-05-17 15:11:57 +00:00
ad
f080bee543 Mark amappl with PR_LARGECACHE. 2020-05-17 15:07:22 +00:00
ad
4cd60295b3 Reported-by: syzbot+3e3c7cfa8093f8de047e@syzkaller.appspotmail.com
Comment out an assertion that's now bogus and add a comment.
2020-05-15 22:35:05 +00:00
ad
9c9ebb954c PR kern/55268: tmpfs is slow
uao_get(): in the PGO_LOCKED case, we're okay to allocate a new page as long
as the caller holds a write lock.  PGO_NOBUSY doesn't put a stop to that.
2020-05-15 22:27:04 +00:00
ad
939a94f3ce uvm_pagemarkdirty(): no need to set radix tree tag unless page is currently
marked clean.
2020-05-15 22:25:18 +00:00
pgoyette
9dd096f8e8 Add missing dependency.
Fixes builds with VM_SWAP but no other users of rijndael crypto code.
2020-05-10 22:28:09 +00:00
riastradh
cdc9c12fff Rename things so the symbol better matches the sysctl name.
No functional change intended, except that the symbol that was
previously `uvm_swap_encryption' is now `uvm_swap_encrypt', backing
the sysctl knob `vm.swap_encrypt'.
2020-05-10 02:38:10 +00:00
riastradh
2e4a8ba1a5 Avoid overflow if a very large number of pages are swapped at once.
Unlikely, but let's make sure we don't hit this ever.
2020-05-09 22:00:48 +00:00
riastradh
373ada04c3 Implement swap encryption.
Enabled by sysctl -w vm.swap_encrypt=1.  Key is generated lazily when
we first need to swap a page.  Key is chosen independently for each
swap device.  The ith swap page is encrypted with AES256-CBC using
AES256_k(le32enc(i) || 0^96) as the initialization vector.  Can be
changed at any time; no need for compatibility with on-disk formats.
Costs one bit of memory per page in each swapdev, plus a few hundred
bytes per swapdev to store the expanded AES key.

Shoulda done this decades ago!  Plan to enable this by default;
performance impact is unlikely to matter because it only happens when
you're already swapping anyway.  Much easier to set up than cgd, so
we can rip out all the documentation about carefully setting up
random-keyed cgd at the right time.
2020-05-09 21:50:39 +00:00
thorpej
790ddc0b33 Make the uvm_voaddr structure more compact, only occupying 2 pointers
worth of space, by encoding the type in the lower bits of the object
pointer.
2020-05-09 15:13:19 +00:00
thorpej
1a07681a27 - In uvm_voaddr_acquire(), take an extra hold on the anon lock obj.
- In uvm_voaddr_release(), if the anon ref count drops to 0, call
  uvm_anfree() rather than uvm_anon_release().  Unconditionally drop
  the anon lock, and release the extra hold on the anon lock obj.

Fixes a panic that occurs if the backing store for a futex backed by
an anon memory location is unmapped while a thread is waiting in the
futex.

Add a test case that reproduced the panic to verify that it's fixed.
2020-04-30 04:18:07 +00:00
rin
545b324688 Add missing \ to fix build for PMAP_CACHE_VIVT, i.e., ARMv4 and prior. 2020-04-27 02:47:26 +00:00
thorpej
11d794387e Disable ubc_direct by default again. There are still stability issues
(e.g. panic during 2020.04.25.00.07.27 amd64 releng test run).
2020-04-26 16:16:13 +00:00
ad
18391da5bf ubc_alloc_direct(): for a write make sure pages are always marked dirty
because there's no managed mapping.
2020-04-24 19:47:03 +00:00
ad
f6da483c1a Enable ubc_direct by default, but only on systems with no more than 2 CPUs
for now.
2020-04-23 21:53:01 +00:00
ad
f5ad84fdb3 PR kern/54759 (vm.ubc_direct deadlock when read()/write() into mapping of itself)
- Add new flag UBC_ISMAPPED which tells ubc_uiomove() the object is mmap()ed
  somewhere.  Use it to decide whether to do direct-mapped copy, rather than
  poking around directly in the vnode in ubc_uiomove(), which is ugly and
  doesn't work for tmpfs.  It would be nicer to contain all this in UVM but
  the filesystem provides the needed locking here (VV_MAPPED) and to
  reinvent that would suck more.

- Rename UBC_UNMAP_FLAG() to UBC_VNODE_FLAGS().  Pass in UBC_ISMAPPED where
  appropriate.
2020-04-23 21:47:07 +00:00
ad
e4cdabc9f4 ubc_direct_release(): unbusy the pages directly since pg->interlock is
being taken.
2020-04-23 21:12:06 +00:00
ad
940e505e51 uvm_aio_aiodone_pages(): only call uvm_pageout_done() if work was done for
the page daemon.
2020-04-19 21:53:38 +00:00