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 CEA02C433DB for ; Fri, 12 Mar 2021 15:59:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3C20B64FF3 for ; Fri, 12 Mar 2021 15:59:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3C20B64FF3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cmpxchg.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C22596B0089; Fri, 12 Mar 2021 10:59:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BF8BA6B008A; Fri, 12 Mar 2021 10:59:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A99D96B008C; Fri, 12 Mar 2021 10:59:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0121.hostedemail.com [216.40.44.121]) by kanga.kvack.org (Postfix) with ESMTP id 8C5506B0089 for ; Fri, 12 Mar 2021 10:59:09 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 539C49089 for ; Fri, 12 Mar 2021 15:59:09 +0000 (UTC) X-FDA: 77911681218.25.B35AB7B Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) by imf17.hostedemail.com (Postfix) with ESMTP id AE7D8407F8FA for ; Fri, 12 Mar 2021 15:59:07 +0000 (UTC) Received: by mail-qk1-f171.google.com with SMTP id d20so24736984qkc.2 for ; Fri, 12 Mar 2021 07:59:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=e2ZA0A/mOLsi4lzgGZoMS7/RbeyMMKnDrF1tb/HRetE=; b=g2iED/s19RmA5nzvph9txgSZopnCVj4H7+WPCv953RbGRj2eG4tOWSQsqpEmWz9o16 MaM+EMwIejJ6ftMqZHsyZfRyYpa443askoYUy0Qd10n0PAZdnCUwhgXtA3FdKRhPk1ky AQ5DB2UR094shT0mFAMg60khBPiAFuUJZEjUEQGiekCFQ647ezr/UJ41JCrz5T30MI0J 6L0TyeIM0ybtNOZzaDEc1h8rWAisJtVD+aPX4dAe8Cg1QHrRHMy9CbfkALRNIDzHTO8Z ct1Oqh80qtMJrC3PrD0hPBkacrA6+MUbPkWJPiq4JYlmpTQ1UMlFejksJGQkWulN9NZY xxVA== 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:message-id:references :mime-version:content-disposition:in-reply-to; bh=e2ZA0A/mOLsi4lzgGZoMS7/RbeyMMKnDrF1tb/HRetE=; b=QgDQr8L7WWO+Ebn5ycfjURROrHoSbI39BH+6Z/f7Ds9HDBt2mpKNljgGELi0ITqpx6 zPx+r3QLhtlB1utNbJoNZODzXYUDGuiiU3woaUmlot1hftS1K1lpS4usatKXLTg16V2A u11fduvg+3Ot5najO06S2oErLcYMfPId+4XIxik2ZP02+tpk8y6WonwtuIdn2qzK6XOd S0gw7hooKWwiTW0kzXIvtN6baI5qKTB1DRu312oJWyYo+3X3OokA73T/oDdLJKdGeaOB 1yXWZgeBrwqActEkAQ6d+Yd4IOl+ld4YgngZk95npVaTwXzuOcj6wER1Hx7NjfoQcnb7 aU3A== X-Gm-Message-State: AOAM530ZRJSB3H3zh7XLDsmY8Ezzs6pwk5LErGMNU+TiJeucyGdrJsTD IzkEAOqOYjIcRqqfQz1UcUsG5w== X-Google-Smtp-Source: ABdhPJxjNKGObpsyxinzAr9Md1Fh10M1E3z8ULPFZAtWDOs2kC1FYHd2gJHrCXtKAPvoRNB2/j4RsQ== X-Received: by 2002:a37:a416:: with SMTP id n22mr13293775qke.259.1615564747182; Fri, 12 Mar 2021 07:59:07 -0800 (PST) Received: from localhost (70.44.39.90.res-cmts.bus.ptd.net. [70.44.39.90]) by smtp.gmail.com with ESMTPSA id k28sm4748130qki.101.2021.03.12.07.59.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Mar 2021 07:59:06 -0800 (PST) Date: Fri, 12 Mar 2021 10:59:05 -0500 From: Johannes Weiner To: Muchun Song Cc: Roman Gushchin , Michal Hocko , Andrew Morton , Shakeel Butt , Vladimir Davydov , LKML , Linux Memory Management List , Xiongchun duan Subject: Re: [External] Re: [PATCH v3 3/4] mm: memcontrol: use obj_cgroup APIs to charge kmem pages Message-ID: References: <20210309100717.253-1-songmuchun@bytedance.com> <20210309100717.253-4-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: AE7D8407F8FA X-Stat-Signature: 671uwo94n7geqw7xia4a78wifejwxffx Received-SPF: none (cmpxchg.org>: No applicable sender policy available) receiver=imf17; identity=mailfrom; envelope-from=""; helo=mail-qk1-f171.google.com; client-ip=209.85.222.171 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615564747-489747 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 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? > > 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. > I will rework the code in the next version. Thanks!