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 30936C4332F for ; Mon, 5 Dec 2022 01:43:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231241AbiLEBn4 (ORCPT ); Sun, 4 Dec 2022 20:43:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231292AbiLEBnz (ORCPT ); Sun, 4 Dec 2022 20:43:55 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 461B412D12 for ; Sun, 4 Dec 2022 17:43:55 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D81C460F43 for ; Mon, 5 Dec 2022 01:43:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39829C433D7; Mon, 5 Dec 2022 01:43:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1670204634; bh=ZspARiB4pMvfwYI+ahpbCtAhWqJjvApLI52noAu9JBk=; h=Date:To:From:Subject:From; b=HO9TV/7rc1s8Vie++xuffNi4QBgBvF7l0inRcd7Ml4UVufNN7C0qBlZFur9B2T2kd +Dop8rVBBzA0t1LmMPXIJ4E6OJ/4Ldeq5H+N1KVJzQ+ea94U/Q0GPcM9c7Qz0U80nL C2vcn3Qabi639sw9yBTezzCzt7jOSHu+bqHQQ9co= Date: Sun, 04 Dec 2022 17:43:53 -0800 To: mm-commits@vger.kernel.org, yuzhao@google.com, shakeelb@google.com, roman.gushchin@linux.dev, mhocko@suse.com, hannes@cmpxchg.org, hughd@google.com, akpm@linux-foundation.org From: Andrew Morton Subject: + mm-memcg-fix-swapcached-stat-accounting.patch added to mm-unstable branch Message-Id: <20221205014354.39829C433D7@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: memcg: fix swapcached stat accounting has been added to the -mm mm-unstable branch. Its filename is mm-memcg-fix-swapcached-stat-accounting.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-memcg-fix-swapcached-stat-accounting.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: Hugh Dickins Subject: mm: memcg: fix swapcached stat accounting Date: Sun, 4 Dec 2022 17:01:03 -0800 (PST) I'd been worried by high "swapcached" counts in memcg OOM reports, thought we had a problem freeing swapcache, but it was just the accounting that was wrong. Two issues: 1. When __remove_mapping() removes swapcache, __delete_from_swap_cache() relies on memcg_data for the right counts to be updated; but that had already been reset by mem_cgroup_swapout(). Swap those calls around - mem_cgroup_swapout() does not require the swapcached flag to be set. 6.1 commit ac35a4902374 ("mm: multi-gen LRU: minimal implementation") already made a similar swap for workingset_eviction(), but not for this. 2. memcg's "swapcached" count was added for memcg v2 stats, but displayed on OOM even for memcg v1: so mem_cgroup_move_account() ought to move it. Link: https://lkml.kernel.org/r/b8b96ee0-1e1e-85f8-df97-c82a11d7cd14@google.com Fixes: b6038942480e ("mm: memcg: add swapcache stat for memcg v2") Signed-off-by: Hugh Dickins Cc: Johannes Weiner Cc: Michal Hocko Cc: Roman Gushchin Cc: Shakeel Butt Cc: Yu Zhao Signed-off-by: Andrew Morton --- mm/memcontrol.c | 6 ++++++ mm/vmscan.c | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) --- a/mm/memcontrol.c~mm-memcg-fix-swapcached-stat-accounting +++ a/mm/memcontrol.c @@ -5756,6 +5756,12 @@ static int mem_cgroup_move_account(struc } } +#ifdef CONFIG_SWAP + if (folio_test_swapcache(folio)) { + __mod_lruvec_state(from_vec, NR_SWAPCACHE, -nr_pages); + __mod_lruvec_state(to_vec, NR_SWAPCACHE, nr_pages); + } +#endif if (folio_test_writeback(folio)) { __mod_lruvec_state(from_vec, NR_WRITEBACK, -nr_pages); __mod_lruvec_state(to_vec, NR_WRITEBACK, nr_pages); --- a/mm/vmscan.c~mm-memcg-fix-swapcached-stat-accounting +++ a/mm/vmscan.c @@ -1368,11 +1368,10 @@ static int __remove_mapping(struct addre if (folio_test_swapcache(folio)) { swp_entry_t swap = folio_swap_entry(folio); - /* get a shadow entry before mem_cgroup_swapout() clears folio_memcg() */ if (reclaimed && !mapping_exiting(mapping)) shadow = workingset_eviction(folio, target_memcg); - mem_cgroup_swapout(folio, swap); __delete_from_swap_cache(folio, swap, shadow); + mem_cgroup_swapout(folio, swap); xa_unlock_irq(&mapping->i_pages); put_swap_folio(folio, swap); } else { _ Patches currently in -mm which might be from hughd@google.com are tmpfs-fix-data-loss-from-failed-fallocate.patch mm-memcg-fix-swapcached-stat-accounting.patch