2001-04-21 15:49:47

by Mike Galbraith

[permalink] [raw]
Subject: try_to_swap_out() deactivating pages w. count > 2

Hi,

A printk added to 2.4.4-pre5 try_to_swap_out()...

drop_pte:
mm->rss--;
{
int age = page->age;
int count = page_count(page);
int cache = PageSwapCache(page);
printk("[pid-%d] page:%p deact:%d cache:%d age:%d count:%d\n",
current->pid, page, !age, cache, age, count-1);
}

make -j30 bzImage

29:17: klogd 1.3-3, log source = /proc/kmsg started.
29:27: SysRq: Log level set to 0
30:04: [pid-4] page:c10e225c deact:1 cache:0 age:0 count:2
30:04: [pid-4] page:c10e33e0 deact:1 cache:0 age:0 count:2
30:04: [pid-4] page:c10e3394 deact:1 cache:0 age:0 count:2
30:04: [pid-4] page:c10e1cb8 deact:1 cache:0 age:0 count:2
30:04: [pid-4] page:c10e1c20 deact:1 cache:0 age:0 count:2
30:04: [pid-4] page:c10eb894 deact:1 cache:0 age:0 count:2
30:04: [pid-4] page:c10eb7b0 deact:1 cache:0 age:0 count:2
30:04: [pid-4] page:c10f0bb4 deact:0 cache:0 age:4 count:3
30:04: [pid-4] page:c10f1320 deact:0 cache:1 age:2 count:1
30:04: [pid-4] page:c10f136c deact:0 cache:1 age:2 count:1
30:04: [pid-4] page:c10599f4 deact:0 cache:0 age:29 count:164 [164? 1]
30:04: [pid-4] page:c10599a8 deact:0 cache:0 age:26 count:164
30:04: [pid-4] page:c105995c deact:0 cache:0 age:37 count:164
30:04: [pid-4] page:c10598c4 deact:0 cache:0 age:34 count:164
30:04: [pid-4] page:c1059878 deact:0 cache:0 age:34 count:164
30:04: [pid-4] page:c105982c deact:0 cache:0 age:34 count:164
30:04: [pid-4] page:c10599f4 deact:0 cache:0 age:32 count:163
30:04: [pid-4] page:c10599a8 deact:0 cache:0 age:26 count:163
30:04: [pid-4] page:c10debbc deact:1 cache:0 age:0 count:2
30:04: [pid-4] page:c10deb70 deact:1 cache:0 age:0 count:2
30:04: [pid-4] page:c10deb24 deact:1 cache:0 age:0 count:2
30:04: [pid-4] page:c10e1aa4 deact:1 cache:0 age:0 count:2

(snip 1000+ lines)

grep c10599f4 log
30:04: [pid-4] page:c10599f4 deact:0 cache:0 age:29 count:164
30:04: [pid-4] page:c10599f4 deact:0 cache:0 age:32 count:163
30:04: [pid-4] page:c10599f4 deact:0 cache:0 age:32 count:162
30:04: [pid-4] page:c10599f4 deact:0 cache:0 age:32 count:161
30:04: [pid-4] page:c10599f4 deact:0 cache:0 age:32 count:160
30:04: [pid-4] page:c10599f4 deact:0 cache:0 age:32 count:159
30:04: [pid-4] page:c10599f4 deact:0 cache:0 age:32 count:158
30:04: [pid-4] page:c10599f4 deact:0 cache:0 age:32 count:157
30:05: [pid-4] page:c10599f4 deact:0 cache:0 age:16 count:155
30:05: [pid-4] page:c10599f4 deact:0 cache:0 age:22 count:156
30:05: [pid-4] page:c10599f4 deact:0 cache:0 age:22 count:155
30:05: [pid-4] page:c10599f4 deact:0 cache:0 age:50 count:157
30:05: [pid-4] page:c10599f4 deact:0 cache:0 age:16 count:157
41:41: [pid-4] page:c10599f4 deact:1 cache:0 age:0 count:59
41:41: [pid-4] page:c10599f4 deact:1 cache:0 age:0 count:58
41:41: [pid-4] page:c10599f4 deact:1 cache:0 age:0 count:57
41:41: [pid-4] page:c10599f4 deact:1 cache:0 age:0 count:56
41:41: [pid-4] page:c10599f4 deact:1 cache:0 age:0 count:55
41:41: [pid-4] page:c10599f4 deact:1 cache:0 age:0 count:54
41:41: [pid-4] page:c10599f4 deact:1 cache:0 age:0 count:53
41:41: [pid-4] page:c10599f4 deact:1 cache:0 age:0 count:52
41:41: [pid-4] page:c10599f4 deact:1 cache:0 age:0 count:51
41:41: [pid-4] page:c10599f4 deact:1 cache:0 age:0 count:50
41:59: [pid-4] page:c10599f4 deact:1 cache:0 age:0 count:49
41:59: [pid-4] page:c10599f4 deact:1 cache:0 age:0 count:48
41:59: [pid-4] page:c10599f4 deact:1 cache:0 age:0 count:47
41:59: [pid-4] page:c10599f4 deact:1 cache:0 age:0 count:46
41:59: [pid-4] page:c10599f4 deact:1 cache:0 age:0 count:45
41:59: [pid-4] page:c10599f4 deact:1 cache:0 age:0 count:44

