lkml.org 
[lkml]   [1998]   [Nov]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Swapping-bug
On Sun, 1 Nov 1998, Ariel Rosenblatt wrote:

>If a process that requires more memory than available and therefore causes
>many of its pages to be swapped (could be around half of the total memory),
>terminates or releases its memory while its pages are still scheduled for
>delayed-write to the disk, all those pages will remain in the swap_cache
>(and even with a high "age" value), so that although nobody needs those
>pages, which should go to the free-list, they hang around there
>indefinitely until other processes run out of memory.ry.free memory.
>When that eventually happens, only then those pages begin to age, while
>good pages are stolen from other processes in the meanwhile.

In the latest 2.1 kernels swap cache pages are not aged anymore (just
because the problem you are reporting).

>The reason is that while pages are scheduled to be written to disk, their

No this should be not the reason. The reason is that if the swap cache
page is shared not in memory but in the swap, the swap cache page remains
there when the process will die. I developd a fix for the problem you are
reporting some time ago but it got not included because it seems that such
swap cache garbage would not hurt. I extracted the fix from an my old
patch. Tell me if it fix the problem you are reporting and if it makes a
performance difference compared to pre-2.1.127-3 (if it will make no a
performance difference you can' t hope to see it included ;-).

Index: linux/include/linux/swap.h
diff -c linux/include/linux/swap.h:1.1.1.1.14.3 linux/include/linux/swap.h:1.1.1.1.14.4
*** linux/include/linux/swap.h:1.1.1.1.14.3 Thu Oct 29 19:42:56 1998
--- linux/include/linux/swap.h Sun Nov 1 18:20:48 1998
***************
*** 90,95 ****
--- 90,96 ----
extern struct page * read_swap_cache_async(unsigned long, int);
#define read_swap_cache(entry) read_swap_cache_async(entry, 1);
extern int FASTCALL(swap_count(unsigned long));
+ extern void FASTCALL(try_to_free_last_swap_entry(unsigned long));
/*
* Make these inline later once they are working properly.
*/
Index: linux/mm/swap_state.c
diff -c linux/mm/swap_state.c:1.1.1.1.14.4 linux/mm/swap_state.c:1.1.1.1.14.5
*** linux/mm/swap_state.c:1.1.1.1.14.4 Fri Oct 30 19:11:15 1998
--- linux/mm/swap_state.c Sun Nov 1 18:20:50 1998
***************
*** 287,292 ****
--- 287,316 ----
return 0;
}

+ void try_to_free_last_swap_entry(unsigned long entry)
+ {
+ struct page * page = lookup_swap_cache(entry);
+ if (page)
+ {
+ /*
+ * The last reference in the swap_map[entry] is caused
+ * by this swap cache page.
+ *
+ * Decrease the page->count increased by __find_page().
+ * -arca
+ */
+ __free_page(page);
+ if (atomic_read(&page->count) == 1)
+ /*
+ * The page is resident in memory only because
+ * it' s in the swap cache so we can remove it
+ * because it can' t be useful anymore.
+ * -arca
+ */
+ delete_from_swap_cache(page);
+ }
+ }
+
/*
* Locate a page of swap in physical memory, reserving swap cache space
* and reading the disk if it is not already cached. If wait==0, we are
Index: linux/mm/swapfile.c
diff -c linux/mm/swapfile.c:1.1.1.1 linux/mm/swapfile.c:1.1.1.1.16.1
*** linux/mm/swapfile.c:1.1.1.1 Fri Oct 2 19:22:39 1998
--- linux/mm/swapfile.c Sun Nov 1 18:20:50 1998
***************
*** 144,153 ****
p->highest_bit = offset;
if (!p->swap_map[offset])
goto bad_free;
! if (p->swap_map[offset] < SWAP_MAP_MAX) {
! if (!--p->swap_map[offset])
nr_swap_pages++;
! }
#ifdef DEBUG_SWAP
printk("DebugVM: swap_free(entry %08lx, count now %d)\n",
entry, p->swap_map[offset]);
--- 144,158 ----
p->highest_bit = offset;
if (!p->swap_map[offset])
goto bad_free;
! if (p->swap_map[offset] < SWAP_MAP_MAX)
! switch(--p->swap_map[offset])
! {
! case 0:
nr_swap_pages++;
! break;
! case 1:
! try_to_free_last_swap_entry(entry);
! }
#ifdef DEBUG_SWAP
printk("DebugVM: swap_free(entry %08lx, count now %d)\n",
entry, p->swap_map[offset]);


Andrea Arcangeli



-
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/

\
 
 \ /
  Last update: 2005-03-22 13:45    [W:3.905 / U:0.020 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site