summaryrefslogtreecommitdiffstats
path: root/sys/kern/sys_pipe.c
Commit message (Collapse)AuthorAgeFilesLines
...
* Add missing break.phk2004-11-161-0/+1
|
* Straighten the ioctl function out to have only one exit point.phk2004-11-151-17/+13
|
* Introduce fdclose() which will clean an entry in a filedesc.phk2004-11-071-9/+1
| | | | | | Replace homerolled versions with call to fdclose(). Make fdunused() static to kern_descrip.c
* Major enhancements to pipe memory usage:silby2004-08-161-55/+136
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - pipespace is now able to resize non-empty pipes; this allows for many more resizing opportunities - Backing is no longer pre-allocated for the reverse direction of pipes. This direction is rarely (if ever) used, so this cuts the amount of map space allocated to a pipe in half. - Pipe growth is now much more dynamic; a pipe will now grow when the total amount of data it contains and the size of the write are larger than the size of pipe. Previously, only individual writes greater than the size of the pipe would cause growth. - In low memory situations, pipes will now shrink during both read and write operations, where possible. Once the memory shortage ends, the growth code will cause these pipes to grow back to an appropriate size. - If the full PIPE_SIZE allocation fails when a new pipe is created, the allocation will be retried with SMALL_PIPE_SIZE. This helps to deal with the situation of a fragmented map after a low memory period has ended. - Minor documentation + code changes to support the above. In total, these changes increase the total number of pipes that can be allocated simultaneously, drastically reducing the chances that pipe allocation will fail. Performance appears unchanged due to dynamic resizing.
* Add locking to the kqueue subsystem. This also makes the kqueue subsystemjmg2004-08-151-6/+11
| | | | | | | | | | | | | a more complete subsystem, and removes the knowlege of how things are implemented from the drivers. Include locking around filter ops, so a module like aio will know when not to be unloaded if there are outstanding knotes using it's filter ops. Currently, it uses the MTX_DUPOK even though it is not always safe to aquire duplicate locks. Witness currently doesn't support the ability to discover if a dup lock is ok (in some cases). Reviewed by: green, rwatson (both earlier versions)
* Standardize pipe locking, ensuring that everything is locked viasilby2004-08-031-152/+115
| | | | | | | | | pipelock(), not via a mixture of mutexes and pipelock(). Additionally, add a few KASSERTS, and change some statements that should have been KASSERTS into KASSERTS. As a result of these cleanups, some segments of code have become significantly shorter and/or easier to read.
* * Add a "how" argument to uma_zone constructors and initialization functionsgreen2004-08-021-6/+8
| | | | | | | | | | | | | | | | | so that they know whether the allocation is supposed to be able to sleep or not. * Allow uma_zone constructors and initialation functions to return either success or error. Almost all of the ones in the tree currently return success unconditionally, but mbuf is a notable exception: the packet zone constructor wants to be able to fail if it cannot suballocate an mbuf cluster, and the mbuf allocators want to be able to fail in general in a MAC kernel if the MAC mbuf initializer fails. This fixes the panics people are seeing when they run out of memory for mbuf clusters. * Allow debug.nosleepwithlocks on WITNESS to be disabled, without changing the default. Both bmilekic and jeff have reviewed the changes made to make failable zone allocations work.
* Don't perform pipe endpoint locking during pipe_create(), as the piperwatson2004-07-231-11/+20
| | | | | | | | | | can't yet be referenced by other threads. In microbenchmarks, this appears to reduce the cost of pipe();close();close() on UP by 10%, and SMP by 7%. The vast majority of the cost of allocating a pipe remains VM magic. Suggested by: silby
* Fix a minor error in pipe_stat - st_size was always reported as 0silby2004-07-201-1/+4
| | | | | when direct writes kicked in. Whether this affected any applications is unknown.
* Revise the direct or optimized case to use uiomove_fromphys() by the readeralc2004-03-271-60/+18
| | | | | | | | | | | | | | | | | instead of ephemeral mappings using pmap_qenter() by the writer. The writer is still, however, responsible for wiring the pages, just not mapping them. Consequently, the allocation of KVA for the direct case is unnecessary. Remove it and the sysctls limiting it, i.e., kern.ipc.maxpipekvawired and kern.ipc.amountpipekvawired. The number of temporarily wired pages is still, however, limited by kern.ipc.maxpipekva. Note: On platforms lacking a direct virtual-to-physical mapping, uiomove_fromphys() uses sf_bufs to cache ephemeral mappings. Thus, the number of available sf_bufs can influence the performance of pipes on platforms such i386. Surprisingly, I saw the greatest gain from this change on such a machine: lmbench's pipe bandwidth result increased from ~1050MB/s to ~1850MB/s on my 2.4GHz, 400MHz FSB P4 Xeon.
* Assert pipe mutex in pipeselwakeup(), as we manipulate pipe_staterwatson2004-02-261-0/+1
| | | | | in a non-atomic manner. It appears to always be called with the mutex (good).
* Update comment regarding MAC labels: we no longer pass endpointsrwatson2004-02-251-7/+3
| | | | | | | into the MAC Framework, just the pipe pair. GC 'hadpeer' used in pipedestroy(), which is no longer needed as we check pipe_present flags on the pair.
* Correct some major SMP-harmful problems in the pipe implementation. Firstgreen2004-02-221-41/+66
| | | | | | | | | | | | of all, PIPE_EOF is not checked pervasively after everything that can drop the pipe mutex and msleep(), so fix. Additionally, though it might not harm anything, pipelock() and pipeunlock() are not used consistently. Third, the kqueue support functions do not use the pipe mutex correctly. Last, but absolutely not least, is a race: if pipe_busy is not set on the closing side of the pipe, the other side that is trying to write to that will crash BECAUSE PIPE_EOF IS NOT SET! Unconditionally set PIPE_EOF, and get rid of all the lockups/crashes I have seen trying to build ports.
* Don't dec/inc the amountpipes counter every time we resize a pipe --rwatson2004-02-031-2/+3
| | | | | | | | | | instead, just dec/inc in the ctor/dtor. For now, increment/decrement in two's, since we're now performing the operation once per pair, not once per pipe. Not really any measurable performance change in my micro-benchmarks, but doing less work is good, especially when it comes to atomic operations. Suggested by: alc
* Catch instances of (pipe == NULL) that were obsoleted with recentrwatson2004-02-031-6/+6
| | | | | | | | changes to jointly allocated pipe pairs. Replace these checks with pipe_present checks. This avoids a NULL pointer dereference when a pipe is half-closed. Submitted by: Peter Edwards <peter.edwards@openet-telecom.com>
* Coalesce pipe allocations and frees. Previously, the pipe coderwatson2004-02-011-91/+150
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | would allocate two 'struct pipe's from the pipe zone, and malloc a mutex. - Create a new "struct pipepair" object holding the two 'struct pipe' instances, struct mutex, and struct label reference. Pipe structures now have a back-pointer to the pipe pair, and a 'pipe_present' flag to indicate whether the half has been closed. - Perform mutex init/destroy in zone init/destroy, avoiding reallocating the mutex for each pipe. Perform most pipe structure setup in zone constructor. - VM memory mappings for pageable buffers are still done outside of the UMA zone. - Change MAC API to speak 'struct pipepair' instead of 'struct pipe', update many policies. MAC labels are also handled outside of the UMA zone for now. Label-only policy modules don't have to be recompiled, but if a module is recompiled, its pipe entry points will need to be updated. If a module actually reached into the pipe structures (unlikely), that would also need to be modified. These changes substantially simplify failure handling in the pipe code as there are many fewer possible failure modes. On half-close, pipes no longer free the 'struct pipe' for the closed half until a full-close takes place. However, VM mapped buffers are still released on half-close. Some code refactoring is now possible to clean up some of the back references, etc; this patch attempts not to change the structure of most of the pipe implementation, only allocation/free code paths, so as to avoid introducing bugs (hopefully). This cuts about 8%-9% off the cost of sequential pipe allocation and free in system call tests on UP and SMP in my micro-benchmarks. May or may not make a difference in macro-benchmarks, but doing less work is good. Reviewed by: juli, tjr Testing help: dwhite, fenestro, scottl, et al
* Fix an error in a KASSERT string: it's pipe_free_kmem(), notrwatson2004-01-311-1/+1
| | | | pipespace(), that contains this KASSERT.
* New file descriptor allocation code, derived from similar code introduceddes2004-01-151-0/+1
| | | | | | | | | | | in OpenBSD by Niels Provos. The patch introduces a bitmap of allocated file descriptors which is used to locate available descriptors when a new one is needed. It also moves the task of growing the file descriptor table out of fdalloc(), reducing complexity in both fdalloc() and do_dup(). Debts of gratitude are owed to tjr@ (who provided the original patch on which this work is based), grog@ (for the gdb(4) man page) and rwatson@ (for assistance with pxeboot(8)).
* Back out 1.160, which was committed by mistake.des2004-01-111-1/+0
|
* Mechanical whitespace cleanup.des2004-01-111-27/+27
|
* Mechanical whitespace cleanup + minor style nits.des2004-01-111-1/+3
|
* Fix the maxpipekva warning message so that it points to the correctsilby2003-12-281-1/+1
| | | | | | sysctl, and shorten the message. Noticed by: bde
* - Implement selwakeuppri() which allows raising the priority of atanimura2003-11-091-1/+1
| | | | | | | | | | | | | thread being waken up. The thread waken up can run at a priority as high as after tsleep(). - Replace selwakeup()s with selwakeuppri()s and pass appropriate priorities. - Add cv_broadcastpri() which raises the priority of the broadcast threads. Used by selwakeuppri() if collision occurs. Not objected in: -arch, -current
* - Delay the allocation of memory for the pipe mutex until we need it.alc2003-11-061-5/+1
| | | | | This avoids the need to free said memory in various error cases along the way.
* - Simplify pipespace() by eliminating the explicit creation of vm objects.alc2003-11-061-10/+2
| | | | | | Instead, let the vm objects be lazily instantiated at fault time. This results in the allocation of fewer vm objects and vm map entries due to aggregation in the vm system.
* Unlock pipe mutex when failing MAC pipe ioctl access control check.rwatson2003-11-031-1/+3
| | | | | Obtained from: TrustedBSD Project Sponsored by: DARPA, Network Associates Laboratories
* Change all SYSCTLS which are readonly and have a related TUNABLEsilby2003-10-211-1/+1
| | | | | from CTLFLAG_RD to CTLFLAG_RDTUN so that sysctl(8) can provide more useful error messages.
* falloc allocates a file structure and adds it to the file descriptordwmalone2003-10-191-1/+3
| | | | | | | | | | | | | | | | | | | | | table, acquiring the necessary locks as it works. It usually returns two references to the new descriptor: one in the descriptor table and one via a pointer argument. As falloc releases the FILEDESC lock before returning, there is a potential for a process to close the reference in the file descriptor table before falloc's caller gets to use the file. I don't think this can happen in practice at the moment, because Giant indirectly protects closes. To stop the file being completly closed in this situation, this change makes falloc set the refcount to two when both references are returned. This makes life easier for several of falloc's callers, because the first thing they previously did was grab an extra reference on the file. Reviewed by: iedowse Idea run past: jhb
* fix a problem referencing free'd memory. This is only a problem forjmg2003-10-121-2/+7
| | | | | | | | | | kqueue write events on a socket and you regularly create tons of pipes which overwrites the structure causing a panic when removing the knote from the list. If the peer has gone away (and it's a write knote), then don't bother trying to remove the knote from the list. Submitted by: Brian Buchanan and myself Obtained from: nCircle
* pipe_build_write_buffer() only requires read access of the page that italc2003-09-121-1/+2
| | | | obtains from pmap_extract_and_hold().
* Use pmap_extract_and_hold() in pipe_build_write_buffer(). Consequently,alc2003-09-081-35/+11
| | | | | | pipe_build_write_buffer() no longer requires Giant on entry. Reviewed by: tegge
* Giant is no longer required by pipe_destroy_write_buffer(). Reducealc2003-09-061-9/+7
| | | | unnecessary white space from pipe_destroy_write_buffer().
* if we got this far, we definately don't have an EBADF. Return a morejmg2003-08-151-1/+1
| | | | | | | sane result of EPIPE. Reported by: nCircle dev team MFC after: 3 day
* - The vm_object pointer in pipe_buffer is unused. Remove it.alc2003-08-131-5/+2
| | | | | - Check for successful initialization of pipe_zone in pipeinit() rather than every call to pipe(2).
* Pipespace() no longer requires Giant.alc2003-08-111-2/+2
|
* More pipe changes:silby2003-08-111-38/+26
| | | | | | | | | | | | | | From alc: Move pageable pipe memory to a seperate kernel submap to avoid awkward vm map interlocking issues. (Bad explanation provided by me.) From me: Rework pipespace accounting code to handle this new layout, and adjust our default values to account for the fact that we now have a solid limit on allocations. Also, remove the "maxpipes" limit, as it no longer has a purpose. (The limit on kva usage solves the problem of having two many pipes.)
* Use vm_page_hold() instead of vm_page_wire(). Otherwise, a multithreadedalc2003-08-111-3/+3
| | | | | | | | | | application could cause a wired page to be freed. In general, vm_page_hold() should be preferred for ephemeral kernel mappings of pages borrowed from a user-level address space. (vm_page_wire() should really be reserved for indefinite duration pinning by the "owner" of the page.) Discussed with: silby Submitted by: tegge
* - Remove GIANT_REQUIRED from pipespace().alc2003-08-081-4/+0
| | | | - Remove a duplicate initialization from pipe_create().
* - Remove GIANT_REQUIRED from pipe_free_kmem().alc2003-08-071-3/+0
| | | | | - Remove the acquisition and release of Giant around pipe_kmem_free() and uma_zfree() in pipeclose().
* Remove test in pipe_write() which causes write(2) to return EAGAINpb2003-07-301-1/+1
| | | | | | | | | | | | on a non-blocking pipe in cases where select(2) returns the file descriptor as ready for write. This in turns causes libc_r, for one, to busy wait in such cases. Note: it is a quick performance fix, a more complex fix might be required in case this turns out to have unexpected side effects. Reviewed by: silby MFC after: 3 days
* The introduction of vm object locking has caused witness to revealalc2003-07-301-1/+1
| | | | | | | | | | | a long-standing mistake in the way a portion of a pipe's KVA is allocated. Specifically, kmem_alloc_pageable() is inappropriate for use in the "direct" case because it allows a preceding vm map entry and vm object to be extended to support the new KVA allocation. However, the direct case KVA allocation should not have a backing vm object. This is corrected by using kmem_alloc_nofault(). Submitted by: tegge (with the above explanation by me)
* A few minor changes:silby2003-07-091-6/+7
| | | | | | | - Use atomic ops to update the bigpipe count - Make the bigpipe count sysctl readable - Remove a duplicate comparison in an if statement - Comment two SYSCTLs.
* Put some concrete limits on pipe memory consumption:silby2003-07-081-17/+68
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Limit the total number of pipes so that we do not exhaust all vm objects in the kernel map. When this limit is reached, a ratelimited message will be printed to the console. - Put a soft limit on the amount of memory consumable by pipes. Once the limit has been reached, all new pipes will be limited to 4K in size, rather than the default of 16K. - Put a limit on the number of pages that may be used for high speed page flipping in order to reduce the amount of wired memory. Pipe writes that occur while this limit is exceeded will fall back to non-page flipping mode. The above values are auto-tuned in subr_param.c and are scaled to take into account both the size of physical memory and the size of the kernel map. These limits help to reduce the "kernel resources exhausted" panics that could be caused by opening a large number of pipes. (Pipes alone are no longer able to exhaust all resources, but other kernel memory hogs in league with pipes may still be able to do so.) PR: 53627 Ideas / comments from: hsu, tjr, dillon@apollo.backplane.com MFC after: 1 week
* Initialize struct fileops with C99 sparse initialization.phk2003-06-181-2/+8
|
* Use __FBSDID().obrien2003-06-111-2/+3
|
* style(9).mux2003-06-091-12/+20
|
* Need to hold the same SMP lock for (knote) list traversal as forhsu2003-04-021-1/+1
| | | | | list manipulation. This lock also protects read-modify-write operations on the pipe_state field.
* - Add vm_paddr_t, a physical address type. This is required for systemsjake2003-03-251-1/+2
| | | | | | | | | | | | | | | where physical addresses larger than virtual addresses, such as i386s with PAE. - Use this to represent physical addresses in the MI vm system and in the i386 pmap code. This also changes the paddr parameter to d_mmap_t. - Fix printf formats to handle physical addresses >4G in the i386 memory detection code, and due to kvtop returning vm_paddr_t instead of u_long. Note that this is a name change only; vm_paddr_t is still the same as vm_offset_t on all currently supported platforms. Sponsored by: DARPA, Network Associates Laboratories Discussed with: re, phk (cdevsw change)
* Back out M_* changes, per decision of the TRB.imp2003-02-191-2/+2
| | | | Approved by: trb
* Do not allow kqueues to be passed via unix domain sockets.alfred2003-02-151-1/+1
|
OpenPOWER on IntegriCloud