Re: page->mapping and page->buffers

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

 



On Mon, Sep 09, 2002 at 09:09:36PM -0400, Haijin Yan wrote:
> > >
> > > IIRC, it points to the list of buffer heads describing the disk
> > > location of the data resident in the page. Buffer heads are the
> > > structs used to schedule traditional (read()/write()) disk
> > > I/O, whereas page->mapping is used for mmap() I/O. So a
> > > "buffer" is just a logical block of data within a page
> > > that correponds to a physical disk block somewhere; and
> > > the buffer head is a description of that relationship. In the
> > > older 2.4 kernels, they were complimentary: when a mmap()ed page
> > > had to be written out, the VM created buffers describing the page
> > > and then handed those buffers off to the disk I/O subsystem. I'm
> > > not sure if things work the same now. (Probably so.)
> >
> > Each page in page cache belongs to an inode or is anonymous. But
> > page_launder() writes the pages out independently of what they belong
> > to. So it one cache. Mappings are there so page_launder knows where to
> > write the page (it calls down to writepage method in mapping).
> >
> > With buffers, IIRC it's still the same way. When a page has to be
> > written to disk, it's turned into buffers and these are queued for disk
> > write.
> >
> 
> Are you guys saying that pages for traditional I/O(read/write) do not
> have page->mapping while clean mmap()ed pages do not have page->buffer?

No. I was trying to say exactly otherwise. Every page that's from a file
_on disk_ or anonymous and swap in on disk will have buffers when it's
dirty. No matter if it became dirty via write or mmap. 

> As far as I know, a page(not anonymous) with its mapping points to
> mapping of inode of the file in page_cache_read() function like this:
> 
> inode = file->f_dentry->d_inode;
> struct address_space *mapping = inode->i_mapping;
> page = page_cache_alloc(mapping);
> page->mapping = mapping;
> 
> when page got swapped, it's mapping is set to
> page->mapping = &swapper_space;
> 
> so when is the condition (!page->mapping) true and what it represents for?

When _anonymous_ page get swapped, it get page->mapping = &swapper_space.
When page is from a file, it has it's mapping being in memory or not.
I looked in the source and it seems, that setting swapper_space is
"lazy" in some circumstances, ie. the page has NULL mapping until we
actually want to swap it the first time, but I am not sure.

> If page->buffers is true, Does that ony mean either page is brought in by
> traditional IO or a disk block is allocated for this mmap()ed page for
> written(because page is dirty)?

Well, it means there is some block device IO to be done on the page.
mmap()ing a page does not matter for this purpose. mmap()ing just
creates PTE for the page, but does not affect how IO works on it.

When a page is written using write, buffers are created. When it's
written using mmap, buffers are created when kernel walks PTEs and
notices the PTE is dirty.

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb@ucw.cz>
--
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