* using mmap() in OSF
@ 1993-11-15 22:46 Stephen Reagan
1993-11-16 12:02 ` Marc Evans
1993-11-16 14:38 ` ivie
0 siblings, 2 replies; 3+ messages in thread
From: Stephen Reagan @ 1993-11-15 22:46 UTC (permalink / raw)
I would like to know if anyone has tried to use the mmap() function
on OSF - I have heard rumors that it doesn't work (unfortunately, this
is non-specific information). I have been looking at Stevens' book as
a guide, but I cannot get enough information to pass any judgement.
Basically I am interested in maintaining a very large disk file in order
to take periodic snapshots of a real-time system that would entail saving
information of up to 60K data points in a file that may be 15Mb or more.
Is using mmap() in this case a reasonable idea? What if I don't know
the exact file size at creation time, but can get it when I read the
data from the file later? Any information, suggestions, or anecdotal
information would be greatly appreciated.
Thanks,
--Steve
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: using mmap() in OSF
1993-11-15 22:46 using mmap() in OSF Stephen Reagan
@ 1993-11-16 12:02 ` Marc Evans
1993-11-16 14:38 ` ivie
1 sibling, 0 replies; 3+ messages in thread
From: Marc Evans @ 1993-11-16 12:02 UTC (permalink / raw)
In article <CGK1xr.7wz@unix.portal.com>, sdr@unix.portal.com (Stephen Reagan) writes:
|> I would like to know if anyone has tried to use the mmap() function
|> on OSF - I have heard rumors that it doesn't work (unfortunately, this
|> is non-specific information). I have been looking at Stevens' book as
|> a guide, but I cannot get enough information to pass any judgement.
|> Basically I am interested in maintaining a very large disk file in order
|> to take periodic snapshots of a real-time system that would entail saving
|> information of up to 60K data points in a file that may be 15Mb or more.
|> Is using mmap() in this case a reasonable idea? What if I don't know
|> the exact file size at creation time, but can get it when I read the
|> data from the file later? Any information, suggestions, or anecdotal
|> information would be greatly appreciated.
The attached hack works fine for me...
#include <unistd.h>
#include <fcntl.h>
#include <memory.h>
#include <sys/types.h>
long WriteFile(int ifd, int ofd)
{
register caddr_t addr, p;
register long nb=0, s=0;
struct stat st;
long size;
long pgsize = sysconf(_SC_PAGE_SIZE);
#if UseMMAP
#include <sys/stat.h>
#include <sys/mman.h>
#define MeOnly (PROT_NONE | PROT_WRITE)
#define YouDecide (MAP_FILE | MAP_VARIABLE | MAP_PRIVATE)
(void)fstat(ifd,&st);
nb = st.st_size;
size = ((nb / pgsize) + 1) * pgsize;
if ((addr = mmap(NULL,size,MeOnly,YouDecide,ifd,0)))
{ (void)madvise(p,size,MADV_SEQUENTIAL);
for (p=addr; p!=&addr[nb]; p+=(s=write(ofd,p,&addr[nb]-p)))
{ if (s < 0)
{ perror("loop error"); break; }
}
(void)munmap(addr,size);
} else
#endif /* UseMMAP */
{ addr = (caddr_t)malloc(pgsize);
while ((nb+=(size=read(ifd,p,pgsize))) > 0)
{ for (p=addr; p!=&addr[size]; p+=(s=write(ofd,p,&addr[size]-p)))
{ if (s < 0)
{ perror("loop error"); break; }
}
}
(void)free(addr);
}
return(nb);
}
main(int argc, char **argv)
{
register int ofd = open(argv[1],O_WRONLY|O_CREAT|O_TRUNC,0777);
register int i = 1;
register int ifd;
(void)printf("Outputing to %s (%d)\n",argv[1],ofd);
while (++i < argc)
{ ifd = open(argv[i],O_RDONLY);
(void)printf("Inputting from %s (%d)\n",argv[i],ifd);
if (ifd >= 0) { WriteFile(ifd,ofd); }
(void)close(ifd);
}
(void)close(ofd);
exit(0);
}
The key thing to remember when using mmap() (at least on DEC OSF/1) is that you
can NOT extend the length of files using it. Your particular problem space
appears to be well suited for the use of mmap() (IMHO). What I would suggest
doing is to write your program such that you use read/write to determine the
length of the file and then write to the furthest byte, which will create what
you need to be able to then mmap it.
- Marc
--
/| -----------------------. ~ . ~
X|=| Marc N. Evans |------------------. ~ .
X| | Software Consultant | Synergytics |-------------------------------.
X| | Marc@Synergytics.Com | 21 Hinds Lane | Specializing in: |
X| | (603) 635-3857 | Pelham, NH, USA | - Unix internals/applications |
X|=|______________________| 03076-3013 | - X11 internals/applications |
X| (____________________| |
X| (_________________________________|
X|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: using mmap() in OSF
1993-11-15 22:46 using mmap() in OSF Stephen Reagan
1993-11-16 12:02 ` Marc Evans
@ 1993-11-16 14:38 ` ivie
1 sibling, 0 replies; 3+ messages in thread
From: ivie @ 1993-11-16 14:38 UTC (permalink / raw)
In article <CGK1xr.7wz@unix.portal.com>, sdr@unix.portal.com (Stephen Reagan) writes:
> I would like to know if anyone has tried to use the mmap() function
> on OSF - I have heard rumors that it doesn't work (unfortunately, this
> is non-specific information).
The variant of mmap() that _I've_ been having trouble with involves mapping
a device driver's CSR space. No magic incantations that I've tried have
resulted in the driver's mmap() routine being called. This may be the source
of the rumor that mmap() doesn't work. BTW, this is on a TURBOchannel
platform, so the processor could theoretically do it; $CRMPSC on VMS with
the same hardware works great.
--
----------------+------------------------------------------------------
Roger Ivie | Don't think of it as a 'new' computer, think of it as
ivie@cc.usu.edu | 'obsolete-ready'
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1993-11-16 14:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1993-11-15 22:46 using mmap() in OSF Stephen Reagan
1993-11-16 12:02 ` Marc Evans
1993-11-16 14:38 ` ivie
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox