diff options
author | phk <phk@FreeBSD.org> | 1996-05-02 08:43:05 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 1996-05-02 08:43:05 +0000 |
commit | 37811d9fc0db7d38415e2e6a6e4edf1fc0cba972 (patch) | |
tree | f3e5cad6b9610b6b082996ce7e9732c47feed41e /lib | |
parent | 4622dbc30bb429e73df5bc451c81d74762753a53 (diff) | |
download | FreeBSD-src-37811d9fc0db7d38415e2e6a6e4edf1fc0cba972.zip FreeBSD-src-37811d9fc0db7d38415e2e6a6e4edf1fc0cba972.tar.gz |
Cache the result of getpagesize() so we only make one syscall.
Use getpagesize instead of CLBYTES.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/gen/getpagesize.c | 20 | ||||
-rw-r--r-- | lib/libc/gen/opendir.c | 15 |
2 files changed, 19 insertions, 16 deletions
diff --git a/lib/libc/gen/getpagesize.c b/lib/libc/gen/getpagesize.c index d586cf6..556ff9e 100644 --- a/lib/libc/gen/getpagesize.c +++ b/lib/libc/gen/getpagesize.c @@ -38,16 +38,24 @@ static char sccsid[] = "@(#)getpagesize.c 8.1 (Berkeley) 6/4/93"; #include <sys/param.h> #include <sys/sysctl.h> +/* + * This is unlikely to change over the running time of any + * program, so we cache the result to save some syscalls. + */ + int getpagesize() { - int mib[2], value; + int mib[2]; + static int value; size_t size; - mib[0] = CTL_HW; - mib[1] = HW_PAGESIZE; - size = sizeof value; - if (sysctl(mib, 2, &value, &size, NULL, 0) == -1) - return (-1); + if (!value) { + mib[0] = CTL_HW; + mib[1] = HW_PAGESIZE; + size = sizeof value; + if (sysctl(mib, 2, &value, &size, NULL, 0) == -1) + return (-1); + } return (value); } diff --git a/lib/libc/gen/opendir.c b/lib/libc/gen/opendir.c index 8cba9cf..a3db45b 100644 --- a/lib/libc/gen/opendir.c +++ b/lib/libc/gen/opendir.c @@ -79,18 +79,13 @@ opendir(name) (dirp = malloc(sizeof(DIR))) == NULL) goto fail; /* - * If CLBYTES is an exact multiple of DIRBLKSIZ, use a CLBYTES - * buffer that it cluster boundary aligned. - * Hopefully this can be a big win someday by allowing page trades - * to user space to be done by getdirentries() + * Use the system page size if that is a multiple of DIRBLKSIZ + * this could speed things up in some cases we hope */ - if ((CLBYTES % DIRBLKSIZ) == 0) { - dirp->dd_buf = malloc(CLBYTES); - dirp->dd_len = CLBYTES; - } else { - dirp->dd_buf = malloc(DIRBLKSIZ); + dirp->dd_len = getpagesize(); + if ((dirp->dd_len % DIRBLKSIZ) != 0) dirp->dd_len = DIRBLKSIZ; - } + dirp->dd_buf = malloc(dirp->dd_len); if (dirp->dd_buf == NULL) goto fail; dirp->dd_fd = fd; |