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 X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE5EBC433DB for ; Mon, 15 Feb 2021 10:16:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5126D64E00 for ; Mon, 15 Feb 2021 10:16:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5126D64E00 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A27178D00EA; Mon, 15 Feb 2021 05:16:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D8F08D00E6; Mon, 15 Feb 2021 05:16:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8EDC88D00EA; Mon, 15 Feb 2021 05:16:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0222.hostedemail.com [216.40.44.222]) by kanga.kvack.org (Postfix) with ESMTP id 7A83D8D00E6 for ; Mon, 15 Feb 2021 05:16:14 -0500 (EST) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 3CA2E8248047 for ; Mon, 15 Feb 2021 10:16:14 +0000 (UTC) X-FDA: 77820097068.03.35689F1 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by imf03.hostedemail.com (Postfix) with ESMTP id D1044C0001EE for ; Mon, 15 Feb 2021 10:16:11 +0000 (UTC) Received: by mail-pg1-f177.google.com with SMTP id o63so3946838pgo.6 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=Jtj3JkPTH8xEOhmEKbw+oH3vYOIA1dCf6/gwV3kNQCP5xcscYSXQ5XQDHhY1gjDe8M tDVU97Zhdyeejr0dREMuZ4ypRlm7tn//N/+yCL0kka/WaBBBat/MbGufAEiSPEShEcey IFeDiFG+DBkk25gcdGgSpEOwu/ZzrjqBLrj8vGXcbr2fbjKgOe/LslzBcpP0lPhM2PI9 TIDR0Mr0y+y8hr98ZJEHXl2B3Wbg4/uwtdmQKRUpMLKDgFFuJQC7lgB5NRaPG3V/YAA4 gyHvFUtKEBGlhkU0r7Lh0glgd7rL4+80K6hb9svdINZneShGgyb2D5X1bOCvfuYkHhEe VmLg== X-Gm-Message-State: AOAM532axAb5IFgxbhdJ3J1a79PUdBg89b6F75HhScgHlXUsrV1xzRmb ZTH3M+Yc4F3jL8VEllDRCAFRKHn0SdnEPcasFMwdBw== X-Google-Smtp-Source: ABdhPJxXBRGesU5JU+bVoojrO9fDffFKJjc/jDshJpJ/mTgNuxqojW5PyGi2EYKVx7xEuXMzUYS0AgT4FZp6AbjIgl0= 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" X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D1044C0001EE X-Stat-Signature: mxy33zcs1o9fkripj87rfe8cwsufc9wk Received-SPF: none (bytedance.com>: No applicable sender policy available) receiver=imf03; identity=mailfrom; envelope-from=""; helo=mail-pg1-f177.google.com; client-ip=209.85.215.177 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1613384171-541067 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, 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