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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5BB5C25B0E for ; Mon, 15 Aug 2022 13:47:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3F9168D0002; Mon, 15 Aug 2022 09:47:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 380BD8D0001; Mon, 15 Aug 2022 09:47:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1FA578D0002; Mon, 15 Aug 2022 09:47:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 092538D0001 for ; Mon, 15 Aug 2022 09:47:25 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id D504E1A0E82 for ; Mon, 15 Aug 2022 13:47:24 +0000 (UTC) X-FDA: 79801954008.08.A2E1773 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) by imf29.hostedemail.com (Postfix) with ESMTP id 7E71E1201C5 for ; Mon, 15 Aug 2022 13:47:24 +0000 (UTC) Received: by mail-wr1-f53.google.com with SMTP id h13so9143423wrf.6 for ; Mon, 15 Aug 2022 06:47:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc; bh=Yns/Jpj95x/nJs+G87dScDOGDHWXu34AZre/Qatzji0=; b=tdkveuBu6uaMJub+24M/znCUtI3DkObWNMw10VbS9Nd/vD8SzGgbPG38IsiEeqbxkx v3WNuqJmqbWiuztrkUQHhrrykz3j04t5AbBbAmOGwR+3iZvGnZ4qj2wNYwDjhclPm/T3 yvvFwFHnbcx8SJ/4lIJK5+zhKaAZ7kT5LZ9QMswh7fdUtMlqTcauTcQFCgMCtGuXTM4x hVhdsLvc0FSKpmTELK5Lxtu8mlm9ksa21N4HDWXQigzhdAqmuClT7WHe9WGXfrXKHuyv xrTii1J3G3ZdH/w0tZWGUHSoyEaJphj3Z4dTmw/yLRw4bbftBtoucTKx8M6591O16k3h QpDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc; bh=Yns/Jpj95x/nJs+G87dScDOGDHWXu34AZre/Qatzji0=; b=qPRlP4hSSXU8LVcyziJFPg78NEk4V6YOzkJGkWEZWjJ8O4014WZAxk7zX8wCLh2Ge8 9Ye1tPtKTBzayeVmvoNGLkN3u5ejrhik31tJ0Dq+VtXxa2ZdQQI9b9zxZNSI/I8OBfYY kw9Xi7lxZG7Xhn9v1g3v+OY60Ci9tjWl8bkCbERVvSKGR3nJOYR16TpbsLwgCcrdQXap P1nBRM9QbSO1SBQOH+gZi9QhJmheGMO4qVblhLo7Y8GtZpiezca1Qm8MMxvWbObJsTDV kRFOlwOsccbuFNJBFX85MmGx2einZeWuD0M/o+gRL03kgZhj2yCXCbNLomdLrYG+DuXF /l+g== X-Gm-Message-State: ACgBeo1V/AXMyLAsicOl+zPQefBGUzvz9At8wQA3iF1c6LBuL3Th2yUt vmKw4qxVwVQfhAK8aASamTGQ1g+y4rR7ZcRfUBBABw== X-Google-Smtp-Source: AA6agR4DOqHCZB04YdslrHQLwV2PFDkZOo7chPxQ87lDW+6PmW4Um6uzPKlV2MDf8WQMBUTWzl1zVobDEFlakYPOxpI= X-Received: by 2002:a5d:4b03:0:b0:220:6b87:8f0f with SMTP id v3-20020a5d4b03000000b002206b878f0fmr8949012wrq.534.1660571242998; Mon, 15 Aug 2022 06:47:22 -0700 (PDT) MIME-Version: 1.0 References: <20220811081913.102770-1-liliguang@baidu.com> <1704B09B-F758-47DF-BDDE-FEA9AB227E12@baidu.com> In-Reply-To: From: Yosry Ahmed Date: Mon, 15 Aug 2022 06:46:46 -0700 Message-ID: Subject: Re: [PATCH] mm: correctly charge compressed memory to its memcg To: "Li,Liguang" Cc: Shakeel Butt , Andrew Morton , Linux-MM , Cgroups , Johannes Weiner , Michal Hocko , Muchun Song , Roman Gushchin Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=tdkveuBu; spf=pass (imf29.hostedemail.com: domain of yosryahmed@google.com designates 209.85.221.53 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660571244; a=rsa-sha256; cv=none; b=jGUYSu3WxyxO/aRhAN+j0q8LY0/QHAc0u+2kt7ae15ZUlxYEvOVElKWFetx7T0beXpYWFM HH/q5ceXa8pm+zQaK1IqwoALm5rcMLm48yBgByla+T2FNDaDQndoZCQ0t0RU/Srpo0IzSI ywAl0zBiEkoH4kAI+v4bSgy64M4B8GA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660571244; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Yns/Jpj95x/nJs+G87dScDOGDHWXu34AZre/Qatzji0=; b=SKRN1Umh6gidZZjXhRP540OuSMPJNsqjoNrc1+QHS3Fxhq0f+iOY+4p4h0g8cYFek4k11M mPuScEfzogzOluQNNy8mSWpxbL6qp5QH7xf+nJhovKbTuIYmYY2VLxbgJ5eF3kQF8mlvD+ NYROYdGaGmB/2X94cB243/trQnKPhW4= Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=tdkveuBu; spf=pass (imf29.hostedemail.com: domain of yosryahmed@google.com designates 209.85.221.53 as permitted sender) smtp.mailfrom=yosryahmed@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspam-User: X-Rspamd-Server: rspam12 X-Stat-Signature: c8ru3eofbbaw1i5s3jqtmnzzxhqb4sjd X-Rspamd-Queue-Id: 7E71E1201C5 X-HE-Tag: 1660571244-927288 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: On Mon, Aug 15, 2022 at 4:48 AM Li,Liguang wrote: > > > > =E5=9C=A8 2022/8/15 =E4=B8=8B=E5=8D=884:10=EF=BC=8C=E2=80=9CYosry Ahmed= =E2=80=9D =E5=86=99=E5=85=A5: > > > > On Sun, Aug 14, 2022 at 7:52 PM Li,Liguang wrote: > > > > > > =E5=9C=A8 2022/8/13 =E4=B8=8A=E5=8D=888:44=EF=BC=8C=E2=80=9CYosry Ahm= ed=E2=80=9D =E5=86=99=E5=85=A5: > > > > > > > On Fri, Aug 12, 2022 at 2:56 PM Shakeel Butt = wrote: > > > > > > > > > > +Andrew & linux-mm > > > > > > > > > > On Thu, Aug 11, 2022 at 5:12 PM Roman Gushchin wrote: > > > > > > > > > > > > On Thu, Aug 11, 2022 at 04:19:13PM +0800, liliguang wrote: > > > > > > > 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. > > > > > > > > > > > > > > Signed-off-by: Li Liguang > > > > > > > --- > > > > > > > mm/memcontrol.c | 2 +- > > > > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > > > > > > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > > > > > > > index b69979c9ced5..6a95ea7c5ee7 100644 > > > > > > > --- a/mm/memcontrol.c > > > > > > > +++ b/mm/memcontrol.c > > > > > > > @@ -2971,7 +2971,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()) > > > > > > > > > > > > Won't the memcg_kmem_enabled() check also cause a problem in that s= ame > > > > scenario (e.g. if CONFIG_MEMCG_KMEM=3Dn)? or am I missing something > > > > here? > > > > > > > > > > Please notes that the return value is a pointer to obj_cgroup, not me= mcg. > > > If CONFIG_MEMCG_KMEM=3Dn or memcg kmem charge is disabled, the NULL n= eed > > > to be returned. > > > > > > > Right. I am not implying that the check should be removed, or that > > this is something this patch should address for that matter. > > > > I just realized while looking at this patch that because we are using > > objcg in zswap charging, it is dependent on memcg kmem charging. I am > > not sure I understand if such dependency is needed? IIUC swapped out > > pages hold references to the memcg they are charged to anyway, so why > > do we need to use objcgs in charging zswap? I feel like I am missing > > something. > > > > The compressed size of swapped out pages is nearly a quarter of its RAM, > and a page in the zswap can store multiple compressed swapped out > pages. So objcg is used here. > > Please check this post for more information. > https://lore.kernel.org/lkml/20220510152847.230957-1-hannes@cmpxchg.org/T= /#mbd0254ffd377bf843ac50850bf0a6d41505a925a Yeah I understand this much, what I don't understand is why we charge the zswap memory through objcg (thus tying it to memcg kmem charging) rather than directly through memcg. > > > > > > > > > > > > > return NULL; > > > > > > > > > > > > > > if (PageMemcgKmem(page)) { > > > > > > > -- > > > > > > > 2.32.0 (Apple Git-132) > > > > > > > > > > > > > > > > > > > Hi Li! > > > > > > > > > > > > The fix looks good to me! As we get objcg pointer from a page a= nd not from > > > > > > the current task, memcg_kmem_bypass() doesn't makes much sense. > > > > > > > > > > > > Acked-by: Roman Gushchin > > > > > > > > > > > > Probably, we need to add > > > > > > Fixes: f4840ccfca25 ("zswap: memcg accounting") > > > > > > > > > > > > Thank you! > > > > > > > > > > You can add: > > > > > > > > > > Acked-by: Shakeel Butt > > > > > > > > >