original development tree for Linux kernel GTP module; now long in mainline.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

245 lines
5.5 KiB

fs: convert fs shrinkers to new scan/count API Convert the filesystem shrinkers to use the new API, and standardise some of the behaviours of the shrinkers at the same time. For example, nr_to_scan means the number of objects to scan, not the number of objects to free. I refactored the CIFS idmap shrinker a little - it really needs to be broken up into a shrinker per tree and keep an item count with the tree root so that we don't need to walk the tree every time the shrinker needs to count the number of objects in the tree (i.e. all the time under memory pressure). [glommer@openvz.org: fixes for ext4, ubifs, nfs, cifs and glock. Fixes are needed mainly due to new code merged in the tree] [assorted fixes folded in] Signed-off-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Glauber Costa <glommer@openvz.org> Acked-by: Mel Gorman <mgorman@suse.de> Acked-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Acked-by: Jan Kara <jack@suse.cz> Acked-by: Steven Whitehouse <swhiteho@redhat.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: "Theodore Ts'o" <tytso@mit.edu> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Cc: Arve Hjønnevåg <arve@android.com> Cc: Carlos Maiolino <cmaiolino@redhat.com> Cc: Christoph Hellwig <hch@lst.de> Cc: Chuck Lever <chuck.lever@oracle.com> Cc: Daniel Vetter <daniel.vetter@ffwll.ch> Cc: David Rientjes <rientjes@google.com> Cc: Gleb Natapov <gleb@redhat.com> Cc: Greg Thelen <gthelen@google.com> Cc: J. Bruce Fields <bfields@redhat.com> Cc: Jan Kara <jack@suse.cz> Cc: Jerome Glisse <jglisse@redhat.com> Cc: John Stultz <john.stultz@linaro.org> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Kent Overstreet <koverstreet@google.com> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Marcelo Tosatti <mtosatti@redhat.com> Cc: Mel Gorman <mgorman@suse.de> Cc: Steven Whitehouse <swhiteho@redhat.com> Cc: Thomas Hellstrom <thellstrom@vmware.com> Cc: Trond Myklebust <Trond.Myklebust@netapp.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
8 years ago
mm: prevent concurrent unmap_mapping_range() on the same inode Michael Leun reported that running parallel opens on a fuse filesystem can trigger a "kernel BUG at mm/truncate.c:475" Gurudas Pai reported the same bug on NFS. The reason is, unmap_mapping_range() is not prepared for more than one concurrent invocation per inode. For example: thread1: going through a big range, stops in the middle of a vma and stores the restart address in vm_truncate_count. thread2: comes in with a small (e.g. single page) unmap request on the same vma, somewhere before restart_address, finds that the vma was already unmapped up to the restart address and happily returns without doing anything. Another scenario would be two big unmap requests, both having to restart the unmapping and each one setting vm_truncate_count to its own value. This could go on forever without any of them being able to finish. Truncate and hole punching already serialize with i_mutex. Other callers of unmap_mapping_range() do not, and it's difficult to get i_mutex protection for all callers. In particular ->d_revalidate(), which calls invalidate_inode_pages2_range() in fuse, may be called with or without i_mutex. This patch adds a new mutex to 'struct address_space' to prevent running multiple concurrent unmap_mapping_range() on the same mapping. [ We'll hopefully get rid of all this with the upcoming mm preemptibility series by Peter Zijlstra, the "mm: Remove i_mmap_mutex lockbreak" patch in particular. But that is for 2.6.39 ] Signed-off-by: Miklos Szeredi <mszeredi@suse.cz> Reported-by: Michael Leun <lkml20101129@newton.leun.net> Reported-by: Gurudas Pai <gurudas.pai@oracle.com> Tested-by: Gurudas Pai <gurudas.pai@oracle.com> Acked-by: Hugh Dickins <hughd@google.com> Cc: stable@kernel.org Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
11 years ago
  1. /*
  2. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  3. * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
  4. *
  5. * This copyrighted material is made available to anyone wishing to use,
  6. * modify, copy, or redistribute it subject to the terms and conditions
  7. * of the GNU General Public License version 2.
  8. */
  9. #include <linux/slab.h>
  10. #include <linux/spinlock.h>
  11. #include <linux/completion.h>
  12. #include <linux/buffer_head.h>
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/gfs2_ondisk.h>
  16. #include <linux/rcupdate.h>
  17. #include <linux/rculist_bl.h>
  18. #include <linux/atomic.h>
  19. #include <linux/mempool.h>
  20. #include "gfs2.h"
  21. #include "incore.h"
  22. #include "super.h"
  23. #include "sys.h"
  24. #include "util.h"
  25. #include "glock.h"
  26. #include "quota.h"
  27. #include "recovery.h"
  28. #include "dir.h"
  29. struct workqueue_struct *gfs2_control_wq;
  30. static struct shrinker qd_shrinker = {
  31. .count_objects = gfs2_qd_shrink_count,
  32. .scan_objects = gfs2_qd_shrink_scan,
  33. .seeks = DEFAULT_SEEKS,
  34. };
  35. static void gfs2_init_inode_once(void *foo)
  36. {
  37. struct gfs2_inode *ip = foo;
  38. inode_init_once(&ip->i_inode);
  39. init_rwsem(&ip->i_rw_mutex);
  40. INIT_LIST_HEAD(&ip->i_trunc_list);
  41. ip->i_res = NULL;
  42. ip->i_hash_cache = NULL;
  43. }
  44. static void gfs2_init_glock_once(void *foo)
  45. {
  46. struct gfs2_glock *gl = foo;
  47. INIT_HLIST_BL_NODE(&gl->gl_list);
  48. spin_lock_init(&gl->gl_spin);
  49. INIT_LIST_HEAD(&gl->gl_holders);
  50. INIT_LIST_HEAD(&gl->gl_lru);
  51. INIT_LIST_HEAD(&gl->gl_ail_list);
  52. atomic_set(&gl->gl_ail_count, 0);
  53. atomic_set(&gl->gl_revokes, 0);
  54. }
  55. static void gfs2_init_gl_aspace_once(void *foo)
  56. {
  57. struct gfs2_glock *gl = foo;
  58. struct address_space *mapping = (struct address_space *)(gl + 1);
  59. gfs2_init_glock_once(gl);
  60. address_space_init_once(mapping);
  61. }
  62. /**
  63. * init_gfs2_fs - Register GFS2 as a filesystem
  64. *
  65. * Returns: 0 on success, error code on failure
  66. */
  67. static int __init init_gfs2_fs(void)
  68. {
  69. int error;
  70. gfs2_str2qstr(&gfs2_qdot, ".");
  71. gfs2_str2qstr(&gfs2_qdotdot, "..");
  72. error = gfs2_sys_init();
  73. if (error)
  74. return error;
  75. error = gfs2_glock_init();
  76. if (error)
  77. goto fail;
  78. error = -ENOMEM;
  79. gfs2_glock_cachep = kmem_cache_create("gfs2_glock",
  80. sizeof(struct gfs2_glock),
  81. 0, 0,
  82. gfs2_init_glock_once);
  83. if (!gfs2_glock_cachep)
  84. goto fail;
  85. gfs2_glock_aspace_cachep = kmem_cache_create("gfs2_glock(aspace)",
  86. sizeof(struct gfs2_glock) +
  87. sizeof(struct address_space),
  88. 0, 0, gfs2_init_gl_aspace_once);
  89. if (!gfs2_glock_aspace_cachep)
  90. goto fail;
  91. gfs2_inode_cachep = kmem_cache_create("gfs2_inode",
  92. sizeof(struct gfs2_inode),
  93. 0, SLAB_RECLAIM_ACCOUNT|
  94. SLAB_MEM_SPREAD,
  95. gfs2_init_inode_once);
  96. if (!gfs2_inode_cachep)
  97. goto fail;
  98. gfs2_bufdata_cachep = kmem_cache_create("gfs2_bufdata",
  99. sizeof(struct gfs2_bufdata),
  100. 0, 0, NULL);
  101. if (!gfs2_bufdata_cachep)
  102. goto fail;
  103. gfs2_rgrpd_cachep = kmem_cache_create("gfs2_rgrpd",
  104. sizeof(struct gfs2_rgrpd),
  105. 0, 0, NULL);
  106. if (!gfs2_rgrpd_cachep)
  107. goto fail;
  108. gfs2_quotad_cachep = kmem_cache_create("gfs2_quotad",
  109. sizeof(struct gfs2_quota_data),
  110. 0, 0, NULL);
  111. if (!gfs2_quotad_cachep)
  112. goto fail;
  113. gfs2_rsrv_cachep = kmem_cache_create("gfs2_mblk",
  114. sizeof(struct gfs2_blkreserv),
  115. 0, 0, NULL);
  116. if (!gfs2_rsrv_cachep)
  117. goto fail;
  118. register_shrinker(&qd_shrinker);
  119. error = register_filesystem(&gfs2_fs_type);
  120. if (error)
  121. goto fail;
  122. error = register_filesystem(&gfs2meta_fs_type);
  123. if (error)
  124. goto fail_unregister;
  125. error = -ENOMEM;
  126. gfs_recovery_wq = alloc_workqueue("gfs_recovery",
  127. WQ_MEM_RECLAIM | WQ_FREEZABLE, 0);
  128. if (!gfs_recovery_wq)
  129. goto fail_wq;
  130. gfs2_control_wq = alloc_workqueue("gfs2_control",
  131. WQ_UNBOUND | WQ_FREEZABLE, 0);
  132. if (!gfs2_control_wq)
  133. goto fail_recovery;
  134. gfs2_page_pool = mempool_create_page_pool(64, 0);
  135. if (!gfs2_page_pool)
  136. goto fail_control;
  137. gfs2_register_debugfs();
  138. printk("GFS2 installed\n");
  139. return 0;
  140. fail_control:
  141. destroy_workqueue(gfs2_control_wq);
  142. fail_recovery:
  143. destroy_workqueue(gfs_recovery_wq);
  144. fail_wq:
  145. unregister_filesystem(&gfs2meta_fs_type);
  146. fail_unregister:
  147. unregister_filesystem(&gfs2_fs_type);
  148. fail:
  149. unregister_shrinker(&qd_shrinker);
  150. gfs2_glock_exit();
  151. if (gfs2_rsrv_cachep)
  152. kmem_cache_destroy(gfs2_rsrv_cachep);
  153. if (gfs2_quotad_cachep)
  154. kmem_cache_destroy(gfs2_quotad_cachep);
  155. if (gfs2_rgrpd_cachep)
  156. kmem_cache_destroy(gfs2_rgrpd_cachep);
  157. if (gfs2_bufdata_cachep)
  158. kmem_cache_destroy(gfs2_bufdata_cachep);
  159. if (gfs2_inode_cachep)
  160. kmem_cache_destroy(gfs2_inode_cachep);
  161. if (gfs2_glock_aspace_cachep)
  162. kmem_cache_destroy(gfs2_glock_aspace_cachep);
  163. if (gfs2_glock_cachep)
  164. kmem_cache_destroy(gfs2_glock_cachep);
  165. gfs2_sys_uninit();
  166. return error;
  167. }
  168. /**
  169. * exit_gfs2_fs - Unregister the file system
  170. *
  171. */
  172. static void __exit exit_gfs2_fs(void)
  173. {
  174. unregister_shrinker(&qd_shrinker);
  175. gfs2_glock_exit();
  176. gfs2_unregister_debugfs();
  177. unregister_filesystem(&gfs2_fs_type);
  178. unregister_filesystem(&gfs2meta_fs_type);
  179. destroy_workqueue(gfs_recovery_wq);
  180. destroy_workqueue(gfs2_control_wq);
  181. rcu_barrier();
  182. mempool_destroy(gfs2_page_pool);
  183. kmem_cache_destroy(gfs2_rsrv_cachep);
  184. kmem_cache_destroy(gfs2_quotad_cachep);
  185. kmem_cache_destroy(gfs2_rgrpd_cachep);
  186. kmem_cache_destroy(gfs2_bufdata_cachep);
  187. kmem_cache_destroy(gfs2_inode_cachep);
  188. kmem_cache_destroy(gfs2_glock_aspace_cachep);
  189. kmem_cache_destroy(gfs2_glock_cachep);
  190. gfs2_sys_uninit();
  191. }
  192. MODULE_DESCRIPTION("Global File System");
  193. MODULE_AUTHOR("Red Hat, Inc.");
  194. MODULE_LICENSE("GPL");
  195. module_init(init_gfs2_fs);
  196. module_exit(exit_gfs2_fs);