From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF03EC3063F for ; Mon, 3 Jul 2023 17:18:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230377AbjGCRSi (ORCPT ); Mon, 3 Jul 2023 13:18:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230052AbjGCRSi (ORCPT ); Mon, 3 Jul 2023 13:18:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D32A01B2 for ; Mon, 3 Jul 2023 10:18:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 584F460FCD for ; Mon, 3 Jul 2023 17:18:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9D7FC433C7; Mon, 3 Jul 2023 17:18:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1688404715; bh=zjT4Zya04HoGew2xH6ThW24OR7QPO8LripJtdLTrXnc=; h=Date:To:From:Subject:From; b=JgFzAinmPNbAffHac4OWMkvYoa0pGkb4YF1oPhd0jvfKbsEH9ANS2TZQLDepoeiSG HnlBJZZ+pUwZct4yEMS1S+oMsmRS391RD5XDHXEFy5jbAok5Z2r8P3a1jV8usvHc5u PAoxmJPG1syJnFYSzsOzmNrqepE58q5oPBI9GHxk= Date: Mon, 03 Jul 2023 10:18:34 -0700 To: mm-commits@vger.kernel.org, surenb@google.com, quic_smanapra@quicinc.com, quic_pkondeti@quicinc.com, minchan@kernel.org, hannes@cmpxchg.org, quic_charante@quicinc.com, akpm@linux-foundation.org From: Andrew Morton Subject: + mm-madvise-fix-uneven-accounting-of-psi.patch added to mm-unstable branch Message-Id: <20230703171835.A9D7FC433C7@smtp.kernel.org> Precedence: bulk Reply-To: linux-kernel@vger.kernel.org List-ID: X-Mailing-List: mm-commits@vger.kernel.org The patch titled Subject: mm: madvise: fix uneven accounting of psi has been added to the -mm mm-unstable branch. Its filename is mm-madvise-fix-uneven-accounting-of-psi.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-madvise-fix-uneven-accounting-of-psi.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Charan Teja Kalla Subject: mm: madvise: fix uneven accounting of psi Date: Mon, 3 Jul 2023 19:36:41 +0530 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/ Link: https://lkml.kernel.org/r/1688393201-11135-1-git-send-email-quic_charante@quicinc.com Signed-off-by: Charan Teja Kalla Suggested-by: Suren Baghdasaryan Reported-by: Sai Manobhiram Manapragada Reported-by: Pavan Kondeti Cc: Johannes Weiner Cc: Minchan Kim Cc: Pavankumar Kondeti Signed-off-by: Andrew Morton --- mm/madvise.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/mm/madvise.c~mm-madvise-fix-uneven-accounting-of-psi +++ a/mm/madvise.c @@ -413,6 +413,8 @@ static int madvise_cold_or_pageout_pte_r 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)) @@ -510,6 +512,8 @@ regular_folio: */ 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)) _ Patches currently in -mm which might be from quic_charante@quicinc.com are mm-madvise-fix-uneven-accounting-of-psi.patch