From patchwork Tue Jul 9 02:36:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13727181 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 A233BC3271E for ; Tue, 9 Jul 2024 02:36:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 220306B0098; Mon, 8 Jul 2024 22:36:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1CE2C6B0099; Mon, 8 Jul 2024 22:36:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 095FA6B009B; Mon, 8 Jul 2024 22:36:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id DF78D6B0098 for ; Mon, 8 Jul 2024 22:36:25 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8212B1612E7 for ; Tue, 9 Jul 2024 02:36:25 +0000 (UTC) X-FDA: 82318650330.13.185079D Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) by imf19.hostedemail.com (Postfix) with ESMTP id E15EF1A0012 for ; Tue, 9 Jul 2024 02:36:23 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=egyH7ntS; spf=pass (imf19.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.45 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=1720492569; 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=Y4tyZfQZh13n8WJqaNDrYKT2RH1lvdWq6QqkJMhvWhE=; b=paRYlPsh3BRQ8zT1rDqHYi8PwUqeWvULkSFuRMMIiUHQepqhqckg3W653fyhCNBfGKspQG 2p2gejrwaZNp9P1zEVnE4Hrc0WtmaJphcsBq4/E3KiZYnz++lyoS0YhIg97x/USmbBu0dZ crEupQ7cdZ8cmHIejuwOVwpCMywPCjM= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=egyH7ntS; spf=pass (imf19.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.45 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=1720492569; a=rsa-sha256; cv=none; b=B8m+8RRf2pEkl+5gXTeFx5Clji/2XmBWpr6LrwazWrep7s1sDrjFutKoQ7ojgRILLM0bls jMwjigDh0QyJpJtTjnetzhy2GO9BdkLPPdEKmYmINPDFQWNMHEFz1mKQXGu15kDC9BCVvk t1QaRt0kPt1w3WRsFTz7ddUGAsDbvjU= Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-58b447c5112so5152971a12.3 for ; Mon, 08 Jul 2024 19:36:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720492582; x=1721097382; darn=kvack.org; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y4tyZfQZh13n8WJqaNDrYKT2RH1lvdWq6QqkJMhvWhE=; b=egyH7ntSw7AgNTzpCE0Ml4uoQgoLeeDADvRY/tuuGyezY1vMrjGzJGVJI2Tg74cbNa 7QdWFV7g5sRYpKQfG8jvzWKQKMFNujOU5/Vu6463EIRTBeH0HQb5v9QhTkox8sZT/V8V tvXUdKaPRR3lgl5T/1p++kiFCO/YP3p7EWSlv2LunFkLRq6SRLrmZfgS/zTOeSbnabAw jpmX5AQ71SE+P/bCJ8jsGhe+vuulx7Mf2jxxLHHqSOPtDUGq3Cn3g7ELdXHr5gfktGbP 9fsiJU2hZ5X71SXoJzwJZCiOg5322SPaaC10MaPy0o1C22I1iboE6PMs7oQ2J7+EkbFZ x5Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720492582; x=1721097382; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y4tyZfQZh13n8WJqaNDrYKT2RH1lvdWq6QqkJMhvWhE=; b=qQo9zgumoq98X+tC0pY8MbsZ/Md0MhJg1mYBp+AyWhYTIXxg3vp6Y0LREw/SMPm/ox kYj1Ug50goVtary3R8up1FtMDBoHPa4Gr/KGT3dWd4Tlqm+Iwl229ZQs0Z0lOHIqdw8v 77ArJ/7eWW4FOUe2W9cFydD9+LGmfcxAKUFnYcmxcjmTJ1QTUat4x5kFf2FXlq39womv OBHiVy7d2+ZDwyG57p3eODzOV8+XF7xs9plO1OFy5+6ORfnHQmmEKGi1evQXcuJuwuOQ Y9gm469Akgcd2jbryQZNiYg9YeoDARyanV/67R94eugxFFs4jbMJj+hjgEVg2+FAHIo/ cbqg== X-Gm-Message-State: AOJu0YyDhntpDr02QGHa4vHXzmCniEvtWtIXB+4vhRWi1oHfhefmNmEw rviMGo32q2CVFp408QUwYWYXSfe+taoc/Gi4KEzBcYHVccFPkiVS X-Google-Smtp-Source: AGHT+IFIX/IbRXxrlYwyIgLKfOuUr+XDE9CmJ5stAxyz6jREZ2FOOXNBpDGe4TNlg6VoOPuhPSALGA== X-Received: by 2002:a05:6402:33d8:b0:58c:f5bd:eb65 with SMTP id 4fb4d7f45d1cf-594bb674df7mr651675a12.22.1720492582055; Mon, 08 Jul 2024 19:36:22 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-594bba54ab2sm510868a12.3.2024.07.08.19.36.21 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Jul 2024 19:36:21 -0700 (PDT) From: Wei Yang To: rppt@kernel.org, akpm@linux-foundation.org, brauner@kernel.org, oleg@redhat.com, tandersen@netflix.com, mjguzik@gmail.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wei Yang , David Hildenbrand Subject: [PATCH v5 1/3] mm/memblock: introduce a new helper memblock_estimated_nr_free_pages() Date: Tue, 9 Jul 2024 02:36:07 +0000 Message-Id: <20240709023609.21332-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: E15EF1A0012 X-Stat-Signature: pgxd8rc7qeymhtoau8mk9xtj1wn6w8rq X-HE-Tag: 1720492583-173856 X-HE-Meta: U2FsdGVkX19StX6BzIaO9urBcBXpwzFFn6YZ6GsLzaFUl5volZqA0o8d7/IrgNBtXdk6dcBwAL4pdRYj7Tfb3GvZLoA6t5pS0f1KbcdM0ZXqpSLfNPl2tiZJzWKKysrjv3igde2qN1Ts/eVXRRMNz0WC6tY8+oLFQPrOzwwkSqsbwVxfQ1LIpKHqAcrZCJPtEM4l7S9TXXHSxrlsHtet5RMPCiKkzzzsa2qC0rPQsaYmfH7bnBuHwdoDbrBanXVZsSZLlktqc1ZmTHxN5xfVX8VLehQlxr6i3l2WTTZ4QDlYnJnKymoOjituJRS8IVK6jus40XKIvzXHJC40MEYTYwvkfGt89DA3fcmokz/erikVewj/hvAvTY4PunmgRIsx3Wd+F/ccfzUz4s+ZxpviDbXnAwR8oI5rLlKBmAl/M6cy5QAcsVeyhjEQIwW/8UXRgC7FQB3jjzrho7hmcLZM1YyVDYO2x9ETUEjzQlVfLYnE02RIiBLiu0FKIYwovV8WplJ6wDVjCPTVXsqbTg5mBNdu/LUy2BMUcGAd26HbmihHZ1JKAl0xdBIMs1YDYP+y7s3oxdCEHgZKeT+4Pz/izA+/16T+DdiiFemAZ+pSn0OE6pYtxJ8U1G822bEkqrXpnZlueJjyu1Ev2E8zv6F/cZ2hqG6BhLMDQVYEAv4bX2K/SxLf59PSPzeJVHQ865if57cfdeS29ZCejgR4EevMR1/PLG9axePuXqbPctJJeqkKrgqCkbXQ7WY8IPxJMDB3/kxPrVCgdfN9Kx48xFHxZPlD0lENXAuhB9KoA5wfmIRwOhOweZ13hC90rh+1xb/x0pk+OzySin0aQBaiP5v2cdktorYL/RNI13u05RN7SJpavk9CGXg3E7Dqx9jzJrwQT2ACzub9fhP3Syg6elkXeNxlHjdo6/8B2L4LRYX+YUX0WhEPkCo7uOyI3XUKRCe07j/pmHxplFYYjtTBlXX d995m1Ba DzRiWft6W2ob6JVDOWnzbawcdEOMl2hrxM5vm0TDEYe4Gc7gV8sKOk7PZ25xMfzDLkD2kq+rDcVqGTw2HBnGSSmjR4Ka3nMG583jT7P5W5b0vDIJxRcnSmU9HPZddsjEMnZB2+Fy10qeO+33V8kOVgoDUwUPLUpjCXwHcBo2kcDRP4AscMR/BJ8NYuww8gACZRFsWeGSIPyh9urCJitTZ1bSKx9wWo+HQ3Xhki7ccfyF0Af9SqG1dysSPuWHokqK/13eh6I6bdmlcLEne/c7f2yewTL00/UWKY5yMm6xFSjyegViMtU0x5mmDJgXN8dZRLAWWjzCE0jQUAiHn30L3xwxYKxxEUF5vIQWFm3fsSjVU/EYzJwCytTpU4gH2CbqYxnfEGU6Gp4/XxK4BdRyVq8rLvj7YAkZSUGHJd0XrOs6x5/xiMl8E8nFbOdn3xxWpmmBPZytZeRduo1mAUZJfQdv1poGvTy1t2wdt+KZ5lWR/Co8= 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: During bootup, system may need the number of free pages in the whole system to do some calculation before all pages are freed to buddy system. Usually this number is get from totalram_pages(). Since we plan to move the free pages accounting in __free_pages_core(), this value may not represent total free pages at the early stage, especially when CONFIG_DEFERRED_STRUCT_PAGE_INIT is enabled. Instead of using raw memblock api, let's introduce a new helper for user to get the estimated number of free pages from memblock point of view. Signed-off-by: Wei Yang CC: David Hildenbrand Reviewed-by: David Hildenbrand Reviewed-by: Mike Rapoport --- v5: cleanup the stale name v4: adjust comment per david's suggestion --- include/linux/memblock.h | 1 + mm/memblock.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 40c62aca36ec..aba7ed9f2531 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -486,6 +486,7 @@ static inline __init_memblock bool memblock_bottom_up(void) phys_addr_t memblock_phys_mem_size(void); phys_addr_t memblock_reserved_size(void); +unsigned long memblock_estimated_nr_free_pages(void); phys_addr_t memblock_start_of_DRAM(void); phys_addr_t memblock_end_of_DRAM(void); void memblock_enforce_memory_limit(phys_addr_t memory_limit); diff --git a/mm/memblock.c b/mm/memblock.c index e81fb68f7f88..ae8e58fc4e7f 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1729,6 +1729,23 @@ phys_addr_t __init_memblock memblock_reserved_size(void) return memblock.reserved.total_size; } +/** + * memblock_estimated_nr_free_pages - return estimated number of free pages + * from memblock point of view + * + * During bootup, subsystems might need a rough estimate of the number of free + * pages in the whole system, before precise numbers are available from the + * buddy. Especially with CONFIG_DEFERRED_STRUCT_PAGE_INIT, the numbers + * obtained from the buddy might be very imprecise during bootup. + * + * Return: + * An estimated number of free pages from memblock point of view. + */ +unsigned long __init memblock_estimated_nr_free_pages(void) +{ + return PHYS_PFN(memblock_phys_mem_size() - memblock_reserved_size()); +} + /* lowest address */ phys_addr_t __init_memblock memblock_start_of_DRAM(void) { From patchwork Tue Jul 9 02:36:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13727182 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 310CBC3DA45 for ; Tue, 9 Jul 2024 02:36:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B94F66B0099; Mon, 8 Jul 2024 22:36:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B1D986B009B; Mon, 8 Jul 2024 22:36:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9709A6B009C; Mon, 8 Jul 2024 22:36:27 -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 739FF6B0099 for ; Mon, 8 Jul 2024 22:36:27 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E70A61216BD for ; Tue, 9 Jul 2024 02:36:26 +0000 (UTC) X-FDA: 82318650372.12.3A1A41F Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) by imf03.hostedemail.com (Postfix) with ESMTP id 377F220009 for ; Tue, 9 Jul 2024 02:36:24 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=SojOmlYl; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.48 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720492551; 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:in-reply-to: references:references:dkim-signature; bh=d/wAyZTOVWvFtpD3rAecyL5NKhlbJZDYmglLcjhS/4M=; b=nGgjW3KcVg/A5iUHMi3vnF4Ih5RQVao8701hCkBQByNOp6Ea+KeZutyNPN7lilWJRHj23L cH/XTbjBAqEWCSM0hzTTFn4vxYz0bfca6xmnMf0rc5xuORX5BICDLQo+261ltPkXMevMEi 1yBH9k2el7SHQAOQAB2t0kusNWFUzr8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720492551; a=rsa-sha256; cv=none; b=IjYHywWWSD6Rr9cACK7Y6DjwOOQu+z7UNGgUn77JX7axQ+dq1qbCGfoz7pHQbGHeaYI+ws eTSqowdyhhKesi5oz4Gmb7aCeKKgFfoSfLNTOsXs6TmmE54CPVk/g7367SgfYC1GTYTKP0 JEDfmhsxEf6/gYubign8yUt+wYRdMBo= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=SojOmlYl; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf03.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.48 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-58b447c519eso5580425a12.3 for ; Mon, 08 Jul 2024 19:36:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720492584; x=1721097384; darn=kvack.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=d/wAyZTOVWvFtpD3rAecyL5NKhlbJZDYmglLcjhS/4M=; b=SojOmlYlYXenVXOgpjUOx63L4A46FfxH+xrV7LZojrk0viOoMuNx8n9u9o2KBVbQ1M nXu2GYiAbtcOqHZUdpeIks/ZVXWh9F7GmIvuOWMy0sSbZxTvPrvAl9c19oreTQofGrVZ I/CNWrqYc0kXkicO3cPjQXQna6s1l0RtbkK2RXUq4IdqP1eNg0qY+ra8XXtp2bO8Jg1j 4PyoTTfX9fzpHYLQnw3TM2eM0VNy6L0NOT0b420eZl+4V2eil2mKyWnwayos4Mnf1RJH +4nNa1zQw/p5/cY3FMW8q89fpM6i148DuNkpA0NksEQBDEyZokNsEeWRUVkTg1KQ+qsa BPpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720492584; x=1721097384; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=d/wAyZTOVWvFtpD3rAecyL5NKhlbJZDYmglLcjhS/4M=; b=W8T4UHpFOFCzXRPBXYHVMNWlnqTxqgLA0ij6elx65SQKpWcQtqNSrBWr/t3QPNPrZO YD7BYeRAbHaK1LFL//9OieVEiRVhFwic0i+FVMHtViVjRhGkxxXSPMsoMBcr4GostZOn St8Ph01jWu678zEXO0x+c+A5vdWNsPNHOxG6jRUXWnm/ELTU86RVuJm5ftdWfQbt1nDz wpW3jfTYL8oxBvgat+eWdz02MvX5zNi5J/9xTdbJuBCK03cPXhS+8nM2LIHzzC3Rv4OP stF3iy7WFxiWw3g01UGnMP65Pd4WHH4nr2okWSzi1cYU3+0Xo2mchtEV081ljAGKsJsZ JiWQ== X-Gm-Message-State: AOJu0YwedZBdMWPUPKYNhvWBn/PlqmCN5JyUe8NpFJNtrPYzOXQsr+UT uve3u3iUgVCwt3+RxUdxB8UcYQW0+snYBo82y7CT0VLifjv1aRpY X-Google-Smtp-Source: AGHT+IG0bFuBDe46akiyEVESqjZ03+fBK7ogEUSgXPWIa2oJals8wXjwQoZDybeIteOOj7JIhyhzvQ== X-Received: by 2002:a17:907:3f19:b0:a77:c548:6456 with SMTP id a640c23a62f3a-a780b88608amr89849466b.59.1720492583774; Mon, 08 Jul 2024 19:36:23 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a780a72fd39sm39561366b.91.2024.07.08.19.36.22 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Jul 2024 19:36:22 -0700 (PDT) From: Wei Yang To: rppt@kernel.org, akpm@linux-foundation.org, brauner@kernel.org, oleg@redhat.com, tandersen@netflix.com, mjguzik@gmail.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wei Yang , David Hildenbrand Subject: [PATCH v5 2/3] kernel/fork.c: get totalram_pages from memblock to calculate max_threads Date: Tue, 9 Jul 2024 02:36:08 +0000 Message-Id: <20240709023609.21332-2-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20240709023609.21332-1-richard.weiyang@gmail.com> References: <20240709023609.21332-1-richard.weiyang@gmail.com> X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 377F220009 X-Stat-Signature: t6eopg5j73989fxks33a9cuobrwyut8h X-Rspam-User: X-HE-Tag: 1720492584-889162 X-HE-Meta: U2FsdGVkX1+KDEaT4gbhPkywXMdtHmCn8FkGTblH/7GA+WlbHGf/xDcqjwFSdHPFBA0O1Pd2dFtdFMFX85H6wlf46XlForU9ZhbEXHuH+KnhcAr5TOe/+bzL9bmE9qDzLIaXEC/1TGAkrzr7eYRaMBh+mGHEpGxpOwGww28G/d5+kEEmVeciUbOwVQBxcJ0aljGUWOy2bokT4OQoyluH7Kpo6Gvc9RJ9/D7Ir7mv3lr+UJUH8s7U0EB0ipi5WoImX7onfNoTkf3dmZuGo/ZkOPnqv6DgqZxyrlSr4/sSEogLA1rKvJe8voXOD5Q2JxwKNrCEvaX2WEescz6IdKnyhW2OI1iy71DQKXcAxG/tCodGSiOTf8ZrhrPemybQln2uPxWzj9zHNZbxNzSzvVfUb+R9X9Izz/8f3ftOqrUxt/lCJgf8KWVSAMhgrACE61JqobT9a8oJGFqO7od1wFt8tdhfMTOwrVJAuo715dVZ1MTWa7cFPr3KtLeZRtWa9Xu8PkAjCpM+4xtikN/DKraB8rIK/Bq3Sjw4/2ddG+Rm+mxr2Sxnq9mJMTLWSnBCEi/7rpCMFNKQMONLX9q9ky0uBLaGANfRT/jbw6J8OrbgqhN62mIMelD+Ogitri7GhAMoLZvWncv4GgUNkyxcPtxcWY+YQHTOzsuICXxZxHvVGNCehT0cvXb7Mk+luM24VZJCos9f14dB255KcEAEWOD+w55USxsp+K/4NJ8gJmXe2nmdNun7HP8xuSTFipTeN6U4Ta/a0xtIM8jbJH+m2muDNq6WsElO48pkfdbJIzUn+DqkU1XokWfCQPz2VLAqIqxzXPgD9eXF2vqvsf2OMvm7NgNcE139xeiJRItmoQJk8qQXaUgpEiE2G2HScnMLOW7oAd3V2n0sd0oRoDI7SY0103q2ljehGEUnvFE9PHzbQqsKBI49UA009kUCMiVs2eWCjq7a2vHjK0XE78CdSUJ 7s4sVF+S /GdPWSAdVlH3Oyxdw9vhuSXJBnXZs3ybZ6U6VmnoPwYNigvCNsLneOL7Tj6ECRNrDZ3t1StwdMPjURGQT/TgGvvjwE/RpAMDCYC2c8c+yDiXs1iFHJI4W/VSMllNP13Aa36ZJUqdk+HH/AT59sIQN8lcBmgkffQ/G/SuNdQzMVw1sNXVcE/DU8wQVA9JfQNFwDyXoGkqhccPHOT/31rCNxc4ekGHIsK6+9wrH2kbEJsPDJoPDUJ/JUUfTZLVnx6wsWpTPvxHFn8hnzqXq1ZZnir+Qq2yGwqGYGZFdJBYeSs/x++pz2Vx+90GUoxE2Zg0tZKAcdN39VeTBov8ba2ky4xTOmaqpth0Zm9uAka4yyNTV4J/k5iTwk76Ai3lajBQ/69U4O0NidVj+wIm8Q1nlslaiaVSG88JhxT2SVHj7j7AQPVlC7JwX7/OCq4qdgfF/3kF/Lb+wfN2Gx3J8se1xGj/sEhMORcbXgdol5UYG5+ILy8Crcge7puIczSgv495YGXi8YcIkV7vR7NOzd8Zn1W2Y7DPxkG43kOtz 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: Since we plan to move the accounting into __free_pages_core(), totalram_pages may not represent the total usable pages on system at this point when defer_init is enabled. Instead we can get the total estimated pages from memblock directly. Signed-off-by: Wei Yang CC: Mike Rapoport (IBM) CC: David Hildenbrand CC: Oleg Nesterov Acked-by: Mike Rapoport --- kernel/fork.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/fork.c b/kernel/fork.c index 279efadabbf2..d6c2a4ccd532 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -999,7 +1000,7 @@ void __init __weak arch_task_cache_init(void) { } static void set_max_threads(unsigned int max_threads_suggested) { u64 threads; - unsigned long nr_pages = totalram_pages(); + unsigned long nr_pages = memblock_estimated_nr_free_pages(); /* * The number of threads shall be limited such that the thread From patchwork Tue Jul 9 02:36:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13727183 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 D32F7C3271E for ; Tue, 9 Jul 2024 02:36:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 552E66B009C; Mon, 8 Jul 2024 22:36:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4DC846B009D; Mon, 8 Jul 2024 22:36:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3326B6B009E; Mon, 8 Jul 2024 22:36:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 0EA646B009C for ; Mon, 8 Jul 2024 22:36:29 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A559340511 for ; Tue, 9 Jul 2024 02:36:28 +0000 (UTC) X-FDA: 82318650456.14.F3436CC Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) by imf29.hostedemail.com (Postfix) with ESMTP id EA364120002 for ; Tue, 9 Jul 2024 02:36:26 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=avq6oyBi; spf=pass (imf29.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.47 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=1720492572; 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:in-reply-to: references:references:dkim-signature; bh=bjE8DwUrlDCrNUnU9lbz6eMDCZBVO75llm/3njyJ2S8=; b=I5UG3vCsBUl+1MV/EvUMPB06dgprE2CGD3VfsgZaqymhYLqI5Gg0THxVpDGr2hnSHgU1UC P5RH9YgWf1w6nwvRv1MeVP9dRbYpv76YJX9/xMSVn5Ksawd7BB61r7OwcF/k8zzbxYCqL5 Ae4y2Ij6NomNTpxqPgOQicZwVaWajxY= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=avq6oyBi; spf=pass (imf29.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.47 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=1720492572; a=rsa-sha256; cv=none; b=YOW0RhrIrd54qdBT4zQC2F1WQo3be/SBoyiQ0EiKYv0U4vsUOo+ocYjceCmo0Lhx6gEOXz YV31qfs3RI6kpkG8Mn4YYNcOfI0fBbmuWC/IZhaulxZt5+Rp4jULE0rSCl4kDlxoLOQoaf +3gNeqhB/NxakKx2HyQgtdV45wbpxis= Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-57cb9a370ddso5777574a12.1 for ; Mon, 08 Jul 2024 19:36:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720492585; x=1721097385; darn=kvack.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=bjE8DwUrlDCrNUnU9lbz6eMDCZBVO75llm/3njyJ2S8=; b=avq6oyBif9ah7QE4oAtfdJOEEK0Ks3KZ2f7MdNN2npOnvr4Y65jc1h7j9LYgL800Wy iVwq5B+Qg0AmiYyGR7m+poJ2jOn2OzxUMAWC+aUSurqteDW6OCG8ikqF1lLKNL5Rli97 hwqo26KPzW848lilcWEOAwTzZMUb5P9ktKSvXeb6RwMKGA56uxNUFu1xVVuBG/y7B5s4 lZn7LPsrMrLD622BdJZzqvBNYKwGd7Y6x4Ysci93694FevUJjcqRYq5EuIpoVvqebNoN UJfHAfnONMp+v44SKmMjW2LTUo1IEdtnSoTk0qiXg1hFIaVV3pNxAd4x9A5MMSFUdJ22 TSYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720492585; x=1721097385; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bjE8DwUrlDCrNUnU9lbz6eMDCZBVO75llm/3njyJ2S8=; b=ZJg8Lv/wWWpud959SIoZC+vxyp3prfCKFUGqqy4MhlxXlLKn9UYqq+yZwvaU/oz9tl /cinSWz+WzBUG93LQ+1n9YaBMi/x/LyImqj1FiP8yYzxjwoX3KAW7Ovv9+AtjBy570he OJ6QzGsiL/LXJTYWLyTOvAeGCFr449WxfwxvkMyb5mlWtVmG9OLVddktmbxiVDfFjtpj lljxbDcd62vTnzF38d87sdYwEaZA2YI0F7/OXRiJU1os5+IbpD2/5OyhTWgsI9kgvLwg +C5rJJNW3lGPCeJuPUJxNVdieEIyd9dk5cIzndRiVQQ29bXPFuSGy6ZZqBHIXkhc/Et0 O4AQ== X-Gm-Message-State: AOJu0YxWYYzVwdaCZYYDjMYWDlVhtQLJsDcNn+g4IyyZw1RfwlDHaU+y taNprebPkfkmhXxTGQmF7Bgaauz/KFYzs0utuUxIK82IOONw0CuD X-Google-Smtp-Source: AGHT+IHjanqjTqcL0Xrni4Axg3PX3dOfKaO04+W/v8kVkKYxuwW8Byhz9w7CuaPm/tiMa9Xtq5i5xw== X-Received: by 2002:a05:6402:651:b0:585:4048:129a with SMTP id 4fb4d7f45d1cf-594bc7c81camr639810a12.31.1720492585198; Mon, 08 Jul 2024 19:36:25 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-594bc4e819bsm500496a12.51.2024.07.08.19.36.24 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Jul 2024 19:36:24 -0700 (PDT) From: Wei Yang To: rppt@kernel.org, akpm@linux-foundation.org, brauner@kernel.org, oleg@redhat.com, tandersen@netflix.com, mjguzik@gmail.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wei Yang Subject: [PATCH v5 3/3] kernel/fork.c: put set_max_threads()/task_struct_whitelist() in __init section Date: Tue, 9 Jul 2024 02:36:09 +0000 Message-Id: <20240709023609.21332-3-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20240709023609.21332-1-richard.weiyang@gmail.com> References: <20240709023609.21332-1-richard.weiyang@gmail.com> X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: EA364120002 X-Stat-Signature: f7t9htj7b6t6u7i7fh9j585jnh5yur7g X-HE-Tag: 1720492586-883706 X-HE-Meta: U2FsdGVkX1+On+gBb8SAXLGwObpfChT3KwTVDuST5dOSJPVK2WUAb4rDxjU2Wvi2XmYuSeDdNHHZ5OkzCAG/bomSJkQ6opX6LaTGjQYinMPsoq7S/T+2w3qjW3op80/pHjmSYIKfPi+UAsMmIYZ/JPUDEssfAlxWXCGIGjj8CH6dzQk198vCI0oS9vvB/H7eEZiYxb2yCYayA9AUuahX0irHQ7mJe5mSQApyKCeqaxt8ROhkmLb5NUaeeDWu6ZUV0vD5H+OQYy4mKFe5brQ4i9LimoZK4hEjByk91KFCs4Z2rR+x1Z1vJ6u3Grkil5/NFttOR5RT3h+qDR3azkFVX5XPb5bBkoELT5YRgVGA/vjVZ77Em5ifYpmz8WjqZXDloWsvzjKv+Zfm/DHRUIOUUr47f38hjqdtLAxZgqDbAWTHoTVvo88tPxOTS/xQHgLZyDBjCM6xztCLjikmW8t5UgiR82cLzUoeEkMEefqF0IDZlbon5vdKnHDUBLIdLmQ0tjTaH/JUi37hRTBNqNaMd5UlJoUPGo/LgmXeKj5ae31lrtAaRlGjv+kbKchskxMEey6kJP3GDQ4gg98zvXVdYWXzxmxzPttW+DQasSiL305i1wsj/5sXOg6NN12SGMqWLbyPw2dpOe9L4u4mAguhb6QZe5qQdolp15XFBK/wVbv9lXFUB7MKdgTVftbBvh7xqbJtjf9mRwSYkxGmYSodbAv455qBg6rXV/d/1O7dTC1oZw1fSUQQ10KDWI0kwFg8T1ySHklYU8fVdufp1FGz9rWl/O6D0v/FumNpqbOej1Gfmhkzrg0T4MWTi+MubtTHHNYopPD3ufZWYPjT/DHLQ/0hXDlZ2EnFQ7on4RO4RU6h1QUhOV2ZuiRlA9ljqIW+OP1ree4hyEbHm4JjLBTPG6IkAnCY1r5eP3lBb4jSUaw+OEkZSKom7nNdqTdJHfady5r+GZcGV/7AgKvfCAx XMNk+xjc BysIu+PZJXiTDQkyAaA3mJ4v50wLkzgyz7sH0JiTrUfPCO3lsutJ9rMfMK03f+YviWS6IiTodDnAiScFj5rNQ/TmFQ6LOhWOAAiSF/Jx1LoRCdODfQjCinD76sdF9+DVm3Q87ACW0+HrZXVMIdsElcxZf/rIYZa/Ehlixy8gWeCAgnsxBCWNt6QktWvntr1Q7UIE+cg7kNlHO3irH5uxE21pQI8cz/4R6x9h7yQSl5XaHIT5xJuT4lqzrgRNQtDDGcINB5m02dCAwTwe00C4rlNEEmRZBSOxklmGDTxMZ7i0yGD/I8UAw4uWxl2tQUx2kqvyOPHkN3Or++sJBL06h/FRnM6+GZccPIvawuh2nUpT9lqZqxiUvVpi5av3CZR7U2Z1R7uNzWqXLL8S/g0a1VWyECTnanYnXiFAVE1pNqVqsHBHXubAJc6neaAcr454WANrG6HUBi3ewIQtnsZRIxfQjQZlFcDjYTQ5Zw04hx6fHpsqwbYFPqZ27q5Pl52OVn6rdrIwN1cGr8mMP7yIjQwsbQ41DzkEtfIvnGxxZ5cs9SyhXk1XxwLd+4Q== 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 set_max_threads()/task_struct_whitelist() is only used by fork_init() during bootup. Let's add __init tag to them. Signed-off-by: Wei Yang Suggested-by: Oleg Nesterov --- kernel/fork.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/fork.c b/kernel/fork.c index d6c2a4ccd532..8d37c046dfeb 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -997,7 +997,7 @@ void __init __weak arch_task_cache_init(void) { } /* * set_max_threads */ -static void set_max_threads(unsigned int max_threads_suggested) +static void __init set_max_threads(unsigned int max_threads_suggested) { u64 threads; unsigned long nr_pages = memblock_estimated_nr_free_pages(); @@ -1023,7 +1023,7 @@ static void set_max_threads(unsigned int max_threads_suggested) int arch_task_struct_size __read_mostly; #endif -static void task_struct_whitelist(unsigned long *offset, unsigned long *size) +static void __init task_struct_whitelist(unsigned long *offset, unsigned long *size) { /* Fetch thread_struct whitelist for the architecture. */ arch_thread_struct_whitelist(offset, size);