AC_SUBST(libpthread)
])
+#
+# Check if we have a working fadvise system call
+#
+AC_DEFUN([AC_HAVE_FADVISE],
+ [ AC_MSG_CHECKING([for fadvise ])
+ AC_TRY_COMPILE([
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+#include <fcntl.h>
+ ], [
+ posix_fadvise(0, 1, 0, 0);
+ ], have_fadvise=yes
+ AC_MSG_RESULT(yes),
+ AC_MSG_RESULT(no))
+ AC_SUBST(have_fadvise)
+ ])
+
+#
+# Check if we have a working madvise system call
+#
+AC_DEFUN([AC_HAVE_MADVISE],
+ [ AC_MSG_CHECKING([for madvise ])
+ AC_TRY_COMPILE([
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+#include <sys/mman.h>
+ ], [
+ posix_madvise(0, 0, MADV_NORMAL);
+ ], have_madvise=yes
+ AC_MSG_RESULT(yes),
+ AC_MSG_RESULT(no))
+ AC_SUBST(have_madvise)
+ ])
+
+#
+# Check if we have a working mincore system call
+#
+AC_DEFUN([AC_HAVE_MINCORE],
+ [ AC_MSG_CHECKING([for mincore ])
+ AC_TRY_COMPILE([
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+#include <sys/mman.h>
+ ], [
+ mincore(0, 0, 0);
+ ], have_mincore=yes
+ AC_MSG_RESULT(yes),
+ AC_MSG_RESULT(no))
+ AC_SUBST(have_mincore)
+ ])
+
+#
+# Check if we have a working sendfile system call
+#
+AC_DEFUN([AC_HAVE_SENDFILE],
+ [ AC_MSG_CHECKING([for sendfile ])
+ AC_TRY_COMPILE([
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+#include <sys/sendfile.h>
+ ], [
+ sendfile(0, 0, 0, 0);
+ ], have_sendfile=yes
+ AC_MSG_RESULT(yes),
+ AC_MSG_RESULT(no))
+ AC_SUBST(have_sendfile)
+ ])
+
+#
+# Check if we have a working fadvise system call
+#
+AC_DEFUN([AC_HAVE_FADVISE],
+ [ AC_MSG_CHECKING([for fadvise ])
+ AC_TRY_COMPILE([
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+#include <fcntl.h>
+ ], [
+ posix_fadvise(0, 1, 0, 0);
+ ], have_fadvise=yes
+ AC_MSG_RESULT(yes),
+ AC_MSG_RESULT(no))
+ AC_SUBST(have_fadvise)
+ ])
+
+#
+# Check if we have a working madvise system call
+#
+AC_DEFUN([AC_HAVE_MADVISE],
+ [ AC_MSG_CHECKING([for madvise ])
+ AC_TRY_COMPILE([
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+#include <sys/mman.h>
+ ], [
+ posix_madvise(0, 0, MADV_NORMAL);
+ ], have_madvise=yes
+ AC_MSG_RESULT(yes),
+ AC_MSG_RESULT(no))
+ AC_SUBST(have_madvise)
+ ])
+
+#
+# Check if we have a working mincore system call
+#
+AC_DEFUN([AC_HAVE_MINCORE],
+ [ AC_MSG_CHECKING([for mincore ])
+ AC_TRY_COMPILE([
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+#include <sys/mman.h>
+ ], [
+ mincore(0, 0, 0);
+ ], have_mincore=yes
+ AC_MSG_RESULT(yes),
+ AC_MSG_RESULT(no))
+ AC_SUBST(have_mincore)
+ ])
+
+#
+# Check if we have a working sendfile system call
+#
+AC_DEFUN([AC_HAVE_SENDFILE],
+ [ AC_MSG_CHECKING([for sendfile ])
+ AC_TRY_COMPILE([
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+#include <sys/sendfile.h>
+ ], [
+ sendfile(0, 0, 0, 0);
+ ], have_sendfile=yes
+ AC_MSG_RESULT(yes),
+ AC_MSG_RESULT(no))
+ AC_SUBST(have_sendfile)
+ ])
+
#
# Check if we have a type for the pointer's size integer (__psint_t)
#
AC_PACKAGE_NEED_PTHREAD_H
AC_PACKAGE_NEED_PTHREADMUTEXINIT
+AC_HAVE_FADVISE
+AC_HAVE_MADVISE
+AC_HAVE_MINCORE
+AC_HAVE_SENDFILE
+
AC_TYPE_PSINT
AC_TYPE_PSUNSIGNED
AC_SIZEOF_POINTERS_AND_LONG
#
-# Copyright (c) 2003 Silicon Graphics, Inc. All Rights Reserved.
+# Copyright (c) 2004 Silicon Graphics, Inc. All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as
ENABLE_READLINE = @enable_readline@
HAVE_ZIPPED_MANPAGES = @have_zipped_manpages@
+HAVE_FADVISE = @have_fadvise@
+HAVE_MADVISE = @have_madvise@
+HAVE_MINCORE = @have_mincore@
+HAVE_SENDFILE = @have_sendfile@
+
ifeq ($(PKG_PLATFORM),linux)
PCFLAGS = -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
endif
mmap.c open.c pread.c prealloc.c pwrite.c quit.c \
truncate.c
-ifeq ($(PKG_PLATFORM),linux)
-CFILES += fadvise.c sendfile.c
-LCFLAGS += -DHAVE_FADVISE -DHAVE_SENDFILE
+ifeq ($(HAVE_FADVISE),yes)
+CFILES += fadvise.c
+LCFLAGS += -DHAVE_FADVISE
else
-LSRCFILES += fadvise.c sendfile.c
+LSRCFILES += fadvise.c
+endif
+
+ifeq ($(HAVE_MADVISE),yes)
+CFILES += madvise.c
+LCFLAGS += -DHAVE_MADVISE
+else
+LSRCFILES += madvise.c
+endif
+
+ifeq ($(HAVE_MINCORE),yes)
+CFILES += mincore.c
+LCFLAGS += -DHAVE_MINCORE
+else
+LSRCFILES += mincore.c
+endif
+
+ifeq ($(HAVE_SENDFILE),yes)
+CFILES += sendfile.c
+LCFLAGS += -DHAVE_SENDFILE
+else
+LSRCFILES += sendfile.c
endif
ifneq ($(PKG_PLATFORM),irix)
}
return NULL;
}
-
-void
-init_commands(void)
-{
- bmap_init();
- fadvise_init();
- file_init();
- freeze_init();
- fsync_init();
- help_init();
- inject_init();
- mmap_init();
- open_init();
- pread_init();
- prealloc_init();
- pwrite_init();
- quit_init();
- resblks_init();
- sendfile_init();
- shutdown_init();
- truncate_init();
-}
extern int command_usage(const cmdinfo_t *ci);
extern int command(int argc, char **argv);
extern const cmdinfo_t *find_command(const char *cmd);
-extern void init_commands(void);
-extern void bmap_init(void);
-extern void file_init(void);
-extern void freeze_init(void);
-extern void fsync_init(void);
-extern void help_init(void);
-extern void inject_init(void);
-extern void mmap_init(void);
-extern void open_init(void);
-extern void pread_init(void);
-extern void prealloc_init(void);
-extern void pwrite_init(void);
-extern void quit_init(void);
-extern void truncate_init(void);
-
-#ifdef HAVE_FADVISE
-extern void fadvise_init(void);
-#else
-#define fadvise_init() do { } while (0)
-#endif
-
-#ifdef HAVE_INJECT
-extern void inject_init(void);
-#else
-#define inject_init() do { } while (0)
-#endif
-
-#ifdef HAVE_RESBLKS
-extern void resblks_init(void);
-#else
-#define resblks_init() do { } while (0)
-#endif
-
-#ifdef HAVE_SENDFILE
-extern void sendfile_init(void);
-#else
-#define sendfile_init() do { } while (0)
-#endif
-
-#ifdef HAVE_SHUTDOWN
-extern void shutdown_init(void);
-#else
-#define shutdown_init() do { } while (0)
-#endif
static cmdinfo_t fadvise_cmd;
-#if !defined(__NR_fadvise64)
-# if defined(__i386__)
-# define __NR_fadvise64 250
-# elif defined(__ia64__)
-# define __NR_fadvise64 1234
-# elif defined(__powerpc__)
-# define __NR_fadvise64 233
-# endif
-#endif
-
-static int
-fadvise64(int fd, off64_t offset, size_t len, int advise)
-{
-#ifdef __NR_fadvise64
- return syscall(__NR_fadvise64, fd, offset, len, advise);
-#else
- errno = ENOSYS; return -1;
-#endif
-}
-
static void
fadvise_help(void)
{
return command_usage(&fadvise_cmd);
}
- if (fadvise64(file->fd, offset, length, advise) < 0) {
+ if (posix_fadvise64(file->fd, offset, length, advise) < 0) {
perror("fadvise");
return 0;
}
exit(1);
}
+void
+init_commands(void)
+{
+ bmap_init();
+ fadvise_init();
+ file_init();
+ freeze_init();
+ fsync_init();
+ help_init();
+ inject_init();
+ mmap_init();
+ open_init();
+ pread_init();
+ prealloc_init();
+ pwrite_init();
+ quit_init();
+ resblks_init();
+ sendfile_init();
+ shutdown_init();
+ truncate_init();
+}
+
void
init(
int argc,
extern int mapcount; /* #entries in the mapping table */
extern mmap_region_t *mapping; /* active mapping table entry */
extern int maplist_f(void);
+extern void *check_mapping_range(mmap_region_t *, off64_t, size_t, int);
/*
* Various xfs_io helper routines/globals
extern int read_buffer(int, off64_t, long long, long long *,
int, int);
extern void dump_buffer(off64_t, ssize_t);
+
+extern void bmap_init(void);
+extern void file_init(void);
+extern void freeze_init(void);
+extern void fsync_init(void);
+extern void help_init(void);
+extern void inject_init(void);
+extern void mmap_init(void);
+extern void open_init(void);
+extern void pread_init(void);
+extern void prealloc_init(void);
+extern void pwrite_init(void);
+extern void quit_init(void);
+extern void truncate_init(void);
+
+#ifdef HAVE_FADVISE
+extern void fadvise_init(void);
+#else
+#define fadvise_init() do { } while (0)
+#endif
+
+#ifdef HAVE_INJECT
+extern void inject_init(void);
+#else
+#define inject_init() do { } while (0)
+#endif
+
+#ifdef HAVE_RESBLKS
+extern void resblks_init(void);
+#else
+#define resblks_init() do { } while (0)
+#endif
+
+#ifdef HAVE_SENDFILE
+extern void sendfile_init(void);
+#else
+#define sendfile_init() do { } while (0)
+#endif
+
+#ifdef HAVE_SHUTDOWN
+extern void shutdown_init(void);
+#else
+#define shutdown_init() do { } while (0)
+#endif
+
+#ifdef HAVE_MADVISE
+extern void madvise_init(void);
+#else
+#define madvise_init() do { } while (0)
+#endif
+
+#ifdef HAVE_MINCORE
+extern void mincore_init(void);
+#else
+#define mincore_init() do { } while (0)
+#endif
+
--- /dev/null
+/*
+ * Copyright (c) 2004 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like. Any license provided herein, whether implied or
+ * otherwise, applies only to this software file. Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc., 59
+ * Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
+ * Mountain View, CA 94043, or:
+ *
+ * http://www.sgi.com
+ *
+ * For further information regarding this notice, see:
+ *
+ * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
+ */
+
+#include <xfs/libxfs.h>
+#include <sys/mman.h>
+#include "command.h"
+#include "input.h"
+#include "init.h"
+#include "io.h"
+
+static cmdinfo_t madvise_cmd;
+
+static void
+madvise_help(void)
+{
+ printf(_(
+"\n"
+" advise the page cache about access patterns expected for a mapping\n"
+"\n"
+" Modifies page cache behavior when operating on the current mapping.\n"
+" The range arguments are required by some advise commands ([*] below).\n"
+" With no arguments, the POSIX_MADV_NORMAL advice is implied.\n"
+" -d -- don't need these pages (POSIX_MADV_DONTNEED) [*]\n"
+" -r -- expect random page references (POSIX_MADV_RANDOM)\n"
+" -s -- expect sequential page references (POSIX_MADV_SEQUENTIAL)\n"
+" -w -- will need these pages (POSIX_MADV_WILLNEED) [*]\n"
+" Notes:\n"
+" NORMAL sets the default readahead setting on the file.\n"
+" RANDOM sets the readahead setting on the file to zero.\n"
+" SEQUENTIAL sets double the default readahead setting on the file.\n"
+" WILLNEED forces the maximum readahead.\n"
+"\n"));
+}
+
+int
+madvise_f(
+ int argc,
+ char **argv)
+{
+ off64_t offset;
+ size_t length;
+ void *start;
+ int advise = MADV_NORMAL;
+ int c, blocksize, sectsize;
+
+ while ((c = getopt(argc, argv, "drsw")) != EOF) {
+ switch (c) {
+ case 'd': /* Don't need these pages */
+ advise = MADV_DONTNEED;
+ break;
+ case 'r': /* Expect random page references */
+ advise = MADV_RANDOM;
+ break;
+ case 's': /* Expect sequential page references */
+ advise = MADV_SEQUENTIAL;
+ break;
+ case 'w': /* Will need these pages */
+ advise = MADV_WILLNEED;
+ break;
+ default:
+ return command_usage(&madvise_cmd);
+ }
+ }
+
+ if (optind == argc) {
+ offset = mapping->offset;
+ length = mapping->length;
+ } else if (optind == argc - 2) {
+ init_cvtnum(&blocksize, §size);
+ offset = cvtnum(blocksize, sectsize, argv[optind]);
+ if (offset < 0) {
+ printf(_("non-numeric offset argument -- %s\n"),
+ argv[optind]);
+ return 0;
+ }
+ optind++;
+ length = cvtnum(blocksize, sectsize, argv[optind]);
+ if (length < 0) {
+ printf(_("non-numeric length argument -- %s\n"),
+ argv[optind]);
+ return 0;
+ }
+ } else {
+ return command_usage(&madvise_cmd);
+ }
+
+ start = check_mapping_range(mapping, offset, length, 1);
+ if (!start)
+ return 0;
+
+ if (madvise(start, length, advise) < 0) {
+ perror("madvise");
+ return 0;
+ }
+ return 0;
+}
+
+void
+madvise_init(void)
+{
+ madvise_cmd.name = _("madvise");
+ madvise_cmd.altname = _("ma");
+ madvise_cmd.cfunc = madvise_f;
+ madvise_cmd.argmin = 0;
+ madvise_cmd.argmax = -1;
+ madvise_cmd.flags = CMD_NOFILE_OK | CMD_FOREIGN_OK;
+ madvise_cmd.args = _("[-drsw] [off len]");
+ madvise_cmd.oneline = _("give advice about use of memory");
+ madvise_cmd.help = madvise_help;
+
+ add_command(&madvise_cmd);
+}
--- /dev/null
+/*
+ * Copyright (c) 2004 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * Further, this software is distributed without any warranty that it is
+ * free of the rightful claim of any third person regarding infringement
+ * or the like. Any license provided herein, whether implied or
+ * otherwise, applies only to this software file. Patent licenses, if
+ * any, provided herein do not apply to combinations of this program with
+ * other software, or any other product whatsoever.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc., 59
+ * Temple Place - Suite 330, Boston MA 02111-1307, USA.
+ *
+ * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
+ * Mountain View, CA 94043, or:
+ *
+ * http://www.sgi.com
+ *
+ * For further information regarding this notice, see:
+ *
+ * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
+ */
+
+#include <xfs/libxfs.h>
+#include <sys/mman.h>
+#include "command.h"
+#include "input.h"
+#include "init.h"
+#include "io.h"
+
+static cmdinfo_t mincore_cmd;
+
+int
+mincore_f(
+ int argc,
+ char **argv)
+{
+ off64_t offset;
+ size_t length;
+ void *start;
+ void *current, *previous;
+ unsigned char *vec;
+ int i, blocksize, sectsize;
+
+ if (argc == 1) {
+ offset = mapping->offset;
+ length = mapping->length;
+ } else if (argc == 3) {
+ init_cvtnum(&blocksize, §size);
+ offset = cvtnum(blocksize, sectsize, argv[1]);
+ if (offset < 0) {
+ printf(_("non-numeric offset argument -- %s\n"),
+ argv[1]);
+ return 0;
+ }
+ length = cvtnum(blocksize, sectsize, argv[2]);
+ if (length < 0) {
+ printf(_("non-numeric length argument -- %s\n"),
+ argv[2]);
+ return 0;
+ }
+ } else {
+ return command_usage(&mincore_cmd);
+ }
+
+ start = check_mapping_range(mapping, offset, length, 1);
+ if (!start)
+ return 0;
+
+ vec = calloc(length/pagesize, sizeof(unsigned char));
+ if (!vec) {
+ perror("calloc");
+ return 0;
+ }
+
+ if (mincore(start, length, vec) < 0) {
+ perror("mincore");
+ free(vec);
+ return 0;
+ }
+
+ previous = NULL;
+ current = start;
+ for (i = 0; i < length/pagesize; i++, current += pagesize) {
+ if (vec[i]) {
+ if (!previous) { /* print start address */
+ printf("0x%lx - ", (unsigned long)current);
+ previous = start + (i * pagesize);
+ }
+ } else if (previous) { /* print end and page count */
+ printf(_("0x%lx %lu pages (%llu : %lu)\n"),
+ (unsigned long)current,
+ (unsigned long)(current - previous) / pagesize,
+ (unsigned long long)offset +
+ (unsigned long long)(previous - start),
+ (unsigned long)(current - previous));
+ previous = NULL;
+ }
+ }
+ if (previous)
+ printf(_("0x%lx %lu pages (%llu : %lu)\n"),
+ (unsigned long)current,
+ (unsigned long)(current - previous) / pagesize,
+ (unsigned long long)offset +
+ (unsigned long long)(previous - start),
+ (unsigned long)(current - previous));
+
+ free(vec);
+ return 0;
+}
+
+void
+mincore_init(void)
+{
+ mincore_cmd.name = _("mincore");
+ mincore_cmd.altname = _("mi");
+ mincore_cmd.cfunc = mincore_f;
+ mincore_cmd.argmin = 0;
+ mincore_cmd.argmax = 2;
+ mincore_cmd.flags = CMD_NOFILE_OK | CMD_FOREIGN_OK;
+ mincore_cmd.args = _("[off len]");
+ mincore_cmd.oneline = _("find mapping pages that are memory resident");
+
+ add_command(&mincore_cmd);
+}
static cmdinfo_t msync_cmd;
static cmdinfo_t munmap_cmd;
static cmdinfo_t mwrite_cmd;
-static cmdinfo_t madvise_cmd;
-static cmdinfo_t mincore_cmd;
mmap_region_t *maptable;
int mapcount;
(long long)map->offset, (long)map->length);
}
-static void *
+void *
check_mapping_range(
mmap_region_t *map,
off64_t offset,
return 0;
}
-static void
-madvise_help(void)
-{
- printf(_(
-"\n"
-" advise the page cache about access patterns expected for a mapping\n"
-"\n"
-" Modifies page cache behavior when operating on the current mapping.\n"
-" The range arguments are required by some advise commands ([*] below).\n"
-" With no arguments, the POSIX_MADV_NORMAL advice is implied.\n"
-" -d -- don't need these pages (POSIX_MADV_DONTNEED) [*]\n"
-" -r -- expect random page references (POSIX_MADV_RANDOM)\n"
-" -s -- expect sequential page references (POSIX_MADV_SEQUENTIAL)\n"
-" -w -- will need these pages (POSIX_MADV_WILLNEED) [*]\n"
-" Notes:\n"
-" NORMAL sets the default readahead setting on the file.\n"
-" RANDOM sets the readahead setting on the file to zero.\n"
-" SEQUENTIAL sets double the default readahead setting on the file.\n"
-" WILLNEED forces the maximum readahead.\n"
-"\n"));
-}
-
-int
-madvise_f(
- int argc,
- char **argv)
-{
- off64_t offset;
- size_t length;
- void *start;
- int advise = MADV_NORMAL;
- int c, blocksize, sectsize;
-
- while ((c = getopt(argc, argv, "drsw")) != EOF) {
- switch (c) {
- case 'd': /* Don't need these pages */
- advise = MADV_DONTNEED;
- break;
- case 'r': /* Expect random page references */
- advise = MADV_RANDOM;
- break;
- case 's': /* Expect sequential page references */
- advise = MADV_SEQUENTIAL;
- break;
- case 'w': /* Will need these pages */
- advise = MADV_WILLNEED;
- break;
- default:
- return command_usage(&madvise_cmd);
- }
- }
-
- if (optind == argc) {
- offset = mapping->offset;
- length = mapping->length;
- } else if (optind == argc - 2) {
- init_cvtnum(&blocksize, §size);
- offset = cvtnum(blocksize, sectsize, argv[optind]);
- if (offset < 0) {
- printf(_("non-numeric offset argument -- %s\n"),
- argv[optind]);
- return 0;
- }
- optind++;
- length = cvtnum(blocksize, sectsize, argv[optind]);
- if (length < 0) {
- printf(_("non-numeric length argument -- %s\n"),
- argv[optind]);
- return 0;
- }
- } else {
- return command_usage(&madvise_cmd);
- }
-
- start = check_mapping_range(mapping, offset, length, 1);
- if (!start)
- return 0;
-
- if (madvise(start, length, advise) < 0) {
- perror("madvise");
- return 0;
- }
- return 0;
-}
-
-#if defined(__sgi__)
-int mincore(caddr_t p, size_t s, char *v) { errno = ENOSYS; return -1; }
-#endif
-
-int
-mincore_f(
- int argc,
- char **argv)
-{
- off64_t offset;
- size_t length;
- void *start;
- void *current, *previous;
- unsigned char *vec;
- int i, blocksize, sectsize;
-
- if (argc == 1) {
- offset = mapping->offset;
- length = mapping->length;
- } else if (argc == 3) {
- init_cvtnum(&blocksize, §size);
- offset = cvtnum(blocksize, sectsize, argv[1]);
- if (offset < 0) {
- printf(_("non-numeric offset argument -- %s\n"),
- argv[1]);
- return 0;
- }
- length = cvtnum(blocksize, sectsize, argv[2]);
- if (length < 0) {
- printf(_("non-numeric length argument -- %s\n"),
- argv[2]);
- return 0;
- }
- } else {
- return command_usage(&mincore_cmd);
- }
-
- start = check_mapping_range(mapping, offset, length, 1);
- if (!start)
- return 0;
-
- vec = calloc(length/pagesize, sizeof(unsigned char));
- if (!vec) {
- perror("calloc");
- return 0;
- }
-
- if (mincore(start, length, vec) < 0) {
- perror("mincore");
- free(vec);
- return 0;
- }
-
- previous = NULL;
- current = start;
- for (i = 0; i < length/pagesize; i++, current += pagesize) {
- if (vec[i]) {
- if (!previous) { /* print start address */
- printf("0x%lx - ", (unsigned long)current);
- previous = start + (i * pagesize);
- }
- } else if (previous) { /* print end and page count */
- printf(_("0x%lx %lu pages (%llu : %lu)\n"),
- (unsigned long)current,
- (unsigned long)(current - previous) / pagesize,
- (unsigned long long)offset +
- (unsigned long long)(previous - start),
- (unsigned long)(current - previous));
- previous = NULL;
- }
- }
- if (previous)
- printf(_("0x%lx %lu pages (%llu : %lu)\n"),
- (unsigned long)current,
- (unsigned long)(current - previous) / pagesize,
- (unsigned long long)offset +
- (unsigned long long)(previous - start),
- (unsigned long)(current - previous));
-
- free(vec);
- return 0;
-}
-
void
mmap_init(void)
{
_("writes data into a region in the current memory mapping");
mwrite_cmd.help = mwrite_help;
- madvise_cmd.name = _("madvise");
- madvise_cmd.altname = _("ma");
- madvise_cmd.cfunc = madvise_f;
- madvise_cmd.argmin = 0;
- madvise_cmd.argmax = -1;
- madvise_cmd.flags = CMD_NOFILE_OK | CMD_FOREIGN_OK;
- madvise_cmd.args = _("[-drsw] [off len]");
- madvise_cmd.oneline = _("give advice about use of memory");
- madvise_cmd.help = madvise_help;
-
- mincore_cmd.name = _("mincore");
- mincore_cmd.altname = _("mi");
- mincore_cmd.cfunc = mincore_f;
- mincore_cmd.argmin = 0;
- mincore_cmd.argmax = 2;
- mincore_cmd.flags = CMD_NOFILE_OK | CMD_FOREIGN_OK;
- mincore_cmd.args = _("[off len]");
- mincore_cmd.oneline = _("find mapping pages that are memory resident");
-
add_command(&mmap_cmd);
add_command(&mread_cmd);
add_command(&msync_cmd);
add_command(&munmap_cmd);
add_command(&mwrite_cmd);
- add_command(&madvise_cmd);
- add_command(&mincore_cmd);
}
LSRCFILES = \
manual_format.m4 \
package_globals.m4 \
+ package_libcdev.m4 \
package_pthread.m4 \
package_types.m4 \
package_utilies.m4 \
--- /dev/null
+#
+# Check if we have a working fadvise system call
+#
+AC_DEFUN([AC_HAVE_FADVISE],
+ [ AC_MSG_CHECKING([for fadvise ])
+ AC_TRY_COMPILE([
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+#include <fcntl.h>
+ ], [
+ posix_fadvise(0, 1, 0, 0);
+ ], have_fadvise=yes
+ AC_MSG_RESULT(yes),
+ AC_MSG_RESULT(no))
+ AC_SUBST(have_fadvise)
+ ])
+
+#
+# Check if we have a working madvise system call
+#
+AC_DEFUN([AC_HAVE_MADVISE],
+ [ AC_MSG_CHECKING([for madvise ])
+ AC_TRY_COMPILE([
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+#include <sys/mman.h>
+ ], [
+ posix_madvise(0, 0, MADV_NORMAL);
+ ], have_madvise=yes
+ AC_MSG_RESULT(yes),
+ AC_MSG_RESULT(no))
+ AC_SUBST(have_madvise)
+ ])
+
+#
+# Check if we have a working mincore system call
+#
+AC_DEFUN([AC_HAVE_MINCORE],
+ [ AC_MSG_CHECKING([for mincore ])
+ AC_TRY_COMPILE([
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+#include <sys/mman.h>
+ ], [
+ mincore(0, 0, 0);
+ ], have_mincore=yes
+ AC_MSG_RESULT(yes),
+ AC_MSG_RESULT(no))
+ AC_SUBST(have_mincore)
+ ])
+
+#
+# Check if we have a working sendfile system call
+#
+AC_DEFUN([AC_HAVE_SENDFILE],
+ [ AC_MSG_CHECKING([for sendfile ])
+ AC_TRY_COMPILE([
+#define _GNU_SOURCE
+#define _FILE_OFFSET_BITS 64
+#include <sys/sendfile.h>
+ ], [
+ sendfile(0, 0, 0, 0);
+ ], have_sendfile=yes
+ AC_MSG_RESULT(yes),
+ AC_MSG_RESULT(no))
+ AC_SUBST(have_sendfile)
+ ])