Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 83062
b: refs/heads/master
c: cb5f7b9
h: refs/heads/master
v: v3
  • Loading branch information
Hugh Dickins authored and Linus Torvalds committed Feb 5, 2008
1 parent 3f7c015 commit bdbad70
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: a0ee5ec520ede1dc8e2194623bcebfd9fab408f2
refs/heads/master: cb5f7b9a47963d9238398cd0c2676473e3c6896d
23 changes: 16 additions & 7 deletions trunk/mm/shmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ static struct backing_dev_info shmem_backing_dev_info __read_mostly = {
};

static LIST_HEAD(shmem_swaplist);
static DEFINE_SPINLOCK(shmem_swaplist_lock);
static DEFINE_MUTEX(shmem_swaplist_mutex);

static void shmem_free_blocks(struct inode *inode, long pages)
{
Expand Down Expand Up @@ -796,9 +796,9 @@ static void shmem_delete_inode(struct inode *inode)
inode->i_size = 0;
shmem_truncate(inode);
if (!list_empty(&info->swaplist)) {
spin_lock(&shmem_swaplist_lock);
mutex_lock(&shmem_swaplist_mutex);
list_del_init(&info->swaplist);
spin_unlock(&shmem_swaplist_lock);
mutex_unlock(&shmem_swaplist_mutex);
}
}
BUG_ON(inode->i_blocks);
Expand Down Expand Up @@ -851,6 +851,14 @@ static int shmem_unuse_inode(struct shmem_inode_info *info, swp_entry_t entry, s
for (idx = SHMEM_NR_DIRECT; idx < limit; idx += ENTRIES_PER_PAGE, dir++) {
if (unlikely(idx == stage)) {
shmem_dir_unmap(dir-1);
if (cond_resched_lock(&info->lock)) {
/* check it has not been truncated */
if (limit > info->next_index) {
limit = info->next_index;
if (idx >= limit)
goto lost2;
}
}
dir = shmem_dir_map(info->i_indirect) +
ENTRIES_PER_PAGE/2 + idx/ENTRIES_PER_PAGEPAGE;
while (!*dir) {
Expand Down Expand Up @@ -924,7 +932,7 @@ int shmem_unuse(swp_entry_t entry, struct page *page)
struct shmem_inode_info *info;
int found = 0;

spin_lock(&shmem_swaplist_lock);
mutex_lock(&shmem_swaplist_mutex);
list_for_each_safe(p, next, &shmem_swaplist) {
info = list_entry(p, struct shmem_inode_info, swaplist);
if (!info->swapped)
Expand All @@ -935,8 +943,9 @@ int shmem_unuse(swp_entry_t entry, struct page *page)
found = 1;
break;
}
cond_resched();
}
spin_unlock(&shmem_swaplist_lock);
mutex_unlock(&shmem_swaplist_mutex);
return found;
}

Expand Down Expand Up @@ -996,10 +1005,10 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
shmem_swp_unmap(entry);
spin_unlock(&info->lock);
if (list_empty(&info->swaplist)) {
spin_lock(&shmem_swaplist_lock);
mutex_lock(&shmem_swaplist_mutex);
/* move instead of add in case we're racing */
list_move_tail(&info->swaplist, &shmem_swaplist);
spin_unlock(&shmem_swaplist_lock);
mutex_unlock(&shmem_swaplist_mutex);
}
swap_duplicate(swap);
BUG_ON(page_mapped(page));
Expand Down

0 comments on commit bdbad70

Please sign in to comment.