(klogd only logged 1196 pages during the whole build)

grep deact:0 log|wc -l = 961
grep count:[12] log|wc -l = 875

grep deact:1 log|wc -l = 235
grep deact:1 log|grep count:[12]|wc -l = 103

1. what kind of page has 164 references?
2. why deactivate pages (lots) with count > 2? PINGpong.

-Mike


2001-04-21 16:08:38

by Mike Galbraith

[permalink] [raw]
Subject: Re: try_to_swap_out() deactivating pages w. count > 2

Oops.. looking at aging too hard :)

What kind of page is it?

-Mike

2001-04-21 16:46:53

by Rik van Riel

[permalink] [raw]
Subject: Re: try_to_swap_out() deactivating pages w. count > 2

On Sat, 21 Apr 2001, Mike Galbraith wrote:

> 30:04: [pid-4] page:c10599f4 deact:0 cache:0 age:29 count:164 [164? 1]
> 30:04: [pid-4] page:c10599a8 deact:0 cache:0 age:26 count:164

> 1. what kind of page has 164 references?

mmap(/lib/libc.so, FLAGS);

> 2. why deactivate pages (lots) with count > 2? PINGpong.

They're not deactivated, they're removed from this proces' virtual
memory mapping.

What I _am_ worried about is the fact that we do this to pages with
a really high page age. These things are in active use and cannot
be swapped out any time soon, yet we do claim swap space for it ...

regards,

Rik
--
Virtual memory is like a game you can't win;
However, without VM there's truly nothing to lose...

http://www.surriel.com/
http://www.conectiva.com/ http://distro.conectiva.com.br/

2001-04-21 17:49:19

by Mike Galbraith

[permalink] [raw]
Subject: Re: try_to_swap_out() deactivating pages w. count > 2

On Sat, 21 Apr 2001, Rik van Riel wrote:

> On Sat, 21 Apr 2001, Mike Galbraith wrote:
>
> > 30:04: [pid-4] page:c10599f4 deact:0 cache:0 age:29 count:164 [164? 1]
> > 30:04: [pid-4] page:c10599a8 deact:0 cache:0 age:26 count:164
>
> > 1. what kind of page has 164 references?
>
> mmap(/lib/libc.so, FLAGS);

I figured that out too in the meantime. (14hrs at a stretch makes
more than eyeballs bleary..)

> > 2. why deactivate pages (lots) with count > 2? PINGpong.
>
> They're not deactivated, they're removed from this proces' virtual
> memory mapping.

blush.. yup.

> What I _am_ worried about is the fact that we do this to pages with
> a really high page age. These things are in active use and cannot
> be swapped out any time soon, yet we do claim swap space for it ...

I'll see if it makes any noticable difference tomorrow. Enough
fruitless effort for one day.

:) Am I likely to learn more about how swapcache works when I try
to instantly donate these to page_launder() tomorrow morning?

