Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4830004pxb; Mon, 15 Feb 2021 02:20:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJwi8Q3W8fVTWxKWLpWT2rHOiF8VgP6Q6FaxzY1GgH0jZWJ0O+QgVOGAlqXQtSl2B4ankamB X-Received: by 2002:a17:907:778e:: with SMTP id ky14mr14870558ejc.154.1613384423550; Mon, 15 Feb 2021 02:20:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613384423; cv=none; d=google.com; s=arc-20160816; b=tHozn02AIsGeixQF8eGtYs/jDN1ILs43pYX7KSqozuo3v42v0pQYB/sR7HDy9JeM4e jJJ6R6vtzNhan7IwUDdKs+QInTygOULLBrkhDV1jisYPbNAhXsJtdzIjIvMYO8txFAwN xdma22Yil/1FofM5Um8I+QpYnMzlaI2lPCCVFrVpZAh0PDf4qQNG526D1i04pD9bSN6S FpSlmhfB5HNhRhBVnD71ypTEitlCrocECbDyAQ6Loc+JUKgiBOd/jA+nJbuUlAgk/14r SBtCvIGFGWaH/3YydVETDyqnaD+xaU5L0Y0IoTP5mTD44YqsQUZ/kGNST433HSqITCoz qBNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=u1c7h/mK6g+ogVZX7ggIUmGlrcBSJghu81rDVUuKJeo=; b=eySsyu3vzlR6Ux108uMMJfEdzSR4QtntcLm5V4/EG7PHcKqGP1fs4xv2NUhADALP/9 fcG+xND23w0h05YCAiyRFtSHdZP7tUevNQcjgFAxZwbuQbPG01cZrc06ELspysYXdE12 O+fkKaS/GijfJneAEZAwGBUT+N/jJRpHjXyKA8bhRZEm4uXu1RVi181N4lijpz8avzcE nC+RqObeDp1yQcUR6+6SdUT1onoUVvWgIy+vcpK+R741QyKbbFR+4nQGA81+7LASvk5c mVtcAsVyCuASNTcLlSwPgecffd6drjG1iKxUSFPVu/0FqzkGR9I3jZxtlBymWF0rhwyY ijCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=0FW5axmz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t6si11935475edy.373.2021.02.15.02.20.00; Mon, 15 Feb 2021 02:20:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=0FW5axmz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229890AbhBOKQ4 (ORCPT + 99 others); Mon, 15 Feb 2021 05:16:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229627AbhBOKQx (ORCPT ); Mon, 15 Feb 2021 05:16:53 -0500 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C3A9C061574 for ; Mon, 15 Feb 2021 02:16:13 -0800 (PST) Received: by mail-pf1-x436.google.com with SMTP id q20so3891160pfu.8 for ; Mon, 15 Feb 2021 02:16:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=u1c7h/mK6g+ogVZX7ggIUmGlrcBSJghu81rDVUuKJeo=; b=0FW5axmzuWLUD9WPtpoYRed/CptLJiwqxxA0oC3HxYlqxYr6uBNojbzJPsUS8mQmkN vDFuP6SBiWLEd/VrJ+S/uJSQAFLY4Ou/4VgcHFNVse+ImTNKDedz2knB9JWla6RAZvG4 lr8hpfYy6vGcOCg28Kh7laHBDZ1r4Fc966DYiIwHqveX9UJb6Tn+PrW7IFxOmNEG+Qmy CELGwkYpG5+N3Z9/e7kkZF01HzyQnlM9RAXis+9nKiHiGKOLRp+FRGv29Wz3cU/ks2TL WLofAn/LIf3heA08rlSbJDpfaDFRBu5ZxClran+mrYIagZ7NE1v75Ep3V9JAmUPnuY8N 2Ogw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=u1c7h/mK6g+ogVZX7ggIUmGlrcBSJghu81rDVUuKJeo=; b=eVd/iruV1bdaofqxOleV9+fb/w5pnDqp9xrae2exmCmbyufFYUERzaCRmzZeO5n5ac ga2BT6dCIHuwNSPFHLMP7xfL+ujtkPlA4pw7XXxdpllEAFfTi1T0ZslaO2fl7ACBhjbx VJeM1QfMd/Ospx+BlY7vgSOTruNRrmS2urgWydsgz28WIOgzGTouPtpYa1jaU9O1dYts m9ScdD5rsC8ALg3FHENrk2IYMvVKA4tUgckMYtoQ9jcncSTIA1W03TT0W+hycYDi+JeZ syyMcJgzgCy4OxAufXwmgibiSkx24asnezHbp4Mbjka6/mnrFcZQrdb7n9QkOdjxbJBB 58Mw== X-Gm-Message-State: AOAM5337+RVpHY+84hAp6W/xYTrzHDXtzHeaXbUeczi48ksfcsnTbpDP vgcpjWJl6iNViiTg+emCBclOF0uKnoHp7tCiC9PLhg== X-Received: by 2002:a63:1f21:: with SMTP id f33mr14468774pgf.31.1613384172566; Mon, 15 Feb 2021 02:16:12 -0800 (PST) MIME-Version: 1.0 References: <20210212170159.32153-1-songmuchun@bytedance.com> <20210212170159.32153-4-songmuchun@bytedance.com> In-Reply-To: From: Muchun Song Date: Mon, 15 Feb 2021 18:15:36 +0800 Message-ID: Subject: Re: [External] Re: [PATCH 4/4] mm: memcontrol: fix swap uncharge on cgroup v2 To: Michal Hocko Cc: Johannes Weiner , Vladimir Davydov , Andrew Morton , Cgroups , Linux Memory Management List , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 15, 2021 at 5:47 PM Michal Hocko wrote: > > On Sat 13-02-21 01:01:59, Muchun Song wrote: > > The swap charges the actual number of swap entries on cgroup v2. > > If a swap cache page is charged successful, and then we uncharge > > the swap counter. It is wrong on cgroup v2. Because the swap > > entry is not freed. > > Is there any actual problem though? Can you describe the specific > scenario please? Swap cache charge life time is a bit tricky and I have > to confess I have to relearn it every time I need to understand it. The > patch would be much more easier to review if the changelog was much more > specific. I copied the reply to Shakeel here. :-) IIUC, I think that we cannot limit the swap to memory.swap.max on cgroup v2. cd /sys/fs/cgroup/ mkdir test cd test echo 8192 > memory.max echo 4096 > memory.swap.max OK. Now we limit swap to 1 page and memory to 2 pages. Firstly, we allocate 1 page from this memory cgroup and swap this page to swap disk. We can see: memory.current: 0 memory.swap.current: 1 Then we touch this page, we will swap in and charge the swap cache page to the memory counter and uncharge the swap counter. memory.current: 1 memory.swap.current: 0 (but actually we use a swap entry) Then we allocate another 1 page from this memory cgroup. memory.current: 2 memory.swap.current: 0 (but actually we use a swap entry) If we swap those 2 pages to swap disk. We can charge and swap those 2 pages successfully. Right? Maybe I am wrong. > > > Fixes: 2d1c498072de ("mm: memcontrol: make swap tracking an integral part of memory control") > > Signed-off-by: Muchun Song > > --- > > mm/memcontrol.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > > index c737c8f05992..be6bc5044150 100644 > > --- a/mm/memcontrol.c > > +++ b/mm/memcontrol.c > > @@ -6753,7 +6753,7 @@ int mem_cgroup_charge(struct page *page, struct mm_struct *mm, gfp_t gfp_mask) > > memcg_check_events(memcg, page); > > local_irq_enable(); > > > > - if (PageSwapCache(page)) { > > + if (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && PageSwapCache(page)) { > > swp_entry_t entry = { .val = page_private(page) }; > > /* > > * The swap entry might not get freed for a long time, > > -- > > 2.11.0 > > -- > Michal Hocko > SUSE Labs