9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: erik quanstrom <quanstro@quanstro.net>
To: 9fans@9fans.net
Subject: [9fans] qread() with a coalescing queue
Date: Wed,  1 Aug 2012 23:35:37 -0400	[thread overview]
Message-ID: <70be562e87fc244821634ca83fe59ab1@brasstown.quanstro.net> (raw)

in qbread, why does qbread only take full blocks for coalescing queues?
(these are only used for the console, and for tcp)  for example:

	if(q->state & Qcoalesce){
		/* when coalescing, 0 length blocks just go away */
		b = q->bfirst;
		if(BLEN(b) <= 0){
			freeb(qremove(q));
			goto again;
		}

		/*  grab the first block plus as many
		 *  following blocks as will completely
		 *  fit in the read.
		 */
		n = 0;
		l = &first;
		m = BLEN(b);
		for(;;) {
			*l = qremove(q);
			l = &b->next;
			n += m;

			b = q->bfirst;
			if(b == nil)
				break;
			m = BLEN(b);
			if(n+m > len)
				break;
		}
	}
	/* code to put extra bytes back on the queue below */

in the typical use with tcp, we're going to have a protocol like 9p or tls running
on top of tcp, and if it does a read of n bytes, it really does need n bytes.  so
splitting reads rather than blocks would seem less efficient because
copying a partial block <= mss should be much faster than a syscall.  (nsec()
with the fd open takes ~7-900ns, but a 1460-byte copy takes ~130ns @ a modest
10gb/s, much less if cache pressure doesn't dominate.)

i noticed this because even with the tcp rx queue full (slow receiver) i was seeing
twice as many reads  as i would have expected.  the following code works fine.

	if(q->state & Qcoalesce){
		/* when coalescing, 0 length blocks just go away */
		b = q->bfirst;
		if(BLEN(b) <= 0){
			freeb(qremove(q));
			goto again;
		}

		/*
		 * grab the first block and as many following
		 * blocks as will partially fit in the read
		 */
		n = 0;
		l = &first;
		m = BLEN(b);
		for(;;) {
			*l = qremove(q);
			l = &b->next;
			n += BLEN(b);
			if(n >= len || (b = q->bfirst) == nil)
				break;
		}
	}
	/* code to put extra bytes back on the queue below */

is there something or some consideration here that i'm missing?

- erik



                 reply	other threads:[~2012-08-02  3:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=70be562e87fc244821634ca83fe59ab1@brasstown.quanstro.net \
    --to=quanstro@quanstro.net \
    --cc=9fans@9fans.net \
    /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;
as well as URLs for NNTP newsgroup(s).