From patchwork Wed Jun 5 01:07:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13686073 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 2BC3BC27C50 for ; Wed, 5 Jun 2024 01:08:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ADAC76B0089; Tue, 4 Jun 2024 21:08:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A89986B008A; Tue, 4 Jun 2024 21:08:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9510F6B008C; Tue, 4 Jun 2024 21:08:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 7662F6B0089 for ; Tue, 4 Jun 2024 21:08:08 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1D53940E70 for ; Wed, 5 Jun 2024 01:08:08 +0000 (UTC) X-FDA: 82195048656.15.0A73B9A Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) by imf04.hostedemail.com (Postfix) with ESMTP id 6D9714000A for ; Wed, 5 Jun 2024 01:08:06 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=U1E9iXCK; spf=pass (imf04.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.167.42 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717549686; a=rsa-sha256; cv=none; b=C3Sj8bZQkqHygZMCbDv8mfBJ87Qeci5Y9nltHap89VD+MMlHjksRu6iOpeKxv+Y+IPGhP+ Du0GRFUa5JAKUxISJQW2AyoXo2vTG3/nMNZbMer8vcd/H0F5T4wLj/X4EkpfWyZbahHrPY nq7ehJezBV6XLa+h4Z/Yfg7I+oRY38o= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=U1E9iXCK; spf=pass (imf04.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.167.42 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717549686; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references:dkim-signature; bh=WzUEwl0tS19vcDGzf3ZDR086YVX9gSe91aivOI2/OYw=; b=Vk7e39RWKkzAAJ9OfyqFAMdnkhyZnPMhJSwPLDohDZ/YFfvZ2sUZbcNidNEF7xQsnDHFYh ccGC5wEjOrXKRbVEL49ZNwWg+cr1N/5QibnNQ5RNh6+MMQp0pi8a0GBHvbQesghCrL2v3s ClGwSD1Bc5CieQcTfTjdIcRm049w0jc= Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-52b9d062526so2683143e87.3 for ; Tue, 04 Jun 2024 18:08:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717549685; x=1718154485; darn=kvack.org; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WzUEwl0tS19vcDGzf3ZDR086YVX9gSe91aivOI2/OYw=; b=U1E9iXCK9uHX2bFcrf4eciQbLTi0lKBK7DTrqo0/V2tWjfp7PS+4c1BRrQh4E/YR9L WI4GAy4JqW4gPqAeRtHv2bNwsawT7gQ4huW/Kgu4Ga6os5CQuFQFcRNT5+3id96qsZuq RzXt55om7b84iFviHYWZfZen3JDNJ96ihty2kHqp5Mz8BT/TIzW077hjdIDhLkRlKBGu GWO0FA92l35iQpBC5iPeNaolp7hTcxyJgOm6WuLm05uczszt/OOzlixjrrj6hwkcsf4U zfmH4qlZcOBZhX2ShsI31/Cm2BzYiiqybGtklkoD1nD8K1jP+rd0L7gSE/tHZ5ym+MHZ oAew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717549685; x=1718154485; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WzUEwl0tS19vcDGzf3ZDR086YVX9gSe91aivOI2/OYw=; b=SM5qoKTQoYKth1upAvUVsmsyDyKaNNNzt4YVCMGcQmLa3/OSmziE7Vc4+kHmrKg9r7 55HO9QKkzxokHizKlbJdJgtUEN8/MerYlxxMvQBZ1W38KwpAi2XNrjAgldyC27rkOZkc OsIkZzjXOIZJ0TBu3Qk4xcDTSRl9/lY2T8hUVf6Tr0YAUo54aT2ngXjyq561IaehygkQ IJR4k08iGG4ZtqlQNFPie/SHlOs15Gp6BkdVnkKI5LzqpN3blBPF7GgfN8nCEBjuUA8K e2qpf+OxsYSqHiSQk0bHKk/p6PJB1YV11RQgc1Y4Tp09E5Fp9eMBLaf5V5bJAoEzMKMc 5klA== X-Gm-Message-State: AOJu0YxzPmMQXmlGxra3aAjGsuZkrMwso65tgBLWfridBiVNs2LM+FMm mVn0UOZnP9QUPI1FZ0Nkd9Oq0/DC1PjpEHqxTzbfMVzEgeJN8GY6 X-Google-Smtp-Source: AGHT+IEue+nVpCKeYzyusjBjakzaKEQ+cCN5eEWznVUwORx/ivYG+61DkXV0uMh8RFKg857Y+A4m/A== X-Received: by 2002:a05:6512:3993:b0:52b:4924:5348 with SMTP id 2adb3069b0e04-52bab4c9c4cmr699333e87.12.1717549684372; Tue, 04 Jun 2024 18:08:04 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57a31bb8247sm8290284a12.30.2024.06.04.18.08.03 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Jun 2024 18:08:03 -0700 (PDT) From: Wei Yang To: rppt@kernel.org, akpm@linux-foundation.org Cc: linux-mm@kvack.org, Wei Yang , "Kirill A . Shutemov" , David Hildenbrand Subject: [PATCH] [RFC] mm/mm_init.c: simplify logic of deferred_[init|free]_pages Date: Wed, 5 Jun 2024 01:07:42 +0000 Message-Id: <20240605010742.11667-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 6D9714000A X-Stat-Signature: tyj33z7w56g78o77zn4dy549r33ochdy X-HE-Tag: 1717549686-677937 X-HE-Meta: U2FsdGVkX19UvZZ9LQ4WPcwThzKCxEJVmsBwC6wwIV67xTFTEfZzKTX1BCOSP58X5tgw46aLRriEbXKzW+JOxfwA0qlRW50FuvXCbzBrDQIJ+dVfxIozIOZOmrrt3ZLQDztjNO6f0NDfmYJh3sIOKDU4QPbWJ3K3ZqV3bTWC+xaLprV2vEM7vjBSY0/jfaRydkyUXmjuB+dUaiNgtoiapMXhRK66l5/uDE8gPkz4p7gH/fF/6tWzJcbKiU4bkO+Gk7bKKip2pwud2iArfb8TY2TPsvurngUwTE9FGNkdg6FrOCQbqohmZTkwXHyYE7ZWQrFGRKvsxqNOh8//5vj2A66LwHhwJYPo/eA9nZNz40NqvAAppmHYnFXPyYIABGGMtVzsQP/HterGSb9ZDGgkObbFc8TWVNPExksn73nBTI1oBk4l1XT82ZMV36L36aTqfm4cAbz8BY2YK3QXGu5Ton6XW5WqqVODUR6grV5bv0ch50ptF6FZLoWg17boSZDpjaCBXIjn7Bm8kE1MLGRUoXTbTgvdeHB7FHDrGxSBKW4QYPif/dtRR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pN8mg== 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: Function deferred_[init|free]_pages are only used in deferred_init_maxorder(), which makes sure the range to init/free is within MAX_ORDER_NR_PAGES size. With this knowledge, we can simplify these two functions. Since * only the first pfn could be IS_MAX_ORDER_ALIGNED() Signed-off-by: Wei Yang CC: Kirill A. Shutemov CC: Mike Rapoport (IBM) CC: David Hildenbrand --- But my question is why we just test pfn_valid for the IS_MAX_ORDER_ALIGNED pfn? I thought we should test pfn_valid for each pfn until the first one in MAX_ORDER pages. Do I miss something? --- mm/mm_init.c | 43 ++++++++++++++----------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/mm/mm_init.c b/mm/mm_init.c index bbaf3a2c1cfd..6a4adf9e7d9a 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -1970,21 +1970,10 @@ static inline bool __init deferred_pfn_valid(unsigned long pfn) static void __init deferred_free_pages(unsigned long pfn, unsigned long end_pfn) { - unsigned long nr_free = 0; - - for (; pfn < end_pfn; pfn++) { - if (!deferred_pfn_valid(pfn)) { - deferred_free_range(pfn - nr_free, nr_free); - nr_free = 0; - } else if (IS_MAX_ORDER_ALIGNED(pfn)) { - deferred_free_range(pfn - nr_free, nr_free); - nr_free = 1; - } else { - nr_free++; - } - } - /* Free the last block of pages to allocator */ - deferred_free_range(pfn - nr_free, nr_free); + if (!deferred_pfn_valid(pfn)) + pfn++; + + deferred_free_range(pfn, end_pfn - pfn); } /* @@ -1992,27 +1981,23 @@ static void __init deferred_free_pages(unsigned long pfn, * by performing it only once every MAX_ORDER_NR_PAGES. * Return number of pages initialized. */ -static unsigned long __init deferred_init_pages(struct zone *zone, - unsigned long pfn, - unsigned long end_pfn) +static unsigned long __init deferred_init_pages(struct zone *zone, + unsigned long pfn, + unsigned long end_pfn) { int nid = zone_to_nid(zone); unsigned long nr_pages = 0; int zid = zone_idx(zone); struct page *page = NULL; - for (; pfn < end_pfn; pfn++) { - if (!deferred_pfn_valid(pfn)) { - page = NULL; - continue; - } else if (!page || IS_MAX_ORDER_ALIGNED(pfn)) { - page = pfn_to_page(pfn); - } else { - page++; - } + if (!deferred_pfn_valid(pfn)) + pfn++; + + page = pfn_to_page(pfn); + nr_pages = end_pfn - pfn; + + for (; pfn < end_pfn; pfn++, page++) __init_single_page(page, pfn, zid, nid); - nr_pages++; - } return nr_pages; }