2010-05-17 22:18:00 +00:00
|
|
|
/*****************************************************************************\
|
|
|
|
* Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
|
|
|
|
* Copyright (C) 2007 The Regents of the University of California.
|
|
|
|
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
|
|
|
|
* Written by Brian Behlendorf <behlendorf1@llnl.gov>.
|
2008-05-26 04:38:26 +00:00
|
|
|
* UCRL-CODE-235197
|
|
|
|
*
|
2010-05-17 22:18:00 +00:00
|
|
|
* This file is part of the SPL, Solaris Porting Layer.
|
|
|
|
* For details, see <http://github.com/behlendorf/spl/>.
|
|
|
|
*
|
|
|
|
* The SPL is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
2008-05-26 04:38:26 +00:00
|
|
|
*
|
2010-05-17 22:18:00 +00:00
|
|
|
* The SPL is distributed in the hope that it will be useful, but WITHOUT
|
2008-05-26 04:38:26 +00:00
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
2010-05-17 22:18:00 +00:00
|
|
|
* with the SPL. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
\*****************************************************************************/
|
2008-05-26 04:38:26 +00:00
|
|
|
|
2008-03-05 00:58:54 +00:00
|
|
|
#ifndef _SPL_VMSYSTM_H
|
|
|
|
#define _SPL_VMSYSTM_H
|
|
|
|
|
2009-02-04 23:15:41 +00:00
|
|
|
#include <linux/mmzone.h>
|
2008-03-05 00:58:54 +00:00
|
|
|
#include <linux/mm.h>
|
2008-05-15 23:39:19 +00:00
|
|
|
#include <linux/swap.h>
|
2009-03-05 17:08:07 +00:00
|
|
|
#include <linux/highmem.h>
|
2008-03-14 00:04:01 +00:00
|
|
|
#include <sys/types.h>
|
2008-03-15 00:05:38 +00:00
|
|
|
#include <asm/uaccess.h>
|
2008-03-14 00:04:01 +00:00
|
|
|
|
2009-03-05 17:08:07 +00:00
|
|
|
/* These values are loosely coupled with the VM page reclaim.
|
2009-02-04 23:15:41 +00:00
|
|
|
* Linux uses its own heuristics to trigger page reclamation, and
|
|
|
|
* because those interface are difficult to interface with. These
|
|
|
|
* values should only be considered as a rough guide to the system
|
2009-03-05 17:08:07 +00:00
|
|
|
* memory state and not as direct evidence that page reclamation.
|
2009-02-04 23:15:41 +00:00
|
|
|
* is or is not currently in progress.
|
|
|
|
*/
|
|
|
|
#define membar_producer() smp_wmb()
|
2008-03-05 00:58:54 +00:00
|
|
|
|
|
|
|
#define physmem num_physpages
|
2009-01-31 04:54:49 +00:00
|
|
|
#define freemem nr_free_pages()
|
2009-02-05 20:26:34 +00:00
|
|
|
#define availrmem spl_kmem_availrmem()
|
2009-02-04 23:15:41 +00:00
|
|
|
|
|
|
|
extern pgcnt_t minfree; /* Sum of zone->pages_min */
|
|
|
|
extern pgcnt_t desfree; /* Sum of zone->pages_low */
|
|
|
|
extern pgcnt_t lotsfree; /* Sum of zone->pages_high */
|
2009-02-05 20:26:34 +00:00
|
|
|
extern pgcnt_t needfree; /* Always 0 unused in new Solaris */
|
|
|
|
extern pgcnt_t swapfs_minfree; /* Solaris default value */
|
|
|
|
extern pgcnt_t swapfs_reserve; /* Solaris default value */
|
2009-02-04 23:15:41 +00:00
|
|
|
|
|
|
|
extern vmem_t *heap_arena; /* primary kernel heap arena */
|
|
|
|
extern vmem_t *zio_alloc_arena; /* arena for zio caches */
|
|
|
|
extern vmem_t *zio_arena; /* arena for allocating zio memory */
|
|
|
|
|
2009-02-05 20:26:34 +00:00
|
|
|
extern pgcnt_t spl_kmem_availrmem(void);
|
|
|
|
extern size_t vmem_size(vmem_t *vmp, int typemask);
|
2008-03-06 23:12:55 +00:00
|
|
|
|
2009-02-25 21:20:40 +00:00
|
|
|
/*
|
|
|
|
* The following symbols are available for use within the kernel
|
|
|
|
* itself, and they used to be available in older kernels. But it
|
|
|
|
* looks like they have been removed perhaps due to lack of use.
|
|
|
|
* For our purposes we need them to access the global memory state
|
|
|
|
* of the system, which is even available to user space process
|
|
|
|
* in /proc/meminfo. It's odd to me that there is no kernel API
|
|
|
|
* to get the same information, minimally the proc handler for
|
|
|
|
* the above mentioned /proc/meminfo file would make use of it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Source linux/fs/proc/mmu.c */
|
|
|
|
#ifndef HAVE_GET_VMALLOC_INFO
|
|
|
|
#ifdef CONFIG_MMU
|
|
|
|
|
|
|
|
struct vmalloc_info {
|
|
|
|
unsigned long used;
|
|
|
|
unsigned long largest_chunk;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef void (*get_vmalloc_info_t)(struct vmalloc_info *);
|
|
|
|
extern get_vmalloc_info_t get_vmalloc_info_fn;
|
|
|
|
|
|
|
|
# define VMEM_ALLOC 0x01
|
|
|
|
# define VMEM_FREE 0x02
|
|
|
|
# define VMALLOC_TOTAL (VMALLOC_END - VMALLOC_START)
|
|
|
|
# define get_vmalloc_info(vmi) get_vmalloc_info_fn(vmi)
|
|
|
|
#else
|
|
|
|
# error "CONFIG_MMU must be defined"
|
|
|
|
#endif /* CONFIG_MMU */
|
|
|
|
#endif /* HAVE_GET_VMALLOC_INFO */
|
|
|
|
|
2009-05-20 21:23:13 +00:00
|
|
|
#ifdef HAVE_PGDAT_HELPERS
|
2009-02-25 21:20:40 +00:00
|
|
|
/* Source linux/mm/mmzone.c */
|
2009-05-20 21:23:13 +00:00
|
|
|
# ifndef HAVE_FIRST_ONLINE_PGDAT
|
2009-02-25 21:20:40 +00:00
|
|
|
typedef struct pglist_data *(*first_online_pgdat_t)(void);
|
|
|
|
extern first_online_pgdat_t first_online_pgdat_fn;
|
2009-05-20 21:23:13 +00:00
|
|
|
# define first_online_pgdat() first_online_pgdat_fn()
|
|
|
|
# endif /* HAVE_FIRST_ONLINE_PGDAT */
|
2009-02-25 21:20:40 +00:00
|
|
|
|
2009-05-20 21:23:13 +00:00
|
|
|
# ifndef HAVE_NEXT_ONLINE_PGDAT
|
2009-02-25 21:20:40 +00:00
|
|
|
typedef struct pglist_data *(*next_online_pgdat_t)(struct pglist_data *);
|
|
|
|
extern next_online_pgdat_t next_online_pgdat_fn;
|
2009-05-20 21:23:13 +00:00
|
|
|
# define next_online_pgdat(pgd) next_online_pgdat_fn(pgd)
|
|
|
|
# endif /* HAVE_NEXT_ONLINE_PGDAT */
|
2009-02-25 21:20:40 +00:00
|
|
|
|
2009-05-20 21:23:13 +00:00
|
|
|
# ifndef HAVE_NEXT_ZONE
|
2009-02-25 21:20:40 +00:00
|
|
|
typedef struct zone *(*next_zone_t)(struct zone *);
|
|
|
|
extern next_zone_t next_zone_fn;
|
2009-05-20 21:23:13 +00:00
|
|
|
# define next_zone(zone) next_zone_fn(zone)
|
|
|
|
# endif /* HAVE_NEXT_ZONE */
|
|
|
|
|
|
|
|
#else /* HAVE_PGDAT_HELPERS */
|
|
|
|
|
|
|
|
# ifndef HAVE_PGDAT_LIST
|
|
|
|
extern struct pglist_data *pgdat_list_addr;
|
|
|
|
# define pgdat_list pgdat_list_addr
|
|
|
|
# endif /* HAVE_PGDAT_LIST */
|
|
|
|
|
|
|
|
#endif /* HAVE_PGDAT_HELPERS */
|
2009-02-25 21:20:40 +00:00
|
|
|
|
|
|
|
/* Source linux/mm/vmstat.c */
|
2009-07-28 22:06:42 +00:00
|
|
|
#if defined(NEED_GET_ZONE_COUNTS) && !defined(HAVE_GET_ZONE_COUNTS)
|
2009-02-25 21:20:40 +00:00
|
|
|
typedef void (*get_zone_counts_t)(unsigned long *, unsigned long *,
|
|
|
|
unsigned long *);
|
|
|
|
extern get_zone_counts_t get_zone_counts_fn;
|
2009-03-17 19:16:31 +00:00
|
|
|
# define get_zone_counts(a,i,f) get_zone_counts_fn(a,i,f)
|
2009-07-28 22:06:42 +00:00
|
|
|
#endif /* NEED_GET_ZONE_COUNTS && !HAVE_GET_ZONE_COUNTS */
|
2009-03-17 19:16:31 +00:00
|
|
|
|
2009-07-28 22:06:42 +00:00
|
|
|
typedef enum spl_zone_stat_item {
|
|
|
|
SPL_NR_FREE_PAGES,
|
|
|
|
SPL_NR_INACTIVE,
|
|
|
|
SPL_NR_ACTIVE,
|
|
|
|
SPL_NR_ZONE_STAT_ITEMS
|
|
|
|
} spl_zone_stat_item_t;
|
|
|
|
|
|
|
|
extern unsigned long spl_global_page_state(spl_zone_stat_item_t);
|
2009-02-25 21:20:40 +00:00
|
|
|
|
2008-03-15 00:05:38 +00:00
|
|
|
#define xcopyin(from, to, size) copy_from_user(to, from, size)
|
|
|
|
#define xcopyout(from, to, size) copy_to_user(to, from, size)
|
|
|
|
|
|
|
|
static __inline__ int
|
|
|
|
copyin(const void *from, void *to, size_t len)
|
|
|
|
{
|
|
|
|
/* On error copyin routine returns -1 */
|
|
|
|
if (xcopyin(from, to, len))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline__ int
|
|
|
|
copyout(const void *from, void *to, size_t len)
|
|
|
|
{
|
|
|
|
/* On error copyout routine returns -1 */
|
|
|
|
if (xcopyout(from, to, len))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline__ int
|
|
|
|
copyinstr(const void *from, void *to, size_t len, size_t *done)
|
|
|
|
{
|
2008-04-01 17:00:06 +00:00
|
|
|
size_t rc;
|
|
|
|
|
2008-03-15 00:05:38 +00:00
|
|
|
if (len == 0)
|
|
|
|
return -ENAMETOOLONG;
|
|
|
|
|
|
|
|
/* XXX: Should return ENAMETOOLONG if 'strlen(from) > len' */
|
|
|
|
|
|
|
|
memset(to, 0, len);
|
2008-04-01 17:00:06 +00:00
|
|
|
rc = copyin(from, to, len - 1);
|
|
|
|
if (done != NULL)
|
|
|
|
*done = rc;
|
2008-03-15 00:05:38 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2008-03-12 21:33:28 +00:00
|
|
|
|
2008-03-05 00:58:54 +00:00
|
|
|
#endif /* SPL_VMSYSTM_H */
|