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 68024C433E0 for ; Sat, 13 Feb 2021 06:48:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B1F7C64E8E for ; Sat, 13 Feb 2021 06:48:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B1F7C64E8E 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 D46548D00BA; Sat, 13 Feb 2021 01:48:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CF4CE8D0060; Sat, 13 Feb 2021 01:48:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C0B1D8D00BA; Sat, 13 Feb 2021 01:48:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0055.hostedemail.com [216.40.44.55]) by kanga.kvack.org (Postfix) with ESMTP id AC1D48D0060 for ; Sat, 13 Feb 2021 01:48:55 -0500 (EST) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 662988248068 for ; Sat, 13 Feb 2021 06:48:55 +0000 (UTC) X-FDA: 77812317030.16.slope63_4b0b33427627 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin16.hostedemail.com (Postfix) with ESMTP id 491CE100E690B for ; Sat, 13 Feb 2021 06:48:55 +0000 (UTC) X-HE-Tag: slope63_4b0b33427627 X-Filterd-Recvd-Size: 5633 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by imf23.hostedemail.com (Postfix) with ESMTP for ; Sat, 13 Feb 2021 06:48:54 +0000 (UTC) Received: by mail-pf1-f176.google.com with SMTP id 189so934551pfy.6 for ; Fri, 12 Feb 2021 22:48:54 -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=SvQPbY0JLL8of3BGGDOMIdtAbjg+M4/SFz/IP/02qIQ=; b=Qmi3QON0oQEQ54YUbGatNEp0xc3/YNtLOTVVx5KzgbwD6xLzcXH/g0Co9uJ4dpyYop wCV9HN1/bZZtAG7NippRen0hStG1KmbBWuUhyoPCUPn0aVe76tYiOAJRG2YYt6hRQtKv Bx6NTRQBgq79QZVKQHdOufm5Xia6818VExEwaGiI+EqLuZfqqdfab+u/NcZ0IK2NeM7V SXIbsxeWwFN8VB7pcGuHkvYGNVhb9kVO695jHYGzPvZrQEaTmOiyCfe28kfQGRN5NYPm KFtsQOlyUxqbSqeq9FONIci5vl5CNHjpXEZpy6cOU+C1ILj9zOOagrDctqSrFJdxYJ4W hyaQ== 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=SvQPbY0JLL8of3BGGDOMIdtAbjg+M4/SFz/IP/02qIQ=; b=iN0HlBYEw8P7wP8zqDmCDmfCGgzAXAXdxZnGY908E+Sdhnnq69CjZf5CUHw3qT2FIR ejiPcojyIArbF6lyDz7tO23nY6kzEXcwJfOKTvfKcKsHbmF65EOuf3VVKm//tVY+kUd1 w4o51wnpUzBvSH629pARX02nin64IyNVz3nLK7x1NOpcZlKjQ0EHTfAHTVZqTjxV0lBD KnFq6iWsnnrA6ixiqruRmeI3LEAs9Fbqbxq8C9kI4OeSLlTKxOqIsO3VNHgH3ixFrUTF RWuJjogtxgEJVikW3ZqW5IzJ0Yfm7FEJ7h0crfqrAVd9jP7/e4EtMv7ieHBRiV2o5ZKr SPLg== X-Gm-Message-State: AOAM5317rpIeDxmpvFWJj9OQ15BCZ52itQd5czdETUPxRl2azSpJrd5g i8wHugEhLGcHi5nN4AC7t57hCrf61uT5j7e9c9fBKg== X-Google-Smtp-Source: ABdhPJxFm5ytrRIuo5OjrqHSAJy0svKyn32Z3N76DjduuptVRhBbBAX9PzKNFsNshl5LDiFRrqXBfTlYJZrJPN0ykdg= X-Received: by 2002:a63:480f:: with SMTP id v15mr6451732pga.341.1613198933433; Fri, 12 Feb 2021 22:48:53 -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: Sat, 13 Feb 2021 14:48:16 +0800 Message-ID: Subject: Re: [External] Re: [PATCH 4/4] mm: memcontrol: fix swap uncharge on cgroup v2 To: Shakeel Butt Cc: Huang Ying , Tim Chen , Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Cgroups , Linux MM , LKML Content-Type: text/plain; charset="UTF-8" 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 Sat, Feb 13, 2021 at 2:57 AM Shakeel Butt wrote: > > CCing more folks. > > On Fri, Feb 12, 2021 at 9:14 AM 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. > > > > Fixes: 2d1c498072de ("mm: memcontrol: make swap tracking an integral part of memory control") > > Signed-off-by: Muchun Song > > What's the user visible impact of this change? 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. > > One impact I can see is that without this patch meminfo's (SwapTotal - > SwapFree) is larger than the sum of top level memory.swap.current. > This change will reduce that gap. > > BTW what about per-cpu slots_ret cache? Should we call > mem_cgroup_uncharge_swap() before putting in the cache after this > change? > > > --- > > 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 > >