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=-8.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 A76B7C433DB for ; Fri, 12 Mar 2021 16:47:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5C6D964DCE for ; Fri, 12 Mar 2021 16:47:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232288AbhCLQqy (ORCPT ); Fri, 12 Mar 2021 11:46:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232253AbhCLQqs (ORCPT ); Fri, 12 Mar 2021 11:46:48 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D130C061574 for ; Fri, 12 Mar 2021 08:46:48 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id ga23-20020a17090b0397b02900c0b81bbcd4so10997716pjb.0 for ; Fri, 12 Mar 2021 08:46:48 -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=2jLAXn4aYpz32jNMagQDm0wpaA4aWgAFhxqORZ7JmIA=; b=Dv9KFMukGJ8sphdRaBO8gtHhv7TABbRb60verndQm+G/beqfhOxT9dy6dfVie6/H6m NoKELrKXVDA4mn4vsnVdXaFpsqejK5CMYZgLhyVRpdkH79VNRG2aPRAvcARf0dLEcG0h DC70zGJHjt/98Vc5Pe4RI7oDXam+5YTzQS/si9aV0Sw9DQCwJdz9iZsVn9mqMEZ5a+MF nfd1g9/OFhh7odWZaPPRLXA9Z3uBfMxOK05ZTj0kb2X0sqjWn/IKRUWTEOWNLYG517T0 z0/3Dz27LoEVe3LVIkS9FUP9KnqQ8pGK8ZxnmvhmsziMWIgDET/SRvZy6syfPefdv1Ql 5apw== 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=2jLAXn4aYpz32jNMagQDm0wpaA4aWgAFhxqORZ7JmIA=; b=S9S+FDDLyg6Rzzi3ZzKDZeaSxHf8M++D6H7C8OYhKLeQMKDxKgHAUPe58BlYG61cjr BCKvc6yZqEGmLM9YtiPDlx8W6/OfzGsck/oCFLSvq4R0cPDhPBx+zgbXmWX61H4ZwGEv RVjSs3bucSZck3AC215cFI9rXCtxhrsc6P0muDMLp8uDbhphR6XK7AMsH3TCmJFBUvlT QAV9j5b7jOb39UsytYn1PTQfWrtL0FUfSTIZ7PnjfK+YE0sKtt5TF/S72S7p0TtkJt36 GHw+F0snfHoxoaqpuNQ5/RZLYW86+VHuY6Bs46+YR3amao8ZJD5HarEZrnbd/d9g7Ot2 YlRg== X-Gm-Message-State: AOAM533isQFlN8vN1vdzkhctbhCaZ+mFrsPg3Gl1rSWmjeRxOHslwX79 q4k6M2Vq1QZj9Abj5hn2kg9xPVql7wkijMSRbBgNAQ== X-Google-Smtp-Source: ABdhPJxgQsLhKqhiH0ayfAGSlfGohtPwCqhQxOwr9KB/1M1c611iD9s+klmbs/jBtCUTyXnFLAagnt92yyhIObinBd8= X-Received: by 2002:a17:902:d4cb:b029:e5:f608:6d5e with SMTP id o11-20020a170902d4cbb02900e5f6086d5emr14093760plg.20.1615567607771; Fri, 12 Mar 2021 08:46:47 -0800 (PST) MIME-Version: 1.0 References: <20210309100717.253-1-songmuchun@bytedance.com> <20210309100717.253-4-songmuchun@bytedance.com> In-Reply-To: From: Muchun Song Date: Sat, 13 Mar 2021 00:46:11 +0800 Message-ID: Subject: Re: [External] Re: [PATCH v3 3/4] mm: memcontrol: use obj_cgroup APIs to charge kmem pages To: Johannes Weiner Cc: Roman Gushchin , Michal Hocko , Andrew Morton , Shakeel Butt , Vladimir Davydov , LKML , Linux Memory Management List , Xiongchun duan Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 12, 2021 at 11:59 PM Johannes Weiner wrote: > > On Fri, Mar 12, 2021 at 05:22:55PM +0800, Muchun Song wrote: > > On Thu, Mar 11, 2021 at 6:05 AM Johannes Weiner wrote: > > > > @@ -6828,7 +6857,7 @@ static void uncharge_batch(const struct uncharge_gather *ug) > > > > > > > > static void uncharge_page(struct page *page, struct uncharge_gather *ug) > > > > { > > > > - unsigned long nr_pages; > > > > + unsigned long nr_pages, nr_kmem; > > > > struct mem_cgroup *memcg; > > > > > > > > VM_BUG_ON_PAGE(PageLRU(page), page); > > > > @@ -6836,34 +6865,44 @@ static void uncharge_page(struct page *page, struct uncharge_gather *ug) > > > > if (!page_memcg_charged(page)) > > > > return; > > > > > > > > + nr_pages = compound_nr(page); > > > > /* > > > > * Nobody should be changing or seriously looking at > > > > - * page memcg at this point, we have fully exclusive > > > > - * access to the page. > > > > + * page memcg or objcg at this point, we have fully > > > > + * exclusive access to the page. > > > > */ > > > > - memcg = page_memcg_check(page); > > > > + if (PageMemcgKmem(page)) { > > > > + struct obj_cgroup *objcg; > > > > + > > > > + objcg = page_objcg(page); > > > > + memcg = obj_cgroup_memcg_get(objcg); > > > > + > > > > + page->memcg_data = 0; > > > > + obj_cgroup_put(objcg); > > > > + nr_kmem = nr_pages; > > > > + } else { > > > > + memcg = page_memcg(page); > > > > + page->memcg_data = 0; > > > > + nr_kmem = 0; > > > > + } > > > > > > Why is all this moved above the uncharge_batch() call? > > > > Before calling obj_cgroup_put(), we need set page->memcg_data > > to zero. So I move "page->memcg_data = 0" to here. > > Yeah, it makes sense to keep those together, but we can move them both > down to after the uncharge, right? Right. I am doing this. > > > > It separates the pointer manipulations from the refcounting, which > > > makes the code very difficult to follow. > > > > > > > + > > > > if (ug->memcg != memcg) { > > > > if (ug->memcg) { > > > > uncharge_batch(ug); > > > > uncharge_gather_clear(ug); > > > > } > > > > ug->memcg = memcg; > > > > + ug->dummy_page = page; > > > > > > Why this change? > > > > Just like ug->memcg, we do not need to set > > ug->dummy_page in every loop. > > Ah, okay. That's a reasonable change, it's just confusing because I > thought this was a requirement for the new code to work. But I didn't > see how it relied on that, and it made me think I'm not understanding > your code ;) It's better to split that into a separate patch. Sorry for confusing you. I will split that into a separate patch. Thanks. > > > I will rework the code in the next version. > > Thanks! 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=-8.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 3057CC433DB for ; Fri, 12 Mar 2021 16:46:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B11A264DCE for ; Fri, 12 Mar 2021 16:46:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B11A264DCE 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 229D46B006C; Fri, 12 Mar 2021 11:46:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1DB1E6B006E; Fri, 12 Mar 2021 11:46:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 02CE46B0070; Fri, 12 Mar 2021 11:46:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0058.hostedemail.com [216.40.44.58]) by kanga.kvack.org (Postfix) with ESMTP id D73A96B006C for ; Fri, 12 Mar 2021 11:46:53 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 9404918250DC6 for ; Fri, 12 Mar 2021 16:46:53 +0000 (UTC) X-FDA: 77911801506.27.105848C Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by imf15.hostedemail.com (Postfix) with ESMTP id CC6AEA0009E4 for ; Fri, 12 Mar 2021 16:46:48 +0000 (UTC) Received: by mail-pj1-f46.google.com with SMTP id q2-20020a17090a2e02b02900bee668844dso10995478pjd.3 for ; Fri, 12 Mar 2021 08:46:48 -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=2jLAXn4aYpz32jNMagQDm0wpaA4aWgAFhxqORZ7JmIA=; b=Dv9KFMukGJ8sphdRaBO8gtHhv7TABbRb60verndQm+G/beqfhOxT9dy6dfVie6/H6m NoKELrKXVDA4mn4vsnVdXaFpsqejK5CMYZgLhyVRpdkH79VNRG2aPRAvcARf0dLEcG0h DC70zGJHjt/98Vc5Pe4RI7oDXam+5YTzQS/si9aV0Sw9DQCwJdz9iZsVn9mqMEZ5a+MF nfd1g9/OFhh7odWZaPPRLXA9Z3uBfMxOK05ZTj0kb2X0sqjWn/IKRUWTEOWNLYG517T0 z0/3Dz27LoEVe3LVIkS9FUP9KnqQ8pGK8ZxnmvhmsziMWIgDET/SRvZy6syfPefdv1Ql 5apw== 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=2jLAXn4aYpz32jNMagQDm0wpaA4aWgAFhxqORZ7JmIA=; b=Wds/OecQEnn1lmbd1tzf7NkOYkN/44IVCO7VNxvSXQrn2hcVqmkMu+l7PGk7y8rPqG QC3OKSfQqpkAuV7OI0Onw0CndCMihZD3UY0WvL82I2OknZa4T86xDOq1EMIcV6YAW/WF h+NxbGT2H6yp/IbbstEvIPe+cqmNmMg2FJthV/0DsUFWIi+147vxt2pcM/aD4lzWDQCP n7+aCNkhYWWWwcCTCVwXoglE0+HZgVZGvGnx/w4P9rHiXmbLmeico3zi+e6LDwEe28c9 FK0j+zTyZGgzugenbsPm33ZouRY1VNDBAZZxouCwT//Uj2rK5w7MsVQNW2dLJ+F+2CKW Tvyg== X-Gm-Message-State: AOAM531pnWyDXspLJ9egvrM4sZ3oBDLlkIrpXU5d8oCRGvYNLS5RJsvk L1kZ2bLbtirWRovZ7EV15jog/D8HueZmgENwXaalvw== X-Google-Smtp-Source: ABdhPJxgQsLhKqhiH0ayfAGSlfGohtPwCqhQxOwr9KB/1M1c611iD9s+klmbs/jBtCUTyXnFLAagnt92yyhIObinBd8= X-Received: by 2002:a17:902:d4cb:b029:e5:f608:6d5e with SMTP id o11-20020a170902d4cbb02900e5f6086d5emr14093760plg.20.1615567607771; Fri, 12 Mar 2021 08:46:47 -0800 (PST) MIME-Version: 1.0 References: <20210309100717.253-1-songmuchun@bytedance.com> <20210309100717.253-4-songmuchun@bytedance.com> In-Reply-To: From: Muchun Song Date: Sat, 13 Mar 2021 00:46:11 +0800 Message-ID: Subject: Re: [External] Re: [PATCH v3 3/4] mm: memcontrol: use obj_cgroup APIs to charge kmem pages To: Johannes Weiner Cc: Roman Gushchin , Michal Hocko , Andrew Morton , Shakeel Butt , Vladimir Davydov , LKML , Linux Memory Management List , Xiongchun duan Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: gz9h9zf43tuoco8i9wtws9piucti4mbw X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: CC6AEA0009E4 Received-SPF: none (bytedance.com>: No applicable sender policy available) receiver=imf15; identity=mailfrom; envelope-from=""; helo=mail-pj1-f46.google.com; client-ip=209.85.216.46 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615567608-859500 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 12, 2021 at 11:59 PM Johannes Weiner wrote: > > On Fri, Mar 12, 2021 at 05:22:55PM +0800, Muchun Song wrote: > > On Thu, Mar 11, 2021 at 6:05 AM Johannes Weiner wrote: > > > > @@ -6828,7 +6857,7 @@ static void uncharge_batch(const struct uncharge_gather *ug) > > > > > > > > static void uncharge_page(struct page *page, struct uncharge_gather *ug) > > > > { > > > > - unsigned long nr_pages; > > > > + unsigned long nr_pages, nr_kmem; > > > > struct mem_cgroup *memcg; > > > > > > > > VM_BUG_ON_PAGE(PageLRU(page), page); > > > > @@ -6836,34 +6865,44 @@ static void uncharge_page(struct page *page, struct uncharge_gather *ug) > > > > if (!page_memcg_charged(page)) > > > > return; > > > > > > > > + nr_pages = compound_nr(page); > > > > /* > > > > * Nobody should be changing or seriously looking at > > > > - * page memcg at this point, we have fully exclusive > > > > - * access to the page. > > > > + * page memcg or objcg at this point, we have fully > > > > + * exclusive access to the page. > > > > */ > > > > - memcg = page_memcg_check(page); > > > > + if (PageMemcgKmem(page)) { > > > > + struct obj_cgroup *objcg; > > > > + > > > > + objcg = page_objcg(page); > > > > + memcg = obj_cgroup_memcg_get(objcg); > > > > + > > > > + page->memcg_data = 0; > > > > + obj_cgroup_put(objcg); > > > > + nr_kmem = nr_pages; > > > > + } else { > > > > + memcg = page_memcg(page); > > > > + page->memcg_data = 0; > > > > + nr_kmem = 0; > > > > + } > > > > > > Why is all this moved above the uncharge_batch() call? > > > > Before calling obj_cgroup_put(), we need set page->memcg_data > > to zero. So I move "page->memcg_data = 0" to here. > > Yeah, it makes sense to keep those together, but we can move them both > down to after the uncharge, right? Right. I am doing this. > > > > It separates the pointer manipulations from the refcounting, which > > > makes the code very difficult to follow. > > > > > > > + > > > > if (ug->memcg != memcg) { > > > > if (ug->memcg) { > > > > uncharge_batch(ug); > > > > uncharge_gather_clear(ug); > > > > } > > > > ug->memcg = memcg; > > > > + ug->dummy_page = page; > > > > > > Why this change? > > > > Just like ug->memcg, we do not need to set > > ug->dummy_page in every loop. > > Ah, okay. That's a reasonable change, it's just confusing because I > thought this was a requirement for the new code to work. But I didn't > see how it relied on that, and it made me think I'm not understanding > your code ;) It's better to split that into a separate patch. Sorry for confusing you. I will split that into a separate patch. Thanks. > > > I will rework the code in the next version. > > Thanks!