From patchwork Mon Oct 5 02:40:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chinwen Chang X-Patchwork-Id: 11816037 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B20246CA for ; Mon, 5 Oct 2020 02:40:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4ADA6207C4 for ; Mon, 5 Oct 2020 02:40:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="Ypj8JnFP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4ADA6207C4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=mediatek.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1D6B86B005D; Sun, 4 Oct 2020 22:40:34 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 162A28E0001; Sun, 4 Oct 2020 22:40:34 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 04FA96B0068; Sun, 4 Oct 2020 22:40:33 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0168.hostedemail.com [216.40.44.168]) by kanga.kvack.org (Postfix) with ESMTP id C9E5F6B005D for ; Sun, 4 Oct 2020 22:40:33 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 55750181AE870 for ; Mon, 5 Oct 2020 02:40:33 +0000 (UTC) X-FDA: 77336318346.27.dogs62_4d00060271ba Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin27.hostedemail.com (Postfix) with ESMTP id 3CBFF3D663 for ; Mon, 5 Oct 2020 02:40:33 +0000 (UTC) X-Spam-Summary: 1,0,0,d306e9fac386b9ef,d41d8cd98f00b204,chinwen.chang@mediatek.com,,RULES_HIT:41:355:379:541:800:966:967:973:988:989:1260:1277:1311:1313:1314:1345:1437:1515:1516:1518:1535:1542:1711:1730:1747:1777:1792:2196:2198:2199:2200:2393:2525:2559:2565:2570:2682:2685:2693:2703:2859:2914:2933:2937:2939:2942:2945:2947:2951:2954:3022:3354:3622:3865:3866:3867:3868:3870:3871:3872:3873:3934:3936:3938:3941:3944:3947:3950:3953:3956:3959:4250:4321:4385:4605:5007:6120:6261:7875:7901:7903:8660:8957:9025:10004:10400:11658:13148:13161:13229:13230,0,RBL:210.61.82.183:@mediatek.com:.lbl8.mailshell.net-64.201.201.201 62.14.12.100;04yfmih7eh1nepci65u7ikawp417uycry7iyq5g5xuxrj47e5djuwuo1urjys1t.18ie8s1wxm98weu8m948bow636e5edoz5coe9r7ib4f6pz789ghr6jbzbes7ziz.a-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:294,LUA_SUMMARY:none X-HE-Tag: dogs62_4d00060271ba X-Filterd-Recvd-Size: 5070 Received: from mailgw01.mediatek.com (unknown [210.61.82.183]) by imf32.hostedemail.com (Postfix) with ESMTP for ; Mon, 5 Oct 2020 02:40:31 +0000 (UTC) X-UUID: abcd50912cb74f30bb7228f514ad075b-20201005 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=Y4xhx9IjgKvrJUycw+ZxzgJtq8e5cl3Sw5tNuSRwHcw=; b=Ypj8JnFP+BHkFzEVeI9hZn9O3w+HuumPGuvsrgHNMiJY91ZzCuyikt0l3zTCVAPUy8/R2Bs97jO58jM/knVCGeHdsUaxIPGlNYj3RJfPEUxNauaUOKiQk+zAD8XYJ7k4h+HHZndyhkylar9QT2bE54xt5JzYYLXVNS6cL6I0McA=; X-UUID: abcd50912cb74f30bb7228f514ad075b-20201005 Received: from mtkcas08.mediatek.inc [(172.21.101.126)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.14 Build 0819 with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1694006210; Mon, 05 Oct 2020 10:40:26 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs08n1.mediatek.inc (172.21.101.55) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 5 Oct 2020 10:40:25 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkcas07.mediatek.inc (172.21.101.84) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 5 Oct 2020 10:40:25 +0800 Received: from mtkswgap22.mediatek.inc (172.21.77.33) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 5 Oct 2020 10:40:25 +0800 From: Chinwen Chang To: Andrew Morton CC: , Subject: [RESEND,PATCH v4 0/3] Try to release mmap_lock temporarily in smaps_rollup Date: Mon, 5 Oct 2020 10:40:11 +0800 Message-ID: <1601865614-4918-1-git-send-email-chinwen.chang@mediatek.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-MTK: N X-Bogosity: Ham, tests=bogofilter, spamicity=0.000784, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Recently, we have observed some janky issues caused by unpleasantly long contention on mmap_lock which is held by smaps_rollup when probing large processes. To address the problem, we let smaps_rollup detect if anyone wants to acquire mmap_lock for write attempts. If yes, just release the lock temporarily to ease the contention. smaps_rollup is a procfs interface which allows users to summarize the process's memory usage without the overhead of seq_* calls. Android uses it to sample the memory usage of various processes to balance its memory pool sizes. If no one wants to take the lock for write requests, smaps_rollup with this patch will behave like the original one. Although there are on-going mmap_lock optimizations like range-based locks, the lock applied to smaps_rollup would be the coarse one, which is hard to avoid the occurrence of aforementioned issues. So the detection and temporary release for write attempts on mmap_lock in smaps_rollup is still necessary. Change since v1: - If current VMA is freed after dropping the lock, it will return - incomplete result. To fix this issue, refine the code flow as - suggested by Steve. [1] Change since v2: - When getting back the mmap lock, the address where you stopped last - time could now be in the middle of a vma. Add one more check to handle - this case as suggested by Michel. [2] Change since v3: - last_stopped is easily confused with last_vma_end. Replace it with - a direct call to smap_gather_stats(vma, &mss, last_vma_end) as - suggested by Steve. [3] [1] https://lore.kernel.org/lkml/bf40676e-b14b-44cd-75ce-419c70194783@arm.com/ [2] https://lore.kernel.org/lkml/CANN689FtCsC71cjAjs0GPspOhgo_HRj+diWsoU1wr98YPktgWg@mail.gmail.com/ [3] https://lore.kernel.org/lkml/db0d40e2-72f3-09d5-c162-9c49218f128f@arm.com/ Chinwen Chang (3): mmap locking API: add mmap_lock_is_contended() mm: smaps*: extend smap_gather_stats to support specified beginning mm: proc: smaps_rollup: do not stall write attempts on mmap_lock fs/proc/task_mmu.c | 96 +++++++++++++++++++++++++++++++++++---- include/linux/mmap_lock.h | 5 ++ 2 files changed, 92 insertions(+), 9 deletions(-)