All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: salikhmetov@gmail.com, linux-mm@kvack.org, jakob@unthought.net,
	linux-kernel@vger.kernel.org, valdis.kletnieks@vt.edu,
	riel@redhat.com, ksm@42.dk, staubach@redhat.com,
	jesper.juhl@gmail.com, torvalds@linux-foundation.org,
	akpm@linux-foundation.org, protasnb@gmail.com,
	r.e.wolff@bitwizard.nl, hidave.darkstar@gmail.com,
	hch@infradead.org
Subject: Re: [PATCH -v6 2/2] Updating ctime and mtime for memory-mapped files
Date: Fri, 18 Jan 2008 11:15:36 +0100	[thread overview]
Message-ID: <1200651337.5920.9.camel@twins> (raw)
In-Reply-To: <E1JFnsg-0008UU-LU@pomaz-ex.szeredi.hu>


On Fri, 2008-01-18 at 10:51 +0100, Miklos Szeredi wrote:

> > diff --git a/mm/msync.c b/mm/msync.c
> > index a4de868..a49af28 100644
> > --- a/mm/msync.c
> > +++ b/mm/msync.c
> > @@ -13,11 +13,33 @@
> >  #include <linux/syscalls.h>
> >  
> >  /*
> > + * Scan the PTEs for pages belonging to the VMA and mark them read-only.
> > + * It will force a pagefault on the next write access.
> > + */
> > +static void vma_wrprotect(struct vm_area_struct *vma)
> > +{
> > +	unsigned long addr;
> > +
> > +	for (addr = vma->vm_start; addr < vma->vm_end; addr += PAGE_SIZE) {
> > +		spinlock_t *ptl;
> > +		pgd_t *pgd = pgd_offset(vma->vm_mm, addr);
> > +		pud_t *pud = pud_offset(pgd, addr);
> > +		pmd_t *pmd = pmd_offset(pud, addr);
> > +		pte_t *pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl);
> > +
> > +		if (pte_dirty(*pte) && pte_write(*pte))
> > +			*pte = pte_wrprotect(*pte);
> > +		pte_unmap_unlock(pte, ptl);
> > +	}
> > +}
> 
> What about ram based filesystems?  They don't start out with read-only
> pte's, so I think they don't want them read-protected now either.
> Unless this is essential for correct mtime/ctime accounting on these
> filesystems (I don't think it really is).  But then the mapping should
> start out read-only as well, otherwise the time update will only work
> after an msync(MS_ASYNC).

page_mkclean() has all the needed logic for this, it also walks the rmap
and cleans out all other users, which I think is needed too for
consistencies sake:

Process A			Process B

mmap(foo.txt)			mmap(foo.txt)

dirty page
				dirty page

msync(MS_ASYNC)

				dirty page

msync(MS_ASYNC) <--- now what?!


So what I would suggest is using the page table walkers from mm, and
walks the page range, obtain the page using vm_normal_page() and call
page_mkclean(). (Oh, and ensure you don't nest the pte lock :-)

All in all, that sounds rather expensive..




WARNING: multiple messages have this Message-ID (diff)
From: Peter Zijlstra <a.p.zijlstra@chello.nl>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: salikhmetov@gmail.com, linux-mm@kvack.org, jakob@unthought.net,
	linux-kernel@vger.kernel.org, valdis.kletnieks@vt.edu,
	riel@redhat.com, ksm@42.dk, staubach@redhat.com,
	jesper.juhl@gmail.com, torvalds@linux-foundation.org,
	akpm@linux-foundation.org, protasnb@gmail.com,
	r.e.wolff@bitwizard.nl, hidave.darkstar@gmail.com,
	hch@infradead.org
Subject: Re: [PATCH -v6 2/2] Updating ctime and mtime for memory-mapped files
Date: Fri, 18 Jan 2008 11:15:36 +0100	[thread overview]
Message-ID: <1200651337.5920.9.camel@twins> (raw)
In-Reply-To: <E1JFnsg-0008UU-LU@pomaz-ex.szeredi.hu>

On Fri, 2008-01-18 at 10:51 +0100, Miklos Szeredi wrote:

> > diff --git a/mm/msync.c b/mm/msync.c
> > index a4de868..a49af28 100644
> > --- a/mm/msync.c
> > +++ b/mm/msync.c
> > @@ -13,11 +13,33 @@
> >  #include <linux/syscalls.h>
> >  
> >  /*
> > + * Scan the PTEs for pages belonging to the VMA and mark them read-only.
> > + * It will force a pagefault on the next write access.
> > + */
> > +static void vma_wrprotect(struct vm_area_struct *vma)
> > +{
> > +	unsigned long addr;
> > +
> > +	for (addr = vma->vm_start; addr < vma->vm_end; addr += PAGE_SIZE) {
> > +		spinlock_t *ptl;
> > +		pgd_t *pgd = pgd_offset(vma->vm_mm, addr);
> > +		pud_t *pud = pud_offset(pgd, addr);
> > +		pmd_t *pmd = pmd_offset(pud, addr);
> > +		pte_t *pte = pte_offset_map_lock(vma->vm_mm, pmd, addr, &ptl);
> > +
> > +		if (pte_dirty(*pte) && pte_write(*pte))
> > +			*pte = pte_wrprotect(*pte);
> > +		pte_unmap_unlock(pte, ptl);
> > +	}
> > +}
> 
> What about ram based filesystems?  They don't start out with read-only
> pte's, so I think they don't want them read-protected now either.
> Unless this is essential for correct mtime/ctime accounting on these
> filesystems (I don't think it really is).  But then the mapping should
> start out read-only as well, otherwise the time update will only work
> after an msync(MS_ASYNC).

page_mkclean() has all the needed logic for this, it also walks the rmap
and cleans out all other users, which I think is needed too for
consistencies sake:

Process A			Process B

mmap(foo.txt)			mmap(foo.txt)

dirty page
				dirty page

msync(MS_ASYNC)

				dirty page

msync(MS_ASYNC) <--- now what?!


So what I would suggest is using the page table walkers from mm, and
walks the page range, obtain the page using vm_normal_page() and call
page_mkclean(). (Oh, and ensure you don't nest the pte lock :-)

All in all, that sounds rather expensive..



--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2008-01-18 10:15 UTC|newest]

Thread overview: 86+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-17 22:31 [PATCH -v6 0/2] Fixing the issue with memory-mapped file times Anton Salikhmetov
2008-01-17 22:31 ` Anton Salikhmetov
2008-01-17 22:31 ` [PATCH -v6 1/2] Massive code cleanup of sys_msync() Anton Salikhmetov
2008-01-17 22:31   ` Anton Salikhmetov
2008-01-18  9:33   ` Miklos Szeredi
2008-01-18  9:33     ` Miklos Szeredi
2008-01-18 10:30     ` Anton Salikhmetov
2008-01-18 10:30       ` Anton Salikhmetov
2008-01-17 22:31 ` [PATCH -v6 2/2] Updating ctime and mtime for memory-mapped files Anton Salikhmetov
2008-01-17 22:31   ` Anton Salikhmetov
2008-01-18  9:51   ` Miklos Szeredi
2008-01-18  9:51     ` Miklos Szeredi
2008-01-18 10:15     ` Peter Zijlstra [this message]
2008-01-18 10:15       ` Peter Zijlstra
2008-01-18 10:25       ` Peter Zijlstra
2008-01-18 10:25         ` Peter Zijlstra
2008-01-18 10:39         ` Anton Salikhmetov
2008-01-18 10:39           ` Anton Salikhmetov
2008-01-18 17:58         ` Linus Torvalds
2008-01-18 17:58           ` Linus Torvalds
2008-01-18 18:11           ` Miklos Szeredi
2008-01-18 18:11             ` Miklos Szeredi
2008-01-18 18:28             ` Rik van Riel
2008-01-18 18:28               ` Rik van Riel
2008-01-18 18:51               ` Miklos Szeredi
2008-01-18 18:51                 ` Miklos Szeredi
2008-01-18 18:43             ` Linus Torvalds
2008-01-18 18:43               ` Linus Torvalds
2008-01-18 18:57               ` Miklos Szeredi
2008-01-18 18:57                 ` Miklos Szeredi
2008-01-18 19:08                 ` Linus Torvalds
2008-01-18 19:08                   ` Linus Torvalds
2008-01-18 19:22                   ` Miklos Szeredi
2008-01-18 19:22                     ` Miklos Szeredi
2008-01-18 19:35                     ` Linus Torvalds
2008-01-18 19:35                       ` Linus Torvalds
2008-01-18 19:58                       ` Anton Salikhmetov
2008-01-18 19:58                         ` Anton Salikhmetov
2008-01-18 20:22                         ` Linus Torvalds
2008-01-18 20:22                           ` Linus Torvalds
2008-01-18 21:03                           ` Anton Salikhmetov
2008-01-18 21:03                             ` Anton Salikhmetov
2008-01-18 21:27                             ` Linus Torvalds
2008-01-18 21:27                               ` Linus Torvalds
2008-01-18 22:04                               ` Anton Salikhmetov
2008-01-18 22:04                                 ` Anton Salikhmetov
2008-01-18 22:21                                 ` Linus Torvalds
2008-01-18 22:21                                   ` Linus Torvalds
2008-01-18 22:35                                   ` Anton Salikhmetov
2008-01-18 22:35                                     ` Anton Salikhmetov
2008-01-18 22:32                       ` Ingo Oeser
2008-01-18 22:32                         ` Ingo Oeser
2008-01-18 22:47                         ` Linus Torvalds
2008-01-18 22:47                           ` Linus Torvalds
2008-01-18 22:54                           ` Rik van Riel
2008-01-18 22:54                             ` Rik van Riel
2008-01-19  0:50                             ` Matt Mackall
2008-01-19  0:50                               ` Matt Mackall
2008-01-19  4:25                               ` Rik van Riel
2008-01-19  4:25                                 ` Rik van Riel
2008-01-19 10:22                               ` Miklos Szeredi
2008-01-19 10:22                                 ` Miklos Szeredi
2008-01-19 15:49                                 ` Matt Mackall
2008-01-19 15:49                                   ` Matt Mackall
2008-01-21 14:25                           ` Peter Staubach
2008-01-21 14:25                             ` Peter Staubach
2008-01-21 14:36                             ` Anton Salikhmetov
2008-01-21 14:36                               ` Anton Salikhmetov
2008-01-18 10:38       ` Miklos Szeredi
2008-01-18 10:38         ` Miklos Szeredi
2008-01-18 11:00         ` Peter Zijlstra
2008-01-18 11:00           ` Peter Zijlstra
2008-01-18 11:17           ` Miklos Szeredi
2008-01-18 11:17             ` Miklos Szeredi
2008-01-18 11:23             ` Peter Zijlstra
2008-01-18 11:23               ` Peter Zijlstra
2008-01-18 11:36               ` Miklos Szeredi
2008-01-18 11:36                 ` Miklos Szeredi
2008-01-18  9:40 ` [PATCH -v6 0/2] Fixing the issue with memory-mapped file times Miklos Szeredi
2008-01-18  9:40   ` Miklos Szeredi
2008-01-18 10:31   ` Anton Salikhmetov
2008-01-18 10:31     ` Anton Salikhmetov
2008-01-18 19:48   ` Anton Salikhmetov
2008-01-18 19:48     ` Anton Salikhmetov
2008-01-19 10:45     ` Miklos Szeredi
2008-01-19 10:45       ` Miklos Szeredi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1200651337.5920.9.camel@twins \
    --to=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=hch@infradead.org \
    --cc=hidave.darkstar@gmail.com \
    --cc=jakob@unthought.net \
    --cc=jesper.juhl@gmail.com \
    --cc=ksm@42.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=miklos@szeredi.hu \
    --cc=protasnb@gmail.com \
    --cc=r.e.wolff@bitwizard.nl \
    --cc=riel@redhat.com \
    --cc=salikhmetov@gmail.com \
    --cc=staubach@redhat.com \
    --cc=torvalds@linux-foundation.org \
    --cc=valdis.kletnieks@vt.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.