[Dctrl-tools-devel] [SCM] Debian control file query tools branch, master, updated. 2.22.2-12-g6a1d34d
Antti-Juhani Kaijanaho
ajk at debian.org
Fri Jun 8 21:42:07 UTC 2012
The following commit has been merged in the master branch:
commit 826bc801475ca264f036d97dc9e150a5c1490255
Author: Antti-Juhani Kaijanaho <ajk at debian.org>
Date: Sat Jun 9 00:08:32 2012 +0300
lib/fsaf.c and others: Remove mmap support (recognize but ignore --mmap).
Signed-off-by: Antti-Juhani Kaijanaho <ajk at debian.org>
diff --git a/debian/changelog b/debian/changelog
index a89f952..1e66f7c 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -13,8 +13,10 @@ dctrl-tools (2.23) UNRELEASED; urgency=low
* tests/0022.{out,err,fails}: New test case, for grep-dctrl
--ignore-parse-errors
* tester.sh: Handle missing diffs gracefully.
+ * lib/fsaf.c and others: Remove mmap support (recognize but ignore --mmap).
+ It was only complicating matters without giving much benefit.
- -- Antti-Juhani Kaijanaho <ajk at debian.org> Fri, 08 Jun 2012 23:21:58 +0300
+ -- Antti-Juhani Kaijanaho <ajk at debian.org> Sat, 09 Jun 2012 00:07:04 +0300
dctrl-tools (2.22.2) unstable; urgency=low
diff --git a/grep-dctrl/grep-dctrl.c b/grep-dctrl/grep-dctrl.c
index 718c798..c68f439 100644
--- a/grep-dctrl/grep-dctrl.c
+++ b/grep-dctrl/grep-dctrl.c
@@ -342,7 +342,7 @@ static error_t parse_opt (int key, char * arg, struct argp_state * state)
break;
case OPT_MMAP:
debug_message("parse_opt: mmap", 0);
- fsaf_mmap = 1;
+ /* ignore */
break;
case 'i':
debug_message("parse_opt: i", 0);
diff --git a/join-dctrl/join-dctrl.c b/join-dctrl/join-dctrl.c
index 36d34b3..ed883a0 100644
--- a/join-dctrl/join-dctrl.c
+++ b/join-dctrl/join-dctrl.c
@@ -188,7 +188,7 @@ static error_t parse_opt (int key, char * arg, struct argp_state * state)
break;
case OPT_MMAP:
debug_message("parse_opt: mmap", 0);
- fsaf_mmap = 1;
+ /* ignore */
break;
case ARGP_KEY_END:
case ARGP_KEY_ARGS: case ARGP_KEY_INIT: case ARGP_KEY_SUCCESS:
diff --git a/lib/fsaf.c b/lib/fsaf.c
index 8da467f..c132dc9 100644
--- a/lib/fsaf.c
+++ b/lib/fsaf.c
@@ -1,5 +1,5 @@
/* dctrl-tools - Debian control file inspection tools
- Copyright © 2003, 2005 Antti-Juhani Kaijanaho
+ Copyright © 2003, 2005, 2012 Antti-Juhani Kaijanaho
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -21,7 +21,6 @@
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -29,14 +28,8 @@
#include "fsaf.h"
#include "msg.h"
-#if !defined(_POSIX_MAPPED_FILES) || _POSIX_MAPPED_FILES == -1
-# warning "No mmap support detected."
-#endif
-
#define READAHEAD 1
-bool fsaf_mmap;
-
FSAF * fsaf_fdopen(int fd, char const *fname)
{
FSAF * rv = malloc(sizeof *rv);
@@ -46,68 +39,32 @@ FSAF * fsaf_fdopen(int fd, char const *fname)
if (rv->fname == NULL) { errno = ENOMEM; free(rv); return 0; }
rv->fd = fd;
rv->eof_mark = (size_t)(-1);
- rv->buf = 0;
- rv->buf_capacity = 0;
rv->buf_offset = 0;
rv->buf_size = 0;
rv->invalid_mark = 0;
-#ifdef _POSIX_MAPPED_FILES
- rv->mapped = false;
- rv->topread = 0;
-#endif
struct stat stat;
int res = fstat(fd, &stat);
- if (res == -1) goto fail;
+ if (res == -1) {
+ free(rv);
+ return 0;
+ }
if (S_ISREG(stat.st_mode)) {
rv->eof_mark = stat.st_size;
-#ifdef _POSIX_MAPPED_FILES
- if (fsaf_mmap) {
- /* try mmapping, it is a regular file */
- size_t eof_pagebound = pg_align(rv->eof_mark, true);
- char * buf = mmap(0, eof_pagebound, PROT_READ,
- MAP_SHARED, fd, 0);
- if (buf != MAP_FAILED) {
- debug_message("mmapping", 0);
- rv->mapped = 1;
- rv->buf = buf;
- rv->buf_capacity = eof_pagebound;
- rv->buf_offset = 0;
- rv->buf_size = rv->eof_mark;
- //madvise(rv->buf, rv->buf_capacity,
- // MADV_SEQUENTIAL);
- }
- }
-#endif
}
-#ifdef _POSIX_MAPPED_FILES
- if (!rv->mapped)
-#endif
- {
- rv->buf_capacity = 65536;
- rv->buf = malloc(rv->buf_capacity);
- if (rv->buf == 0) rv->buf_capacity = 0;
- }
+ rv->buf_capacity = 65536;
+ rv->buf = malloc(rv->buf_capacity);
+ if (rv->buf == 0) rv->buf_capacity = 0;
return rv;
-fail:
- free(rv);
- return 0;
}
void fsaf_close(FSAF * fp)
{
assert(fp != 0);
-#if _POSIX_MAPPED_FILES
- if (fp->mapped) {
- munmap(fp->buf, fp->buf_capacity);
- free(fp);
- return;
- }
-#endif
free(fp->fname);
free(fp->buf);
free(fp);
@@ -181,34 +138,15 @@ struct fsaf_read_rv fsaf_read(FSAF * fp, size_t offset, size_t len)
/* Make sure we don't read past the EOF mark. */
if (offset + len > fp->eof_mark) len = fp->eof_mark - offset;
-#if _POSIX_MAPPED_FILES
- if (fp->mapped) {
-#if 0 /* madvise seems not to give a noteworthy efficiency boost */
- /* Notify the kernel that we will soon want more of
- * the data, but do this only once for each page! */
- if (offset + len >= fp->topread) {
- size_t base = align(offset - fp->buf_offset, 1);
- size_t rl = READAHEAD * pagesize;
- madvise(fp->buf + base, rl, MADV_WILLNEED);
- fp->topread += rl;
- }
-#endif
- } else
-#endif
- {
- /* Ensure that we have enough data in the buffer.
- * This is only executed if we are not dealing with a
- * mapped file. */
- assert(offset >= fp->buf_offset);
- if (offset - fp->buf_offset + len > fp->buf_size) {
- slurp(fp, offset - fp->buf_offset + len - fp->buf_size);
- if (offset - fp->buf_offset + len > fp->buf_size) {
- len = fp->buf_size - (offset - fp->buf_offset);
- }
- }
-
- }
-
+ /* Ensure that we have enough data in the buffer. */
+ assert(offset >= fp->buf_offset);
+ if (offset - fp->buf_offset + len > fp->buf_size) {
+ slurp(fp, offset - fp->buf_offset + len - fp->buf_size);
+ if (offset - fp->buf_offset + len > fp->buf_size) {
+ len = fp->buf_size - (offset - fp->buf_offset);
+ }
+ }
+
assert(offset - fp->buf_offset + len <= fp->buf_size);
assert(offset + len <= fp->eof_mark);
rv.b = fp->buf + (offset - fp->buf_offset);
@@ -221,14 +159,6 @@ void fsaf_invalidate(FSAF * fp, size_t offset)
assert(fp->eof_mark >= offset);
if (fp->invalid_mark >= offset) return;
-#ifdef _POSIX_MAPPED_FILES
- if (fp->mapped) {
- size_t old = pg_align(fp->eof_mark - fp->buf_offset, 0);
- size_t new = pg_align(offset - fp->buf_offset, 0);
- madvise(fp->buf + old, new - old, MADV_DONTNEED);
- }
-#endif
-
fp->invalid_mark = offset;
}
diff --git a/lib/fsaf.h b/lib/fsaf.h
index 8c8e2ce..6f5f91a 100644
--- a/lib/fsaf.h
+++ b/lib/fsaf.h
@@ -1,5 +1,5 @@
/* dctrl-tools - Debian control file inspection tools
- Copyright © 2003, 2005 Antti-Juhani Kaijanaho
+ Copyright © 2003, 2005, 2012 Antti-Juhani Kaijanaho
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -35,17 +35,10 @@ struct fsaf_private {
size_t buf_size;
size_t invalid_mark;
size_t eof_mark; /* can be (size_t)(-1) if not reached yet */
-#ifdef _POSIX_MAPPED_FILES
- bool mapped;
- size_t topread; /* marks the top of what has been read ahead */
-#endif
};
typedef struct fsaf_private FSAF;
-/* True if FSAF should not use mmap even if it is possible. */
-extern bool fsaf_mmap;
-
/* Open a FSAF for the given fd. Only read access is supported for
* now. The whole file is initially valid. */
FSAF * fsaf_fdopen(int fd, char const *fname);
diff --git a/sort-dctrl/sort-dctrl.c b/sort-dctrl/sort-dctrl.c
index ebea165..efc8bf3 100644
--- a/sort-dctrl/sort-dctrl.c
+++ b/sort-dctrl/sort-dctrl.c
@@ -110,7 +110,7 @@ static error_t parse_opt (int key, char * arg, struct argp_state * state)
break;
case OPT_MMAP:
debug_message("parse_opt: mmap", 0);
- fsaf_mmap = 1;
+ /* ignore */
break;
case ARGP_KEY_ARG:
debug_message("parse_opt: argument", 0);
diff --git a/tbl-dctrl/tbl-dctrl.c b/tbl-dctrl/tbl-dctrl.c
index 12efcd6..ea2c1ba 100644
--- a/tbl-dctrl/tbl-dctrl.c
+++ b/tbl-dctrl/tbl-dctrl.c
@@ -325,7 +325,7 @@ static error_t parse_opt (int key, char * arg, struct argp_state * state)
break;
case OPT_MMAP:
debug_message("parse_opt: mmap", 0);
- fsaf_mmap = 1;
+ /* ignore */
break;
case ARGP_KEY_END:
case ARGP_KEY_ARGS: case ARGP_KEY_INIT: case ARGP_KEY_SUCCESS:
--
Debian control file query tools
More information about the Dctrl-tools-devel
mailing list