diff options
author | Hugh Dickins <hugh@veritas.com> | 2008-02-05 01:28:53 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2008-02-05 12:44:15 -0500 |
commit | 2e0e26c76a35de8f8bec6b2b917518cfeb52888a (patch) | |
tree | 1357781bfe035c2401c65b2d0203385a47516bf5 /mm/shmem.c | |
parent | cb5f7b9a47963d9238398cd0c2676473e3c6896d (diff) |
tmpfs: open a window in shmem_unuse_inode
There are a couple of reasons (patches follow) why it would be good to open a
window for sleep in shmem_unuse_inode, between its search for a matching swap
entry, and its handling of the entry found.
shmem_unuse_inode must then use igrab to hold the inode against deletion in
that window, and its corresponding iput might result in deletion: so it had
better unlock_page before the iput, and might as well release the page too.
Nor is there any need to hold on to shmem_swaplist_mutex once we know we'll
leave the loop. So this unwinding moves from try_to_unuse and shmem_unuse
into shmem_unuse_inode, in the case when it finds a match.
Let try_to_unuse break on error in the shmem_unuse case, as it does in the
unuse_mm case: though at this point in the series, no error to break on.
Signed-off-by: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/shmem.c')
-rw-r--r-- | mm/shmem.c | 57 |
1 files changed, 35 insertions, 22 deletions
diff --git a/mm/shmem.c b/mm/shmem.c index 2e03d6031c24..a0126c437105 100644 --- a/mm/shmem.c +++ b/mm/shmem.c | |||
@@ -838,10 +838,8 @@ static int shmem_unuse_inode(struct shmem_inode_info *info, swp_entry_t entry, s | |||
838 | if (size > SHMEM_NR_DIRECT) | 838 | if (size > SHMEM_NR_DIRECT) |
839 | size = SHMEM_NR_DIRECT; | 839 | size = SHMEM_NR_DIRECT; |
840 | offset = shmem_find_swp(entry, ptr, ptr+size); | 840 | offset = shmem_find_swp(entry, ptr, ptr+size); |
841 | if (offset >= 0) { | 841 | if (offset >= 0) |
842 | shmem_swp_balance_unmap(); | ||
843 | goto found; | 842 | goto found; |
844 | } | ||
845 | if (!info->i_indirect) | 843 | if (!info->i_indirect) |
846 | goto lost2; | 844 | goto lost2; |
847 | 845 | ||
@@ -879,11 +877,11 @@ static int shmem_unuse_inode(struct shmem_inode_info *info, swp_entry_t entry, s | |||
879 | if (size > ENTRIES_PER_PAGE) | 877 | if (size > ENTRIES_PER_PAGE) |
880 | size = ENTRIES_PER_PAGE; | 878 | size = ENTRIES_PER_PAGE; |
881 | offset = shmem_find_swp(entry, ptr, ptr+size); | 879 | offset = shmem_find_swp(entry, ptr, ptr+size); |
880 | shmem_swp_unmap(ptr); | ||
882 | if (offset >= 0) { | 881 | if (offset >= 0) { |
883 | shmem_dir_unmap(dir); | 882 | shmem_dir_unmap(dir); |
884 | goto found; | 883 | goto found; |
885 | } | 884 | } |
886 | shmem_swp_unmap(ptr); | ||
887 | } | 885 | } |
888 | } | 886 | } |
889 | lost1: | 887 | lost1: |
@@ -893,10 +891,25 @@ lost2: | |||
893 | return 0; | 891 | return 0; |
894 | found: | 892 | found: |
895 | idx += offset; | 893 | idx += offset; |
896 | inode = &info->vfs_inode; | 894 | inode = igrab(&info->vfs_inode); |
897 | error = add_to_page_cache(page, inode->i_mapping, idx, GFP_ATOMIC); | 895 | spin_unlock(&info->lock); |
896 | |||
897 | /* move head to start search for next from here */ | ||
898 | list_move_tail(&shmem_swaplist, &info->swaplist); | ||
899 | mutex_unlock(&shmem_swaplist_mutex); | ||
900 | |||
901 | error = 1; | ||
902 | if (!inode) | ||
903 | goto out; | ||
904 | |||
905 | spin_lock(&info->lock); | ||
906 | ptr = shmem_swp_entry(info, idx, NULL); | ||
907 | if (ptr && ptr->val == entry.val) | ||
908 | error = add_to_page_cache(page, inode->i_mapping, | ||
909 | idx, GFP_ATOMIC); | ||
898 | if (error == -EEXIST) { | 910 | if (error == -EEXIST) { |
899 | struct page *filepage = find_get_page(inode->i_mapping, idx); | 911 | struct page *filepage = find_get_page(inode->i_mapping, idx); |
912 | error = 1; | ||
900 | if (filepage) { | 913 | if (filepage) { |
901 | /* | 914 | /* |
902 | * There might be a more uptodate page coming down | 915 | * There might be a more uptodate page coming down |
@@ -911,16 +924,18 @@ found: | |||
911 | delete_from_swap_cache(page); | 924 | delete_from_swap_cache(page); |
912 | set_page_dirty(page); | 925 | set_page_dirty(page); |
913 | info->flags |= SHMEM_PAGEIN; | 926 | info->flags |= SHMEM_PAGEIN; |
914 | shmem_swp_set(info, ptr + offset, 0); | 927 | shmem_swp_set(info, ptr, 0); |
928 | swap_free(entry); | ||
929 | error = 1; /* not an error, but entry was found */ | ||
915 | } | 930 | } |
916 | shmem_swp_unmap(ptr); | 931 | if (ptr) |
932 | shmem_swp_unmap(ptr); | ||
917 | spin_unlock(&info->lock); | 933 | spin_unlock(&info->lock); |
918 | /* | 934 | out: |
919 | * Decrement swap count even when the entry is left behind: | 935 | unlock_page(page); |
920 | * try_to_unuse will skip over mms, then reincrement count. | 936 | page_cache_release(page); |
921 | */ | 937 | iput(inode); /* allows for NULL */ |
922 | swap_free(entry); | 938 | return error; |
923 | return 1; | ||
924 | } | 939 | } |
925 | 940 | ||
926 | /* | 941 | /* |
@@ -935,18 +950,16 @@ int shmem_unuse(swp_entry_t entry, struct page *page) | |||
935 | mutex_lock(&shmem_swaplist_mutex); | 950 | mutex_lock(&shmem_swaplist_mutex); |
936 | list_for_each_safe(p, next, &shmem_swaplist) { | 951 | list_for_each_safe(p, next, &shmem_swaplist) { |
937 | info = list_entry(p, struct shmem_inode_info, swaplist); | 952 | info = list_entry(p, struct shmem_inode_info, swaplist); |
938 | if (!info->swapped) | 953 | if (info->swapped) |
954 | found = shmem_unuse_inode(info, entry, page); | ||
955 | else | ||
939 | list_del_init(&info->swaplist); | 956 | list_del_init(&info->swaplist); |
940 | else if (shmem_unuse_inode(info, entry, page)) { | ||
941 | /* move head to start search for next from here */ | ||
942 | list_move_tail(&shmem_swaplist, &info->swaplist); | ||
943 | found = 1; | ||
944 | break; | ||
945 | } | ||
946 | cond_resched(); | 957 | cond_resched(); |
958 | if (found) | ||
959 | goto out; | ||
947 | } | 960 | } |
948 | mutex_unlock(&shmem_swaplist_mutex); | 961 | mutex_unlock(&shmem_swaplist_mutex); |
949 | return found; | 962 | out: return found; /* 0 or 1 or -ENOMEM */ |
950 | } | 963 | } |
951 | 964 | ||
952 | /* | 965 | /* |