From patchwork Tue Jun 27 10:33:12 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: 13294335 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 393EAEB64D9 for ; Tue, 27 Jun 2023 10:33:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B68088D0002; Tue, 27 Jun 2023 06:33:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AC71E8D0001; Tue, 27 Jun 2023 06:33:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 941358D0002; Tue, 27 Jun 2023 06:33:45 -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 7E6C28D0001 for ; Tue, 27 Jun 2023 06:33:45 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 13624A0915 for ; Tue, 27 Jun 2023 10:33:45 +0000 (UTC) X-FDA: 80948166810.02.6F322D9 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by imf08.hostedemail.com (Postfix) with ESMTP id B9406160019 for ; Tue, 27 Jun 2023 10:33:42 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=NIHdoA++; spf=pass (imf08.hostedemail.com: domain of quic_charante@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_charante@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687862023; 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=KNfM7LtSPiwBmqZlNfK7ibDUjnF4FMfkSTe1KSMBQEA=; b=FKk/6CRNp4rBolpQQNUg+HZyqEAGyNSVsPIWdAMI3Q9YHFc0kqY7NaXQ+wv9JwzI1U7rs5 CViar6NEnin5gN+pKZ2SDlcitXck6iPwglwd3IggEz9fyeJR17Zr4pzMDKh4YjFt60oiYp yje096/X/IJd8VN+Jk+AFZT05DGC/Qo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687862023; a=rsa-sha256; cv=none; b=rTbCjUlU/M9b2e3rolGthI+m/mxHX8MRLCtyC6E/ff9LFELtnuGNLJAfyQQ/R2oYwIzvVf Axs9GpQhV1yISQ8Bk9Be5vhDP7wHRVG6yjDJJPMeZAxTU9hCz6dbe7tYz20vLrMhn06QdM Uvz9PcUReIfW+RV2B92Deux4EY6ZeNQ= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=NIHdoA++; spf=pass (imf08.hostedemail.com: domain of quic_charante@quicinc.com designates 205.220.168.131 as permitted sender) smtp.mailfrom=quic_charante@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35R6DeUa022382; Tue, 27 Jun 2023 10:33:36 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=KNfM7LtSPiwBmqZlNfK7ibDUjnF4FMfkSTe1KSMBQEA=; b=NIHdoA++jQ2lUqsWmW4PYcagoLjDwqAsSH2dgCsSHUftWqz78VP0uBRMsU5qRLYitFzU uMecvmP7hJzTmvbMEeBh/1+LmjnmY80HCkfm7+TmAMhXFZS1r8QIXAp/kYvhJECxnfrQ zAvU6CMu2LmTxEFs/RRwLrj2JvAxgE+IA1pcmdhwvJOEmQZOS+wEudfvhJHPOAmgISg6 f4KGTpiuKc1Kbv+p4nmEtZggjh61aAMtIId3epGvn3DOWpgZPEvWkKXTbmrQSvHF705T yJgGMjRI10q8cZySuPXvKX+CLDziCBvAefV8TvmRnnfOh2fw4vGRL3bJyy7HP4Lu3Luy 9Q== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3rfartacnv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Jun 2023 10:33:35 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 35RAXZkQ026200 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Jun 2023 10:33:35 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; Tue, 27 Jun 2023 03:33:32 -0700 From: Charan Teja Kalla To: , , , CC: , , , , Charan Teja Kalla Subject: [PATCH V2] mm: madvise: fix uneven accounting of psi Date: Tue, 27 Jun 2023 16:03:12 +0530 Message-ID: <1687861992-8722-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: UM7BJlhXhIMhYVR-PACN7WE7fg6XDZyc X-Proofpoint-ORIG-GUID: UM7BJlhXhIMhYVR-PACN7WE7fg6XDZyc 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-06-27_06,2023-06-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 clxscore=1011 bulkscore=0 mlxscore=0 lowpriorityscore=0 impostorscore=0 priorityscore=1501 suspectscore=0 malwarescore=0 spamscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306270096 X-Stat-Signature: 777yrjwdg3rrsqtt4ajhp411om7ujzcb X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: B9406160019 X-Rspam-User: X-HE-Tag: 1687862022-265847 X-HE-Meta: U2FsdGVkX19Lwbqdts8xiIbktFeg3x7f65OAIM3q4xFF7LOFOvPwQj2rznQJOfZ4pZ2oBlxS9hqVlRRpR2P0vGfF1JgZeGgLDoi0+5IuRcG1miTflsuYphdIvQz/5X4g5cNhUEUJEIj5nZBs4a+PD9WD3BFD5OPAtaNy1V7alC3H78/+U0UnaSA+QKvb5xM+3yhS1AxSWs8E/9tx5v2opB1wshEgKKucgfsxJrEWG/FvW8Y1XBNP9Qq47patETTdYDBznuy79gRvi5qkJPWsgcFVsl0AbZhzQml97nau1R3EhbA0X7hQ4SbU+UgDH0AqHskprmqYRCpGkKrTkELy8pm7i3mIyxxqUOWdlpQE7m8Od2ztLZ5mU0K+uK5Ay1rnHvyjzdoHc6lKAcNxxUhFqtkR3Sa9+rhVf5aUK2ipgc6OxH81gQ3e+Ar28PDdV812naTPXYuk80TAX4DZ/yMmsfP8F93URsmtSh5H1OA3T/6Xry1p73xsermSPwbX0NwGqx1KPFQMaZzv35EcH7EA1VCXFriyJuDXUxkUDzqZSUy8L8CrWGLHkTpvPpaN3+YfV0XGyauYBMCp/XMm76ESBcHAAihS5yW7v/MSIetG/FQ/LWcT7GaPdPwmlTfY5GZHR+JJH7MkOkvlfAdOdPqLA/fXFjSAnvIGtIlC9WiGSqVtI/MFQvq91HIQepVyLrKSTXxXrjEg6Vr8CO87+4pzvpZsq/l9bwxdevKqOlsCKfa5Y25PpFHpcO2T9ntqwldmXKuIyUUonbKMOUU9AP2wFETayQdBBNSpsnMzZkScgGsV+vYgYMFgSIriMaGWkS20Pig3hk3Fl2TSfdB4TmoAeHMp6+M4MRYxmWwx78hPSmLsXqvz6cyQ+KD9sxqcUx1cJbZIja2eIG6FRgQPHJCMkMeKQN4Z6QTzofMON5hFdNp7lxZ66AS2Iz9WbIySA8gV8hJGM46rZ+e5YfOjIzW 4bFV1Bdf nRD1zzB7jmK7d4hvqx4MpPfGfbn4lxohCpCs7TvrUwBM4AVJ9CQ4ipYSUWnhpYT4gW0F6p50Z/E5DgFzU+4jNOoNES/ogHgEszRc7qsovr3Szi8AnAUtpl6EmPujkvFxjO4N162hzroBaNv+xTd8xxW6isq8/ykpTtw4GmqdbpbGS6zXWZIJKeYLM6aToHzNR/HH2FM6+SkoAMjA2isl7IyJK3Zwdq+kLc801kRVYf7AhR1JqgjRftYj329q1lDVwyKjY2w54BkEEKRx+6G0UEebM2S9mo/Qkyhw1OAFd1TV99hHQaTzxb9Ha0yrpkQXN2CGq4iGuur3i61T9CEItu8Vw3lMHD98mlYZAAhGBVHHOrlLr7CxirpFAPkWoFfWNtah/ 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. This accounting of PSI for memory is not consistent in the cases where clients use madvise(COLD/PAGEOUT) to 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 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 both the operations of MADV_PAGEOUT and reclaim of the MADV_COLD operated folio account for PSI. d) madvise(MADV_COLD) transfers the folio from active list to inactive list. Such folios may not have the Workingset thus reclaim operation on such folio doesn't account for PSI. As said above, the MADV_PAGEOUT on a folio is accounts for memory PSI in b) and c) but not in a). Reclaim of a folio on which MADV_COLD is performed accounts memory PSI in c) but not in d) which is an inconsistent behaviour. 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 --- V2: Made changes as per the comments from Johannes/Suren. V1: https://lore.kernel.org/all/1685531374-6091-1-git-send-email-quic_charante@quicinc.com/ mm/madvise.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/madvise.c b/mm/madvise.c index d9e7b42..76fb31f 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -413,6 +413,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, folio_clear_referenced(folio); folio_test_clear_young(folio); + folio_set_workingset(folio); if (pageout) { if (folio_isolate_lru(folio)) { if (folio_test_unevictable(folio)) @@ -512,6 +513,7 @@ static int madvise_cold_or_pageout_pte_range(pmd_t *pmd, */ folio_clear_referenced(folio); folio_test_clear_young(folio); + folio_set_workingset(folio); if (pageout) { if (folio_isolate_lru(folio)) { if (folio_test_unevictable(folio))