[4] mm:c2ce9f00 page:c1001060 deact:0 cache:1 buf:0 age:5 cnt:1
[2285] mm:c67ef760 page:c1002b18 deact:0 cache:1 buf:0 age:5 cnt:1

-Mike

2001-04-21 17:43:38

by Linus Torvalds

[permalink] [raw]
Subject: Re: try_to_swap_out() deactivating pages w. count > 2

In article <Pine.LNX.4.21.0104211336390.1685-100000@imladris.rielhome.conectiva>,
Rik van Riel <[email protected]> wrote:
>
>What I _am_ worried about is the fact that we do this to pages with
>a really high page age. These things are in active use and cannot
>be swapped out any time soon, yet we do claim swap space for it ...

Ehh... And if we didn't do that, then how could they every become less
active?

We should _absolutely_ do the swap space reclaiming without looking at
the page count. If we don't, you will never free those pages, and I have
a trivial exploit for you that will basically mlock all pages in memory.

try_to_swap_out() _absolutely_ does the right thing. Also note how it
will need to allocate the swap space backing store only once.

Linus

2001-04-21 17:56:31

by Rik van Riel

[permalink] [raw]
Subject: Re: try_to_swap_out() deactivating pages w. count > 2

On Sat, 21 Apr 2001, Linus Torvalds wrote:
> In article <Pine.LNX.4.21.0104211336390.1685-100000@imladris.rielhome.conectiva>,
> Rik van Riel <[email protected]> wrote:
> >
> >What I _am_ worried about is the fact that we do this to pages with
> >a really high page age. These things are in active use and cannot
> >be swapped out any time soon, yet we do claim swap space for it ...
>
> Ehh... And if we didn't do that, then how could they every become less
> active?
>
> We should _absolutely_ do the swap space reclaiming without looking at
> the page count.

page->age != page->count

Rik
--
Virtual memory is like a game you can't win;
However, without VM there's truly nothing to lose...

http://www.surriel.com/
http://www.conectiva.com/ http://distro.conectiva.com.br/

2001-04-21 18:01:11

by Rik van Riel

[permalink] [raw]
Subject: Re: try_to_swap_out() deactivating pages w. count > 2

On Sat, 21 Apr 2001, Rik van Riel wrote:
> On Sat, 21 Apr 2001, Linus Torvalds wrote:

> > Ehh... And if we didn't do that, then how could they every become less
> > active?
> >
> > We should _absolutely_ do the swap space reclaiming without looking at
> > the page count.
>
> page->age != page->count

Umm, forget that. We only decrease page->age in refill_inactive_scan,
so we NEED to put it there. You're right, I should wake up and think
a bit more about my own code ;)

Rik
--
Virtual memory is like a game you can't win;
However, without VM there's truly nothing to lose...

http://www.surriel.com/
http://www.conectiva.com/ http://distro.conectiva.com.br/

2001-04-21 18:03:41

by Linus Torvalds

[permalink] [raw]
Subject: Re: try_to_swap_out() deactivating pages w. count > 2


On Sat, 21 Apr 2001, Rik van Riel wrote:
> >
> > We should _absolutely_ do the swap space reclaiming without looking at
> > the page count.
>
> page->age != page->count

It's all the same thing.

The page age and count are used to decice when the page actually gets
thrown _out_ of memory. That's a decision that is based on the _physical_
page attributes.

But try_to_swap_out() is based on the attribute on this particular virtual
mapping of the page. If this particular virtual mapping does not have the
"accessed" bit set, then try_to_swap_out() should get rid of that virtual
mapping. It should absolutely not use the global page characteristics
(either global usage count or global age) in making that decision. Because
those do not matter - they have absoilutely no meaning for this virtual
mapping of the page.

Put another way: if process A is a heavy user of a page, and process B
just touched it once and will never touch it again, what do you think
should happen?

Answer: the page should be dropped from process B. It's a cheap thing to
do (we can get it back if necessary without any IO), and it means that if
we end up having toi actually swap out the page eventually, we will not be
confused by "noise" in the page count from a mappign that hasn't been
active for a long time.

Linus