* [PATCH] ksm: use FAULT_FLAG_ALLOW_RETRY in breaking COW
@ 2011-11-19 11:50 Hillf Danton
2011-11-21 4:16 ` Hugh Dickins
2011-11-21 23:10 ` Michel Lespinasse
0 siblings, 2 replies; 6+ messages in thread
From: Hillf Danton @ 2011-11-19 11:50 UTC (permalink / raw)
To: Hugh Dickins
Cc: Andrea Arcangeli, Andrew Morton, linux-mm, LKML, Michal Hocko
The flag, FAULT_FLAG_ALLOW_RETRY, was introduced by the patch,
mm: retry page fault when blocking on disk transfer
commit: d065bd810b6deb67d4897a14bfe21f8eb526ba99
for reducing mmap_sem hold times that are caused by waiting for disk
transfers when accessing file mapped VMAs.
To break COW, handle_mm_fault() is repeated with mmap_sem held, where
the introduced flag could be used again.
The straight way is to add changes in break_ksm(), but the function could be
under write-mode mmap_sem, so it has to be dupilcated.
Signed-off-by: Hillf Danton <dhillf@gmail.com>
---
--- a/mm/ksm.c Sat Nov 19 16:08:10 2011
+++ b/mm/ksm.c Sat Nov 19 19:33:49 2011
@@ -394,7 +394,31 @@ static void break_cow(struct rmap_item *
goto out;
if (!(vma->vm_flags & VM_MERGEABLE) || !vma->anon_vma)
goto out;
- break_ksm(vma, addr);
+ for (;;) {
+ struct page *page;
+ int ret;
+
+ page = follow_page(vma, addr, FOLL_GET);
+ if (IS_ERR_OR_NULL(page))
+ break;
+
+ if (PageKsm(page))
+ ret = handle_mm_fault(mm, vma, addr,
+ FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_WRITE);
+ else
+ ret = VM_FAULT_WRITE;
+
+ put_page(page);
+
+ if (!(ret & (VM_FAULT_WRITE|VM_FAULT_SIGBUS|VM_FAULT_OOM))) {
+ if (ret & VM_FAULT_RETRY)
+ down_read(&mm->mmap_sem);
+ } else {
+ if (ret & VM_FAULT_RETRY)
+ return;
+ break;
+ }
+ }
out:
up_read(&mm->mmap_sem);
}
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ksm: use FAULT_FLAG_ALLOW_RETRY in breaking COW
2011-11-19 11:50 [PATCH] ksm: use FAULT_FLAG_ALLOW_RETRY in breaking COW Hillf Danton
@ 2011-11-21 4:16 ` Hugh Dickins
2011-11-21 13:47 ` Hillf Danton
2011-11-21 23:10 ` Michel Lespinasse
1 sibling, 1 reply; 6+ messages in thread
From: Hugh Dickins @ 2011-11-21 4:16 UTC (permalink / raw)
To: Hillf Danton
Cc: Michel Lespinasse, Andrea Arcangeli, Andrew Morton, linux-mm,
LKML, Michal Hocko
On Sat, 19 Nov 2011, Hillf Danton wrote:
> The flag, FAULT_FLAG_ALLOW_RETRY, was introduced by the patch,
>
> mm: retry page fault when blocking on disk transfer
> commit: d065bd810b6deb67d4897a14bfe21f8eb526ba99
>
> for reducing mmap_sem hold times that are caused by waiting for disk
> transfers when accessing file mapped VMAs.
>
> To break COW, handle_mm_fault() is repeated with mmap_sem held, where
> the introduced flag could be used again.
>
> The straight way is to add changes in break_ksm(), but the function could be
> under write-mode mmap_sem, so it has to be dupilcated.
>
> Signed-off-by: Hillf Danton <dhillf@gmail.com>
Thank you for making the patch; but unless I'm mistaken - please
correct me if so - I think it's better to keep break_cow() simple
than add special FAULT_FLAG_ALLOW_RETRY handling there. Do you
have any evidence that its down_read of mmap_sem is a problem in
some workload? I sense that you're using it "because it's there".
I'm sceptical on several grounds.
One, break_cow() is itself only called on an "error" path: not
really an error, but when KSM's bet that it can merge pages turns
out to be wrong before it can complete the merge; not a rare case,
but not on the hot path.
Two, break_ksm()'s loop is required for correctness, but it
is a rare case that it actually needs to go round a second time.
The typical case it's needed (am I forgetting a more common one?)
is when userspace access flips a pte bit in between handle_pte_fault()
noting faulting pte, and the chosen fault handler checking pte_same()
before committing to its action. With the page marked PageKsm, yet
not in the stable tree, even page reclaim is unable to interfere.
Three, FAULT_FLAG_ALLOW_RETRY is acted upon only in lock_page_or_retry(),
which is called only from filemap_fault() (not the case here since we
don't consider file pages for conversion to PageKsm) or do_swap_page();
yet the fault we're provoking would be handled by do_wp_page().
Four, lock_page_or_retry() is called in those places when there's a
possibility that the page is being read in from disk, to drop the
mmap_sem across the slow I/O. There is no precedent for dropping
mmap_sem here while allocating a new page, nor when pte_same() fails:
in the former case it could only be a win when the system is already
slowed by memory pressure, in the latter case there's little point,
since mmap_sem would be reacquired in a moment.
I think that amounts to a genial Nack!
Hugh
> ---
>
> --- a/mm/ksm.c Sat Nov 19 16:08:10 2011
> +++ b/mm/ksm.c Sat Nov 19 19:33:49 2011
> @@ -394,7 +394,31 @@ static void break_cow(struct rmap_item *
> goto out;
> if (!(vma->vm_flags & VM_MERGEABLE) || !vma->anon_vma)
> goto out;
> - break_ksm(vma, addr);
> + for (;;) {
> + struct page *page;
> + int ret;
> +
> + page = follow_page(vma, addr, FOLL_GET);
> + if (IS_ERR_OR_NULL(page))
> + break;
> +
> + if (PageKsm(page))
> + ret = handle_mm_fault(mm, vma, addr,
> + FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_WRITE);
> + else
> + ret = VM_FAULT_WRITE;
> +
> + put_page(page);
> +
> + if (!(ret & (VM_FAULT_WRITE|VM_FAULT_SIGBUS|VM_FAULT_OOM))) {
> + if (ret & VM_FAULT_RETRY)
> + down_read(&mm->mmap_sem);
> + } else {
> + if (ret & VM_FAULT_RETRY)
> + return;
> + break;
> + }
> + }
> out:
> up_read(&mm->mmap_sem);
> }
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ksm: use FAULT_FLAG_ALLOW_RETRY in breaking COW
2011-11-21 4:16 ` Hugh Dickins
@ 2011-11-21 13:47 ` Hillf Danton
2011-11-21 22:23 ` Hugh Dickins
0 siblings, 1 reply; 6+ messages in thread
From: Hillf Danton @ 2011-11-21 13:47 UTC (permalink / raw)
To: Hugh Dickins
Cc: Michel Lespinasse, Andrea Arcangeli, Andrew Morton, linux-mm,
LKML, Michal Hocko
On Mon, Nov 21, 2011 at 12:16 PM, Hugh Dickins <hughd@google.com> wrote:
> On Sat, 19 Nov 2011, Hillf Danton wrote:
>
>> The flag, FAULT_FLAG_ALLOW_RETRY, was introduced by the patch,
>>
>> mm: retry page fault when blocking on disk transfer
>> commit: d065bd810b6deb67d4897a14bfe21f8eb526ba99
>>
>> for reducing mmap_sem hold times that are caused by waiting for disk
>> transfers when accessing file mapped VMAs.
>>
>> To break COW, handle_mm_fault() is repeated with mmap_sem held, where
>> the introduced flag could be used again.
>>
>> The straight way is to add changes in break_ksm(), but the function could be
>> under write-mode mmap_sem, so it has to be dupilcated.
>>
>> Signed-off-by: Hillf Danton <dhillf@gmail.com>
>
> Thank you for making the patch; but unless I'm mistaken - please
> correct me if so - I think it's better to keep break_cow() simple
> than add special FAULT_FLAG_ALLOW_RETRY handling there. Do you
> have any evidence that its down_read of mmap_sem is a problem in
> some workload? I sense that you're using it "because it's there".
>
> I'm sceptical on several grounds.
>
> One, break_cow() is itself only called on an "error" path: not
> really an error, but when KSM's bet that it can merge pages turns
> out to be wrong before it can complete the merge; not a rare case,
> but not on the hot path.
>
> Two, break_ksm()'s loop is required for correctness, but it
> is a rare case that it actually needs to go round a second time.
> The typical case it's needed (am I forgetting a more common one?)
> is when userspace access flips a pte bit in between handle_pte_fault()
> noting faulting pte, and the chosen fault handler checking pte_same()
> before committing to its action. With the page marked PageKsm, yet
> not in the stable tree, even page reclaim is unable to interfere.
>
> Three, FAULT_FLAG_ALLOW_RETRY is acted upon only in lock_page_or_retry(),
> which is called only from filemap_fault() (not the case here since we
> don't consider file pages for conversion to PageKsm) or do_swap_page();
> yet the fault we're provoking would be handled by do_wp_page().
>
> Four, lock_page_or_retry() is called in those places when there's a
> possibility that the page is being read in from disk, to drop the
> mmap_sem across the slow I/O. There is no precedent for dropping
> mmap_sem here while allocating a new page, nor when pte_same() fails:
> in the former case it could only be a win when the system is already
> slowed by memory pressure, in the latter case there's little point,
> since mmap_sem would be reacquired in a moment.
>
> I think that amounts to a genial Nack!
>
Hello Hugh,
After reading your reply and the comments in break_ksm(), if the patch does
not mess up
"The important thing is to not let VM_MERGEABLE be cleared while any
such pages might remain in the area",
and
"because handle_mm_fault() may back out if there's
any difficulty e.g. if pte accessed bit gets updated concurrently",
then if the path in which lock_page_or_retry() is called is not involved,
mmap_sem is not upped, so the patch has nearly same behavior with break_ksm.
And the overhead of the patch, I think, could match break_ksm.
With dozen cases of writers of mmap_sem in the mm directory, the patch looks
more flexible in rare and rare corners.
Best regards
Hillf
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ksm: use FAULT_FLAG_ALLOW_RETRY in breaking COW
2011-11-21 13:47 ` Hillf Danton
@ 2011-11-21 22:23 ` Hugh Dickins
2011-11-22 13:04 ` Hillf Danton
0 siblings, 1 reply; 6+ messages in thread
From: Hugh Dickins @ 2011-11-21 22:23 UTC (permalink / raw)
To: Hillf Danton
Cc: Michel Lespinasse, Andrea Arcangeli, Andrew Morton, linux-mm,
LKML, Michal Hocko
On Mon, 21 Nov 2011, Hillf Danton wrote:
> On Mon, Nov 21, 2011 at 12:16 PM, Hugh Dickins <hughd@google.com> wrote:
>
> After reading your reply and the comments in break_ksm(), if the patch does
> not mess up
> "The important thing is to not let VM_MERGEABLE be cleared while any
> such pages might remain in the area",
> and
> "because handle_mm_fault() may back out if there's
> any difficulty e.g. if pte accessed bit gets updated concurrently",
>
> then if the path in which lock_page_or_retry() is called is not involved,
> mmap_sem is not upped, so the patch has nearly same behavior with break_ksm.
>
> And the overhead of the patch, I think, could match break_ksm.
>
> With dozen cases of writers of mmap_sem in the mm directory, the patch looks
> more flexible in rare and rare corners.
But what's the point in enlarging the kernel, adding code to make
break_cow() look more complicated, when there's no way in which the
addition can make an improvement?
Adding in a FAULT_FLAG_ALLOW_RETRY flag is not enough for mmap_sem
to be dropped for retry: you'd need a lock_page_or_retry() on the
faulting path and I do not see that here - please point it out to
me if you can see it.
(And I'll be somewhat sceptical if you respond with patches adding
lock_page_or_retry() all over, in order to meet this objection!)
Hugh
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ksm: use FAULT_FLAG_ALLOW_RETRY in breaking COW
2011-11-19 11:50 [PATCH] ksm: use FAULT_FLAG_ALLOW_RETRY in breaking COW Hillf Danton
2011-11-21 4:16 ` Hugh Dickins
@ 2011-11-21 23:10 ` Michel Lespinasse
1 sibling, 0 replies; 6+ messages in thread
From: Michel Lespinasse @ 2011-11-21 23:10 UTC (permalink / raw)
To: Hillf Danton
Cc: Hugh Dickins, Andrea Arcangeli, Andrew Morton, linux-mm, LKML,
Michal Hocko
On Sat, Nov 19, 2011 at 3:50 AM, Hillf Danton <dhillf@gmail.com> wrote:
> The flag, FAULT_FLAG_ALLOW_RETRY, was introduced by the patch,
>
> mm: retry page fault when blocking on disk transfer
> commit: d065bd810b6deb67d4897a14bfe21f8eb526ba99
>
> for reducing mmap_sem hold times that are caused by waiting for disk
> transfers when accessing file mapped VMAs.
>
> To break COW, handle_mm_fault() is repeated with mmap_sem held, where
> the introduced flag could be used again.
>
> The straight way is to add changes in break_ksm(), but the function could be
> under write-mode mmap_sem, so it has to be dupilcated.
>
> Signed-off-by: Hillf Danton <dhillf@gmail.com>
I have to concur with Hugh here - FAULT_FLAG_ALLOW_RETRY was
introduced to avoid holding mmap_sem while we block on a disk read,
but you shouldn't hit this case in the break COW case, so there seems
to be little point in adding the flag there.
--
Michel "Walken" Lespinasse
A program is never fully debugged until the last user dies.
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] ksm: use FAULT_FLAG_ALLOW_RETRY in breaking COW
2011-11-21 22:23 ` Hugh Dickins
@ 2011-11-22 13:04 ` Hillf Danton
0 siblings, 0 replies; 6+ messages in thread
From: Hillf Danton @ 2011-11-22 13:04 UTC (permalink / raw)
To: Hugh Dickins
Cc: Michel Lespinasse, Andrea Arcangeli, Andrew Morton, linux-mm,
LKML, Michal Hocko
On Tue, Nov 22, 2011 at 6:23 AM, Hugh Dickins <hughd@google.com> wrote:
> But what's the point in enlarging the kernel, adding code to make
> break_cow() look more complicated, when there's no way in which the
> addition can make an improvement?
>
Hello Hugh
Thanks for correcting me, there is no real point to complicate the function.
Hillf
--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2011-11-22 13:04 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-19 11:50 [PATCH] ksm: use FAULT_FLAG_ALLOW_RETRY in breaking COW Hillf Danton
2011-11-21 4:16 ` Hugh Dickins
2011-11-21 13:47 ` Hillf Danton
2011-11-21 22:23 ` Hugh Dickins
2011-11-22 13:04 ` Hillf Danton
2011-11-21 23:10 ` Michel Lespinasse
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).