Linux Headquarters
[ Register ]
[ About us ] [ Home Page ]

[ Kernel ] [ Documentation ] [ Links ] [ Books ]

Kernel v2.4.11 /mm/shmem.c

Filename:/mm/shmem.c
Lines Added:21
Lines Deleted:18
Also changed in: (Previous) 2.4.11-pre6  2.4.11-pre5  2.4.11-pre4  2.4.10-ac10  2.4.10-ac9  2.4.10-ac8 
(Following) 2.4.12  2.4.12-ac1  2.4.12-ac2  2.4.12-ac3  2.4.12-ac4  2.4.12-ac5 

Location
[  2.4.11
  [  mm
     o  shmem.c

Patch

diff -u --recursive --new-file v2.4.10/linux/mm/shmem.c linux/mm/shmem.c
--- v2.4.10/linux/mm/shmem.c   Sun Sep 23 11:41:01 2001
+++ linux/mm/shmem.c   Thu Oct  4 16:46:30 2001
@@ -245,6 +245,14 @@
    index = page->index;
    inode = mapping->host;
    info = &inode->u.shmem_i;
+getswap:
+   swap = get_swap_page();
+   if (!swap.val) {
+      activate_page(page);
+      SetPageDirty(page);
+      error = -ENOMEM;
+      goto out;
+   }
 
    spin_lock(&info->lock);
    entry = shmem_swp_entry(info, index);
@@ -257,32 +265,27 @@
    /* Remove it from the page cache */
    lru_cache_del(page);
    remove_inode_page(page);
+   page_cache_release(page);
 
-   swap_list_lock();
-   swap = get_swap_page();
-
-   if (!swap.val) {
-      swap_list_unlock();
-      /* Add it back to the page cache */
+   /* Add it to the swap cache */
+   if (add_to_swap_cache(page, swap) != 0) {
+      /*
+       * Raced with "speculative" read_swap_cache_async.
+       * Add page back to page cache, unref swap, try again.
+       */
       add_to_page_cache_locked(page, mapping, index);
-      activate_page(page);
-      SetPageDirty(page);
-      error = -ENOMEM;
-      goto out;
+      spin_unlock(&info->lock);
+      swap_free(swap);
+      goto getswap;
    }
 
-   /* Add it to the swap cache */
-   add_to_swap_cache(page, swap);
-   swap_list_unlock();
-
-   set_page_dirty(page);
-   info->swapped++;
    *entry = swap;
+   info->swapped++;
+   spin_unlock(&info->lock);
+   set_page_dirty(page);
    error = 0;
 out:
-   spin_unlock(&info->lock);
    UnlockPage(page);
-   page_cache_release(page);
    return error;
 }
 


Comments: webmaster (at) linuxhq.com.
Advertising: banners (at) linuxhq.com.
Compilation ©1998-2008 Linux Headquarters, Inc.