From: Steven Price <steven.price@arm.com>
To: Chinwen Chang <chinwen.chang@mediatek.com>,
Matthias Brugger <matthias.bgg@gmail.com>,
Michel Lespinasse <walken@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
Vlastimil Babka <vbabka@suse.cz>,
Daniel Jordan <daniel.m.jordan@oracle.com>,
Davidlohr Bueso <dbueso@suse.de>,
Alexey Dobriyan <adobriyan@gmail.com>,
"Matthew Wilcox (Oracle)" <willy@infradead.org>,
Jason Gunthorpe <jgg@ziepe.ca>, Song Liu <songliubraving@fb.com>,
Jimmy Assarsson <jimmyassarsson@gmail.com>,
Huang Ying <ying.huang@intel.com>
Cc: linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-mediatek@lists.infradead.org,
linux-fsdevel@vger.kernel.org, wsd_upstream@mediatek.com
Subject: Re: [PATCH 2/2] mm: proc: smaps_rollup: do not stall write attempts on mmap_lock
Date: Wed, 12 Aug 2020 09:39:09 +0100 [thread overview]
Message-ID: <bf40676e-b14b-44cd-75ce-419c70194783@arm.com> (raw)
In-Reply-To: <1597120955-16495-3-git-send-email-chinwen.chang@mediatek.com>
On 11/08/2020 05:42, Chinwen Chang wrote:
> smaps_rollup will try to grab mmap_lock and go through the whole vma
> list until it finishes the iterating. When encountering large processes,
> the mmap_lock will be held for a longer time, which may block other
> write requests like mmap and munmap from progressing smoothly.
>
> There are upcoming mmap_lock optimizations like range-based locks, but
> the lock applied to smaps_rollup would be the coarse type, which doesn't
> avoid the occurrence of unpleasant contention.
>
> To solve aforementioned issue, we add a check which detects whether
> anyone wants to grab mmap_lock for write attempts.
>
> Signed-off-by: Chinwen Chang <chinwen.chang@mediatek.com>
> ---
> fs/proc/task_mmu.c | 21 +++++++++++++++++++++
> 1 file changed, 21 insertions(+)
>
> diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
> index dbda449..4b51f25 100644
> --- a/fs/proc/task_mmu.c
> +++ b/fs/proc/task_mmu.c
> @@ -856,6 +856,27 @@ static int show_smaps_rollup(struct seq_file *m, void *v)
> for (vma = priv->mm->mmap; vma; vma = vma->vm_next) {
> smap_gather_stats(vma, &mss);
> last_vma_end = vma->vm_end;
> +
> + /*
> + * Release mmap_lock temporarily if someone wants to
> + * access it for write request.
> + */
> + if (mmap_lock_is_contended(mm)) {
> + mmap_read_unlock(mm);
> + ret = mmap_read_lock_killable(mm);
> + if (ret) {
> + release_task_mempolicy(priv);
> + goto out_put_mm;
> + }
> +
> + /* Check whether current vma is available */
> + vma = find_vma(mm, last_vma_end - 1);
> + if (vma && vma->vm_start < last_vma_end)
I may be wrong, but this looks like it could return incorrect results.
For example if we start reading with the following VMAs:
+------+------+-----------+
| VMA1 | VMA2 | VMA3 |
+------+------+-----------+
| | | |
4k 8k 16k 400k
Then after reading VMA2 we drop the lock due to contention. So:
last_vma_end = 16k
Then if VMA2 is freed while the lock is dropped, so we have:
+------+ +-----------+
| VMA1 | | VMA3 |
+------+ +-----------+
| | | |
4k 8k 16k 400k
find_vma(mm, 16k-1) will then return VMA3 and the condition vm_start <
last_vma_end will be false.
> + continue;
> +
> + /* Current vma is not available, just break */
> + break;
Which means we break out here and report an incomplete output (the
numbers will be much smaller than reality).
Would it be better to have a loop like:
for (vma = priv->mm->mmap; vma;) {
smap_gather_stats(vma, &mss);
last_vma_end = vma->vm_end;
if (contended) {
/* drop/acquire lock */
vma = find_vma(mm, last_vma_end - 1);
if (!vma)
break;
if (vma->vm_start >= last_vma_end)
continue;
}
vma = vma->vm_next;
}
that way if the VMA is removed while the lock is dropped the loop can
just continue from the next VMA.
Or perhaps I missed something obvious? I haven't actually tested
anything above.
Steve
> + }
> }
>
> show_vma_header_prefix(m, priv->mm->mmap->vm_start,
>
next prev parent reply other threads:[~2020-08-12 8:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-11 4:42 [PATCH 0/2] Try to release mmap_lock temporarily in smaps_rollup Chinwen Chang
2020-08-11 4:42 ` [PATCH 1/2] mmap locking API: add mmap_lock_is_contended() Chinwen Chang
2020-08-11 4:42 ` [PATCH 2/2] mm: proc: smaps_rollup: do not stall write attempts on mmap_lock Chinwen Chang
2020-08-12 8:39 ` Steven Price [this message]
2020-08-12 9:26 ` Chinwen Chang
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=bf40676e-b14b-44cd-75ce-419c70194783@arm.com \
--to=steven.price@arm.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=chinwen.chang@mediatek.com \
--cc=daniel.m.jordan@oracle.com \
--cc=dbueso@suse.de \
--cc=jgg@ziepe.ca \
--cc=jimmyassarsson@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=matthias.bgg@gmail.com \
--cc=songliubraving@fb.com \
--cc=vbabka@suse.cz \
--cc=walken@google.com \
--cc=willy@infradead.org \
--cc=wsd_upstream@mediatek.com \
--cc=ying.huang@intel.com \
/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 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).