Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5862366pxb; Tue, 16 Feb 2021 09:18:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJySGUfde/hik6kZPpCLrc8BKDiqxGJUozJmKxFAAzlL1env0KxvyjquhEosuVDnalF6q6ak X-Received: by 2002:a17:907:98a8:: with SMTP id ju8mr21017519ejc.35.1613495911200; Tue, 16 Feb 2021 09:18:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613495911; cv=none; d=google.com; s=arc-20160816; b=forWfyviHsGIhBDbjev2q+Me0Tv+TBuT2eA6JW9tY/5sqsG8anIn7NZw7MOnXxeWd3 YynJjWSP1E6TLMnEgwZY2eWUPa1mXFq03us4oEhok45/2UyXSpZCuqKJ5//QBFbGgRRL gCqJngCQro7cfPBajQEkdeNswK2D1jk/3vb0C4YAe8onb19cmZ9VOl2LDOo0pEiC566C l9AOUpQGTA4+kYpS+Zl4dB0HAjrrlE5tL19wCS7DO0jXH4F6PB+H6xGfW+HcsP8Bh/da GX9D9mu3MaGxh1zgT8RXZsVjzZe8FNTuPZ/TltpJsymWVXUVH1wTYQayF39ToQoV6yq4 vJoA== 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=E45USrfwyuPTU85r3q5N9FFFgs4PphB6lqH5aUk4Cag=; b=CUtiIdoe9BYKSqX4kNNlA8Tvw0hbmVLyN7XSpki8BqtQk0pcKgHLH501NaMyXBu/WS CFhQr+zlBma1/vlrCOxJNK0pf5Le/5zmZUBsisq1Dzk6iiltXGM/Shd0fXl3YjTwF0sB FcWbdJy38QLpMCAv/G8dbrcjcJ/TR+6QLEqIEBjTAo2ticZFWY+I/oLhxAuxwSgFYUww gMT/tQg+Ry93UfH6KHdCwNvnUApO3+le0SUkCGKyrRhoxEIEvqZo2/OcLlSF2mZp/L/c 0f1z/KUkIwKP8WhkG1BZJ1mYaztPLosadYUWcOScj64nFaWjuFCt3l9/bzKb0VA0tB4S uI2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=uKAmePCY; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p18si14754745ejy.191.2021.02.16.09.18.07; Tue, 16 Feb 2021 09:18:31 -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=@google.com header.s=20161025 header.b=uKAmePCY; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230481AbhBPRRY (ORCPT + 99 others); Tue, 16 Feb 2021 12:17:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230429AbhBPRRX (ORCPT ); Tue, 16 Feb 2021 12:17:23 -0500 Received: from mail-lj1-x231.google.com (mail-lj1-x231.google.com [IPv6:2a00:1450:4864:20::231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEC11C061574 for ; Tue, 16 Feb 2021 09:16:37 -0800 (PST) Received: by mail-lj1-x231.google.com with SMTP id j6so12806757ljo.5 for ; Tue, 16 Feb 2021 09:16:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=E45USrfwyuPTU85r3q5N9FFFgs4PphB6lqH5aUk4Cag=; b=uKAmePCYTggNcKv8e6HwrE/wfBPlHBLs09fukIDn1Ad8eGiyXdq6UVoUHACc5UoJCE 3zvOhCdBL7paJpiTVqgjW/9Ln+PbRjS+i/9EK2u5XKpZQ8iRUEu1fvlDnBpoENJ61vJV xamLT1E0WOt/77sNcTXjJxBpkwIl5RrePfmtw0KFg2DKLqob1a4wdYxNfEB6iY+zZQLh T73T2gxzFEIfdIthKZ+fVjxhiCYxIDTziJVgXH7GQiAJOCvGXQZK0xyN017joVbw4A0I vLlIr+HnHG9caI+/8IiRynC1jQ7pDqyTTR8CIPFBsuFA8z4k9Hp5BTpdMneZU8Fsi1uF 2WVg== 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=E45USrfwyuPTU85r3q5N9FFFgs4PphB6lqH5aUk4Cag=; b=Ev3MRDUvFgM2o+VyfNRneuwGlkt9KKY/9+fy/+LKRNqEG4DG3QVGKmc0NrxCSh5K70 HBaHttCuu5eICkjsi8GEiIx9vbLX4H0/1XOtUbxfe5Ki0K5B3bPqhOeSTuDvVirEnNoh WqxwbtT5GAx0EGsGffSMO9y3Reo0YSGkrsoeNug0ip6TPiWLMnAhLfZFSVctyvYeym/4 53FFNEFfQEjerepO5s8sns59BpmvGVueV0qPWpuLrkZwlOgEFyJuYE4CYwJq52ZXE7Nt yrYmuu6W1UvIVvDhhQXz9EaBmhjx6L7ESy5U2lMEKX1LIaEcIcvS0KRHXdgS6oe+sYO6 myPQ== X-Gm-Message-State: AOAM533pUGX702IQjCBC5G8ZHt4uIUyNLcbeX7hjcBVKrnmIydAkBqfP 9FUuyr96VEt4PlRP4MeMwEUINWsJ8a/jsaKXD4xmPQ== X-Received: by 2002:a2e:9806:: with SMTP id a6mr12304184ljj.456.1613495795934; Tue, 16 Feb 2021 09:16:35 -0800 (PST) MIME-Version: 1.0 References: <20210212170159.32153-1-songmuchun@bytedance.com> <20210212170159.32153-4-songmuchun@bytedance.com> In-Reply-To: From: Shakeel Butt Date: Tue, 16 Feb 2021 09:16:24 -0800 Message-ID: Subject: Re: [External] Re: [PATCH 4/4] mm: memcontrol: fix swap uncharge on cgroup v2 To: Muchun Song Cc: Huang Ying , Tim Chen , Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Cgroups , Linux MM , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 12, 2021 at 10:48 PM Muchun Song wrote: > > 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. > I was trying to repro this but couldn't and later remembered that swap on zram skips the swapcache and thus is not impacted by this issue. This is reproducible on swap on disk and I see Johannes has already described in good detail.