aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/sys_pipe.c
Commit message (Collapse)AuthorAgeFilesLines
* - In pipe() return the error returned by pipe_create(), rather thenGleb Smirnoff2006-01-301-2/+3
| | | | | | | | | | | hardcoded ENFILES, which is incorrect. pipe_create() can fail due to ENOMEM. - Update manual page, describing ENOMEM return code. Reviewed by: arch Notes: svn path=/head/; revision=155035
* In pipe_write(): when uiomove() fails, do not spin on it forever.Xin LI2005-12-161-0/+2
| | | | | | | | | Submitted by: Kostik Belousov <kostikbel at gmail.com> on -current@ Message-ID: <20051216151016.GE84442@deviant.zoral.local> MFC After: 3 weeks Notes: svn path=/head/; revision=153484
* Fix the recent panics/LORs/hangs created by my kqueue commit by:Suleiman Souhlal2005-07-011-2/+4
| | | | | | | | | | | | | | | | | | | | - Introducing the possibility of using locks different than mutexes for the knlist locking. In order to do this, we add three arguments to knlist_init() to specify the functions to use to lock, unlock and check if the lock is owned. If these arguments are NULL, we assume mtx_lock, mtx_unlock and mtx_owned, respectively. - Using the vnode lock for the knlist locking, when doing kqueue operations on a vnode. This way, we don't have to lock the vnode while holding a mutex, in filt_vfsread. Reviewed by: jmg Approved by: re (scottl), scottl (mentor override) Pointyhat to: ssouhlal Will be happy: everyone Notes: svn path=/head/; revision=147730
* Rearrange the kninit calls for both directions of a pipe so thatMike Silbersack2005-01-171-1/+3
| | | | | | | | | | | | they both happen before pipe backing allocation occurs. Previously, a pipe memory shortage would cause a panic due to a KNOTE call on an uninitialized si_note. Reported by: Peter Holm MFC after: 1 week Notes: svn path=/head/; revision=140369
* /* -> /*- for copyright notices, minor format tweaks as necessaryWarner Losh2005-01-061-1/+1
| | | | Notes: svn path=/head/; revision=139804
* Correct a bug introduced in sys_pipe.c:1.179: in pipe_ioctl(),Robert Watson2004-11-231-2/+5
| | | | | | | | | | | | release the pipe mutex before calling fsetown(), as fsetown() may block. The sigio code protects the pipe sigio data using its own mutex, and the pipe reference count held by the caller will prevent the pipe from being prematurely garbage-collected. Discovered by: imp Notes: svn path=/head/; revision=138032
* Add missing break.Poul-Henning Kamp2004-11-161-0/+1
| | | | Notes: svn path=/head/; revision=137764
* Straighten the ioctl function out to have only one exit point.Poul-Henning Kamp2004-11-151-17/+13
| | | | Notes: svn path=/head/; revision=137752
* Introduce fdclose() which will clean an entry in a filedesc.Poul-Henning Kamp2004-11-071-9/+1
| | | | | | | | | Replace homerolled versions with call to fdclose(). Make fdunused() static to kern_descrip.c Notes: svn path=/head/; revision=137355
* Major enhancements to pipe memory usage:Mike Silbersack2004-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. Notes: svn path=/head/; revision=133790
* Add locking to the kqueue subsystem. This also makes the kqueue subsystemJohn-Mark Gurney2004-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) Notes: svn path=/head/; revision=133741
* Standardize pipe locking, ensuring that everything is locked viaMike Silbersack2004-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. Notes: svn path=/head/; revision=133049
* * Add a "how" argument to uma_zone constructors and initialization functionsBrian Feldman2004-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. Notes: svn path=/head/; revision=132987
* Don't perform pipe endpoint locking during pipe_create(), as the pipeRobert Watson2004-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 Notes: svn path=/head/; revision=132579
* Fix a minor error in pipe_stat - st_size was always reported as 0Mike Silbersack2004-07-201-1/+4
| | | | | | | | when direct writes kicked in. Whether this affected any applications is unknown. Notes: svn path=/head/; revision=132436
* Revise the direct or optimized case to use uiomove_fromphys() by the readerAlan Cox2004-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. Notes: svn path=/head/; revision=127501
* Assert pipe mutex in pipeselwakeup(), as we manipulate pipe_stateRobert Watson2004-02-261-0/+1
| | | | | | | | in a non-atomic manner. It appears to always be called with the mutex (good). Notes: svn path=/head/; revision=126252
* Update comment regarding MAC labels: we no longer pass endpointsRobert Watson2004-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. Notes: svn path=/head/; revision=126249
* Correct some major SMP-harmful problems in the pipe implementation. FirstBrian Feldman2004-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. Notes: svn path=/head/; revision=126131
* Don't dec/inc the amountpipes counter every time we resize a pipe --Robert Watson2004-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 Notes: svn path=/head/; revision=125367
* Catch instances of (pipe == NULL) that were obsoleted with recentRobert Watson2004-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> Notes: svn path=/head/; revision=125364
* Coalesce pipe allocations and frees. Previously, the pipe codeRobert Watson2004-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 Notes: svn path=/head/; revision=125293
* Fix an error in a KASSERT string: it's pipe_free_kmem(), notRobert Watson2004-01-311-1/+1
| | | | | | | pipespace(), that contains this KASSERT. Notes: svn path=/head/; revision=125281
* New file descriptor allocation code, derived from similar code introducedDag-Erling Smørgrav2004-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)). Notes: svn path=/head/; revision=124548
* Back out 1.160, which was committed by mistake.Dag-Erling Smørgrav2004-01-111-1/+0
| | | | Notes: svn path=/head/; revision=124399
* Mechanical whitespace cleanup.Dag-Erling Smørgrav2004-01-111-27/+27
| | | | Notes: svn path=/head/; revision=124394
* Mechanical whitespace cleanup + minor style nits.Dag-Erling Smørgrav2004-01-111-1/+3
| | | | Notes: svn path=/head/; revision=124391
* Fix the maxpipekva warning message so that it points to the correctMike Silbersack2003-12-281-1/+1
| | | | | | | | | sysctl, and shorten the message. Noticed by: bde Notes: svn path=/head/; revision=123915
* - Implement selwakeuppri() which allows raising the priority of aSeigo Tanimura2003-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 Notes: svn path=/head/; revision=122352
* - Delay the allocation of memory for the pipe mutex until we need it.Alan Cox2003-11-061-5/+1
| | | | | | | | This avoids the need to free said memory in various error cases along the way. Notes: svn path=/head/; revision=122164
* - Simplify pipespace() by eliminating the explicit creation of vm objects.Alan Cox2003-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. Notes: svn path=/head/; revision=122163
* Unlock pipe mutex when failing MAC pipe ioctl access control check.Robert Watson2003-11-031-1/+3
| | | | | | | | Obtained from: TrustedBSD Project Sponsored by: DARPA, Network Associates Laboratories Notes: svn path=/head/; revision=121970
* Change all SYSCTLS which are readonly and have a related TUNABLEMike Silbersack2003-10-211-1/+1
| | | | | | | | from CTLFLAG_RD to CTLFLAG_RDTUN so that sysctl(8) can provide more useful error messages. Notes: svn path=/head/; revision=121307
* falloc allocates a file structure and adds it to the file descriptorDavid Malone2003-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 Notes: svn path=/head/; revision=121256
* fix a problem referencing free'd memory. This is only a problem forJohn-Mark Gurney2003-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 Notes: svn path=/head/; revision=121018
* pipe_build_write_buffer() only requires read access of the page that itAlan Cox2003-09-121-1/+2
| | | | | | | obtains from pmap_extract_and_hold(). Notes: svn path=/head/; revision=120000
* Use pmap_extract_and_hold() in pipe_build_write_buffer(). Consequently,Alan Cox2003-09-081-35/+11
| | | | | | | | | pipe_build_write_buffer() no longer requires Giant on entry. Reviewed by: tegge Notes: svn path=/head/; revision=119872
* Giant is no longer required by pipe_destroy_write_buffer(). ReduceAlan Cox2003-09-061-9/+7
| | | | | | | unnecessary white space from pipe_destroy_write_buffer(). Notes: svn path=/head/; revision=119811
* if we got this far, we definately don't have an EBADF. Return a moreJohn-Mark Gurney2003-08-151-1/+1
| | | | | | | | | | sane result of EPIPE. Reported by: nCircle dev team MFC after: 3 day Notes: svn path=/head/; revision=118929
* - The vm_object pointer in pipe_buffer is unused. Remove it.Alan Cox2003-08-131-5/+2
| | | | | | | | - Check for successful initialization of pipe_zone in pipeinit() rather than every call to pipe(2). Notes: svn path=/head/; revision=118880
* Pipespace() no longer requires Giant.Alan Cox2003-08-111-2/+2
| | | | Notes: svn path=/head/; revision=118799
* More pipe changes:Mike Silbersack2003-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.) Notes: svn path=/head/; revision=118764
* Use vm_page_hold() instead of vm_page_wire(). Otherwise, a multithreadedAlan Cox2003-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 Notes: svn path=/head/; revision=118757
* - Remove GIANT_REQUIRED from pipespace().Alan Cox2003-08-081-4/+0
| | | | | | | - Remove a duplicate initialization from pipe_create(). Notes: svn path=/head/; revision=118677
* - Remove GIANT_REQUIRED from pipe_free_kmem().Alan Cox2003-08-071-3/+0
| | | | | | | | - Remove the acquisition and release of Giant around pipe_kmem_free() and uma_zfree() in pipeclose(). Notes: svn path=/head/; revision=118572
* Remove test in pipe_write() which causes write(2) to return EAGAINPierre Beyssac2003-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 Notes: svn path=/head/; revision=118230
* The introduction of vm object locking has caused witness to revealAlan Cox2003-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) Notes: svn path=/head/; revision=118220
* A few minor changes:Mike Silbersack2003-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. Notes: svn path=/head/; revision=117364
* Put some concrete limits on pipe memory consumption:Mike Silbersack2003-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 Notes: svn path=/head/; revision=117325
* Initialize struct fileops with C99 sparse initialization.Poul-Henning Kamp2003-06-181-2/+8
| | | | Notes: svn path=/head/; revision=116546