From patchwork Mon Nov 14 19:48:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Weiner X-Patchwork-Id: 13042766 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 1DB87C4332F for ; Mon, 14 Nov 2022 19:48:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3E9906B0071; Mon, 14 Nov 2022 14:48:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 399508E0001; Mon, 14 Nov 2022 14:48:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 261066B0073; Mon, 14 Nov 2022 14:48:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 1676F6B0071 for ; Mon, 14 Nov 2022 14:48:10 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id AD126140EAE for ; Mon, 14 Nov 2022 19:48:09 +0000 (UTC) X-FDA: 80133083898.16.EE6F577 Received: from mail-qv1-f45.google.com (mail-qv1-f45.google.com [209.85.219.45]) by imf28.hostedemail.com (Postfix) with ESMTP id D30FFC000E for ; Mon, 14 Nov 2022 19:48:08 +0000 (UTC) Received: by mail-qv1-f45.google.com with SMTP id w10so8446626qvr.3 for ; Mon, 14 Nov 2022 11:48:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=omJyx+p3MZnXmMetOfD+Vb81mPQBWZRFtKehGT/esV0=; b=oPRUVWptCQQmFoRVOuC0Bg4LNaPVc12ejrt634brCi0WT/hC+s0sQDVTF10pFjtxTY 2yzL0yNRUHUd1oX17N/BxcyF/qmvW3QhZXrPtNzOoYFRIF5RqMINMd8PvVISkRHPY2nu 68op9yrb34dqOW+3Y/FmdRZGxNalulMhlZOhIWvbmehB0CgB/lnmP/jC1uO6+q+bozBP R2kGUT3x9G/BALjKomL4YolNC6TRbHvc0sb4+upz0vx0CduE+3gfG/V/K3kVbe2xce5l UexYq0kHvri6fpktU2NgA+FKrK4tHRhL88cyTTD/yRn0z7X5yBdQ4jbRxt0ut+v9nLt0 MaLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=omJyx+p3MZnXmMetOfD+Vb81mPQBWZRFtKehGT/esV0=; b=79QTvOn0uxa0Z19cl/w8hjvQUIXXeCA16kI9a47Q9quUJBd/NWQG/XD+Bb5B8swct1 xKl0r/Lxw/NMzZnqzeMdJnbgit7H/CKmIe3MdRCe0ll/0ULSza8GDuYqt/WeGgghTWXm Xz7fSJWfiVbb5dwVnh6xr+Mp8oKK8mqdp7rJKuUOAkNMgvrXVXzAQUzUBdeHFC+uSNm3 CFPTdOwU2xKXL9jZ4R+2Q5WWSZG7i28KremmCywNx2gIkFkjMi1pG1qfDS3U8wzRqkNu GP+Jbh0yBEz1OBQyoTlhh0g7V++YP+1w1XXtnOw/uLXYamm88iESxnKqe7oVjCN0oarD /mHQ== X-Gm-Message-State: ANoB5pleBZG6S354KA6D7JuOekl7rs2smPl23rUboqmhJQf0i4vYA5T/ /WnboUm+Q0NkiqPznNWz0GPt1A== X-Google-Smtp-Source: AA0mqf4wUNlfuKye4Owp4CiIw1RKoijXmW0oaG+ryyGoW8oK71GRxdThjAXUznrw22jSjvSwItFBFA== X-Received: by 2002:a05:6214:2b9c:b0:4bb:684e:c94f with SMTP id kr28-20020a0562142b9c00b004bb684ec94fmr13996725qvb.52.1668455287880; Mon, 14 Nov 2022 11:48:07 -0800 (PST) Received: from localhost ([2620:10d:c091:480::1:e032]) by smtp.gmail.com with ESMTPSA id s36-20020a05622a1aa400b0039cc944ebdasm6121471qtc.54.2022.11.14.11.48.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 11:48:07 -0800 (PST) From: Johannes Weiner To: Andrew Morton Cc: linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, Li Liguang , stable@vger.kernel.org, Shakeel Butt , Muchun Song Subject: [PATCH] mm: correctly charge compressed memory to its memcg Date: Mon, 14 Nov 2022 14:48:28 -0500 Message-Id: <20221114194828.100822-1-hannes@cmpxchg.org> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668455289; a=rsa-sha256; cv=none; b=u6Fh1IqDZfTGp0ilh9oh7rm07Ei9mjgXO50vQPssd1FiBLKKHhY+0r0lvF7EFRNucCaL9L I8/Jn7mFo1OfZoK1TXwwLuZocC64yHBbK1KDnDessRbqqGG6rPLHi52yEhhqz3B7Zjn3NH Z4Wt3Q8h8ZSQzYb1Rd04EpE8H2mr4ZY= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=oPRUVWpt; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf28.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.45 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668455289; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=omJyx+p3MZnXmMetOfD+Vb81mPQBWZRFtKehGT/esV0=; b=KuerSKOnuQIEgxmc3W96FC7WnxhIJkSrWqk5MURqz50cyyyVAzGE9a/6ywiwvIKXfpB/bx ReUKzaoDqhakbZwAINcW6prloUDhSgbWbOPPv1mWLMMbR3zNVNHbqGgcZ/TJLof7LBXQOJ DpBS3OCSn4vTFjLxsHRVs3UOzd+97sQ= X-Rspamd-Queue-Id: D30FFC000E X-Rspam-User: Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=oPRUVWpt; dmarc=pass (policy=none) header.from=cmpxchg.org; spf=pass (imf28.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.219.45 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org X-Rspamd-Server: rspam06 X-Stat-Signature: tgyc8dke6r11ygqh65k7eueotwgqh7ji X-HE-Tag: 1668455288-362758 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: From: Li Liguang Kswapd will reclaim memory when memory pressure is high, the annonymous memory will be compressed and stored in the zpool if zswap is enabled. The memcg_kmem_bypass() in get_obj_cgroup_from_page() will bypass the kernel thread and cause the compressed memory not charged to its memory cgroup. Remove the memcg_kmem_bypass() and properly charge compressed memory to its corresponding memory cgroup. Link: https://lore.kernel.org/linux-mm/CALvZod4nnn8BHYqAM4xtcR0Ddo2-Wr8uKm9h_CHWUaXw7g_DCg@mail.gmail.com/ Fixes: f4840ccfca25 ("zswap: memcg accounting") Cc: stable@vger.kernel.org # 5.19+ Acked-by: Shakeel Butt Acked-by: Shakeel Butt Reviewed-by: Muchun Song Signed-off-by: Li Liguang Signed-off-by: Johannes Weiner --- mm/memcontrol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) This fell through the cracks in summer as it didn't make it to the right mailing lists. Resending. I know it's close to 6.1-final, but the fix should be safe to put in. It's straight-forward and obvious code-wise. We also have large parts of production running on it without problems. diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 2d8549ae1b30..a1a35c12635e 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3026,7 +3026,7 @@ struct obj_cgroup *get_obj_cgroup_from_page(struct page *page) { struct obj_cgroup *objcg; - if (!memcg_kmem_enabled() || memcg_kmem_bypass()) + if (!memcg_kmem_enabled()) return NULL; if (PageMemcgKmem(page)) {