From patchwork Mon Jul 8 01:00: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: 13726112 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 6B4E0C38150 for ; Mon, 8 Jul 2024 01:00:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D577E6B007B; Sun, 7 Jul 2024 21:00:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D071E6B0082; Sun, 7 Jul 2024 21:00:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF5AD6B0083; Sun, 7 Jul 2024 21:00:23 -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 9C9596B007B for ; Sun, 7 Jul 2024 21:00:23 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 17D69A0F74 for ; Mon, 8 Jul 2024 01:00:23 +0000 (UTC) X-FDA: 82314779526.21.EA5C45C Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) by imf20.hostedemail.com (Postfix) with ESMTP id 5FE8C1C0007 for ; Mon, 8 Jul 2024 01:00:21 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=f6KkLV68; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf20.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.44 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=1720400389; 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=H3NdiAyId3OkrVUGqOgRgAW66faEghB0UHBtTZW80kM=; b=k9wukL6rDoyDyVwdmm5fzUVUPvYDCKJ7luECb0jIU67k+vC5G2sTBdzrE/bmTQlGDTUuFg yEwVJWPfAeJKObdvXzLVOx4NqbgsDO+7LqMejhXDMql0C/Kp48QK+GBHskTHq37IsH0IAp bV0Hdostmc7iU0UFWgt8TS3IKZw9aXk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720400389; a=rsa-sha256; cv=none; b=oKKLlXKOkzEoNc65kk5pWGzD09m1OSMRe61HhY0XrZOIH9Zmu9Y8xWY+yEBk2gXAxLGyXg 8lKo8J686qkmonev8eIcE5hKMsUJ58LmByaqvpOSmT1lv1XjxpzXcvD3SPze7FvwEgWgD1 mlm4zZ1FwA/pit0koRurQW8c+Q4wYNE= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=f6KkLV68; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf20.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.44 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a77d9217e6fso208507666b.2 for ; Sun, 07 Jul 2024 18:00:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720400420; x=1721005220; darn=kvack.org; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=H3NdiAyId3OkrVUGqOgRgAW66faEghB0UHBtTZW80kM=; b=f6KkLV689G8IwClGyeygANUIid7X1z+quBy4yHh36N5JwJOmSqWnqkDefKFtD7eZQ0 8oljK9p5+XigNqWRXvr9KbWpCPkrw0IGRHdyOnVfTE2ePF7BJ+OD73+oNcdodVx5iDy4 JSA4EGrUeGlJuk+iYQtCK+XGXcDRK1iGruYEv66KhlX6yMkIzW3Z21pcgFEIm07dlmbh duGPGRcqvYNDGz5sQH//j7068AX14noFg4kAr38rxBHttfTpKfRR0xQ7yfItgu5OJKiu dAfOtpRKrQs/I3YHQgofSdYBSCfzqWbD8iKp6D62jBf0wn3Bpb8T+vIcDaJzKxxM3Zht Xi9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720400420; x=1721005220; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H3NdiAyId3OkrVUGqOgRgAW66faEghB0UHBtTZW80kM=; b=R8LBTvFNk1lgExK2EUBzgh+NgGkhDjPjsJtWf95CpGzx0fUQEfLbZs0iYPENq6JGNl 6r93Hvd4pPVTqA1/5S0rLDCs7Ksx6PeF8KbYW1V53bW7b3NkwyQqihMrkAfqJMwGrupm W3s+8gq9UOIQoHHoJjb8Aa1k64upUsxjttw3WHP23cCpygBGdjJpAvjDpALyMiOPM08H +LubvrO9wQOH7fCNcevHmYY23WKS4l7lVuKUwWyFbQ+5C+jC+gAfnnsykstc2DPyooCp zJ9nzS6I6T2NqF9utgWdsQyVqnJBih2lmuuY3rsF9sCpEzIVTMLs1TMJgEkotP4dB8Gf YfYQ== X-Gm-Message-State: AOJu0Yy49Ldoy3N5gLh8Y9j5H6oVd/rw1yF7EHcNKPc1x05kAa6zN5Tv OEe2FxD1CwigxSaPmMZls5kNoCwzzSGP+QKunv/TUJlZcM47LjPf X-Google-Smtp-Source: AGHT+IH0ggJbCGlEbdNIAlUNjEkV2/8ro0xOqCXLERCyOHyPaxPfuby2ZfgoB96xxYv+uuaOgXO/Tg== X-Received: by 2002:a17:906:34d3:b0:a6f:3155:bb89 with SMTP id a640c23a62f3a-a77ba72759cmr734858766b.70.1720400419585; Sun, 07 Jul 2024 18:00:19 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a77e3f48abcsm175087666b.186.2024.07.07.18.00.18 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 07 Jul 2024 18:00:19 -0700 (PDT) From: Wei Yang To: rppt@kernel.org, akpm@linux-foundation.org, brauner@kernel.org, oleg@redhat.com, mjguzik@gmail.com, tandersen@netflix.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wei Yang , David Hildenbrand Subject: [PATCH v4 1/3] mm/memblock: introduce a new helper memblock_estimated_nr_free_pages() Date: Mon, 8 Jul 2024 01:00:08 +0000 Message-Id: <20240708010010.32347-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 5FE8C1C0007 X-Stat-Signature: iwyyschpwt8x1qgkynpd81rdrbm1okjb X-Rspam-User: X-HE-Tag: 1720400421-329946 X-HE-Meta: U2FsdGVkX18zYfFSm8pgOW7YEFZE1yAF6sYPGr5SBirIDGcrWKufEyuErSTR4DKlxhvj/DM251HzExB2PiasPYul06auXW5s5XMfIDKEWpPPp9tQ+j3ESJx5IBw78RbpaBUT61cN2Qizck65KJWnY8PTY/IdcpYz+WaYUYf2umIBQjyFDUB+cPCwoFCIjZiNch9Lyz/23f0NRX5IgKnW5GgPYvZfQiPOxg9wPVvbAbJwnse6j4HzC4QNJu0CWJLJ+c0u+KWybJvp4q37S3lA2xe43QduBwcbp+sF+mGu11oc1k4NLwmjhYPsTyF2/yXvxJ+qeZwbpMbKJdr6PxUtFgNYzQIzWAP0MkHJiaSszIzJ7ZAffFMbYGREx1EJi90Iind/bytmSw6/lp10m5PZOpefUE5+7Wvt+961TkE5NlK8sJTcZurB6kU5mV/zkMc3elHQGGqlHy8zbMGt1V8JrYZLNopTNyLR4Pe7zmXfFhWeYjjbehTxJe6JSGVJTz84D03He2+OVSLXA/ss+DTpO2R7RGCU9mn0lWlypC1umeAf3b2sacpPmgsWTrOBSWzu/Q0eWj/seqoMYb728U78YAbCKZgXAzf2Om+QvOkN4rYfGKjUabdFL0rKV5V3Kz+/0/WD5KOi/zrg0V8OW+wz3rVb8v3lA1KwcYCn5niYV2CdpT7mTU2HKu+//28ymMV9IM+qHdVtwoatgQQhk/HvhQbrla6h0qRjVTvwLBdzvDnQkfO3P6GtgW+o3pP4IMAi2GDLmvnyoCmHzeyKiSGt54gBGdgEEno746HQjN5ESokhlHQs2FdplAaj13DJp9Y2eaqhHR9X4gpIE0bGDVo0rOyjrtMsnMtj8nyo1CT2n76Yl4kD6CaunfZ56PQGzhxuXTuL/+Dimg1uWF5W2zWEBj4x/iv7mDDz2kERK5ZcKejB1fm6wOngCVG5NjuSuCOA6Lyz9x+PeOdvOMDc0k4 Oo3mBc5N 3LFPV9oEcxpG6dcz5sxGoMrRXvsoceU11pf0aWhWoHyFNFHih8ZYdK+ONJqC5BIK8p9ZmuTK/WAosx65Lq8TbxEuuScxai1PwwdZywPrXWcX91ReiAuilAqxmgYR/1rqrGFVQYb79n5owh6uqPZI05wAVka35OatMaeN7qxotNOIcnlO2FEXvPap25Vw4C5HUpkDVv/BhltF/drGRVwB6AuzV1o2n01FojwdJuZOz9yYnFuEwbmi3on51MQfOWSNOwJR+KoDKEMWP1qEeoZVQ6dw6+zFzXvum/dp9YL6NIsfub45cNw/MA+4D6/6kVMZbZ9eSIeh3LXr3v4QCSW9fB9JMgdbL5WvwrIgOuB2FphzOG69bNa/U9/Z3cwnPdToUuAqXG9LdG1t1dClY8FsPW3D2/EDNBsi7eR31Y1rTo1eKP4UB4w8Sr8Hb3dJgJkZxWlFnWvqioc39wk+dkPjTysQ6cSNBqSwuCHR8IAH0cyOzR3g= 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 --- v4: adjust comment per david's suggestion --- include/linux/memblock.h | 1 + mm/memblock.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 40c62aca36ec..7d1c32b3dc12 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_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..26162902789f 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1729,6 +1729,26 @@ 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. + * + * While we can get the estimated number of free pages from memblock, which is + * good enough for estimation. + * + * 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 Mon Jul 8 01:00: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: 13726113 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 AD00DC3DA42 for ; Mon, 8 Jul 2024 01:00:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 393F36B0082; Sun, 7 Jul 2024 21:00:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 347AE6B0083; Sun, 7 Jul 2024 21:00:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1E4746B0088; Sun, 7 Jul 2024 21:00:25 -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 033876B0082 for ; Sun, 7 Jul 2024 21:00:24 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id A6D87160FAF for ; Mon, 8 Jul 2024 01:00:24 +0000 (UTC) X-FDA: 82314779568.15.4B23FBB Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) by imf15.hostedemail.com (Postfix) with ESMTP id E6125A0005 for ; Mon, 8 Jul 2024 01:00:22 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=JH3RZ2Vh; spf=pass (imf15.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.54 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=1720400384; 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=hlxAVPd+z/4aF6F4fWIjQzN+IGGbLzBgd/ODx938I10=; b=k8O5FFgVZYizEBX5scOKbij/tcoSD9AkVlHptPKMoMmC1S6kk7dnoITCpWAu+TiFh6l1tA H4IQkqyXEBtmlti304vML58l+NschqRHmUDrt3Oj7L2CaUwYrjWB8qhALILrH10RAiQcyg izo9DfMdOmpljA9XHS9oy+IsiBlJOt4= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=JH3RZ2Vh; spf=pass (imf15.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.54 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=1720400384; a=rsa-sha256; cv=none; b=zrlwBTOEmJKT5SAgZTZA6Xy3Hh1e5evzf7T+pdnoS3PF6egvlgdC++6TB6ZF8MFVtLxoVU 2y+svsrorjU4vZOFGM+9BIE4062/cbSwmlVuzPR6GEzsag7T16w6UsBlgiSea+EWt0cBUA sn+d4wxSkJhr3d6DhXHhigBFeGfPr2I= Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-58b0dddab63so4852031a12.3 for ; Sun, 07 Jul 2024 18:00:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720400421; x=1721005221; 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=hlxAVPd+z/4aF6F4fWIjQzN+IGGbLzBgd/ODx938I10=; b=JH3RZ2Vh9+KlqM0LsXuaqT8/QtLOVl5XkSL1wz9dIARjjbYtyIgIpzTCxmmYdyNl6W QGauRONW5PKEAbvZ9yg1TnyOYJZWp6sQAsWDCd8JqFuxhFRfcIazqUacyER45codmVfs kgDgzIzPqM/Cwizsd2rwyOOnkK/o8uht2zZEdG2NVGzqphIuWb0iQvr/ypxmsayV7zm3 ZYto1JFEHn+MV+XGYZuzv48W09sKPrPZW+OycWXTNJlRgKprPjiUgecWwRErq7tC4D29 ruFPHamHo01afeptdloPlOnE5PCbUHlrZmPSx8ONXSLXp25dGT/gjjrGMBSacF84xbYJ I2VQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720400421; x=1721005221; 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=hlxAVPd+z/4aF6F4fWIjQzN+IGGbLzBgd/ODx938I10=; b=VOV+FveShos9xU0bbafGbDPNyoXeRSNDolZdhPekD+VBWpbQvxKu4F1oK9Fblv5jmm M2YMcqVI0NMXbpyYE2JJIGIMxatWgTRHjfRhuP75mv9T2MpR83pDpxpQfwaPmUeZyyOt nPE0hyFC/1JD/gEzPh31znIQrjN+Yfmhl+nkKeg/VjqmTZSivzgjjhW+H6dq4wKQ8Yfq qmkHBJGwjlymaXYBoqrClTQTQUpu6P9XF8Wt4KtrsoviSt7bZP4brETgblcz5a+v3qnx vW3w6gDno/Fey4FP0d1Jyl3SWypK4G2RKEN1qzDSQftNZDWldc5E39NBGHu7RjstbfQb 726w== X-Gm-Message-State: AOJu0Yz2AGzhmQDOLb/qt9Xw9Cr9CRCrFigbIlvnzGEe6Jx5GYibUat/ lzNP1Hi9tJjoJJvz+X0GDS+gidpMzh4wc0WzLbMcd6wAHbNUbee/ X-Google-Smtp-Source: AGHT+IFX5JH5fjmnJZzHRqOg0baK8jtW9JI8FZKW4fJv88ESO66YeKMsIB3wCBd+Yn1bb+6es6HRXQ== X-Received: by 2002:a05:6402:5255:b0:58c:7c2f:5c0b with SMTP id 4fb4d7f45d1cf-58e5b4ae20dmr5541899a12.25.1720400421288; Sun, 07 Jul 2024 18:00:21 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-58ceee04b51sm5987050a12.71.2024.07.07.18.00.19 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 07 Jul 2024 18:00:20 -0700 (PDT) From: Wei Yang To: rppt@kernel.org, akpm@linux-foundation.org, brauner@kernel.org, oleg@redhat.com, mjguzik@gmail.com, tandersen@netflix.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wei Yang , David Hildenbrand Subject: [PATCH v4 2/3] kernel/fork.c: get totalram_pages from memblock to calculate max_threads Date: Mon, 8 Jul 2024 01:00:09 +0000 Message-Id: <20240708010010.32347-2-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20240708010010.32347-1-richard.weiyang@gmail.com> References: <20240708010010.32347-1-richard.weiyang@gmail.com> X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: E6125A0005 X-Stat-Signature: ewu4uhyyayxns4ecet65md51hhybxdkc X-Rspam-User: X-HE-Tag: 1720400422-71286 X-HE-Meta: U2FsdGVkX1+2uk6/mOMNi/Xjoazm7MhmRYC17KR1wpuH1SeQALlAZZC/LaCUnJLrUSDli8rQY2ld5oqIlemgHvAj4vkQcAI0pun+us184w5qPMS7uap2QbqLKXrPgr04yH+Wgll7Ohp3DlW2TFSsm9FKY3mWV2nndu/PFiucmsm1BOTkt863jgc6yDQFPe4BWSV9Xv4WQqexkJYPbvJ1/vbbBsO3gtE3WtkRNOXvqD6lMzZlGA9vFgpOZs/MUOOmZc7M3Za8X2hRPXutNLceeKTMUvVA6BTQyvc97M4r1xGiDlTAgVaLCnwCitOgNj3j4ddtMm0ZmN8BXMBaMIev8Xv6MRuWRNi1v38JoukVVwcNQyj/9D5A7aXP5N2tU74CsukbEn+2RJx1+SbTGp1TJBCTmIckQNNdn3gU3dT55mkVxGeUkpoHAkUciy9JQfdYk2Fuq2vnletcuDjldy5WzJ6N/VedhiL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ogofilter, 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 --- kernel/fork.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/fork.c b/kernel/fork.c index 99076dbe27d8..e80e889543f3 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_pages(); /* * The number of threads shall be limited such that the thread From patchwork Mon Jul 8 01:00:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13726114 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 8E06BC3DA41 for ; Mon, 8 Jul 2024 01:00:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 913A06B0088; Sun, 7 Jul 2024 21:00:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 825B76B0089; Sun, 7 Jul 2024 21:00:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6ED046B008A; Sun, 7 Jul 2024 21:00:26 -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 529916B0088 for ; Sun, 7 Jul 2024 21:00:26 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 037B2160A4C for ; Mon, 8 Jul 2024 01:00:25 +0000 (UTC) X-FDA: 82314779652.26.7048B14 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) by imf09.hostedemail.com (Postfix) with ESMTP id 43B2414001F for ; Mon, 8 Jul 2024 01:00:24 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=DhJvevbM; spf=pass (imf09.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.50 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=1720400401; 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=d1GfZdw5ohet6O1nYdwlJF2qI1saYkoy2VpOhi2t3L8=; b=hcjUYuz31R/2OEm+mZf73sic/rbiUcDDUIwV/Wex//WGAF1qBWVVvntr3ZuqyGnzPaOViE PTQcb5NTR/SlbcV2jF3TAakWTU66eR4DUBxq19d0DDAjx9w9sYs25ZbNyhkg5NAXglaPfn Lh4FnAWhTtDfxyjQmWA89K26b/4T+uE= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=DhJvevbM; spf=pass (imf09.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.50 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=1720400401; a=rsa-sha256; cv=none; b=TfG2NaLVZmd/usPhcbnnfdOz8CwfrDFh6X5NBiyx4X8slxhNSa9ZWoIF3yZP/PPJScFrIB YSYN1Iuyob2xeszmNJqcQaEDv/adkYV9MmNwWWSLpeBVU3PBAbr8V40j/RsgfK4qXphbHi Vo6VUhj16+ivdt2o1/E5brmzomjpUqo= Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a7523f0870cso395846466b.3 for ; Sun, 07 Jul 2024 18:00:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720400423; x=1721005223; 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=d1GfZdw5ohet6O1nYdwlJF2qI1saYkoy2VpOhi2t3L8=; b=DhJvevbMxfMRgz5I1F/dsQSybI0A5I95I7AVM0w0kPMJP1FKwvzkDJgVNS+xjjQxQD 9mkEdKZB37CXOg2TQDmeLELFDK5WloUWm9o1/tVBNFWEy4wlWG/3YiFqYuR4CMoaYo4v 31KXezlfLWifZ+sWQxbfjdnLYSZ2XNN4Ejmtz13aGbcmC6aIj6MqWkoSb3fSBqID+yX+ OFFkFfkZnO1K5AFQRbj3qSXyHr9ZUsExpk+k8b+WF8QjG3kq/Fy8qIbkyEb4hZpvl+ti 7cgwSDgFEfZde3OEz5Gk07r9+vNe7EroYht62Fq91CgWBkpkExyn6KGuB/VtIvQRda0z GLGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720400423; x=1721005223; 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=d1GfZdw5ohet6O1nYdwlJF2qI1saYkoy2VpOhi2t3L8=; b=usk7jjV19CP3xQMx/PzivKeogiarRm6KVGVOFiThc3+uwxvpleL0hY8PEJvpxJPazQ 7e3ep2i1m978unBHiFcMVHkyHs3dYddUWD7cE7OKOkKh2VwLEsiuhapuMsInZqJI01H0 SLBRQrrc9w8hhgRtiF7q7czFbmhFGEFmyFjFX9pkdjgen6qhBuI9Aa3hJ09XlJi1KYM3 79W1nFIFxe0EAXE0Wf1SiHn/JVgYpkb/wMRtcxUKj5duOvZZK+eUlVysrYON3+QeUdJ9 jhpndprT93kOX1TGMD2YPagvnNUvhbIop4RMXjZh1MAO9+940X7L3t3hlK1iAbHo8GKN ZTkQ== X-Gm-Message-State: AOJu0YylfJUzXnyXHsPQLuT3sVB63cI4QvF7pncasrwyENgW0kq+tQnR /ZSA7IjcgH/j8L3chgP+b8thKmhMiE7NPIBVB571jLqSe4WPwX9GUCNCfUOV X-Google-Smtp-Source: AGHT+IFF/9vfwlHq4uyZ+604i2WZBVekmv9JpXMh9mEhQ568VnjOZHP7nqNEXVDdNyqCqOx53fR5ag== X-Received: by 2002:a17:906:368c:b0:a75:fb2:8bb2 with SMTP id a640c23a62f3a-a77ba44d1a0mr576797666b.13.1720400422931; Sun, 07 Jul 2024 18:00:22 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a77df3d7cb3sm194480366b.100.2024.07.07.18.00.21 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 07 Jul 2024 18:00:21 -0700 (PDT) From: Wei Yang To: rppt@kernel.org, akpm@linux-foundation.org, brauner@kernel.org, oleg@redhat.com, mjguzik@gmail.com, tandersen@netflix.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wei Yang Subject: [PATCH v4 3/3] kernel/fork.c: put set_max_threads()/task_struct_whitelist() in __init section Date: Mon, 8 Jul 2024 01:00:10 +0000 Message-Id: <20240708010010.32347-3-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20240708010010.32347-1-richard.weiyang@gmail.com> References: <20240708010010.32347-1-richard.weiyang@gmail.com> X-Stat-Signature: fm6cj1iwcmckof9cuhusu4643qi45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Xi GQxJfd5E ljyEQ28hor6laeXdvRf6Xel5Ht7y245ur0IOyLKlE2pREWvCpXjFCl285qm6oT9F0RKlca7ZBsNshdnUl8aM8JRbXkMEnuiwA4ciYuIYYhk9OoUoiAPLmvjp192qFxb1cvmwAEH1e2SvIHVuNT75krL9Le25WAFgkzzegDWx4Np18Va+6F6NpiIUXPjtqzXslQi1t50UC0vNmIhmjrroM9V+lQ1z7+8UdOIA5aBiLekW7QDg/zpTu0jpR7EkOVigbYJwOp6/2DoCc+Fd53wzmZjLNNN7RJq9jCkA1VsombS39HT+oePfmCFZ4VMryBvho/+IQ2w/sO++AzOljpppIhJKuM7IevCixzexOXM44HE4KqAoRL2kZRLbMXFURr7MGmvm+8VVaTMRLmio6K107TmDwGbL7iqnA/Q7OQKyBP9pEhkBdzGh+dF9Akt/u9KkbYffkdWECe/5gJ62RJyiDyWsA+7+5kBZF5viAV/rlm46TYeg= 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 e80e889543f3..da0b4545d380 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_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);