linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Daniel McNeil <daniel@osdl.org>
To: Andrea Arcangeli <andrea@suse.de>
Cc: Andrew Morton <akpm@digeo.com>,
	dmccr@us.ibm.com, mika.penttila@kolumbus.fi, linux-mm@kvack.org,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: Race between vmtruncate and mapped areas?
Date: 15 May 2003 09:38:26 -0700	[thread overview]
Message-ID: <1053016706.2693.10.camel@ibm-c.pdx.osdl.net> (raw)
In-Reply-To: <20030515094041.GA1429@dualathlon.random>

[-- Attachment #1: Type: text/plain, Size: 940 bytes --]

On Thu, 2003-05-15 at 02:40, Andrea Arcangeli wrote:
> On Thu, May 15, 2003 at 02:20:00AM -0700, Andrew Morton wrote:
> > Andrea Arcangeli <andrea@suse.de> wrote:
> > >
> > > and it's still racy
> > 
> > damn, and it just booted ;)
> > 
> > I'm just a little bit concerned over the ever-expanding inode.  Do you
> > think the dual sequence numbers can be replaced by a single generation
> > counter?
> 
> yes, I wrote it as a single counter first, but was unreadable and it had
> more branches, so I added the other sequence number to make it cleaner.
> I don't mind another 4 bytes, that cacheline should be hot anyways.

You could use the seqlock.h sequence locking.  It only uses 1 sequence
counter.  The 2.5 isize patch 1 has a sequence lock without the spinlock
so it only uses 4 bytes and it is somewhat more readable.  I don't
think it has more branches.

I've attached the isize seqlock.h patch.
-- 
Daniel McNeil <daniel@osdl.org>

[-- Attachment #2: patch-2.5.69-isize.1 --]
[-- Type: text/x-patch, Size: 1603 bytes --]

diff -rupN -X /home/daniel/dontdiff linux-2.5.69/include/linux/seqlock.h linux-2.5.69-isize/include/linux/seqlock.h
--- linux-2.5.69/include/linux/seqlock.h	Sun May  4 16:53:14 2003
+++ linux-2.5.69-isize/include/linux/seqlock.h	Wed May  7 16:00:25 2003
@@ -94,6 +94,57 @@ static inline int read_seqretry(const se
 	return (iv & 1) | (sl->sequence ^ iv);
 }
 
+
+/*
+ * Version using sequence counter only. 
+ * This can be used when code has its own mutex protecting the
+ * updating starting before the write_seqcntbeqin() and ending
+ * after the write_seqcntend().
+ */
+
+typedef struct seqcnt {
+	unsigned sequence;
+} seqcnt_t;
+
+#define SEQCNT_ZERO { 0 }
+#define seqcnt_init(x)	do { *(x) = (seqcnt_t) SEQCNT_ZERO; } while (0)
+
+/* Start of read using pointer to a sequence counter only.  */
+static inline unsigned read_seqcntbegin(const seqcnt_t *s)
+{
+	unsigned ret = s->sequence;
+	smp_rmb();
+	return ret;
+}
+
+/* Test if reader processed invalid data.
+ * Equivalent to: iv is odd or sequence number has changed.
+ *                (iv & 1) || (*s != iv)
+ * Using xor saves one conditional branch.
+ */
+static inline int read_seqcntretry(const seqcnt_t *s, unsigned iv)
+{
+	smp_rmb();
+	return (iv & 1) | (s->sequence ^ iv);
+}
+
+
+/* 
+ * Sequence counter only version assumes that callers are using their
+ * own mutexing.
+ */
+static inline void write_seqcntbegin(seqcnt_t *s)
+{
+	s->sequence++;
+	smp_wmb();			
+}	
+
+static inline void write_seqcntend(seqcnt_t *s) 
+{
+	smp_wmb();
+	s->sequence++;
+}
+
 /*
  * Possible sw/hw IRQ protected versions of the interfaces.
  */

  parent reply	other threads:[~2003-05-15 16:38 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-13 20:44 Dave McCracken
2003-05-13 20:58 ` Mika Penttilä
2003-05-13 21:04   ` William Lee Irwin III
2003-05-13 22:26   ` Dave McCracken
2003-05-13 22:49     ` William Lee Irwin III
2003-05-13 23:00       ` Dave McCracken
2003-05-13 23:11         ` William Lee Irwin III
2003-05-13 23:16           ` Dave McCracken
2003-05-13 23:20             ` William Lee Irwin III
2003-05-13 23:28               ` Dave McCracken
2003-05-13 23:29                 ` William Lee Irwin III
2003-05-13 23:16         ` William Lee Irwin III
2003-05-14  1:10         ` Andrew Morton
2003-05-14 15:02           ` Dave McCracken
2003-05-14  1:10     ` Andrew Morton
2003-05-14 15:02       ` Dave McCracken
2003-05-14 15:06         ` William Lee Irwin III
2003-05-14 15:25           ` Dave McCracken
2003-05-14 16:42           ` Gerrit Huizenga
2003-05-14 17:34         ` Andrew Morton
2003-05-14 17:42           ` Dave McCracken
2003-05-14 17:57             ` Andrew Morton
2003-05-14 18:05               ` Dave McCracken
2003-05-14 18:17                 ` Andrew Morton
2003-05-14 18:24                   ` Dave McCracken
2003-05-14 18:53                     ` Andrew Morton
2003-05-15  8:50                       ` Andrea Arcangeli
2003-05-14 19:02               ` Rik van Riel
2003-05-14 19:04                 ` Rik van Riel
2003-05-14 19:07                   ` Dave McCracken
2003-05-14 19:11                     ` Rik van Riel
2003-05-15  0:49             ` Andrea Arcangeli
2003-05-15  2:36               ` Rik van Riel
2003-05-15  9:46                 ` Andrea Arcangeli
2003-05-15  9:55                   ` Andrew Morton
2003-05-15  8:32               ` Andrew Morton
2003-05-15  8:42                 ` Andrew Morton
2003-05-15  8:55                 ` Andrea Arcangeli
2003-05-15  9:20                   ` Andrew Morton
2003-05-15  9:40                     ` Andrea Arcangeli
2003-05-15  9:58                       ` Andrew Morton
2003-05-15 16:38                       ` Daniel McNeil [this message]
2003-05-15 19:19                         ` Andrea Arcangeli
2003-05-15 22:04                           ` Daniel McNeil
2003-05-15 23:17                             ` Andrea Arcangeli
2003-05-17  0:27                               ` Daniel McNeil
2003-05-17 17:29                                 ` Andrea Arcangeli
2003-05-13 21:00 ` William Lee Irwin III
2003-05-17 18:19 Paul McKenney
2003-05-17 18:42 ` Andrea Arcangeli
2003-05-19 18:11 Paul McKenney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1053016706.2693.10.camel@ibm-c.pdx.osdl.net \
    --to=daniel@osdl.org \
    --cc=akpm@digeo.com \
    --cc=andrea@suse.de \
    --cc=dmccr@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mika.penttila@kolumbus.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox