From patchwork Thu Aug 11 23:16:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zi Yan X-Patchwork-Id: 12941803 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 87188C25B0E for ; Thu, 11 Aug 2022 23:17:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C2958E0008; Thu, 11 Aug 2022 19:16:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4743D8E0007; Thu, 11 Aug 2022 19:16:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1B2828E0008; Thu, 11 Aug 2022 19:16:52 -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 07FF28E0007 for ; Thu, 11 Aug 2022 19:16:52 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id DB7B516190B for ; Thu, 11 Aug 2022 23:16:51 +0000 (UTC) X-FDA: 79788873822.30.2DD7F91 Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by imf06.hostedemail.com (Postfix) with ESMTP id 7A1E718016F for ; Thu, 11 Aug 2022 23:16:51 +0000 (UTC) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 14A385C017E; Thu, 11 Aug 2022 19:16:51 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 11 Aug 2022 19:16:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to :reply-to:sender:subject:subject:to:to; s=fm1; t=1660259811; x= 1660346211; bh=nROMsz3ppqqra2BzZ2pVt6LG8fK1ajXOrNIiQ4woogA=; b=H GhqMn6eaMGEs9dwuksbm0QcC3P1rGK72b5S0638UqCuG1FAGndSFzv4qnD4/RbJ/ lbu/YQ69n7Zx0ar+GDe+0F1raAkVeAf0pPq1tsyjn0t6ZpbN+gFN7QaawTabboLd r+6g520P+po+Rg8by3137hkpijb0MIM9NQ5cXMJxfjsxqt1DzLF+tdIFH3GgediS gSHViQ0w+6TclsLvjXA9hkATpo8Eij7yul54/KFP1StkA/dLCC2TKkMS9wBLNoGl GKStVAtIBRbe9RqfzuZ4aiAMJxxlUoV9A3gmiJPplxI1oMYnrPj1quw0WkHpYhm4 ilvsLH29cn6MJvcVKozDg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; t=1660259811; x=1660346211; bh=n ROMsz3ppqqra2BzZ2pVt6LG8fK1ajXOrNIiQ4woogA=; b=f/gWE8mW8X+chpd90 Y/rfrDG37b2vNVgdyu5fpeAsXvdMf80MvaxJOJE5T9nhMdZ4kxVewOBntrVyoQKm UJHjRyaAcKIYvpsogON+CZf5+4+c+BUavfhMDmp1CMv20uIr735Oi90POIVGv1ia JextHr2gCouPaso7Kfis1Rhm+6O0ObpBeIdwpSwiKtjdPkUolSxzNl/lPl41T7np 1jFP2ffXKLF85ioAGiqMcARR1nwY2EOXmSSlcroFAuAnOY7eOEbtJQW3Gp4i6Gig rDLv9/lvPIGfes18MppOBpEfjL0+Kp7ialY7Jx9dd3w9CBLwI/avm8pjF3whh72w Yta2A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdeghedgudelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhhrggfgsedtqhertdertddtnecuhfhrohhmpegkihcu jggrnhcuoeiiihdrhigrnhesshgvnhhtrdgtohhmqeenucggtffrrghtthgvrhhnpeegge ehudfgudduvdelheehteegledtteeiveeuhfffveekhfevueefieeijeegvdenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpeiiihdrhigrnhessh gvnhhtrdgtohhm X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 11 Aug 2022 19:16:50 -0400 (EDT) From: Zi Yan To: linux-mm@kvack.org Cc: David Hildenbrand , Matthew Wilcox , Vlastimil Babka , "Kirill A . Shutemov" , Mike Kravetz , John Hubbard , Yang Shi , David Rientjes , James Houghton , Mike Rapoport , linux-kernel@vger.kernel.org Subject: [RFC PATCH v2 09/12] mm: Make MAX_ORDER of buddy allocator configurable via Kconfig SET_MAX_ORDER. Date: Thu, 11 Aug 2022 19:16:40 -0400 Message-Id: <20220811231643.1012912-10-zi.yan@sent.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220811231643.1012912-1-zi.yan@sent.com> References: <20220811231643.1012912-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660259811; a=rsa-sha256; cv=none; b=rH4tyUnJ50sJ7aM4LipdoeI3+JwTonuHL7rM/KISHtmyEuDMYXj/FwQlxsk3wHbQW/Cg/z yD0ZIJ/2UKuDcoa3phcANSzpg7typYwWjrpzmZd/IST2HUi0zOpusJxscfT9cPFYxDF4Ax Eulgs5UX+dIjl0N17KbvzgUWDPjU2b4= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b="H GhqMn6"; dkim=pass header.d=messagingengine.com header.s=fm1 header.b="f/gWE8mW"; spf=pass (imf06.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.28 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660259811; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=nROMsz3ppqqra2BzZ2pVt6LG8fK1ajXOrNIiQ4woogA=; b=t5PJpR76/Hb7/Y3ntxohKAV+O/fnO4HUfFwSE+CgyylxZR0LxlSVYRSebERptirKxYOuH4 L14YQKgrNxpq3Ye/MephOjOe462X72ADlR5g6nVNwWdDfI8mV6jtYNPv+Urqp4ClFgEcAk PHpSSi36NLu1IzuR8WyBHeo3KaN/QJ4= X-Stat-Signature: 6knf37sxm5wogxcnbxbemqkej74z6jeu X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 7A1E718016F Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=sent.com header.s=fm1 header.b="H GhqMn6"; dkim=pass header.d=messagingengine.com header.s=fm1 header.b="f/gWE8mW"; spf=pass (imf06.hostedemail.com: domain of zi.yan@sent.com designates 66.111.4.28 as permitted sender) smtp.mailfrom=zi.yan@sent.com; dmarc=pass (policy=none) header.from=sent.com X-Rspam-User: X-HE-Tag: 1660259811-700243 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: From: Zi Yan With SPARSEMEM_VMEMMAP, all struct page are virtually contigous, thus kernel can manipulate arbitrarily large pages. By checking PFN validity during buddy page merging process, all free pages in buddy allocator's free area have their PFNs contiguous even if the system has several not physically contiguous memory sections. With these two conditions, it is OK to remove the restriction of MAX_ORDER + PAGE_SHIFT < SECTION_SIZE_BITS and change MAX_ORDER freely. Add SET_MAX_ORDER to allow MAX_ORDER adjustment when arch does not set its own MAX_ORDER via ARCH_FORCE_MAX_ORDER. Make it depend on SPARSEMEM_VMEMMAP, when MAX_ORDER is not limited by SECTION_SIZE_BITS. Signed-off-by: Zi Yan Cc: Kees Cook Cc: Peter Zijlstra Cc: Nicholas Piggin Cc: Thomas Gleixner Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org --- arch/Kconfig | 4 ++++ include/linux/mmzone.h | 17 ++++++++++++++--- mm/Kconfig | 14 ++++++++++++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index f330410da63a..24baee6c3feb 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -11,6 +11,10 @@ source "arch/$(SRCARCH)/Kconfig" menu "General architecture-dependent options" +config ARCH_FORCE_MAX_ORDER + int + default "0" + config CRASH_CORE bool diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index e93faa3d7f1d..b83b481e250b 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -24,11 +24,14 @@ #include /* Free memory management - zoned buddy allocator. */ -#ifndef CONFIG_ARCH_FORCE_MAX_ORDER -#define MAX_ORDER 10 -#else +#ifdef CONFIG_SET_MAX_ORDER +#define MAX_ORDER CONFIG_SET_MAX_ORDER +#elif CONFIG_ARCH_FORCE_MAX_ORDER != 0 #define MAX_ORDER CONFIG_ARCH_FORCE_MAX_ORDER +#else +#define MAX_ORDER 10 #endif + #define MAX_ORDER_NR_PAGES (1 << MAX_ORDER) /* @@ -1379,9 +1382,17 @@ static inline bool movable_only_nodes(nodemask_t *nodes) #define SECTION_BLOCKFLAGS_BITS \ ((1UL << (PFN_SECTION_SHIFT - pageblock_order)) * NR_PAGEBLOCK_BITS) +/* + * The MAX_ORDER check is not necessary when CONFIG_SET_MAX_ORDER is set, since + * it depends on CONFIG_SPARSEMEM_VMEMMAP, where all struct page are virtually + * contiguous, thus > section size pages can be allocated and manipulated + * without worrying about non-contiguous struct page. + */ +#ifndef CONFIG_SET_MAX_ORDER #if (MAX_ORDER + PAGE_SHIFT) > SECTION_SIZE_BITS #error Allocator MAX_ORDER exceeds SECTION_SIZE #endif +#endif /* CONFIG_SET_MAX_ORDER*/ static inline unsigned long pfn_to_section_nr(unsigned long pfn) { diff --git a/mm/Kconfig b/mm/Kconfig index bbe31e85afee..e558f5679707 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -441,6 +441,20 @@ config SPARSEMEM_VMEMMAP pfn_to_page and page_to_pfn operations. This is the most efficient option when sufficient kernel resources are available. +config SET_MAX_ORDER + int "Set maximum order of buddy allocator" + depends on SPARSEMEM_VMEMMAP && (ARCH_FORCE_MAX_ORDER = 0) + range 10 255 + default "10" + help + The kernel memory allocator divides physically contiguous memory + blocks into "zones", where each zone is a power of two number of + pages. This option selects the largest power of two that the kernel + keeps in the memory allocator. If you need to allocate very large + blocks of physically contiguous memory, then you may need to + increase this value. A value of 10 means that the largest free memory + block is 2^10 pages. + config HAVE_MEMBLOCK_PHYS_MAP bool