From patchwork Thu Sep 8 03:55:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 12969598 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 22F61C38145 for ; Thu, 8 Sep 2022 03:21:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6FDD96B0072; Wed, 7 Sep 2022 23:21:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6AD9F6B0073; Wed, 7 Sep 2022 23:21:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 576408D0001; Wed, 7 Sep 2022 23:21:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 45E356B0072 for ; Wed, 7 Sep 2022 23:21:40 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1A06C40C21 for ; Thu, 8 Sep 2022 03:21:40 +0000 (UTC) X-FDA: 79887468360.23.87415C0 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf12.hostedemail.com (Postfix) with ESMTP id 36A7440091 for ; Thu, 8 Sep 2022 03:21:39 +0000 (UTC) Received: from dggpemm500020.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MNPT32jW4zmVFn; Thu, 8 Sep 2022 11:17:59 +0800 (CST) Received: from dggpemm100009.china.huawei.com (7.185.36.113) by dggpemm500020.china.huawei.com (7.185.36.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 8 Sep 2022 11:21:35 +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; Thu, 8 Sep 2022 11:21:34 +0800 From: Liu Shixin To: Andrew Morton , "Kirill A . Shutemov" , Andrea Arcangeli CC: , , Liu Shixin , Kefeng Wang Subject: [PATCH v2] mm/huge_memory: prevent THP_ZERO_PAGE_ALLOC increased twice Date: Thu, 8 Sep 2022 11:55:33 +0800 Message-ID: <20220908035533.2186159-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: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemm100009.china.huawei.com (7.185.36.113) X-CFilter-Loop: Reflected ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662607299; a=rsa-sha256; cv=none; b=UhR5vQw4iH2uw3DoVguCgvhuPENeUakepCI8XeKd1jquoCtQTC4t9+YPn4kXvipMZQHYhS WEFkXEnQo39dOx87BI3r+JDYY9gipEH2dZKqFrBPkb5RiQU7POmbUqkqJi2QeWNmGBHbdA RiT8x7kvDO7PZGOtSwRBpMmKhkxPwtg= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; spf=pass (imf12.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662607299; 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=RAWnUnN0T0RN6vhWtig/LupGwECqM/CirppgXb10ZfU=; b=ACef+Xijf11KBtPibPLEFaOQgToYDWydGf13Ex25Y/SBSTiU7VQBi5R0cyXeGP6bdEToxQ 6LdztGN1ugbE+dOaTx2LTxJbQ7XeGIuZKpFm+Z9z5Nq3PiLwYoWpJUjX4B7CkCUdAIuRu/ II0dZ3ZPe8sQPFSI3Fz2Wy6EkngAyEA= Authentication-Results: imf12.hostedemail.com; dkim=none; spf=pass (imf12.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=liushixin2@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-Stat-Signature: zx5mceh4krhr7n5grdgsnnga7auaygy9 X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 36A7440091 X-HE-Tag: 1662607299-103210 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. Redefine its meaning to indicate the times a huge zero page used for thp is successfully allocated. Update Documentation/admin-guide/mm/transhuge.rst together. Signed-off-by: Liu Shixin --- v1->v2: Update documnet. Documentation/admin-guide/mm/transhuge.rst | 7 +++---- mm/huge_memory.c | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Documentation/admin-guide/mm/transhuge.rst b/Documentation/admin-guide/mm/transhuge.rst index c9c37f16eef8..8e3418ec4503 100644 --- a/Documentation/admin-guide/mm/transhuge.rst +++ b/Documentation/admin-guide/mm/transhuge.rst @@ -366,10 +366,9 @@ thp_split_pmd page table entry. thp_zero_page_alloc - is incremented every time a huge zero page is - successfully allocated. It includes allocations which where - dropped due race with other allocation. Note, it doesn't count - every map of the huge zero page, only its allocation. + is incremented every time a huge zero page used for thp is + successfully allocated. Note, it doesn't count every map of + the huge zero page, only its allocation. thp_zero_page_alloc_failed is incremented if kernel fails to allocate 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; }