From patchwork Mon Sep 5 13:38:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 12966108 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A38BECAAD3 for ; Mon, 5 Sep 2022 13:03:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 022868D0096; Mon, 5 Sep 2022 09:03:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F13958D0076; Mon, 5 Sep 2022 09:03:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E026A8D0096; Mon, 5 Sep 2022 09:03:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D11318D0076 for ; Mon, 5 Sep 2022 09:03:56 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A49B3C18D1 for ; Mon, 5 Sep 2022 13:03:56 +0000 (UTC) X-FDA: 79878049272.09.FA276BC Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf04.hostedemail.com (Postfix) with ESMTP id F298140072 for ; Mon, 5 Sep 2022 13:03:54 +0000 (UTC) Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MLpYV6fJ3znTTj; Mon, 5 Sep 2022 21:01:18 +0800 (CST) Received: from dggpemm100009.china.huawei.com (7.185.36.113) by dggpemm500024.china.huawei.com (7.185.36.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 5 Sep 2022 21:03:50 +0800 Received: from huawei.com (10.175.113.32) by dggpemm100009.china.huawei.com (7.185.36.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 5 Sep 2022 21:03:50 +0800 From: Liu Shixin To: Andrew Morton CC: , , Liu Shixin , Kefeng Wang Subject: [PATCH] mm/huge_memory: prevent THP_ZERO_PAGE_ALLOC increased twice Date: Mon, 5 Sep 2022 21:38:13 +0800 Message-ID: <20220905133813.2253703-1-liushixin2@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.175.113.32] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm100009.china.huawei.com (7.185.36.113) X-CFilter-Loop: Reflected ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662383035; a=rsa-sha256; cv=none; b=weXnZASV9FKvraK2fNeZ0zaRoXQpPS2As4wEmqlMfF9siZWZUdfALeecDW0xcaIV14NhvL bt5s5KvxcQVWF/gxkcLPqaNsLb1tzXirRqIwSf3I+6KFSLEZSnAMmzdNaGbzqnO+NuMDDU Kb52bfXzZTj0E86L3sgBxMbtsgc3Tdw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662383035; h=from:from:sender: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: references; bh=NYCJ1Lw6jIlYMoLlrt7SuVKGDofuJk45NjuLPuZiEaw=; b=o1148RT8o2xpaMtBtngk2f8zINAPWZjiByZ7y6chV0YsXIYNoGuAc8qdHFSKFDUK1hPV9O cLGS+LVKP0OEU4CcZlEgBRSwbH6q2qV6Q3RV8AujMYTJJoqFMIC98dlZX8rqgCytnviFcw abgH8oyBDJIHih2P8+2UazVyNF0BHuo= Authentication-Results: imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Rspamd-Server: rspam06 X-Stat-Signature: ieobpcy9pmwjbbwb9dfzuiqwm3hfpf7k X-Rspam-User: X-Rspamd-Queue-Id: F298140072 X-HE-Tag: 1662383034-815957 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: If two or more threads call get_huge_zero_page concurrently, THP_ZERO_PAGE_ALLOC may increased two or more times. But actually, this should only count as once since the extra zero pages has been freed. Signed-off-by: Liu Shixin --- mm/huge_memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 88d98241a635..5c83a424803a 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -163,7 +163,6 @@ static bool get_huge_zero_page(void) count_vm_event(THP_ZERO_PAGE_ALLOC_FAILED); return false; } - count_vm_event(THP_ZERO_PAGE_ALLOC); preempt_disable(); if (cmpxchg(&huge_zero_page, NULL, zero_page)) { preempt_enable(); @@ -175,6 +174,7 @@ static bool get_huge_zero_page(void) /* We take additional reference here. It will be put back by shrinker */ atomic_set(&huge_zero_refcount, 2); preempt_enable(); + count_vm_event(THP_ZERO_PAGE_ALLOC); return true; }