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.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,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 77770C433E0 for ; Tue, 26 Jan 2021 08:01:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 16CC12251D for ; Tue, 26 Jan 2021 08:01:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 16CC12251D Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3D2158D00AB; Tue, 26 Jan 2021 03:01:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 382B68D0076; Tue, 26 Jan 2021 03:01:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 24A818D00AB; Tue, 26 Jan 2021 03:01:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0138.hostedemail.com [216.40.44.138]) by kanga.kvack.org (Postfix) with ESMTP id 0CC0A8D0076 for ; Tue, 26 Jan 2021 03:01:04 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id C720F1EE6 for ; Tue, 26 Jan 2021 08:01:03 +0000 (UTC) X-FDA: 77747180406.21.nut48_100e8252758c Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id 92A6B180442CB for ; Tue, 26 Jan 2021 08:01:03 +0000 (UTC) X-HE-Tag: nut48_100e8252758c X-Filterd-Recvd-Size: 4428 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Tue, 26 Jan 2021 08:01:02 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1611648061; h=from:from:reply-to: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=9slJ+Ud3Qp4uGdxPfooc/fvRWSdUmMjQcd1zwclQhNE=; b=BqSNfuQw+L7EsMgvK+5Nq1aDStIFDn3EWnzSOTHH+JyJ+5H6YFgje+4FqkNJHtZg6w7OU4 hTRElZv2hMncP46wT1TZJGUYN0tZ/ab9xRlu8BHxw5UUs4p0GJZwzNOyRQxVGcAi/oq5yY 6cP3FJDMFNjT45b6GZ3jBF1neXenBOo= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 762F5ADD6; Tue, 26 Jan 2021 08:01:01 +0000 (UTC) Date: Tue, 26 Jan 2021 09:01:00 +0100 From: Michal Hocko To: Waiman Long Cc: Johannes Weiner , Matthew Wilcox , Andrew Morton , Alex Shi , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/filemap: Adding missing mem_cgroup_uncharge() to __add_to_page_cache_locked() Message-ID: <20210126080100.GC827@dhcp22.suse.cz> References: <20210125042441.20030-1-longman@redhat.com> <20210125092815.GB827@dhcp22.suse.cz> <20210125160328.GP827@dhcp22.suse.cz> <20210125162506.GF308988@casper.infradead.org> <20210125164118.GS827@dhcp22.suse.cz> <20210125181436.GV827@dhcp22.suse.cz> <53eb7692-e559-a914-e103-adfe951d7a7c@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: 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 Mon 25-01-21 13:57:18, Waiman Long wrote: > On 1/25/21 1:52 PM, Johannes Weiner wrote: > > On Mon, Jan 25, 2021 at 01:23:58PM -0500, Waiman Long wrote: > > > On 1/25/21 1:14 PM, Michal Hocko wrote: [...] > > > > With the proposed simplification by Willy > > > > Acked-by: Michal Hocko > > > Thank for the ack. However, I am a bit confused about what you mean= by > > > simplification. There is another linux-next patch that changes the = condition > > > for mem_cgroup_charge() to > > >=20 > > > -=A0=A0=A0=A0=A0=A0 if (!huge) { > > > +=A0=A0=A0=A0=A0=A0 if (!huge && !page_is_secretmem(page)) { > > > =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 error =3D mem_cgroup= _charge(page, current->mm, gfp); > > >=20 > > > That is the main reason why I introduced the boolean variable as I = don't > > > want to call the external page_is_secretmem() function twice. > > The variable works for me. > >=20 > > On the other hand, as Michal points out, the uncharge function will b= e > > called again on the page when it's being freed (in non-fscache cases)= , > > so you're already relying on being able to call it on any page - > > charged, uncharged, never charged. It would be fine to call it > > unconditionally in the error path. Aesthetic preference, I guess. Yes aesthetic preference... Just compare to=20 diff --git a/mm/filemap.c b/mm/filemap.c index 5c9d564317a5..7aa05420107e 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -896,11 +896,14 @@ noinline int __add_to_page_cache_locked(struct page= *page, =20 if (xas_error(&xas)) { error =3D xas_error(&xas); - goto error; + goto error_uncharge; } =20 trace_mm_filemap_add_to_page_cache(page); return 0; +error_uncharge: + /* memcg will ignore uncharged pages */ + mem_cgroup_uncharge(page); error: page->mapping =3D NULL; /* Leave page->index set: truncation relies upon it */ which resembles our usual state unwinding style much more. > That may be true. However, I haven't fully studied how the huge page me= mory > accounting work to make sure the uncharge function can be called for hu= ge > pages. ... but this is rather lame argument to make, don't you think. This sounds like a ducktaping engineering to me. Over time this leads to a terrible code. Seriously! All that being said I do not want to block this or bother people with more emails but geez --=20 Michal Hocko SUSE Labs