Whamcloud - gitweb
LU-9859 libcfs: move tgt_descs to standard Linux bitmaps.
[fs/lustre-release.git] / libcfs / include / libcfs / linux / linux-mem.h
index fb2c946..80668b1 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
 #ifndef __LIBCFS_LINUX_CFS_MEM_H__
 #define __LIBCFS_LINUX_CFS_MEM_H__
 
-#ifndef __LIBCFS_LIBCFS_H__
-#error Do not #include this file directly. #include <libcfs/libcfs.h> instead
-#endif
-
-#ifndef __KERNEL__
-#error This include is only for kernel use.
-#endif
-
 #include <linux/mm.h>
 #include <linux/vmalloc.h>
 #include <linux/pagemap.h>
 #ifdef HAVE_MM_INLINE
 # include <linux/mm_inline.h>
 #endif
-
-#ifndef HAVE_LIBCFS_CPT
-/* Need this for cfs_cpt_table */
-#include <libcfs/libcfs_cpu.h>
+#include <linux/sched.h>
+#ifdef HAVE_SCHED_HEADERS
+#include <linux/sched/mm.h>
 #endif
 
-#define CFS_PAGE_MASK                   (~((__u64)PAGE_CACHE_SIZE-1))
-
-#define page_index(p)       ((p)->index)
-
-
-#define memory_pressure_get() (current->flags & PF_MEMALLOC)
-#define memory_pressure_set() do { current->flags |= PF_MEMALLOC; } while (0)
-#define memory_pressure_clr() do { current->flags &= ~PF_MEMALLOC; } while (0)
-
-#if BITS_PER_LONG == 32
-/* limit to lowmem on 32-bit systems */
-#define NUM_CACHEPAGES \
-       min(totalram_pages, 1UL << (30 - PAGE_CACHE_SHIFT) * 3 / 4)
+#ifdef HAVE_TOTALRAM_PAGES_AS_FUNC
+ #ifndef cfs_totalram_pages
+  #define cfs_totalram_pages() totalram_pages()
+ #endif
 #else
-#define NUM_CACHEPAGES totalram_pages
+ #ifndef cfs_totalram_pages
+  #define cfs_totalram_pages() totalram_pages
+ #endif
 #endif
 
-/*
- * In Linux there is no way to determine whether current execution context is
- * blockable.
- */
-#define ALLOC_ATOMIC_TRY   GFP_ATOMIC
-/* GFP_IOFS was added in 2.6.33 kernel */
-#ifndef GFP_IOFS
-#define GFP_IOFS       (__GFP_IO | __GFP_FS)
-#endif
+#ifndef HAVE_MEMALLOC_RECLAIM
+static inline unsigned int memalloc_noreclaim_save(void)
+{
+       unsigned int flags = current->flags & PF_MEMALLOC;
 
-#define DECL_MMSPACE                mm_segment_t __oldfs
-#define MMSPACE_OPEN \
-        do { __oldfs = get_fs(); set_fs(get_ds());} while(0)
-#define MMSPACE_CLOSE               set_fs(__oldfs)
+       current->flags |= PF_MEMALLOC;
+       return flags;
+}
+
+static inline void memalloc_noreclaim_restore(unsigned int flags)
+{
+       current->flags = (current->flags & ~PF_MEMALLOC) | flags;
+}
+#endif /* !HAVE_MEMALLOC_RECLAIM */
+
+#ifndef HAVE_BITMAP_ALLOC
+static inline unsigned long *bitmap_alloc(unsigned int nbits, gfp_t flags)
+{
+       return kmalloc_array(BITS_TO_LONGS(nbits), sizeof(unsigned long),
+                            flags);
+}
 
+static inline unsigned long *bitmap_zalloc(unsigned int nbits, gfp_t flags)
+{
+       return bitmap_alloc(nbits, flags | __GFP_ZERO);
+}
 
-extern void *cfs_cpt_malloc(struct cfs_cpt_table *cptab, int cpt,
-                           size_t nr_bytes, gfp_t flags);
-extern void *cfs_cpt_vzalloc(struct cfs_cpt_table *cptab, int cpt,
-                            size_t nr_bytes);
-extern struct page *cfs_page_cpt_alloc(struct cfs_cpt_table *cptab,
-                                     int cpt, gfp_t flags);
-extern void *cfs_mem_cache_cpt_alloc(struct kmem_cache *cachep,
-                                    struct cfs_cpt_table *cptab,
-                                    int cpt, gfp_t flags);
+static inline void bitmap_free(const unsigned long *bitmap)
+{
+       kfree(bitmap);
+}
+#endif /* !HAVE_BITMAP_ALLOC */
 
 /*
  * Shrinker
  */
-#ifdef HAVE_SHRINK_CONTROL
 # define SHRINKER_ARGS(sc, nr_to_scan, gfp_mask)  \
                        struct shrinker *shrinker, \
                        struct shrink_control *sc
 # define shrink_param(sc, var) ((sc)->var)
-#else
-struct shrink_control {
-       gfp_t gfp_mask;
-       unsigned long nr_to_scan;
-};
-# ifdef HAVE_SHRINKER_WANT_SHRINK_PTR
-#  define SHRINKER_ARGS(sc, nr_to_scan, gfp_mask)  \
-                        struct shrinker *shrinker, \
-                        int nr_to_scan, gfp_t gfp_mask
-# else
-#  define SHRINKER_ARGS(sc, nr_to_scan, gfp_mask)  \
-                        int nr_to_scan, gfp_t gfp_mask
-# endif
-       /* avoid conflict with spl mm_compat.h */
-# define HAVE_SHRINK_CONTROL_STRUCT 1
-# define shrink_param(sc, var) (var)
-#endif
 
 #ifdef HAVE_SHRINKER_COUNT
 struct shrinker_var {