diff options
author | Poul-Henning Kamp <phk@FreeBSD.org> | 1996-05-02 08:43:05 +0000 |
---|---|---|
committer | Poul-Henning Kamp <phk@FreeBSD.org> | 1996-05-02 08:43:05 +0000 |
commit | d71458ee72dc019a408ccd80b4f12abc573da287 (patch) | |
tree | f3e5cad6b9610b6b082996ce7e9732c47feed41e | |
parent | 3a91de068ccffd54e9f0b1cf75c197f8a5d9f132 (diff) |
Notes
-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 d586cf68d5343..556ff9e032daa 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 8cba9cf75390c..a3db45b18d779 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; |