All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andi Kleen <andi@firstfloor.org>
To: Anton Salikhmetov <salikhmetov@gmail.com>
Cc: 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@osdl.org
Subject: Re: [PATCH -v7 2/2] Update ctime and mtime for memory-mapped files
Date: 22 Jan 2008 05:39:43 +0100	[thread overview]
Message-ID: <p737ii2o4mo.fsf@crumb.suse.de> (raw)
In-Reply-To: <12009619584168-git-send-email-salikhmetov@gmail.com>

Anton Salikhmetov <salikhmetov@gmail.com> writes:

You should probably put your design document somewhere in Documentation
with a patch.

> + * 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);

This means on i386 with highmem ptes you will map/flush tlb/unmap each
PTE individually. You will do 512 times as much work as really needed
per PTE leaf page.

The performance critical address space walkers use a different design
pattern that avoids this.

> +		if (pte_dirty(*pte) && pte_write(*pte)) {
> +			pte_t entry = ptep_clear_flush(vma, addr, pte);

Flushing TLBs unbatched can also be very expensive because if the MM is
shared by several CPUs you'll have a inter-processor interrupt for 
each iteration. They are quite costly even on smaller systems.

It would be better if you did a single flush_tlb_range() at the end.
This means on x86 this will currently always do a full flush, but that's
still better than really slowing down in the heavily multithreaded case.

-Andi

WARNING: multiple messages have this Message-ID (diff)
From: Andi Kleen <andi@firstfloor.org>
To: Anton Salikhmetov <salikhmetov@gmail.com>
Cc: 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@osdl.org
Subject: Re: [PATCH -v7 2/2] Update ctime and mtime for memory-mapped files
Date: 22 Jan 2008 05:39:43 +0100	[thread overview]
Message-ID: <p737ii2o4mo.fsf@crumb.suse.de> (raw)
In-Reply-To: <12009619584168-git-send-email-salikhmetov@gmail.com>

Anton Salikhmetov <salikhmetov@gmail.com> writes:

You should probably put your design document somewhere in Documentation
with a patch.

> + * 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);

This means on i386 with highmem ptes you will map/flush tlb/unmap each
PTE individually. You will do 512 times as much work as really needed
per PTE leaf page.

The performance critical address space walkers use a different design
pattern that avoids this.

> +		if (pte_dirty(*pte) && pte_write(*pte)) {
> +			pte_t entry = ptep_clear_flush(vma, addr, pte);

Flushing TLBs unbatched can also be very expensive because if the MM is
shared by several CPUs you'll have a inter-processor interrupt for 
each iteration. They are quite costly even on smaller systems.

It would be better if you did a single flush_tlb_range() at the end.
This means on x86 this will currently always do a full flush, but that's
still better than really slowing down in the heavily multithreaded case.

-Andi

--
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>

  parent reply	other threads:[~2008-01-22  4:39 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-22  0:32 [PATCH -v7 0/2] Fixing the issue with memory-mapped file times Anton Salikhmetov
2008-01-22  0:32 ` Anton Salikhmetov
2008-01-22  0:32 ` [PATCH -v7 1/2] Massive code cleanup of sys_msync() Anton Salikhmetov
2008-01-22  0:32   ` Anton Salikhmetov
2008-01-22  0:32 ` [PATCH -v7 2/2] Update ctime and mtime for memory-mapped files Anton Salikhmetov
2008-01-22  0:32   ` Anton Salikhmetov
2008-01-22  1:40   ` Jesper Juhl
2008-01-22  1:40     ` Jesper Juhl
2008-01-22  1:51     ` Anton Salikhmetov
2008-01-22  1:51       ` Anton Salikhmetov
2008-01-22  1:54       ` Jesper Juhl
2008-01-22  1:54         ` Jesper Juhl
2008-01-22  1:57         ` Anton Salikhmetov
2008-01-22  1:57           ` Anton Salikhmetov
2008-01-22  2:18           ` Jesper Juhl
2008-01-22  2:18             ` Jesper Juhl
2008-01-22  2:07       ` Anton Salikhmetov
2008-01-22  2:07         ` Anton Salikhmetov
2008-01-22  2:16         ` Jesper Juhl
2008-01-22  2:16           ` Jesper Juhl
2008-01-22  2:16   ` Linus Torvalds
2008-01-22  2:16     ` Linus Torvalds
2008-01-22  2:39     ` Anton Salikhmetov
2008-01-22  2:39       ` Anton Salikhmetov
2008-01-22  8:52       ` Miklos Szeredi
2008-01-22  8:52         ` Miklos Szeredi
2008-01-22  4:39   ` Andi Kleen [this message]
2008-01-22  4:39     ` Andi Kleen
2008-01-22  1:34 ` [PATCH -v7 0/2] Fixing the issue with memory-mapped file times Jesper Juhl
2008-01-22  1:34   ` Jesper Juhl
2008-01-22  1:40   ` Anton Salikhmetov
2008-01-22  1:40     ` Anton Salikhmetov

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=p737ii2o4mo.fsf@crumb.suse.de \
    --to=andi@firstfloor.org \
    --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=riel@redhat.com \
    --cc=salikhmetov@gmail.com \
    --cc=staubach@redhat.com \
    --cc=torvalds@osdl.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.