From patchwork Fri Sep 9 02:16:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Shixin X-Patchwork-Id: 12970923 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 51D53C54EE9 for ; Fri, 9 Sep 2022 01:42:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AEE988D0003; Thu, 8 Sep 2022 21:42:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A9DB48D0001; Thu, 8 Sep 2022 21:42:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 98CF98D0003; Thu, 8 Sep 2022 21:42:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 89E458D0001 for ; Thu, 8 Sep 2022 21:42:56 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 61ECC1C5E62 for ; Fri, 9 Sep 2022 01:42:56 +0000 (UTC) X-FDA: 79890848352.26.5D51D33 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf18.hostedemail.com (Postfix) with ESMTP id 5DD541C0075 for ; Fri, 9 Sep 2022 01:42:55 +0000 (UTC) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4MNzDN54cRzlVqy; Fri, 9 Sep 2022 09:39:00 +0800 (CST) Received: from dggpemm100009.china.huawei.com (7.185.36.113) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Fri, 9 Sep 2022 09:42:51 +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; Fri, 9 Sep 2022 09:42:51 +0800 From: Liu Shixin To: Andrew Morton , "Kirill A . Shutemov" , Andrea Arcangeli CC: , , Liu Shixin , Kefeng Wang Subject: [PATCH v3] mm/huge_memory: prevent THP_ZERO_PAGE_ALLOC increased twice Date: Fri, 9 Sep 2022 10:16:53 +0800 Message-ID: <20220909021653.3371879-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: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm100009.china.huawei.com (7.185.36.113) X-CFilter-Loop: Reflected ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662687776; a=rsa-sha256; cv=none; b=PetxyQfT/MR4nVK/S8UqNnKdVuxcMcHw0JP3za43y4QefDJLksMbsRpb2vVjwgc86b+5I5 0xmrrsiGyQl5xxBAPD3jrPdT+A/S9FI7oJD9Erd+vZYFMc/BpRQoDYQ/r0Yxcah45qvoXg +57cLSNmFSI31A5mhoOOVb0uwEZs5pI= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf18.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=liushixin2@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662687776; 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=+SNvP1jSn7slxCM4guqH7xyQJ1i+p03VYThsexIPmN4=; b=7CMZG4NiXLXDoPTjemCT1Asvxt7WVBZTkLFbxM3AU/1IN+KKKcw9eA+NKL/Pg7mewXbAgi 1ojrsykKTfHrgsq4pfr35zkOYhNL8BkR5T6lQmdmoOHzrGzIAvy9axvYYFj0UPvhtlGFtx jKmX2smcGeOU/ft8P1K8nii2jzSGm74= X-Rspam-User: X-Rspamd-Server: rspam05 Authentication-Results: imf18.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf18.hostedemail.com: domain of liushixin2@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=liushixin2@huawei.com X-Stat-Signature: qk79enomokewix4d3fk4z7jswmwhu5nb X-Rspamd-Queue-Id: 5DD541C0075 X-HE-Tag: 1662687775-275141 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: Since user who read THP_ZERO_PAGE_ALLOC may be more concerned about the huge zero pages that are really allocated using for thp and can indicated the times of calling huge_zero_page_shrinker. It is misleading to increase twice if two threads call get_huge_zero_page concurrently. Don't increase the value if the huge page is not really used. Update Documentation/admin-guide/mm/transhuge.rst together. Signed-off-by: Liu Shixin --- v2->v3: Update the commit message. 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; }