Re: what does mm/swap_state.c:swap_count() return?

Rik van Riel (riel@nl.linux.org)
Sun, 14 Nov 1999 22:35:54 +0100 (CET)


On Sun, 14 Nov 1999 afei@jhu.edu wrote:

> 134 int swap_count(unsigned long entry)
> 135 {

[snip lots of tests, arriving at the common case]

> 153 retval = p->swap_map[offset];

Here the function sets retval to the number of users of
a particular page. /usr/bin/grep is your friend here, it
could have told you that the only user of swap_count()
is mm/memory.c::do_wp_page(), which has the following
comment just before the call to swap_count():

/*
* We can avoid the copy if:
* - we're the only user (count == 1)
* - the only other user is the swap cache,
* and the only swap cache user is itself,
* in which case we can remove the page
* from the swap cache.
*/
switch (page_count(old_page)) {
case 2:
if (!PageSwapCache(old_page))
break;
if (swap_count(old_page) != 1)
break;
delete_from_swap_cache(old_page);
/* FallThrough */

Here you can see that Linux tests if the page has
!= 1 users on a write fault to a swapcached page.

If we have multiple users of that same page, we
copy the page and give the writing process its
own copy. If we're the only user we'll just
invalidate the swap cache and let the process
go on and dirty its page.

Rik

--
The Internet is not a network of computers. It is a network
of people. That is its real strength.

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/