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=-10.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 12FE1C433E6 for ; Mon, 25 Jan 2021 14:09:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9C43A2145D for ; Mon, 25 Jan 2021 14:09:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9C43A2145D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B041D8D0002; Mon, 25 Jan 2021 09:09:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A8CA58D0001; Mon, 25 Jan 2021 09:09:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 954828D0002; Mon, 25 Jan 2021 09:09:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0144.hostedemail.com [216.40.44.144]) by kanga.kvack.org (Postfix) with ESMTP id 7B7048D0001 for ; Mon, 25 Jan 2021 09:09:35 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 373B5180AE7F3 for ; Mon, 25 Jan 2021 14:09:35 +0000 (UTC) X-FDA: 77744480310.21.glass92_5b0939027586 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id 0EFA5180442C3 for ; Mon, 25 Jan 2021 14:09:35 +0000 (UTC) X-HE-Tag: glass92_5b0939027586 X-Filterd-Recvd-Size: 4027 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Mon, 25 Jan 2021 14:09:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611583773; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1tk4eS0Y2Vo2oPY0Z4JxAQzLc8itlAhOCREG8ddZvOI=; b=HIGkrnTR2Lsr418vfRiSMhUHCdspIPJjCT67257oUqbpgUC12r3RYZ++6rVtWt5UI0WWQq +IUf9zU/CFZqZlBu7Y2HlbiajdHCXNd8Shn/cj61IyIH3nU++gCjGkS2bbWYedtOLy7M28 f0E56sVsqlC5q1+9FToUFTN/SvXAAiE= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-269-SQGrC9dfPNiAj-kd1C9gig-1; Mon, 25 Jan 2021 09:09:29 -0500 X-MC-Unique: SQGrC9dfPNiAj-kd1C9gig-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 03975180A0A5; Mon, 25 Jan 2021 14:09:28 +0000 (UTC) Received: from llong.remote.csb (ovpn-117-163.rdu2.redhat.com [10.10.117.163]) by smtp.corp.redhat.com (Postfix) with ESMTP id 13F365D731; Mon, 25 Jan 2021 14:09:26 +0000 (UTC) Subject: Re: [PATCH] mm/filemap: Adding missing mem_cgroup_uncharge() to __add_to_page_cache_locked() To: Matthew Wilcox Cc: Andrew Morton , Johannes Weiner , Alex Shi , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20210125042441.20030-1-longman@redhat.com> <20210125043631.GD308988@casper.infradead.org> From: Waiman Long Organization: Red Hat Message-ID: <1f234e4f-be0d-ecf9-7934-4be3de0d6fe5@redhat.com> Date: Mon, 25 Jan 2021 09:09:26 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20210125043631.GD308988@casper.infradead.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Content-Transfer-Encoding: quoted-printable 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 1/24/21 11:36 PM, Matthew Wilcox wrote: > On Sun, Jan 24, 2021 at 11:24:41PM -0500, Waiman Long wrote: >> diff --git a/mm/filemap.c b/mm/filemap.c >> index 5c9d564317a5..aa0e0fb04670 100644 >> --- a/mm/filemap.c >> +++ b/mm/filemap.c >> @@ -835,6 +835,7 @@ noinline int __add_to_page_cache_locked(struct pag= e *page, >> XA_STATE(xas, &mapping->i_pages, offset); >> int huge =3D PageHuge(page); >> int error; >> + bool charged =3D false; > I don't think we need this extra bool. > >> @@ -896,6 +898,8 @@ noinline int __add_to_page_cache_locked(struct pag= e *page, >> =20 >> if (xas_error(&xas)) { >> error =3D xas_error(&xas); >> + if (charged) >> + mem_cgroup_uncharge(page); >> goto error; >> } > Better: > > - goto error; > + goto uncharge; > ... > +uncharge: > + if (!huge) > + mem_cgroup_uncharge(page); > error: > ... > That was my original plan. After finding out there was a potentially=20 conflicting patch in linux-next: commit 7a02fa97b897 ("secretmem: add memcg accounting") @@ -839,7 +840,7 @@ noinline int __add_to_page_cache_locked(struct page=20 *page, =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 page->mapping =3D mapping; =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 page->index =3D offset; -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!huge) { +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (!huge && !page_is_secretmem(pag= e)) { =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 error =3D mem_cgroup_charge(page, current->mm, gfp); =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 if (error) =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 goto e= rror; Adding a boolean is an easy way out without conflicting it. Cheers, Longman