Article View: news.software.nntp
Article #15732Re: patch for nnrpd 1.5.1 to mmap .overview files
From: Jan-Pieter Cornet
Date: Tue, 11 Mar 1997 00:00
Date: Tue, 11 Mar 1997 00:00
126 lines
4878 bytes
4878 bytes
In article <5fv1s9$8ki$1@news.demos.su>,
Andrew A. Vasilyev <andy@snm.demos.su> wrote:
>In news.software.nntp Jan-Pieter Cornet <johnpc@xs4all.nl> wrote:
>JC>Below is a patch to mmap() .overview files, and binary search them.
>JC>This greatly speeds up the XOVER command (and other commands that
>JC>use the .overview database), especially when you have really large
>JC>groups.
>
>
> There are at least 2 problems with this patch under Solaris (and
> I'm afraid not only under this OS):
>
> 1. 4-th argument of mmap() ('flags') should be MAP_SHARED, not 0
> as in given source, because mmap() failed with EINVAL (there is
> no flag == 0).
"Oops". That is most probably the reason Chris Bellomy sees the huge
performance decrease with this patch... or it could be getpagesize doesn't
work on solaris 2.5.1.
It should've said MAP_SHARED there, don't know why I changed that... I
have been tinkering with the mmap() arguments because I was seeing
errors, but in the end they were caused by something else.
> 2. We mmap() a region with the size of (f_size + pagesize - 1) & ~pagesize,
> but munmap() only file_size. Not so good.
I guess that could be classified as a bug as well.
I've patched these problems in my source. Patch included below.
Note: this is a patch against the earlier patched version! If you want
the entire patch, contact me.
--
#! ##### Jan-Pieter Cornet ##### <johnpc@xs4all.net> ##### perl
++$_;$!=$_+++$_;($:,$,,$/,$*)=$!=~/.(.)...(.)(.).(.)/;$!=$_+$_;
($@,$\,$~)=$!=~/(.)(.).(.)/; $_="$,$/$:"; $@++; $~="$~$_";($_)=
\$$=~/\((.)/;$|=++$_;$_++;$|++;$~="$~ $@$:";`$~$/$\$*$, $|>&$_`
--- 1.31 1997/03/06 17:29:26
+++ article.c 1997/03/11 16:42:30
@@ -1,4 +1,4 @@
-/* $Revision: 1.31 $
+/* $Revision: 1.32 $
**
** Article-related routines.
*/
@@ -77,6 +77,7 @@
STATIC caddr_t OVERshm = (caddr_t) NULL; /* location of mmap */
STATIC size_t OVERsize; /* size of mmap */
+STATIC size_t OVERmsize; /* real size of mmap */
STATIC int OVERfd; /* fd of file */
STATIC ARTNUM OVERfirst, OVERlast; /* first/last entries */
STATIC int OVERopens; /* Number of opens done */
@@ -813,7 +814,17 @@
return FALSE;
}
/* get memory pagesize if we don't have it already */
- if ( ! pagesize && ! (pagesize = getpagesize()) ) {
+ if ( ! pagesize && !
+#ifdef _SC_PAGE_SIZE
+ (pagesize = sysconf(_SC_PAGE_SIZE))
+#else
+# ifdef _SC_PAGESIZE
+ (pagesize = sysconf(_SC_PAGESIZE))
+# else
+ (pagesize = getpagesize())
+# endif
+#endif
+ ) {
syslog(L_NOTICE, "%s: Can't getpagesize", ClientHost);
return FALSE;
}
@@ -834,8 +845,9 @@
(void)close(OVERfd);
return FALSE;
}
- if ( (OVERshm = mmap(NULL, (OVERsize + pagesize - 1) & ~pagesize,
- PROT_READ, 0, OVERfd, 0)) == (caddr_t) -1 )
+ OVERmsize = (OVERsize + pagesize - 1) & ~pagesize;
+ if ( (OVERshm = mmap(NULL, OVERmsize, PROT_READ, MAP_SHARED, OVERfd, 0))
+ == (caddr_t) -1 )
{
syslog(L_NOTICE, "%s can't mmap %s: %m", ClientHost, name);
(void)close(OVERfd);
@@ -845,7 +857,7 @@
/* get first entry */
if ( (OVERfirst = atol((char*) OVERshm)) == 0 ) {
syslog(L_NOTICE, "%s: %s: bad format", ClientHost, name);
- (void)munmap(OVERshm, OVERsize);
+ (void)munmap(OVERshm, OVERmsize);
(void)close(OVERfd);
OVERshm = NULL;
return FALSE;
@@ -867,7 +879,7 @@
do {
p = memrchr(OVERshm + OVERsize - 1, '\n', OVERsize - 1);
if ( p == NULL ) {
- (void)munmap(OVERshm, OVERsize);
+ (void)munmap(OVERshm, OVERmsize);
(void)close(OVERfd);
OVERshm = NULL;
return FALSE;
@@ -877,7 +889,7 @@
OVERsize - 1)) == NULL )
{
syslog(L_NOTICE, "%s: %s: bad format", ClientHost, name);
- (void)munmap(OVERshm, OVERsize);
+ (void)munmap(OVERshm, OVERmsize);
(void)close(OVERfd);
OVERshm = NULL;
return FALSE;
@@ -898,7 +910,7 @@
OVERclose()
{
if ( OVERshm ) {
- if ( munmap(OVERshm, OVERsize) == -1 ) {
+ if ( munmap(OVERshm, OVERmsize) == -1 ) {
syslog(L_NOTICE, "%s can't munmap: %m", ClientHost);
}
(void)close(OVERfd);
Technical Details
Message-ID:
<5g429n$d2s$1@news1.xs4all.nl>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mailReferences:
<331EE55D.1493@cwix.net> <5fmjjf$qcg$1@news1.xs4all.nl> <5fn38s$3q0$1@news1.xs4all.nl> <5fv1s9$8ki$1@news.demos.su>Show Full Headers
Complete Article Headers
Message-ID: <5g429n$d2s$1@news1.xs4all.nl> Subject: Re: patch for nnrpd 1.5.1 to mmap .overview files Date: Tue, 11 Mar 1997 00:00:00 +0000 From: johnpc@xs4all.nl (Jan-Pieter Cornet) References: <331EE55D.1493@cwix.net> <5fmjjf$qcg$1@news1.xs4all.nl> <5fn38s$3q0$1@news1.xs4all.nl> <5fv1s9$8ki$1@news.demos.su> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail X-Deja-AN: 224703100 X-XS4ALL-Date: Tue, 11 Mar 1997 17:46:47 CET Organization: XS4ALL Newsgroups: news.software.nntp