Re: No copy on write system call?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,
This is never going to happen as per my understanding.
You need to know internals of write system call for
that.
Lets say you have a huge buffer to write and you
triggered write system call.
Internally generic_file_write is called the page is
allocated in kernel space. Your buffer is cut down
into the PAGE_SIZE buffers for example a buffer of 40k
and PAGE_SIZE is 4k then 10 pages are allocated.
The page allocation is followed by prepare_write and
commit_write.
Now If your system is under pressure which may occur 
at page allocation. Then all the dirty inode are
flushed to the storage. For that writepage is called
on each inodes address space.This way  write can
request any huge buffer.Yes you can avoid to go
through Page cache by O_DIRECT flag. But i am not
clear about that mechanism.
Prasanna
--- stackframe@xxxxxxxxxxx wrote:
> How is it that a write (man 2 write) can be passed a
> buffer 
> that exceeds most of the physical and virtual memory
> on a 
> system and work successfully?
> 
> I wrote a simple program that allocates a large
> buffer on 
> the heap, zeros the space and then calls write 
> (man 2 write).  Even though the buffer is almost as
> large 
> as physical memory + page space the call completes
> without 
> error.  In my example I allocated 705MB on a system
> that 
> has 256MB physical and 512MB virtual.  When it
> completes 
> there is a 705MB file on disk as expected.
> 
> So is it in the case of the sys_write that the
> memory is 
> accessed and allowed to page fault as needed while
> running 
> in the context of the kernel?  Most of the kernel
> books 
> talk about using copy_from_user on system calls
> before
> using memory from the user.  Strace shows one write 
> call with the entire length.
> 
> So what is going on to allow this to happen?
> 
> Thanks,
> Tony
> 
> 
> --
> Kernelnewbies: Help each other learn about the Linux
> kernel.
> Archive:      
> http://mail.nl.linux.org/kernelnewbies/
> FAQ:           http://kernelnewbies.org/faq/
> 
> 


		
__________________________________ 
Do you Yahoo!? 
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/ 

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux