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=-14.8 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1, USER_IN_DEF_DKIM_WL autolearn=no 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 400DCC433E0 for ; Fri, 5 Mar 2021 23:21:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D416F650A3 for ; Fri, 5 Mar 2021 23:21:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D416F650A3 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 29DC16B006E; Fri, 5 Mar 2021 18:21:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 274656B0070; Fri, 5 Mar 2021 18:21:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1151C6B0071; Fri, 5 Mar 2021 18:21:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0046.hostedemail.com [216.40.44.46]) by kanga.kvack.org (Postfix) with ESMTP id E7A086B006E for ; Fri, 5 Mar 2021 18:21:06 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 9B22B1DF7 for ; Fri, 5 Mar 2021 23:21:06 +0000 (UTC) X-FDA: 77887393332.15.AA8A83B Received: from mail-oo1-f46.google.com (mail-oo1-f46.google.com [209.85.161.46]) by imf19.hostedemail.com (Postfix) with ESMTP id 7535590009EF for ; Fri, 5 Mar 2021 23:21:05 +0000 (UTC) Received: by mail-oo1-f46.google.com with SMTP id l11so826597oov.13 for ; Fri, 05 Mar 2021 15:21:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=r0cTPvXdPd9aXoIuTSiB+0BptUG2HNyX6VD0hnKItjg=; b=IbW9BqWseyXJunfwk6vypcVhPM+2f00lqu+yPIf3i41yBB3U5kG6VJwHyyyzipvUcp Jdclyo7xbJuBiOMrpb+Xx8T4Y8lg73KtuHhrAZcbWI8SKiUkS61MweoA31Psyv9zholn qSagH5RJmp3v8GEPtNkbIfOC2ukMr68AEhnOeuR+z9ftl9I/2ghIBnJxLPNhlEAh7+vk JSKIdRV1Pmp+08NC0NUfZ/EnxiirZfHnuEsdaiUqDTT6qqJPzWnBtUuDCT/s4UZn/TeD 47KfBlUwFBGH+ZLQ47DM7ivUbE88YHaKoQXHKYxF5Kodqils0+P4mK4R1D5nnRjkLRRJ uqBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=r0cTPvXdPd9aXoIuTSiB+0BptUG2HNyX6VD0hnKItjg=; b=HAIZUFsy+sEe726vgndXNf3/ch3Z/KmuKlih4VTVi7uUOTh/YI/THQE7OotEG7FtzW aJZldltISUDEqcRcIQICSvqado8vI/zdmGtlvuMZx8I8EtObtdg+ywkBkb0foD5ScA0k +ih6x/tgcATM6FJsHd6D54tlSSDdACcUXjY+vYBtSo0Vl8tOSMB2sMQfPd5UTUHiEiTz h9TUL0iTI3oYxRR4MOJFrNzfuvQA+HYzVSEPqd880T46Vz1qIR4ZLV5MySuWLKmDaQQ1 l04k9WcToq/rAKrLDvaJ26xVk0Zf/IJC+UDp2UI400fduOnmkAjMt3fpTpED2S4d5FqN e9KA== X-Gm-Message-State: AOAM5315NIFHQDs4zBPstY3HxWLHs+7RL/LE2qMNdoSbTACTOpwiI1+A upEpdLdtlVtW7q76hlU2FpKBNA== X-Google-Smtp-Source: ABdhPJyMn01Wil1haFmcAK+6+8fcnT0623GSoZtJmaRyLgGlXr9kwy3JOLmI4ArIAhR8ycFa8AgYWw== X-Received: by 2002:a4a:8ed2:: with SMTP id c18mr9855324ool.66.1614986465301; Fri, 05 Mar 2021 15:21:05 -0800 (PST) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id f193sm824054oig.8.2021.03.05.15.21.04 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Fri, 05 Mar 2021 15:21:04 -0800 (PST) Date: Fri, 5 Mar 2021 15:20:48 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Shakeel Butt cc: Hugh Dickins , Johannes Weiner , Roman Gushchin , Michal Hocko , Andrew Morton , Cgroups , Linux MM , LKML Subject: Re: [PATCH v4] memcg: charge before adding to swapcache on swapin In-Reply-To: Message-ID: References: <20210305212639.775498-1-shakeelb@google.com> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 7535590009EF X-Stat-Signature: uky8dc4b81y6y56jednkn7ip3qcetea1 Received-SPF: none (google.com>: No applicable sender policy available) receiver=imf19; identity=mailfrom; envelope-from=""; helo=mail-oo1-f46.google.com; client-ip=209.85.161.46 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614986465-592332 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 Fri, 5 Mar 2021, Shakeel Butt wrote: > On Fri, Mar 5, 2021 at 1:26 PM Shakeel Butt wrote: > > > > Currently the kernel adds the page, allocated for swapin, to the > > swapcache before charging the page. This is fine but now we want a > > per-memcg swapcache stat which is essential for folks who wants to > > transparently migrate from cgroup v1's memsw to cgroup v2's memory and > > swap counters. In addition charging a page before exposing it to other > > parts of the kernel is a step in the right direction. > > > > To correctly maintain the per-memcg swapcache stat, this patch has > > adopted to charge the page before adding it to swapcache. One > > challenge in this option is the failure case of add_to_swap_cache() on > > which we need to undo the mem_cgroup_charge(). Specifically undoing > > mem_cgroup_uncharge_swap() is not simple. > > > > To resolve the issue, this patch introduces transaction like interface > > to charge a page for swapin. The function mem_cgroup_charge_swapin_page() > > initiates the charging of the page and mem_cgroup_finish_swapin_page() > > completes the charging process. So, the kernel starts the charging > > process of the page for swapin with mem_cgroup_charge_swapin_page(), > > adds the page to the swapcache and on success completes the charging > > process with mem_cgroup_finish_swapin_page(). > > And of course I forgot to update the commit message. > > Andrew, please replace the third paragraph with the following para: > > To resolve the issue, this patch decouples the charging for swapin pages from > mem_cgroup_charge(). Two new functions are introduced, > mem_cgroup_swapin_charge_page() for just charging the swapin page and > mem_cgroup_swapin_uncharge_swap() for uncharging the swap slot once the > page has been successfully added to the swapcache. Lgtm Hugh