Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp54710pxt; Thu, 5 Aug 2021 17:46:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8phcZJ0TmsqPLRZjdjYmNsrBkWNgk2E/Yd+croy8Y5k5rieTFlHcZEowWguHAo6ZPRcwq X-Received: by 2002:aa7:d757:: with SMTP id a23mr9875392eds.29.1628210807536; Thu, 05 Aug 2021 17:46:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628210807; cv=none; d=google.com; s=arc-20160816; b=HmvycF9ZmPsapkP5rVUQfjziZrz4fFoDdtT4Qcft0BHYn1bbq58bo7HrjTa25lsJYz EXstEtIuTeWSK1HwD+K3X2jNlIMMeN9EAAArmDn0FH/39UOoLEg5K7ssABOX2CkloyQ/ sR/x0J2K8gliL+hjQYq0aIGPcDIM4UmAOYX6uzP22maLLQUnWjEBKl/apDET41v8OGMN knM04vL6N32eOr9jUrIFGjKQJv5knabu3toJMCXNpCtUvRXDxR1cghhNgiBy8Ylh2gHG tgsomGCMlgx5fs1tpx8Eo0wmqy+4Bmpmw34WFHW4V01MQzubbUHgbFO5Yd8AgeTbzmNc WwDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version:reply-to :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=orYSo+lwOeqVcrCXP6bMLdXhBxG79CHa8pLqvu93F90=; b=oqDbq0ylSo/OPv+ML4LzXjFZvOA8aTYT9waoYKpHLpjUhfKOuYYW016Z39V9ahVbI7 xHp91A0m1Y31/8tEHKu6fOmzefQA/s6QO2uHlP50z+fcXUSqk74ELzoSZC9j5A76cKY7 VAonq6jgFT3fvx1plDB7g7RhmLlDJ2IbU2l07P22k07VbkEWc5oNhvIlDuT+ecFpKUWB WqSHi4Ma3/dDWbknUypL2JWqegExiPZGyr4eWBQ2M6VFD0aGjZw9Mb7PADFpwAtnszn4 sfhPKlgoIiHpum+RmV+raMUevQJbVbMtTjJFwsn8T9cXDdLM29uwxMIvKkZ1TRK4+GQH vrcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sent.com header.s=fm1 header.b=JLiPNY0a; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=tvn74sNC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bv8si7882196ejb.87.2021.08.05.17.46.24; Thu, 05 Aug 2021 17:46:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@sent.com header.s=fm1 header.b=JLiPNY0a; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=tvn74sNC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241745AbhHETGN (ORCPT + 99 others); Thu, 5 Aug 2021 15:06:13 -0400 Received: from new3-smtp.messagingengine.com ([66.111.4.229]:55877 "EHLO new3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242235AbhHETEJ (ORCPT ); Thu, 5 Aug 2021 15:04:09 -0400 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailnew.nyi.internal (Postfix) with ESMTP id 17EEE5810BB; Thu, 5 Aug 2021 15:03:55 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 05 Aug 2021 15:03:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=from :to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; s=fm1; bh=orYSo+lwOeqVc rCXP6bMLdXhBxG79CHa8pLqvu93F90=; b=JLiPNY0alezfanhcEGypspe2ruEbc +S3RVW03KEkS07YejHfFIg6iCZiCQsu9h5DwzMb0jG/b0FrkS4c9Y/NdKeacdvTK 5IEMf1NOtxdyT73Rrqkne+wzqMExrCYGUhVRLM03HCgH5m3P+z644LCalPwbCIVm pRvg3/y4tHPT7QOKLXK7FYSnNes3rxiWEY2Fen+iycw4IPFF11hOpw2BCMjH5s6z h5CWBKWlUi+I5CIkqwWeoiOd5Brg/GLBCxFsUeeC1gqF3j1D29yY23T4ZAfbI2fn 9TUNpofZvkpjxrWCLsbmytqsxyFTB838/bJYc4+xyvgFCm88NUZWSPgqw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:reply-to:subject :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=orYSo+lwOeqVcrCXP6bMLdXhBxG79CHa8pLqvu93F90=; b=tvn74sNC FppmdcuF0YkjcIsFmOlGO1oUWpkEbiGuwrgia1EXDOKlIC/zLyaHOHfhbYtbhkWN 7g8yMwgdPehka5KZaWsaChTzPoZKaUEQj1pJxR/gAF+2F20xDi5lM8YPawRtracc QWoEsFmHsl199Ji6XBbG7EfaBsygOXf8YUMjjuymzwm1BOUVI1kFPP+vjzdxsBVL yqzrJZtkow5KsmlTgNLtGxS7UPkMG8UZhiFB+QFdtaZ6hceTPyMdsIRgdk94f6lc tuA3WgTCU4tme0WjeqbcAd9Nj178lT6Q7iAFqheIt/2/RpgDVTGcRrKUOq03SUNa Ib0cAzncyRmNKQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvtddrieelgdduvdelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfrhgggfestdhqredtredttdenucfhrhhomhepkghiucgj rghnuceoiihirdihrghnsehsvghnthdrtghomheqnecuggftrfgrthhtvghrnhepieejue dvueduuefhgefhheeiuedvtedvuefgieegveetueeiueehtdegudehfeelnecuvehluhhs thgvrhfuihiivgepfeenucfrrghrrghmpehmrghilhhfrhhomhepiihirdihrghnsehsvg hnthdrtghomh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 5 Aug 2021 15:03:54 -0400 (EDT) From: Zi Yan To: David Hildenbrand , linux-mm@kvack.org Cc: Matthew Wilcox , Vlastimil Babka , "Kirill A . Shutemov" , Mike Kravetz , Michal Hocko , John Hubbard , linux-kernel@vger.kernel.org, Zi Yan , Kees Cook , Peter Zijlstra , Nicholas Piggin , Thomas Gleixner Subject: [RFC PATCH 12/15] mm: Make MAX_ORDER of buddy allocator configurable via Kconfig SET_MAX_ORDER. Date: Thu, 5 Aug 2021 15:02:50 -0400 Message-Id: <20210805190253.2795604-13-zi.yan@sent.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210805190253.2795604-1-zi.yan@sent.com> References: <20210805190253.2795604-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 - 1 + 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 | 14 +++++++++++++- mm/Kconfig | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/arch/Kconfig b/arch/Kconfig index 01a3f8048cb7..40bd222adeb8 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -11,6 +11,10 @@ source "arch/$(SRCARCH)/Kconfig" =20 menu "General architecture-dependent options" =20 +config ARCH_FORCE_MAX_ORDER + int + default "0" + config CRASH_CORE bool =20 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 04f790ed81b7..322b995942e5 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -25,10 +25,14 @@ =20 /* Free memory management - zoned buddy allocator. */ #ifndef CONFIG_ARCH_FORCE_MAX_ORDER +#ifdef CONFIG_SET_MAX_ORDER +#define MAX_ORDER CONFIG_SET_MAX_ORDER +#else #define MAX_ORDER 11 +#endif /* CONFIG_SET_MAX_ORDER */ #else #define MAX_ORDER CONFIG_ARCH_FORCE_MAX_ORDER -#endif +#endif /* CONFIG_ARCH_FORCE_MAX_ORDER */ #define MAX_ORDER_NR_PAGES (1 << (MAX_ORDER - 1)) =20 /* @@ -1245,12 +1249,20 @@ static inline struct zoneref *first_zones_zonelist(= struct zonelist *zonelist, #define SECTION_BLOCKFLAGS_BITS \ ((1UL << (PFN_SECTION_SHIFT - pageblock_order)) * NR_PAGEBLOCK_BITS) =20 +/* + * 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 virtu= ally + * contiguous, thus > section size pages can be allocated and manipulated + * without worrying about non-contiguous struct page. + */ +#ifndef CONFIG_SET_MAX_ORDER /* NO_MAX_ORDER_CHECK when compiling x64 32bit VDSO for 64bit system */ #ifndef NO_MAX_ORDER_CHECK #if (MAX_ORDER - 1 + PAGE_SHIFT) > SECTION_SIZE_BITS #error Allocator MAX_ORDER exceeds SECTION_SIZE #endif #endif /* NO_MAX_ORDER_CHECK */ +#endif /* CONFIG_SET_MAX_ORDER*/ =20 static inline unsigned long pfn_to_section_nr(unsigned long pfn) { diff --git a/mm/Kconfig b/mm/Kconfig index 1f9bd3371765..3a030b439501 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -89,6 +89,22 @@ config SPARSEMEM_VMEMMAP pfn_to_page and page_to_pfn operations. This is the most efficient option when sufficient kernel resources are available. =20 +config SET_MAX_ORDER + int "Set maximum order of buddy allocator" + depends on SPARSEMEM_VMEMMAP && (ARCH_FORCE_MAX_ORDER =3D 0) + range 11 255 + default "11" + 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. + + This config option is actually maximum order plus one. For example, + a value of 11 means that the largest free memory block is 2^10 pages. + config HAVE_MEMBLOCK_PHYS_MAP bool =20 --=20 2.30.2