From patchwork Wed Sep 25 11:02:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hua Su X-Patchwork-Id: 13811884 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 F1219C369CF for ; Wed, 25 Sep 2024 11:02:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 61F1F6B0089; Wed, 25 Sep 2024 07:02:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A87C6B008C; Wed, 25 Sep 2024 07:02:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 421EF6B0092; Wed, 25 Sep 2024 07:02:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 1EF4B6B0089 for ; Wed, 25 Sep 2024 07:02:51 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 8DB2BA01FE for ; Wed, 25 Sep 2024 11:02:50 +0000 (UTC) X-FDA: 82602972900.09.B731DA9 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by imf03.hostedemail.com (Postfix) with ESMTP id A3EB92000E for ; Wed, 25 Sep 2024 11:02:48 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=FYPzIxJS; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of suhua.tanke@gmail.com designates 209.85.210.174 as permitted sender) smtp.mailfrom=suhua.tanke@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727262133; a=rsa-sha256; cv=none; b=5bYvhY2ibEoeElYhPJMe7H88SKaQ3qeKW4OgcVWdoJKW55KkFntNWhzcd4tzPy6MsatuMu wbEF7Q+qJ4U1i8LZ8HlhVg5SaU/2AlAQXP2Cfjq9SMleBy494mB8OlEVkkGFH9+5lR7hr1 +4EGEFnMXg0bglWRfYsJ0aZuJMX/y2M= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=FYPzIxJS; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of suhua.tanke@gmail.com designates 209.85.210.174 as permitted sender) smtp.mailfrom=suhua.tanke@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727262133; 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:dkim-signature; bh=Ceyj2o9QOKbh7xeEuScadckePN7JH5NC03dCcJMcGQI=; b=SNy/q87D235iF54USQ06Z0OzD72QO/b8Wi2MWAlp01yA/gW89CfUnirR+xF9+yJ5sQ5ZJ4 ooi/CjxQcUpbUfMQh8UTdNcwhHuAL7wwwuGP8epRyHcJy4uFfo2iV3TJE2vDaqHvh1vtTc PIsR0D98Rq9AIjwXRwYS/aaJwQ7pIxA= Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-718d704704aso5733943b3a.3 for ; Wed, 25 Sep 2024 04:02:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727262167; x=1727866967; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Ceyj2o9QOKbh7xeEuScadckePN7JH5NC03dCcJMcGQI=; b=FYPzIxJSW35SN7+6CBFfMesMOWocO+EOqiDRSywQ6mKGgcYNrtEP8AZCgyjTLZ27xY pot/CD9tlfTmx54mr7R2AmzvaZkjXAWSX+cpuyG4DP+OAMMiG1nzrfqWrw2vsCl4R994 weNfbCbUqqHkBIkgs7fjK3THq7yNdvoMI1UXdWK0HLzWWjydsaHu019lGEAHnK2f28UA 62/ZaAUO+MS824ehdWlUzdklDEfw/OCnOQDjcSSGTyWPH+6rNwhh0tOiPO09bvgOkBqx Bc8fzymdRtEettUtwd0M+wgJxpzk55WJ1HSc7K+wMmAhk7bmN13OWOlpKTCPzk4nDZAI +RsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727262167; x=1727866967; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Ceyj2o9QOKbh7xeEuScadckePN7JH5NC03dCcJMcGQI=; b=LHV8eMwsora8AlbdFQ4hczHf4gf78KpyaQOXoA16a9ifsyGXMsDD4oN0k/SmgPLAev 6K5P4EqPuTK8YWeJ7sC5Hgv0+nwNnoxslHGeccZfrZjX8b7K9ov0sxx8pxqzTU21A/0f AoJgDzQ+vzaiknouDy6t57ndifm4QnxJEwrKtYpJWrxD5oqT31uE765LAwNFXj85XpwO 3MtVbe6r/0uc8fjDUV/khYIbjfBEWCB0NDv6+RzzmZi76gbT9QQ0qeonpNveYFdHMQU8 YJ8Mg+Jo1sBapMFQduTQtuRXsfeV/fgKFiQJGdt6rXB1Ugv7DPbdv0BoDE/8Q2UaZCok HChw== X-Forwarded-Encrypted: i=1; AJvYcCWNnZ9ErPvtC4ECBVZQYMYTYdSJ3pZratnNraLaYv//3WMEXdqIJzdvvNFD7N5XDLrmzcEJiEthlg==@kvack.org X-Gm-Message-State: AOJu0YxoUhQOlh01QRWcgTt7R6HP6SovK5HHrFq5LMRc8MEAbBLx79UO 2ARTQETMPrMCv9EjMmXZccx/CXqFBVrBX+uW+kGfQj3bRXStOg1h X-Google-Smtp-Source: AGHT+IFNcyHeyTxm8cb7thd2RC5B6sYdTx/bOe6ID57RG8tqxQBhzZmHrBhkrzBlQIBh3l/rGX0QCQ== X-Received: by 2002:a05:6a21:78e:b0:1d2:e1cc:649c with SMTP id adf61e73a8af0-1d4d4aaf073mr2902845637.15.1727262167177; Wed, 25 Sep 2024 04:02:47 -0700 (PDT) Received: from suhua-virtual-machine.localdomain ([36.112.24.11]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71afc843571sm2547604b3a.47.2024.09.25.04.02.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2024 04:02:46 -0700 (PDT) From: suhua X-Google-Original-From: suhua To: rppt@kernel.org, akpm@linux-foundation.org Cc: muchun.song@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, suhua Subject: [PATCH v1] memblock: Initialized the memory of memblock.reserve to the MIGRATE_MOVABL Date: Wed, 25 Sep 2024 19:02:35 +0800 Message-Id: <20240925110235.3157-1-suhua1@kingsoft.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: A3EB92000E X-Rspamd-Server: rspam01 X-Stat-Signature: w4kw5yymszpu6odt3659i9b7314x4zti X-HE-Tag: 1727262168-53437 X-HE-Meta: U2FsdGVkX18HFxl2J5ybOFsy0n3GScGdQZ6v/3xk9NbRVnmV3+2p2Bz6KecRsJep0DBGXBz4ssmbG/o3isRC7wBe9oP5JXJe0szWp3gnwTPGaSxmbqujun11KZZvxbYUlvsjAaegKAaGUNBPu8ElIRXwpI1kT0o6irnun6t5dMhEyv3e3TTDWwMjD9Y31MQV4sdVSZW/uMH8aMf/7wwBLolXYmnKicsH7zCEpre4u9y0fUjV4iH4p4EEgQp0qIxWRjzXH7UHQyDNUm9y3bkrJg3iNidRUOO/7hVKhDGzD+DP1lZgXLLlWR6kwppoKjuOvpOUmb41k9xBpT7oelQu0veKdY/lAb9XS5xJCG1mSpVzzSqeM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0pl1PqMkxQlOnaRIDwVvu+u/XHAkYZKcFgnTe84lFAIh3EwqSsMng1U0i3Z4BgBBubj6URGnEW8FYeJPaGylyTgQnmPi9g93nbXjuN5tI4QBUwHy6HVgG7+J6kIeBAYDVdNyqZqrXsFhVQ32HB7m5Ls4obKuG1eI+U7M5Gm1 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: List-Subscribe: List-Unsubscribe: After sparse_init function requests memory for struct page in memblock and adds it to memblock.reserved, this memory area is present in both memblock.memory and memblock.reserved. When CONFIG_DEFERRED_STRUCT_PAGE_INIT is not set. The memmap_init function is called during the initialization of the free area of the zone, this function calls for_each_mem_pfn_range to initialize all memblock.memory, excluding memory that is also placed in memblock.reserved, such as the struct page metadata that describes the page, 1TB memory is about 16GB, and generally this part of reserved memory occupies more than 90% of the total reserved memory of the system. So all memory in memblock.memory is set to MIGRATE_MOVABLE according to the alignment of pageblock_nr_pages. For example, if hugetlb_optimize_vmemmap=1, huge pages are allocated, the freed pages are placed on buddy's MIGRATE_MOVABL list for use. When CONFIG_DEFERRED_STRUCT_PAGE_INIT=y, only the first_deferred_pfn range is initialized in memmap_init. The subsequent free_low_memory_core_early initializes all memblock.reserved memory but not MIGRATE_MOVABL. All memblock.memory is set to MIGRATE_MOVABL when it is placed in buddy via free_low_memory_core_early and deferred_init_memmap. As a result, when hugetlb_optimize_vmemmap=1 and huge pages are allocated, the freed pages will be placed on buddy's MIGRATE_UNMOVABL list (For example, on machines with 1TB of memory, alloc 2MB huge page size of 1000GB frees up about 15GB to MIGRATE_UNMOVABL). Since the huge page alloc requires a MIGRATE_MOVABL page, a fallback is performed to alloc memory from MIGRATE_UNMOVABL for MIGRATE_MOVABL. Large amount of UNMOVABL memory is not conducive to defragmentation, so the reserved memory is also set to MIGRATE_MOVABLE in the free_low_memory_core_early phase following the alignment of pageblock_nr_pages. Eg: echo 500000 > /proc/sys/vm/nr_hugepages cat /proc/pagetypeinfo before: Free pages count per migrate type at order 0 1 2 3 4 5 6 7 8 9 10 … Node 0, zone Normal, type Unmovable 51 2 1 28 53 35 35 43 40 69 3852 Node 0, zone Normal, type Movable 6485 4610 666 202 200 185 208 87 54 2 240 Node 0, zone Normal, type Reclaimable 2 2 1 23 13 1 2 1 0 1 0 Node 0, zone Normal, type HighAtomic 0 0 0 0 0 0 0 0 0 0 0 Node 0, zone Normal, type Isolate 0 0 0 0 0 0 0 0 0 0 0 Unmovable ≈ 15GB after: Free pages count per migrate type at order 0 1 2 3 4 5 6 7 8 9 10 … Node 0, zone Normal, type Unmovable 0 1 1 0 0 0 0 1 1 1 0 Node 0, zone Normal, type Movable 1563 4107 1119 189 256 368 286 132 109 4 3841 Node 0, zone Normal, type Reclaimable 2 2 1 23 13 1 2 1 0 1 0 Node 0, zone Normal, type HighAtomic 0 0 0 0 0 0 0 0 0 0 0 Node 0, zone Normal, type Isolate 0 0 0 0 0 0 0 0 0 0 0 Signed-off-by: suhua --- mm/mm_init.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/mm_init.c b/mm/mm_init.c index 4ba5607aaf19..e0190e3f8f26 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -722,6 +722,12 @@ static void __meminit init_reserved_page(unsigned long pfn, int nid) if (zone_spans_pfn(zone, pfn)) break; } + + if (pageblock_aligned(pfn)) { + set_pageblock_migratetype(pfn_to_page(pfn), MIGRATE_MOVABLE); + cond_resched(); + } + __init_single_page(pfn_to_page(pfn), pfn, zid, nid); } #else