From owner-freebsd-smp Thu Mar 22 8:43:49 2001 Delivered-To: freebsd-smp@freebsd.org Received: from prism.flugsvamp.com (cb58709-a.mdsn1.wi.home.com [24.17.241.9]) by hub.freebsd.org (Postfix) with ESMTP id 5DC0237B71B for ; Thu, 22 Mar 2001 08:43:46 -0800 (PST) (envelope-from jlemon@flugsvamp.com) Received: (from jlemon@localhost) by prism.flugsvamp.com (8.11.0/8.11.0) id f2MGdgW18437; Thu, 22 Mar 2001 10:39:42 -0600 (CST) (envelope-from jlemon) Date: Thu, 22 Mar 2001 10:39:42 -0600 (CST) From: Jonathan Lemon Message-Id: <200103221639.f2MGdgW18437@prism.flugsvamp.com> To: dot@dotat.at, smp@freebsd.org Subject: Re: Locked data-structures and delayed writes. X-Newsgroups: local.mail.freebsd-smp In-Reply-To: Organization: Cc: Sender: owner-freebsd-smp@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org In article you write: > >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? Uhm. Why would things be broken simply because the write is delayed? This isn't a trick answer; if you don't subsequently read the location, then why would it matter if the write is delayed? (modulo writes to device memory; in these cases, you probably want to mark the writes as uncacheable) Now, if your modify involves doing a read of the location, then that is a different question. The ia-32 architecture uses a strong cache coherence model, so that writes to the same location appear to be seen in the same order by all processors (write serialization). So even if the memory write in modify() above is delayed until after the release_lock() call, any reads from that location will return the new data. On other architectures, you may need to explicitly manage the cache coherence yourself. >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. On the alpha, the write buffers are physically addressed, so if the virtual address mapping is removed, it will not affect the delayed write, since the write does not require the page tables. I'm not sure what Intel does; I would guess probably the same thing. I would assume that if some architecture uses virtually addressed blocks in a write buffer (!!), then part of the task of a TLB flush be to complete the delayed write before removing the mapping. -- Jonathan To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-smp" in the body of the message