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.3 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_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 669BDC433DB for ; Fri, 5 Mar 2021 21:54:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BB629650A6 for ; Fri, 5 Mar 2021 21:54:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BB629650A6 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 340186B0006; Fri, 5 Mar 2021 16:54:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2EFBA6B006C; Fri, 5 Mar 2021 16:54:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 190EB6B006E; Fri, 5 Mar 2021 16:54:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0099.hostedemail.com [216.40.44.99]) by kanga.kvack.org (Postfix) with ESMTP id F36CF6B0006 for ; Fri, 5 Mar 2021 16:54:08 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id A73C75DDC for ; Fri, 5 Mar 2021 21:54:08 +0000 (UTC) X-FDA: 77887174176.10.DE661D8 Received: from mail-lj1-f174.google.com (mail-lj1-f174.google.com [209.85.208.174]) by imf13.hostedemail.com (Postfix) with ESMTP id 0AAF9E0011F1 for ; Fri, 5 Mar 2021 21:54:06 +0000 (UTC) Received: by mail-lj1-f174.google.com with SMTP id u4so4670204ljh.6 for ; Fri, 05 Mar 2021 13:54:07 -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=GsmMJABHzjW2imdiPFuBeArH9DaQyKHwBF7blWrk06o=; b=VYmZTqRzqRfXYYbPq4vU9UkIKIyFebUXF+fHNRjhr3iifCoNKRu+HHXLMeqm3xZDYH i/gCvMdtE+8hqyPAwuxNSjW68kzaprBvJIaGcDgPw+YIXsLC3xeJezFFtsAEpTKdOx/l E56fv7ugEoJKKG17KZJjvavpZVmn3wZVN2pFQitux0AKhBjP0+5b9tL5zUPEgg1DYfvp kqViuMiNWrI04N0ARC+2m8FUediMH3GRg0Otv+JUML8gKufh33kbXSd/Y/kxBGPAOsJl uYraYW1I5R8fGG6MeY5DxqeGmVMhAFur0jBoZOhgMofoB1vh/obnYN37d7XtUsZlSAn6 WBuw== 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=GsmMJABHzjW2imdiPFuBeArH9DaQyKHwBF7blWrk06o=; b=ps0c8aL5iaETARjjCz6vZSskYmPhNbBLo9gDFoNp3t8zDW/WH8HSAVoSbyFp07K+3g nxiVWQtVRNUliY5NMBeujK5WLEdCHaAL9pFKmo8o3g+MiZD9ij2KuHldPZllHt4/cTRs oVz9NYNjoSTUIcp/o5vcjgsPl9QhyUwxlxDGRaFMkhVRZmXwusQQo4JW+ahuamm3mh4N jC2Dky+Vq75a4Ic2nhQYlYjSvXAZ57NpGr4Mjs8l08xtVpZHXA09EhFEqNiLThRhqXox u0EfcR406br5IOE2Iwu/ypDUqMuvjLBJpt9wNSpJiQmUu5jK2J8nCjmxZWW7KLqfEdf5 Q/UQ== X-Gm-Message-State: AOAM530/vomf9VhnrLwEcx/nct9rBxDi2Z8UHGsxtjR1nDS56/Zr80/n XxZYn/mdfPJth5VLn89vLNnEIAHilnZ+dNql/Zb0Mw== X-Google-Smtp-Source: ABdhPJwOIepxZeN1ajeIR8EKiu0p/vlD2aPti7IKeBUrk0Xh0mg0RU2cYdzMCTqxs3DSJnhfPhO1OiTwxhYIVXVSTY0= X-Received: by 2002:a2e:9cc4:: with SMTP id g4mr6555699ljj.34.1614981246415; Fri, 05 Mar 2021 13:54:06 -0800 (PST) MIME-Version: 1.0 References: <20210305212639.775498-1-shakeelb@google.com> In-Reply-To: <20210305212639.775498-1-shakeelb@google.com> From: Shakeel Butt Date: Fri, 5 Mar 2021 13:53:54 -0800 Message-ID: Subject: Re: [PATCH v4] memcg: charge before adding to swapcache on swapin To: Hugh Dickins , Johannes Weiner Cc: Roman Gushchin , Michal Hocko , Andrew Morton , Cgroups , Linux MM , LKML Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: ree4wo6dqcgr7trnm6e79cehxg9dh7ob X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 0AAF9E0011F1 Received-SPF: none (google.com>: No applicable sender policy available) receiver=imf13; identity=mailfrom; envelope-from=""; helo=mail-lj1-f174.google.com; client-ip=209.85.208.174 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1614981246-356808 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, 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.