shmem.c (87039546544479d4bedb19d0ea525270c43c1c9b) shmem.c (af53d3e9e04024885de5b4fda51e5fa362ae2bd8)
1/*
2 * Resizable virtual memory filesystem for Linux.
3 *
4 * Copyright (C) 2000 Linus Torvalds.
5 * 2000 Transmeta Corp.
6 * 2000-2001 Christoph Rohland
7 * 2000-2001 SAP AG
8 * 2002 Red Hat Inc.

--- 1067 unchanged lines hidden (view full) ---

1076 if (!list_empty(&info->shrinklist)) {
1077 spin_lock(&sbinfo->shrinklist_lock);
1078 if (!list_empty(&info->shrinklist)) {
1079 list_del_init(&info->shrinklist);
1080 sbinfo->shrinklist_len--;
1081 }
1082 spin_unlock(&sbinfo->shrinklist_lock);
1083 }
1/*
2 * Resizable virtual memory filesystem for Linux.
3 *
4 * Copyright (C) 2000 Linus Torvalds.
5 * 2000 Transmeta Corp.
6 * 2000-2001 Christoph Rohland
7 * 2000-2001 SAP AG
8 * 2002 Red Hat Inc.

--- 1067 unchanged lines hidden (view full) ---

1076 if (!list_empty(&info->shrinklist)) {
1077 spin_lock(&sbinfo->shrinklist_lock);
1078 if (!list_empty(&info->shrinklist)) {
1079 list_del_init(&info->shrinklist);
1080 sbinfo->shrinklist_len--;
1081 }
1082 spin_unlock(&sbinfo->shrinklist_lock);
1083 }
1084 if (!list_empty(&info->swaplist)) {
1084 while (!list_empty(&info->swaplist)) {
1085 /* Wait while shmem_unuse() is scanning this inode... */
1086 wait_var_event(&info->stop_eviction,
1087 !atomic_read(&info->stop_eviction));
1085 mutex_lock(&shmem_swaplist_mutex);
1088 mutex_lock(&shmem_swaplist_mutex);
1086 list_del_init(&info->swaplist);
1089 /* ...but beware of the race if we peeked too early */
1090 if (!atomic_read(&info->stop_eviction))
1091 list_del_init(&info->swaplist);
1087 mutex_unlock(&shmem_swaplist_mutex);
1088 }
1089 }
1090
1091 simple_xattrs_free(&info->xattrs);
1092 WARN_ON(inode->i_blocks);
1093 shmem_free_inode(inode->i_sb);
1094 clear_inode(inode);

--- 127 unchanged lines hidden (view full) ---

1222 * Read all the shared memory data that resides in the swap
1223 * device 'type' back into memory, so the swap device can be
1224 * unused.
1225 */
1226int shmem_unuse(unsigned int type, bool frontswap,
1227 unsigned long *fs_pages_to_unuse)
1228{
1229 struct shmem_inode_info *info, *next;
1092 mutex_unlock(&shmem_swaplist_mutex);
1093 }
1094 }
1095
1096 simple_xattrs_free(&info->xattrs);
1097 WARN_ON(inode->i_blocks);
1098 shmem_free_inode(inode->i_sb);
1099 clear_inode(inode);

--- 127 unchanged lines hidden (view full) ---

