⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1.t

📁 早期freebsd实现
💻 T
📖 第 1 页 / 共 2 页
字号:
currently envisioned.The details of the system call interface are contained in Appendix A..SHRegions.PPThe virtual memory interface is designed to support both large,sparse address spaces as well as small, densely-used address spaces.In this context, ``small'' is an address space roughly thesize of the physical memory on the machine, while ``large'' may extend up to the maximum addressability of the machine.A process may divide its address space up into a number of regions.Initially a process begins with four regions; a shared read-only fill-on-demand region with its text,a private fill-on-demand region for its initialized data,a private zero-fill-on-demand region for its uninitialized data and heap,and a private zero-fill-on-demand region for its stack.In addition to these regions, a process may allocate new ones.The regions may not overlap and the system may impose an alignmentconstraint, but the size of the region should not be limitedbeyond the constraints of the size of the virtual address space..PPEach new region may be mapped either as private or shared.When it is privately mapped, changes to the contents of the regionare not reflected to any other process that map the same region.Regions may be mapped read-only or read-write.As an example, a shared library would be implemented as two regions;a shared read-only region for the text, and a private read-writeregion for the global variables associated with the library..PPA region may be allocated with one of several allocation strategies.It may map some memory hardware on the machine such as a frame buffer.Since the hardware is responsible for storing the data,such regions must be exclusive use if they are privately mapped..PPA region can map all or part of a file.As the pages are first accessed, the region is filled in with theappropriate part of the file.If the region is mapped read-write and shared, changes to thecontents of the region are reflected back into the contents of the file.If the region is read-write but private,changes to the region are copied to a private page that is notvisible to other processes mapping the file,and these modified pages are not reflected back to the file..PPThe final type of region is ``anonymous memory''.Uninitialed data uses such a region, privately mapped;it is zero-fill-on-demand and its contents are abandonedwhen the last reference is dropped.Unlike a region that is mapped from a file,the contents of an anonymous region will never be read from orwritten to a disk unless memory is short and part of the regionmust be paged to a swap area.If one of these regions is mapped shared,then all processes see the changes in the region.This difference has important performance considerations;the overhead of reading, flushing, and possibly allocating a fileis much higher than simply zeroing memory..PPIf several processes wish to share a region,then they must have some way of rendezvousing.For a mapped file this is easy;the name of the file is used as the rendezvous point.However, processes may not need the semantics of mapped filesnor be willing to pay the overhead associated with them.For anonymous memory they must use some other rendezvous point.Our current interface allows processes to associate adescriptor with a region, which it may then pass to otherprocesses that wish to attach to the region.Such a descriptor may be bound into the UNIX file systemname space so that other processes can find it just asthey would with a mapped file..SHShared memory as high speed interprocess communication.PPThe primary use envisioned for shared memory is toprovide a high speed interprocess communication (IPC) mechanismbetween cooperating processes.Existing IPC mechanisms (\fIi.e.\fP pipes, sockets, or streams)require a system call to hand off a setof data destined for another process, and another system callby the recipient process to receive the data.Even if the data can be transferred by remapping the data pagesto avoid a memory to memory copy, the overhead of doing the systemcalls limits the throughput of all but the largest transfers.Shared memory, by contrast, allows processes to share data at anylevel of granularity without system intervention..PPHowever, to maintain all but the simplest of data structures,the processes must serialize their modifications to shareddata structures if they are to avoid corrupting them.This serialization is typically done with semaphores.Unfortunately, most implementations of semaphores aredone with system calls. Thus processes are once again limited by the need to do twosystem calls per transaction, one to lock the semaphore, thesecond to release it.The net effect is that the shared memory model provides little if any improvement in interprocess bandwidth..PPTo achieve a significant improvement in interprocess bandwidthrequires a large decrease in the number of system calls needed toachieve the interaction.In profiling applications that useserialization locks such as the UNIX kernel,one typically finds that most locks are not contested.Thus if one can find a way to avoid doing a system call in the casein which a lock is not contested,one would expect to be able to dramatically reduce the numberof system calls needed to achieve serialization..PPIn our design, cooperating processes manage their semaphoresin their own address space.In the typical case, a process executes an atomic test-and-set instructionto acquire a lock, finds it free, and thus is able to get it.Only in the (rare) case where the lock is already set does the processneed to do a system call to wait for the lock to clear.When a process is finished with a lock, it can clear the lock itself.Only if the ``WANT'' flag for the lock has been set isit necessary for the process to do a system call to cause the otherprocess(es) to be awakened..PPAnother issue that must be considered is portability.Some computers require access to special hardware to implementatomic interprocessor test-and-set. For such machines the setting and clearing of locks wouldall have to be done with system calls;applications could still use the same interface without change,though they would tend to run slowly..PPThe other issue of compatibility is with System V's semaphoreimplementation.Since the System V interface has been in existence for several years,and applications have been built that depend on this interface,it is important that this interface also be available.Although the interface is based on system calls for both setting andclearing locks,the same interface can be obtained using our interface withoutsystem calls in most cases..PPThis implementation can be achieved as follows.System V allows entire sets of semaphores to be set concurrently.If any of the locks are unavailable, the process is put to sleepuntil they all become available.Under our paradigm, a single additional semaphore is definedthat serializes access to the set of semaphores being simulated.Once obtained in the usual way, the set of semaphores can beinspected to see if the desired ones are available.If they are available, they are set, the guardian semaphoreis released and the process proceeds.If one or more of the requested set is not available,the guardian semaphore is released and the process selects anunavailable semaphores for which to wait.On being reawakened, the whole selection process must be repeated..PPIn all the above examples, there appears to be a race condition.Between the time that the process finds that a semaphore is locked,and the time that it manages to call the system to sleep on thesemaphore another process may unlock the semaphore and issue a wakeup call.Luckily the race can be avoided.The insight that is critical is that the process and the kernel agreeon the physical byte of memory that is being used for the semaphore.The system call to put a process to sleep takes a pointerto the desired semaphore as its argument so that once insidethe kernel, the kernel can repeat the test-and-set.If the lock has cleared(and possibly the wakeup issued) between the time that the processdid the test-and-set and eventually got into the sleep request system call,then the kernel immediately resumes the process rather than puttingit to sleep.Thus the only problem to solve is how the kernel interlocks between testinga semaphore and going to sleep;this problem has already been solved on existing systems..NHReferences.sp.IP [Babaoglu79] 20Babaoglu, O., and Joy, W.,``Data Structures Added in the Berkeley Virtual Memory Extensionsto the UNIX Operating System''Computer Systems Research Group, Dept of EECS, University of California,Berkeley, CA 94720, USA, November 1979..IP [Someren84] 20Someren, J. van,``Paging in Berkeley UNIX'',Laboratorium voor schakeltechniek en techneik v.d. informatieverwerkende machines,Codenummer 051560-44(1984)01, February 1984.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -