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.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 A41BCC433E0 for ; Sat, 6 Mar 2021 03:18:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0E3EF65012 for ; Sat, 6 Mar 2021 03:18:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0E3EF65012 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 65D5C6B0006; Fri, 5 Mar 2021 22:18:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 60E246B006C; Fri, 5 Mar 2021 22:18:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D5BC6B006E; Fri, 5 Mar 2021 22:18:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0055.hostedemail.com [216.40.44.55]) by kanga.kvack.org (Postfix) with ESMTP id 327236B0006 for ; Fri, 5 Mar 2021 22:18:51 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id E6CD78249980 for ; Sat, 6 Mar 2021 03:18:50 +0000 (UTC) X-FDA: 77887992420.21.D41B96E Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) by imf23.hostedemail.com (Postfix) with ESMTP id BEBE5A0000FA for ; Sat, 6 Mar 2021 03:18:49 +0000 (UTC) Received: from DGGEMS409-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4DsqWg6ZtSzlT1B; Sat, 6 Mar 2021 11:16:31 +0800 (CST) Received: from [10.174.179.20] (10.174.179.20) by DGGEMS409-HUB.china.huawei.com (10.3.19.209) with Microsoft SMTP Server id 14.3.498.0; Sat, 6 Mar 2021 11:18:39 +0800 Subject: Re: [PATCH 4/5] khugepaged: remove unnecessary mem_cgroup_uncharge() in collapse_[file|huge_page] To: "Kirill A. Shutemov" CC: , , , , , , References: <20210304123013.23560-1-linmiaohe@huawei.com> <20210304123013.23560-5-linmiaohe@huawei.com> <20210305173809.ufg6rfgmvgbvwxih@box> From: Miaohe Lin Message-ID: <06f49699-6657-30f1-292d-b3d94d35d9f6@huawei.com> Date: Sat, 6 Mar 2021 11:18:38 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20210305173809.ufg6rfgmvgbvwxih@box> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.179.20] X-CFilter-Loop: Reflected X-Stat-Signature: rmzri43gmhx7ibqxtdeh6k69y4tj9cf1 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: BEBE5A0000FA Received-SPF: none (huawei.com>: No applicable sender policy available) receiver=imf23; identity=mailfrom; envelope-from=""; helo=szxga04-in.huawei.com; client-ip=45.249.212.190 X-HE-DKIM-Result: none/none X-HE-Tag: 1615000729-869233 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 2021/3/6 1:38, Kirill A. Shutemov wrote: > On Thu, Mar 04, 2021 at 07:30:12AM -0500, Miaohe Lin wrote: >> Since commit 7ae88534cdd9 ("mm: move mem_cgroup_uncharge out of >> __page_cache_release()"), the mem_cgroup will be uncharged when hpage is >> freed. Uncharge mem_cgroup here is harmless but it looks confusing and >> buggy: if mem_cgroup charge failed, we will call mem_cgroup_uncharge() >> uncorrectly in error path because hpage is not IS_ERR_OR_NULL(). >> >> Signed-off-by: Miaohe Lin > > Hm. I'm not sure about this patch. > > For !NUMA the page will get allocated and freed very early: in > khugepaged_do_scan() and with the change mem_cgroup_charge() may get > called twice for two different mm_structs. Many thanks for point it out. > > Is it safe? I'am sorry I missed the !NUMA case! :( In !NUMA case, hpage may not be freed in the khugepaged_do_scan() while loop. Thus mem_cgroup_charge() may get called twice for two different mm_structs. In fact, mem_cgroup_uncharge() may also get called twice __but__ it's safe to do this. The imbalance of mem_cgroup_charge() and mem_cgroup_uncharge() looks buggy and weird __but__ it's safe to call mem_cgroup_uncharge() many times with or without a successful mem_cgroup_charge() call. So I would drop this patch. > Thanks again.