Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp3085091rwb; Mon, 5 Sep 2022 06:18:24 -0700 (PDT) X-Google-Smtp-Source: AA6agR48mtZ50Bec0RJxk5mmsYV2iS49K6hMs6P+x7/UVnVixg/3VbTx+OngCc8wYEOE65DqojbC X-Received: by 2002:a17:902:a60b:b0:176:7707:a711 with SMTP id u11-20020a170902a60b00b001767707a711mr13331561plq.144.1662383903903; Mon, 05 Sep 2022 06:18:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662383903; cv=none; d=google.com; s=arc-20160816; b=htxcqm1CpBwFfy6UG/XqdHgP53V3m4R4P/LVtJhcvr2gAwXufvEOuXF94EKaDCzcC6 Ya6fbpWwwCIZ9dD5jf4JDqe9UoVWBDwpOQw/p0vWktU6uDyvemssDw2lZuthwzRbBZJt PeyPAeJrYzr31Hz+KSMEABwWl2v4Vl2GWYBI5lcvk0jdZOpB+ROSWuEHy58ll7IxQADa xvEJNIbbsHSgxSsC03e0dlHrvmmUePn59OIlObDGSLpKc1lVqN3+k78lzU5ziZ7wPrRI z6GBUH998NQTC2tCU3bME29VFQytesoxfmP8wk3gws5Axvniqa27JwOjC/09htxB4ATl 7U2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=NYCJ1Lw6jIlYMoLlrt7SuVKGDofuJk45NjuLPuZiEaw=; b=1HALfj81JTssG/rfYrPnKPXRtW3/LhrhJ3h2jKYc75q+2oPXt4RgemLLn4JSRJWYTF mVbKDWdLKnv2Yv3sykX+miXgdPcVOZyQ9wxKQtoVZqzzikaH+Ki4fSJYuO1eBT5WxueS GiqdjwIfzojyUQHlvxT3LPHvVwxd+mQbhTFQw6DgbXsWDuNdVTjHiyGkvp4TDecbJzkB omN5MQ+RhzkIdOSwGZZ3K+kiWJUhpOcy75x/PFbd9zgUcTAs59mTjGcHPQ0xpXrmYfbi LNRTs/3C6eigzIKUhSZCrq2dIEpP1JEBCzlVoH0LXb1CwD++dc3ndqzOA2frWCs9sKhD bqtQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q3-20020a056a00088300b0052fac3954e9si11127459pfj.227.2022.09.05.06.18.08; Mon, 05 Sep 2022 06:18:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236288AbiIEND4 (ORCPT + 99 others); Mon, 5 Sep 2022 09:03:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235897AbiIENDy (ORCPT ); Mon, 5 Sep 2022 09:03:54 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09F8328E3B for ; Mon, 5 Sep 2022 06:03:53 -0700 (PDT) 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 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII 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 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; } -- 2.25.1