Operating System - HP-UX
1826341 Members
4051 Online
109692 Solutions
New Discussion

Creating files of large size without occupying filesystem space

 
Mukundan_1
Occasional Contributor

Creating files of large size without occupying filesystem space

Can somebody tell me what system calls are used to create a large file on HP-UX but the file does not occupy disk space.
if you do a ls -l on the large file(let's say its 5gb oracle tempfile). it shows 5gb. but if you do a df -k the disk space allocation shows that there filesystem has not used the 5gb.
i know this is how oracle does tempfile allocation quickly. it creates the file and shows it as 5gb initially but it does not grab the disk space initally it grabs it when you need them. how does oracle do it? what kind of system calls do you think go into tricking us into believing that 5gb file is out there.
can any unix guru with internals knowledge explain to me.
5 REPLIES 5
Pete Randall
Outstanding Contributor

Re: Creating files of large size without occupying filesystem space

I think prealloc would be the one you're looking for.


Pete

Pete
RAC_1
Honored Contributor

Re: Creating files of large size without occupying filesystem space

These files are called as sparse files. Read the man page of prealloc

Anil
There is no substitute to HARDWORK
Jeff Schussele
Honored Contributor

Re: Creating files of large size without occupying filesystem space

Hi,

Well technically it doesn't use the space when a sparse file is created with prealloc.
It just defines beginning and ending block addresses.
BUT the space is *not* available for any other purpose at the same time. So it is used in a sense because nothing else can use it you could say.

My 2 cents,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Mukundan_1
Occasional Contributor

Re: Creating files of large size without occupying filesystem space

I appreciate the replies, but i ran into some issues where there are other large files(not oracle datafiles) that were in the same filesystem. when the database ran some large queries it used the temp files, but the queries failed because the tempfiles could not expand because of the filesystem became full.
so as per your post the the blocks in sparse files are not used by anybody else seems to be not case.

I know the cause, i know the workaround as far as oracle. I know oracle documentation cautions about this, but there is no explanation as to how oracle creates files like this.I am just curious to find from the o/s level how is this happening.

If someone can guide me to specific document or post that talks about this type of file creation that is great. I am not looking for pointers in some general direction.
Sundar_7
Honored Contributor

Re: Creating files of large size without occupying filesystem space

Files created by prealloc actually occupy the space.

:(root)> prealloc TESTFILE 50000000
:(root)> ls -lrt TESTFILE
-rw-rw-r-- 1 root sys 50000000 Aug 31 10:44 TESTFILE
:(root)> du -sk TESTFILE
48829 TESTFILE

So you can use the dd and echo to create sparse file.

:(root)> echo | dd bs=1024 seek=100000 of=large
0+1 records in
0+1 records out
:(root)> ls -lrt large
-rw-rw-r-- 1 root sys 102400001 Aug 31 10:44 large
:(root)> du -sk large
8 large
:(root)>

If you want to simulate the behaviour in C, you could open a file using open(), write a byte, lseek() and write a byte again. The resulting file will be of size greater than just 2 bytes.
Learn What to do ,How to do and more importantly When to do ?