1227 * Read all the shared memory data that resides in the swap
1228 * device 'type' back into memory, so the swap device can be
1229 * unused.
1230 */
1231int shmem_unuse(unsigned int type, bool frontswap,
1232 unsigned long *fs_pages_to_unuse)
1233{
1234 struct shmem_inode_info *info, *next;
1230 struct inode *inode;
1231 struct inode *prev_inode = NULL;
1232 int error = 0;
1233
1234 if (list_empty(&shmem_swaplist))
1235 return 0;
1236
1237 mutex_lock(&shmem_swaplist_mutex);
1235 int error = 0;
1236
1237 if (list_empty(&shmem_swaplist))
1238 return 0;
1239
1240 mutex_lock(&shmem_swaplist_mutex);
1238
1239 /*
1240 * The extra refcount on the inode is necessary to safely dereference
1241 * p->next after re-acquiring the lock. New shmem inodes with swap
1242 * get added to the end of the list and we will scan them all.
1243 */
1244 list_for_each_entry_safe(info, next, &shmem_swaplist, swaplist) {
1245 if (!info->swapped) {
1246 list_del_init(&info->swaplist);
1247 continue;
1248 }
1241 list_for_each_entry_safe(info, next, &shmem_swaplist, swaplist) {
1242 if (!info->swapped) {
1243 list_del_init(&info->swaplist);
1244 continue;
1245 }
1249
1250 inode = igrab(&info->vfs_inode);
1251 if (!inode)
1252 continue;
1253
1246 /*
1247 * Drop the swaplist mutex while searching the inode for swap;
1248 * but before doing so, make sure shmem_evict_inode() will not
1249 * remove placeholder inode from swaplist, nor let it be freed
1250 * (igrab() would protect from unlink, but not from unmount).
1251 */
1252 atomic_inc(&info->stop_eviction);
1254 mutex_unlock(&shmem_swaplist_mutex);
1253 mutex_unlock(&shmem_swaplist_mutex);
1255 if (prev_inode)
1256 iput(prev_inode);
1257 prev_inode = inode;
1258
1254
1259 error = shmem_unuse_inode(inode, type, frontswap,
1255 error = shmem_unuse_inode(&info->vfs_inode, type, frontswap,
1260 fs_pages_to_unuse);
1261 cond_resched();
1262
1263 mutex_lock(&shmem_swaplist_mutex);
1264 next = list_next_entry(info, swaplist);
1265 if (!info->swapped)
1266 list_del_init(&info->swaplist);
1256 fs_pages_to_unuse);
1257 cond_resched();
1258
1259 mutex_lock(&shmem_swaplist_mutex);
1260 next = list_next_entry(info, swaplist);
1261 if (!info->swapped)
1262 list_del_init(&info->swaplist);
1263 if (atomic_dec_and_test(&info->stop_eviction))
1264 wake_up_var(&info->stop_eviction);
1267 if (error)
1268 break;
1269 }
1270 mutex_unlock(&shmem_swaplist_mutex);
1271
1265 if (error)
1266 break;
1267 }
1268 mutex_unlock(&shmem_swaplist_mutex);
1269
1272 if (prev_inode)
1273 iput(prev_inode);
1274
1275 return error;
1276}
1277
1278/*
1279 * Move the page from the page cache to the swap cache.
1280 */
1281static int shmem_writepage(struct page *page, struct writeback_control *wbc)
1282{

--- 950 unchanged lines hidden (view full) ---

2233 inode->i_ino = get_next_ino();
2234 inode_init_owner(inode, dir, mode);
2235 inode->i_blocks = 0;
2236 inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
2237 inode->i_generation = prandom_u32();
2238 info = SHMEM_I(inode);
2239 memset(info, 0, (char *)inode - (char *)info);
2240 spin_lock_init(&info->lock);
1270 return error;
1271}
1272
1273/*
1274 * Move the page from the page cache to the swap cache.
1275 */
1276static int shmem_writepage(struct page *page, struct writeback_control *wbc)
1277{

--- 950 unchanged lines hidden (view full) ---

2228 inode->i_ino = get_next_ino();
2229 inode_init_owner(inode, dir, mode);
2230 inode->i_blocks = 0;
2231 inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
2232 inode->i_generation = prandom_u32();
2233 info = SHMEM_I(inode);
2234 memset(info, 0, (char *)inode - (char *)info);
2235 spin_lock_init(&info->lock);
2236 atomic_set(&info->stop_eviction, 0);
2241 info->seals = F_SEAL_SEAL;
2242 info->flags = flags & VM_NORESERVE;
2243 INIT_LIST_HEAD(&info->shrinklist);
2244 INIT_LIST_HEAD(&info->swaplist);
2245 simple_xattrs_init(&info->xattrs);
2246 cache_no_acl(inode);
2247
2248 switch (mode & S_IFMT) {

--- 1871 unchanged lines hidden ---
2237 info->seals = F_SEAL_SEAL;
2238 info->flags = flags & VM_NORESERVE;
2239 INIT_LIST_HEAD(&info->shrinklist);
2240 INIT_LIST_HEAD(&info->swaplist);
2241 simple_xattrs_init(&info->xattrs);
2242 cache_no_acl(inode);
2243
2244 switch (mode & S_IFMT) {

--- 1871 unchanged lines hidden ---