9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: cinap_lenrek@felloff.net
To: 9fans@9fans.net
Subject: [9fans] imagereclaim()
Date: Sat,  1 Mar 2014 22:46:00 +0100	[thread overview]
Message-ID: <329d8901cc6fd72ba935ebbb2c5e2d84@felloff.net> (raw)

the imagereclaim algorithm is wrong.

	/*
	 * All the pages with images backing them are at the
	 * end of the list (see putpage) so start there and work
	 * backward.
	 */
	for(p = palloc.tail; p && p->image && n<1000; p = p->prev) {
		if(p->ref == 0 && canlock(p)) {
			if(p->ref == 0) {
				n++;
				uncachepage(p);
			}
			unlock(p);
		}
	}

1) the uncachepage() call breaks the invariant that pages
cached in a image are at the end of the page freelist. this
can cause a gab of uncached pages in a run of cached pages
from the end of the freelist. imagereclaim() will be unable
to reclaim the images refered by the pages after the gab.

in 9front, we unchain the page and put it back on the head
of the freelist after uncachepage().

2) there needs to a check to skip pages with
p->imagge->notext != 0 in case you use the mount cache
(port/cache.c). trying to uncache a page on a notext
image will not reclaim any image structures.

3) bonus: when you run a program from ramfs, the
ramfs will stay arround for quite a while even after
the program has long exited and the ramfs has been
unmounted. the reason is that we still cache the pages
of the program keeping the image arround. the image
has a Chan* reference to the original text file. until
the image is reclaimed and the channel closed, the mount
will stay arround preventing the fileserver (ramfs) from
exiting.

one can avoid keeping the chan reference by separately
tracking the number of page references to an image.
so when image->ref == image->pgref, we know that all
references to a image are from the page freelist.
in that case, one can close the channel in the image.
when the image gets attached again (attachimage()),
we take a new reference to the supplied channel and
stick it on the image.

use the channels mountid and quid to check for
file equality as mountid's are not reused within the
same kernel. no need to keep the channel arround.

i suspect the bigboy hack (which increases the conf.nimage
parameter to 2000 in pc/main.c confinit() for cpu servers)
might be partially due to this imagereclaim() bug trying
to cure the symptom.

--
cinap



             reply	other threads:[~2014-03-01 21:46 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-01 21:46 cinap_lenrek [this message]
2014-03-01 21:55 ` erik quanstrom
2014-03-01 22:22   ` cinap_lenrek
2014-03-01 22:52     ` erik quanstrom
2014-03-01 23:05       ` cinap_lenrek
2014-03-01 23:11         ` erik quanstrom
2014-03-01 23:14         ` Charles Forsyth
2014-03-02  1:21           ` cinap_lenrek
2014-03-02  3:14             ` erik quanstrom
2014-03-02  3:55               ` cinap_lenrek
2014-03-02  4:05                 ` erik quanstrom
2014-03-02  4:30                   ` cinap_lenrek
2014-03-02  9:48                 ` Charles Forsyth
2014-03-02 18:46                   ` cinap_lenrek
2014-03-02 18:53                     ` Charles Forsyth
2014-03-02 22:59                       ` Anthony Martin
2014-03-03  1:00                         ` erik quanstrom
2014-03-01 23:09     ` Charles Forsyth

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=329d8901cc6fd72ba935ebbb2c5e2d84@felloff.net \
    --to=cinap_lenrek@felloff.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).