From patchwork Wed May 31 11:09:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charan Teja Kalla X-Patchwork-Id: 13261980 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93CE8C77B7C for ; Wed, 31 May 2023 11:10:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1C3BB8E0005; Wed, 31 May 2023 07:10:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 173348E0001; Wed, 31 May 2023 07:10:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 03AFC8E0005; Wed, 31 May 2023 07:10:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E826A8E0001 for ; Wed, 31 May 2023 07:10:34 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 47951802EC for ; Wed, 31 May 2023 11:10:34 +0000 (UTC) X-FDA: 80850281988.19.310BBDB Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf28.hostedemail.com (Postfix) with ESMTP id EDBECC0011 for ; Wed, 31 May 2023 11:10:30 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=BYrFiJLH; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf28.hostedemail.com: domain of quic_charante@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_charante@quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685531431; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=w0KeEXQFRBlqfa9GOpSBvyxn8umTaMqKZQuHqMXdjpA=; b=njb5smA9jKpzIBkI8WWGMyMBP5e8vbJJv/cZxfRdb2drrwhbVHJka2cc+MTRANEsVjg6Y5 FBGhcRLcPztYy6NcIRKWWvnJhKcsnQ3WCtUqmo/B5iYpUdUhg5EFxlB5AoH6sFCyT+qU4m bNhtXTBMPLw+2yZu+mhWlUIUu+9mMak= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=BYrFiJLH; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf28.hostedemail.com: domain of quic_charante@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_charante@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685531431; a=rsa-sha256; cv=none; b=XHwItEToXRYgr9ySedUuckGac9AywLuA142gfRFwFHa3+sNjtC8kYaiB+sZJ1cMr8bMgUn 14yTHPMQNX8W3vzYJwGwe0hm/N8cKy0zggTUIp+b/lScZIicQIQUQZy+MInZPIfMOZ69PJ Lgl0xnwtOxrKlWSZP+6h8tfMgqrX5P8= Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 34V7el0v001988; Wed, 31 May 2023 11:10:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=qcppdkim1; bh=w0KeEXQFRBlqfa9GOpSBvyxn8umTaMqKZQuHqMXdjpA=; b=BYrFiJLHtjk0VQJVQznbTf3qdu1iPJckp2ZIih/aQTDZhMVPYozPTSYAHxhOlecPmkTR 9ZH52rjZPZCxfqFQ9K3S9vrtVb/CuyBIhXTlhU7LpScdMlFj5cmhFT9+2HtwxJ5xpyt4 9D2RvYeJjQcmetD8QkqqOmqFeBiYrS7SclkWfxtQwa9Q3XSBHcMNGgAM/9rFyTUCfKgq iD8GNsp4h4GhYWsZYxINCaXF40ziPeAdkpYhqAnJwUeTYR7OahDyiaOKSvf0j2/DXNaG cPXx83bjZKrFe5txEnDeL10GGwfCOao+zoO0sfIpSMHjB2OMrJ3lYcB+05+rkP6L/wrL MQ== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3qx0sbrkeg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 31 May 2023 11:10:21 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 34VBAHxM016538 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 31 May 2023 11:10:18 GMT Received: from hu-charante-hyd.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Wed, 31 May 2023 04:10:15 -0700 From: Charan Teja Kalla To: , , CC: , , , Charan Teja Kalla Subject: [PATCH] mm: madvise: fix uneven accounting of psi Date: Wed, 31 May 2023 16:39:34 +0530 Message-ID: <1685531374-6091-1-git-send-email-quic_charante@quicinc.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: vIMLouYFIPeLAVxXQXv94qn2SwORAR8K X-Proofpoint-ORIG-GUID: vIMLouYFIPeLAVxXQXv94qn2SwORAR8K X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-05-31_06,2023-05-31_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 mlxlogscore=999 mlxscore=0 lowpriorityscore=0 phishscore=0 impostorscore=0 priorityscore=1501 clxscore=1011 bulkscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2304280000 definitions=main-2305310096 X-Rspamd-Queue-Id: EDBECC0011 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: nych8j5pq3qwtxa7zsgtx13dkeqcoufb X-HE-Tag: 1685531430-780430 X-HE-Meta: U2FsdGVkX1/YsyDdvg8UTEIk4vX58WV6bBr/6L+QM6eeT6/fn+wrh42+SyPAYrnl06nb4Y7uAeGyo4XPDPVqQzdWQRMGi/Fhe2ZmMzi5zyCXvpTeU29hVah1hghw/gQsQU3qWeNOqMaY6fRePXFkWgLT6uRijUmTsgtRo2gE4DWKx0BtrJ1U62MjyWgci/21ItSGVyr6wIhTtJm1K2PcQ0EfI0wFICk1f8Ch14OhR0rmuNmyoAG33Demb352EMkfoeFa8eRQzEzauJBXng+KOCo9zIhtilNHDdSeTkNdCteLv2wgRYNV50n2Peyd89/9vdoLnV65IYpJnMOS0/kBAt5afdyKAnUPv1xlTbUkOZsQyCJ62P9xQYysLEhR4UOdW86+uS8SKLNI3On1L3vgPKoxsSHbHGo8jqwjdBdZTqb0o2jN5Pp4Bbm+I4CVSonzbxgehOsTu8y15bFcs5IasOwnbpvvdsZLdu1WXD4aTIZ8JIC6mcNKPc2T1aQwgAPmqhHtuyt1CgweC1B6B18H/NM7uTtBlL6uKRBUeXWJG7NG5UMyfj+pJSHQvIT5aRoi7QMA1rWEsLLW6M5hU2wj5d1O0NdGcqOPyDjHbRkV9HVQLK1SY2KZpoXhEsz8LCKoEcXmZmTEZbBYWlzY0IpcahEOupwNfnJgEPaE7Z3Y60SraCWemzkCiQ0iH17mx0LpfSJW3LGoIBF+/Nzm++ZVdB1Ju5bS8Z+fIEj6IqKLFGq0e4Ci8FvMTx78oMFyKJhsIjczbUH+OdSY5Rgrm6yB6itQ8AUxOJ50nFvNN9mzV75UoQrEjMU50hCaCh8tHj5c9ax2FvNLZV2gf/s4HxRqa9X0d+Xmkn/h9JGWBmDGQhUCmL3UskHbNEZCYS7sgtwDom3jUx2jF04BmrVW+KnF8CYyJbRU2CpjQiQF+OlKQY43uD/ZlE3lmH5E4CN51PS4tpRAY/GGco2XXN2+21T 1uyszVz0 qrUS98JlVybHKgeVOrNjH25/Yy36GM77sbu2I5I6FoqzEpyNaIylhUotwJSOj0n0vzLA/TT+HawnikWTMjdQR5qjdrAi4AQjhjmorlcPmkT2QxpC0r5g42xp0M6V3H2UYODNH/D8tBqgz4mXMWv67BegMK5Tlra8LjDRQNKUTL2e25DjuOZ8xaKHyqaEsVutVdT3cAlMVoJUq/o57IL8Og3YBlXZ1HBGD6KzYeO09vjbRI4JrtcGoldg7U2X2TT+c+xOARVOQjuEUvqQfyuti518EF3wLxDoN/7FDJyyPfOiWN3OGgeJJ/36OIqjLmTjlYiDE1XgXnubJDmc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: A folio turns into a Workingset during: 1) shrink_active_list() placing the folio from active to inactive list. 2) When a workingset transition is happening during the folio refault. And when Workingset is set on a folio, PSI for memory can be accounted during a) That folio is being reclaimed and b) Refault of that folio. There exists clients who can do the proactive reclaim using the system calls like madvise(), whose folios can be safely treated as inactive folios assuming the client knows that these folios are not needed in the near future thus wanted to reclaim them. For such folios psi is not accounted uniformly: a) A folio started at inactive and moved to active as part of accesses. Workingset is absent on the folio thus madvise(MADV_PAGEOUT) don't account such folios for PSI. b) When the same folio transition from inactive->active and then to inactive through shrink_active_list(). Workingset is set on the folio thus madvise(MADV_PAGEOUT) account such folios for PSI. c) When the same folio is part of active list directly as a result of folio refault and this was a workingset folio prior to eviction. Workingset is set on the folio thus madvise(MADV_PAGEOUT) account such folios for PSI. As said about the MADV_PAGEOUT on a folio is accounted in b) and c) but not in a) which is inconsistent. Remove this inconsistency by always not considering the PSI for folios that are getting reclaimed through madvise(MADV_PAGEOUT) by clearing the Workingset on a folio. This consistency of clearing the workingset was chosen under the assumption that client knows these folios are not in active use thus reclaiming them hence not eligible as workingset folios. Probably it is the same reason why workingset is not set on a folio through MADV_COLD but during the shrink_active_list() though both the actions make the folio put onto the inactive list. This patch is tested on Android, Snapdragon SoC with 8Gb RAM, 4GB swap mounted on zram which has 2GB of backingdev. The test case involved launching some memory hungry apps in an order and do the proactive reclaim for the app that went to background using madvise(MADV_PAGEOUT). We are seeing ~40% less total values of psi mem some and full when this patch is combined with [1]. [1]https://lore.kernel.org/all/20220214214921.419687-1-hannes@cmpxchg.org/T/#u Signed-off-by: Charan Teja Kalla --- mm/madvise.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index 340125d..3410c39 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -409,8 +409,10 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, if (folio_isolate_lru(folio)) { if (folio_test_unevictable(folio)) folio_putback_lru(folio); - else + else { + folio_clear_workingset(folio); list_add(&folio->lru, &folio_list); + } } } else folio_deactivate(folio); @@ -503,8 +505,10 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, if (folio_isolate_lru(folio)) { if (folio_test_unevictable(folio)) folio_putback_lru(folio); - else + else { + folio_clear_workingset(folio); list_add(&folio->lru, &folio_list); + } } } else folio_deactivate(folio);