From patchwork Mon Jul 3 14:06:41 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: 13300179 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 A0048EB64DC for ; Mon, 3 Jul 2023 14:07:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2DA19280005; Mon, 3 Jul 2023 10:07:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 28975280001; Mon, 3 Jul 2023 10:07:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 150F4280005; Mon, 3 Jul 2023 10:07:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 059CA280001 for ; Mon, 3 Jul 2023 10:07:29 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C623012092E for ; Mon, 3 Jul 2023 14:07:28 +0000 (UTC) X-FDA: 80970478176.19.506E030 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by imf23.hostedemail.com (Postfix) with ESMTP id 30419140067 for ; Mon, 3 Jul 2023 14:07:13 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=IOpVsP20; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf23.hostedemail.com: domain of quic_charante@quicinc.com designates 205.220.168.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=1688393234; 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=1wxDIUyK/AiVZYBoO+Xsd4mjrqxHTTfot/+BBVdBvzs=; b=iP89q44DlSbWM9AnFbbbb0CJNPM1DUhPOcDtybT0GcZCjPz+pKq079TX9WS0U3IlLKeiY3 7On/aqdZbcVrcZ5r0/vbjPC0HxBdGow1UW9wYm5qs10VZtS+nKC4MSOsuhivIWHABzV0/g ZpJ+ILXctUT9ueb1D/+IZk06F9pC2QA= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=IOpVsP20; dmarc=pass (policy=none) header.from=quicinc.com; spf=pass (imf23.hostedemail.com: domain of quic_charante@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_charante@quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688393234; a=rsa-sha256; cv=none; b=eDIAmztGFpZUzO/ya9+h681ukVM5v/FASeRwZgCv8qflmccAtun6vpmk4hD72K+jsccNmw qWbqt8JiygOOh3//2VwlEg6jmeUdDcVCx8mLjUtqF4qbh3zHYlAU4foMxvYh7etuydBnv4 aSMBo0tF2wXsXuH6Lh3pfVBCpf21/s0= Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3639x5Jp024460; Mon, 3 Jul 2023 14:07:05 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=1wxDIUyK/AiVZYBoO+Xsd4mjrqxHTTfot/+BBVdBvzs=; b=IOpVsP20GY0CJaBoNPe+rbKFKY2t+zj53Zn0AuxoJdFFDlQna3hZAvVohOs1y6KtxZRK lLOyPUoc/FC7fSb6YcKJef5Q50b7qo0RNGxPAwytzPVTEh9LXN4zar7OfUf+tQckWlT9 a33+tS4+rWrjzPa2XuNTnpJ3ITGvyYrcYYbi6kzf05BlggEvk6LTpNbb/BiFFjfHJQ5f YtJTMdkolX/VVZn6H784jJXUFOdJjCOWjm2as+1bzTTW9cF4mw1FEt8R+0KX7JzYhj0v 0x27KX6Ndnvsfmf9C32TbcgLHShzwCdj0cDRlsHYuR4AQumB4x9DskgQZbo9GouQ3NPB sA== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3rjday3yt3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 03 Jul 2023 14:07:04 +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 363E74le013803 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 3 Jul 2023 14:07:04 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.1118.7; Mon, 3 Jul 2023 07:07:01 -0700 From: Charan Teja Kalla To: , , , CC: , , , , Charan Teja Kalla Subject: [PATCH V3] mm: madvise: fix uneven accounting of psi Date: Mon, 3 Jul 2023 19:36:41 +0530 Message-ID: <1688393201-11135-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-ORIG-GUID: UvyzWPktQeHm9UAUH417xKvX8T74p-qh X-Proofpoint-GUID: UvyzWPktQeHm9UAUH417xKvX8T74p-qh X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-03_10,2023-06-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 impostorscore=0 malwarescore=0 phishscore=0 spamscore=0 suspectscore=0 lowpriorityscore=0 bulkscore=0 mlxlogscore=999 mlxscore=0 priorityscore=1501 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2307030127 X-Rspamd-Queue-Id: 30419140067 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: patur6thnebb4ddkdwz5kgmpc9g3ra4f X-HE-Tag: 1688393233-24075 X-HE-Meta: U2FsdGVkX19WFu74nw26o5L8ffHEM32JQRQ9Bkr9Au0WXpKGVXujvIFvPdVjvgmQDa94VgV2XsoSkixK/uuPoiuO/x+GRWAg9Oswyiz5NwJVrMKOwAXEKqbjO//1XAfX204unhB4jA7fGDU1RalqEDh8jtkHlSQo/mG2KMB3KN4QMChGhFCTKFaGm73ts3AO/Yks+wjYZVL/2n0lmb+6C5lqBgKSlzqbfoWsDSuHhJpkhgc1x9NxFLpXgQZFVfslqqmLhmofhpw6UaYr7++xse5Tk53P2EYf1iHpa2nOZKuySRaPmEglS2pcou8eaXnYxLCjKpxgnTfToncpyuXPOz2xlqpkwzZgOsKPPtmnoTKF35e6b3MsMM1cBVzUamYUM6HaI9a5IW2pZTO03bnyTpobeQSZP4Yc63fwQZLqjjmyrK6yyd6pgiud82Ip469k0V9OSCX1s3MdWNzgRv3a+G40am20qX3v4rhgIeKuioMpiw2QjxnBD956s5x0nBTTqISFPhghDzn8U2VrhcJe/9YR9JECeE+RTK3n5AI2nrpi+ytznUOGS8qT2FkV4nqS5m5UDWyceLD+KEEQqCzdThtUtNg0Otr6FMymFvyKpx44ZAp10kbCdGf3TvNmEmP2zyTWU31jQ9+PeopK8fCjXVXg8EiINQmFJjk3ckO8O2bLa4A9nUtryOG90m0a651GWUvCQrV56cGBXjJY8yODEUnM/ASG0/61JL6Hn9Lndndr63lDEXCHJ6E1lxj3x/w/cN48Aui+kAulOCAuHiV8x7o5tYQ1rJXuY+Ny0BwU3JpCg0kTviTI/60KMUU9PV6aZT3+7rWkQOd6zmH/2bra/RpJ9QVQ90UmRLL5PVX0InkUiRVGv4sk0sasHcpPV6oBMnromYp91CYcBzsVpbpX1CoGu84JC2KT/NLogV4d6LyH3c5md6UUN3vfF1+RwMNUmlIKY90mGA//6BxLaK4 JiVKApi0 9mTZl2w1CIrMtY7rU2eHR5FgOfFs4N7WGaX2asEDkQPw8I0Z0Atnd21Jyv2jkhHwGovfXHVIyvySSb6j2upGgGLQjSrv5I2skNNebHlZ1J07vTDI+zwQbt3uPNkRdYJ//lBdbN6RktD55l3R4qfLWqVKiGEIHRd3uo0vwC70fmvwql9tCRyGPsZBnetAFASiMgeidxNJN6s+wT9q6JckXYTVraK2sf6zzVzuB7+28dBxt1uHRk1DjLekDDtHIN/jUae9qG8SKGuy7ExgSvkFCuoDa6XcPF95zfmYtmAPCzml9amg5LDMfM3grhepkPGGKSQGXQLAg60pHkhBsuT/XBZQ7PDZA+KispZzxogKdeSCMFb4QQ/EK/UMGr9D0/PjrDjOq X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, 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, for usual reclaims. This accounting of PSI for memory is not consistent for reclaim + refault operation between usual reclaim and madvise(COLD/PAGEOUT) which deactivate or proactively reclaim a folio: a) A folio started at inactive and moved to active as part of accesses. Workingset is absent on the folio thus refault of it when reclaimed through MADV_PAGEOUT operation doesn't account 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 refault of it when reclaimed through MADV_PAGEOUT operation accounts 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 the refault of it when reclaimed through MADV_PAGEOUT/MADV_COLD operation accounts for PSI. d) MADV_COLD transfers the folio from active list to inactive list. Such folios may not have the Workingset thus refault operation on such folio doesn't account for PSI. As said above, refault operation caused because of MADV_PAGEOUT on a folio is accounts for memory PSI in b) and c) but not in a). Refault caused by the reclaim of a folio on which MADV_COLD is performed accounts memory PSI in c) but not in d). These behaviours are inconsistent w.r.t usual reclaim + refault operation. Make this PSI accounting always consistent by turning a folio into a workingset one whenever it is leaving the active list. Also, accounting of PSI on a folio whenever it leaves the active list as part of the MADV_COLD/PAGEOUT operation helps the users whether they are operating on proper folios[1]. [1] https://lore.kernel.org/all/20230605180013.GD221380@cmpxchg.org/ Suggested-by: Suren Baghdasaryan Reported-by: Sai Manobhiram Manapragada Reported-by: Pavan Kondeti Signed-off-by: Charan Teja Kalla Acked-by: Johannes Weiner --- V3: Incorporated comments from Johannes/Pavan. V2: Made changes as per the comments from Johannes/Suren. https://lore.kernel.org/all/1687861992-8722-1-git-send-email-quic_charante@quicinc.com/ V1: https://lore.kernel.org/all/1685531374-6091-1-git-send-email-quic_charante@quicinc.com/ mm/madvise.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/madvise.c b/mm/madvise.c index d9e7b42..d00a843 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -413,6 +413,8 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, folio_clear_referenced(folio); folio_test_clear_young(folio); + if (folio_test_active(folio)) + folio_set_workingset(folio); if (pageout) { if (folio_isolate_lru(folio)) { if (folio_test_unevictable(folio)) @@ -512,6 +514,8 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, */ folio_clear_referenced(folio); folio_test_clear_young(folio); + if (folio_test_active(folio)) + folio_set_workingset(folio); if (pageout) { if (folio_isolate_lru(folio)) { if (folio_test_unevictable(folio))