From owner-freebsd-smp Thu Mar 22 11: 1:29 2001 Delivered-To: freebsd-smp@freebsd.org Received: from meow.osd.bsdi.com (meow.osd.bsdi.com [204.216.28.88]) by hub.freebsd.org (Postfix) with ESMTP id 627EC37B720 for ; Thu, 22 Mar 2001 11:01:26 -0800 (PST) (envelope-from jhb@FreeBSD.org) Received: from laptop.baldwin.cx (john@jhb-laptop.osd.bsdi.com [204.216.28.241]) by meow.osd.bsdi.com (8.11.2/8.11.2) with ESMTP id f2MIxsG80547; Thu, 22 Mar 2001 10:59:54 -0800 (PST) (envelope-from jhb@FreeBSD.org) Message-ID: X-Mailer: XFMail 1.4.0 on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 In-Reply-To: Date: Thu, 22 Mar 2001 10:59:42 -0800 (PST) From: John Baldwin To: Tony Finch Subject: RE: Locked data-structures and delayed writes. Cc: freebsd-smp@FreeBSD.org Sender: owner-freebsd-smp@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org On 22-Mar-01 Tony Finch wrote: > > I've been having an interesting discussion elsewhere with someone > about the problems caused by delayed writes within the CPU. He's of > the general opinion that everything is broken and can be very > enlightening when explaining why he thinks this but he can also be > frustratingly vague. > > Anyway, the question at hand is what happens if two threads on > different CPUs are accessing the same locked data structure when the > CPU delays writes to RAM, i.e. > > acquire_lock(s); > modify(s); > release_lock(s); > > Things are very broken if the write can be delayed until after the > lock is released. What prevents that? Memory barriers. When we acquire a lock, we enforce a memory barrier to ensure that the data accesses to actually obtain the lock are obtained before we perform any 'sensitive' operations. Secondly, we use another memory barrier during the release to ensure that all 'sensitive' operations are finished before the lock is released. > A related question, but perhaps more implausible, is what happens if a > page is unmapped from underneath a delayed write. This is particularly > pathological if the destination page was mmapped and the program is > exiting: the write may be lost. If the program doesn't need the data, who cares if it is lost? If the data is not program specific (e.g. kernel data structures) then the page won't be unmapped. :) However, it is actually a concern to make sure that if the data is still in the cache, it doesnt' get written out later when some other program is using this page. This can be handled in various ways depending on what cache architecture is being used. For an excellent treatment of this topic, see "Unix Systems for Modern Architectures: Symmetric Multiprocessing and Caching for Kernel Programmers" by Curt Schimmel ISBN 0-201-63338-8. > Tony. > -- > f.a.n.finch fanf@covalent.net dot@dotat.at -- John Baldwin -- http://www.FreeBSD.org/~jhb/ PGP Key: http://www.baldwin.cx/~john/pgpkey.asc "Power Users Use the Power to Serve!" - http://www.FreeBSD.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-smp" in the body of the message