From patchwork Tue May 18 09:06:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 12264243 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69354C433B4 for ; Tue, 18 May 2021 09:08:07 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E210560720 for ; Tue, 18 May 2021 09:08:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E210560720 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=CPF2QRU5r/ED7+oUgvGknDWDO6TsWDNVEVxh82JSHcg=; b=D/2abfEdFDZhhqA7/KobVcblA jd6coHeJyFzvDG4eUb9wg1CL2xvHtNBlCQvUsFNm7k2CO27Yb3bMD5qKu8H4lOGfoV86YIJ8iLe6J qmxRjVDhB62xcfq4OPLqgoPFe1ArDNI2rc9o8q3GGj0vbvjMb4yWlsXmYyX+3pGKFKz33+W7zQN6Y NPLeQGp6mKJCy5rvbOa0lbPUcyCXqmrbQl/Bn47HFizIwg98jxIkfBhYMr5EeuwkQr5q2F6B6112v TNms6RIM0NU3FLi7wwj1spiGIqk7dtv8457FbYhUuQ39bxZWXRgj5NyqR7jyhIvvYUI3AiKRYjvC2 Kdjog9mMA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1livgU-0002RL-K7; Tue, 18 May 2021 09:06:38 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1livgI-0002Om-GR for linux-arm-kernel@desiato.infradead.org; Tue, 18 May 2021 09:06:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=4smYcTa15UYqyc9U7xtsvhzdUIi7+SqKvfQW3p1ngQE=; b=wMjICTBp4o+Xxybp1n63/eNWCH iA1Qv5/GFnl2Q4Uj+504aTlKbSMWxF0xq0TibOU5j0x86uWsqNNGgfPBeNRPGLbODWyGK/2AbYOyH k2zlZG+BZ1ufVb+E3jPjq1CqSii2g2acgK31aW04QbAo3db/i2+VD9wgLGxjcTrRSo0H2YQrlsqLY 5PbpBC4tDTt4ACUvmHqmGqK/S6gqKtACcO6wil/rLIeuVh1kfWZ0tjc5Cx1tToMUvxofcNLDYtiz0 j2bxGMJeA82ORb1spzBo6U9wZmzHnNnQHhO32IPh/E1cyCaM+RnwYq72Y7eVXgkpe/ufELWZME7m2 dltVCXjg==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1livgF-00EUPi-Vn for linux-arm-kernel@lists.infradead.org; Tue, 18 May 2021 09:06:25 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3617D6135B; Tue, 18 May 2021 09:06:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621328783; bh=qrNdjflpUvLivu9UtSwHedId14adKJHrYDNOU0/V3Hs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XfTTMQYAEQMi3fqTkr2dL4u5aQ32iekJ2f11E6d0LfIrcTlOXc5RujyIPrdD67aVM L2u5P1RKGkPDNEfqHTuTR4n63y7AtCLBctt7+wkO85ZYjOwurRE16omdDCkeCv7xkl 3UYTPnmlKWi2EFQ7CxUkYEkPVAkTxLLHSt+0WXy5+cx3uC4dk3sexIgpsEN61Cxsl4 2QnHzfeS+5aReMvTzQVK8tQsfYJUtDkzpubLJ3l8xTJTIaubeaTKrl9UP9wmi3qtKD ZpKgI2X5y/4CpFybv1p2DziIl2YD9kbAWzSrckVpt3fgdHSiexgXnFBPv+RCj0z1Rd L44IAuWPcIjJw== From: Mike Rapoport To: linux-arm-kernel@lists.infradead.org Cc: Andrew Morton , Kefeng Wang , Mike Rapoport , Mike Rapoport , Russell King , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/3] memblock: free_unused_memmap: use pageblock units instead of MAX_ORDER Date: Tue, 18 May 2021 12:06:11 +0300 Message-Id: <20210518090613.21519-2-rppt@kernel.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210518090613.21519-1-rppt@kernel.org> References: <20210518090613.21519-1-rppt@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210518_020624_070060_DA434E85 X-CRM114-Status: GOOD ( 13.63 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Mike Rapoport The code that frees unused memory map uses rounds start and end of the holes that are freed to MAX_ORDER_NR_PAGES to preserve continuity of the memory map for MAX_ORDER regions. Lots of core memory management functionality relies on homogeneity of the memory map within each pageblock which size may differ from MAX_ORDER in certain configurations. Although currently, for the architectures that use free_unused_memmap(), pageblock_order and MAX_ORDER are equivalent, it is cleaner to have common notation thought mm code. Replace MAX_ORDER_NR_PAGES with pageblock_nr_pages and update the comments to make it more clear why the alignment to pageblock boundaries is required. Signed-off-by: Mike Rapoport --- mm/memblock.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mm/memblock.c b/mm/memblock.c index afaefa8fc6ab..97fa87541b5f 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1943,11 +1943,11 @@ static void __init free_unused_memmap(void) start = min(start, ALIGN(prev_end, PAGES_PER_SECTION)); #else /* - * Align down here since the VM subsystem insists that the - * memmap entries are valid from the bank start aligned to - * MAX_ORDER_NR_PAGES. + * Align down here since many operations in VM subsystem + * presume that there are no holes in the memory map inside + * a pageblock */ - start = round_down(start, MAX_ORDER_NR_PAGES); + start = round_down(start, pageblock_nr_pages); #endif /* @@ -1958,11 +1958,11 @@ static void __init free_unused_memmap(void) free_memmap(prev_end, start); /* - * Align up here since the VM subsystem insists that the - * memmap entries are valid from the bank end aligned to - * MAX_ORDER_NR_PAGES. + * Align up here since many operations in VM subsystem + * presume that there are no holes in the memory map inside + * a pageblock */ - prev_end = ALIGN(end, MAX_ORDER_NR_PAGES); + prev_end = ALIGN(end, pageblock_nr_pages); } #ifdef CONFIG_SPARSEMEM From patchwork Tue May 18 09:06:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 12264245 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E662C433B4 for ; Tue, 18 May 2021 09:08:12 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5E7A16108D for ; Tue, 18 May 2021 09:08:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5E7A16108D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=vs+Yh1aq2QkIEuYeYYuKKx2R5/pDLmOe9MCxJRpJ3cM=; b=Elh3xFAtbmtxQKINWe5Xo/nlF GjpqgUM6TRbq1Mwfrs02XlzIvd+feMsjnlggeq3exQLb5DGnMofhz+9NlWlYEen0lupzWnndv1dT+ Koc9NozBFxqOMAMZucmJ0z7WjYC91V0OXoypOljukmqt2ZHRj/7RJOme2QSgat5wb4rH8FLpG4GIl 140juGkRxiPTJi/ujytZDt0Jifz4wZ6sCToYgMjm6vFKxFvUJnCuaUTeA/e8m1V6YB7rfKaPjm5UW ECAUg0f8rNN/kZTiWJXHhRqMKYOdQezT+xfwKsXJXEIo4Np7kQVeA7DBdXHdGDHO9XLP7yeXbf47F Pcmx+WG3A==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1livgf-0002Tc-23; Tue, 18 May 2021 09:06:49 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1livgL-0002PX-Ja for linux-arm-kernel@desiato.infradead.org; Tue, 18 May 2021 09:06:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=6B4X+w0gstcYRgmA/S9+I4BaeY2ESvlDWN9mSom1Hqo=; b=s671xEvpCFk+Wb3JHMlRhQ9iqw Fjmxvv6GRZT5IfGkvdguZs9i5mX/0uC/tP2LghKPJ0LNx9NJuvxkxM0R0gtuqatuv023iyz3ASDVX DfbopYSEjBd+TzgNW4FmuHwC4Q0YxkfesxlLw7XSlu/5CPW4KARzG/7+DJ/j9NAKcPhRpWeztagVa Nd24QjIJEQCF74URGMKbyJhTbLde8VnxXiav0t55we0U3/yPn632JJGIoIhOTnjKsqbMHJMAyJ3J/ Wpg8ypG5BdOMHZYNGAcd71v55TdTAiwfEzZ0umfvzJPtKGfHmVlsjCFvOxNJxkVm87SxrdL6c+iEL 07UY3+9Q==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1livgJ-00EUQa-4U for linux-arm-kernel@lists.infradead.org; Tue, 18 May 2021 09:06:28 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 34AC86108D; Tue, 18 May 2021 09:06:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621328786; bh=8S/jBfuQqPw5Y9SjeyOmElG9wuJ/AnCGL+Y38mTgWSw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GiPSzD3EHlwQp2twmDYDpgwIJ+zYdl24Jne4bvdQbA/dO2SFfZoDD0RBu/OB1oFBM Gnzin6LGBxpmo/uJqT0ZQtLQReJHKqBVUUfi/dCG8iL5c/miJdVGl7ZtN2BaswRMfM dwJsiZvxb3ObGV60edfQNhVqmbHcZ0GLl5gmqUja1gSsVkCalkXG1yeKLSGeDQWt33 +YRwhxPRnSYIFoviTH0GkegVHUEAxDVqo3siMMTcm84PHk3AYo8BbvCuIi1v08B2Jj plXqKlFXodC8Z54ua1hfiYSBgglKyKY7yd5B2gBNZfsLbz1YH3LGwFwP3R+x2ZXFXM nFXFz2y5tzF3Q== From: Mike Rapoport To: linux-arm-kernel@lists.infradead.org Cc: Andrew Morton , Kefeng Wang , Mike Rapoport , Mike Rapoport , Russell King , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 2/3] memblock: align freed memory map on pageblock boundaries with SPARSEMEM Date: Tue, 18 May 2021 12:06:12 +0300 Message-Id: <20210518090613.21519-3-rppt@kernel.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210518090613.21519-1-rppt@kernel.org> References: <20210518090613.21519-1-rppt@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210518_020627_214880_48AFC45A X-CRM114-Status: GOOD ( 13.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Mike Rapoport When CONFIG_SPARSEMEM=y the ranges of the memory map that are freed are not aligned to the pageblock boundaries which breaks assumptions about homogeneity of the memory map throughout core mm code. Make sure that the freed memory map is always aligned on pageblock boundaries regardless of the memory model selection. Signed-off-by: Mike Rapoport --- mm/memblock.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mm/memblock.c b/mm/memblock.c index 97fa87541b5f..2e25d69739e0 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1941,14 +1941,13 @@ static void __init free_unused_memmap(void) * due to SPARSEMEM sections which aren't present. */ start = min(start, ALIGN(prev_end, PAGES_PER_SECTION)); -#else +#endif /* * Align down here since many operations in VM subsystem * presume that there are no holes in the memory map inside * a pageblock */ start = round_down(start, pageblock_nr_pages); -#endif /* * If we had a previous bank, and there is a space @@ -1966,8 +1965,10 @@ static void __init free_unused_memmap(void) } #ifdef CONFIG_SPARSEMEM - if (!IS_ALIGNED(prev_end, PAGES_PER_SECTION)) + if (!IS_ALIGNED(prev_end, PAGES_PER_SECTION)) { + prev_end = ALIGN(end, pageblock_nr_pages); free_memmap(prev_end, ALIGN(prev_end, PAGES_PER_SECTION)); + } #endif } From patchwork Tue May 18 09:06:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 12264247 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EDEF0C433ED for ; Tue, 18 May 2021 09:08:24 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BB612610CC for ; Tue, 18 May 2021 09:08:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BB612610CC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=HT0woBlFjUGmVTSNuCDgEMx793NK1+NGm9WRQ+OttvY=; b=Bp/Kf34dmSe6WlQI4YnkGfAnA KWWVPEjObkILBXyEFxToN29hqqYlUvRPWJHqbOLcgGKfJo+B7wMAJESXba/y70FmBbqaUePJ+TuwO qcbMKdok5HNlo83bGy9Pxu9VlZT5xDZqlvslwTvz0tWCi2UZ73tQ84cg30Pjm6/KIt7XV26WKMewG k6V+VmdKgPlYuW/wRiOG3ppIG7pSB/mFR5Ibqrb3OHFf/nxHqUgiNtKxZDfYXdKQsH08k/8vZAP9Q j0JDlGN4Qv9H6T8a2LEKK8zO2953LP/leJ9QP2Y58dQNzhIFIJKnYq8rCvRne/7FPpZ0xowtVIyk6 /KWcn6XMA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1livgp-0002Vi-Mz; Tue, 18 May 2021 09:06:59 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1livgP-0002Py-2N for linux-arm-kernel@desiato.infradead.org; Tue, 18 May 2021 09:06:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=q9CJp87B8gPJYMJvikJXD3+SXfgg2u7NWvQoTze/cjM=; b=WkwhD+Kf+bfwT6F2ZYkM3BgV+4 tcScWg/IZ2/JcxzQZQ8NTfLzlNDyY5qWMKmKGjiq9IK4JLHBpDuKPpgrqTVOh5POwAFGjp4Vy3YC4 9JMJ1NQPCCbtpH6b4gsaPvdYrHoAp111pHqna49JsXKFkBb4i6BEH2yX1+rmrZlzJDx96LBsdAX2Y 5HlOYTht+X2/1hCqD1/tigvqHZPz7vsehgJx84NlX3JYzMNMQAlj35BNdB00havROxzVvu9pQWa6V TI0K8arQV0pipIzjqZABic8DeXNY8nxdvw4q/iz7yJyTwkkSQc0IgLboRxPCm8OegEVvAIpWVR1mN +7iyNz8A==; Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1livgM-00EUS0-8j for linux-arm-kernel@lists.infradead.org; Tue, 18 May 2021 09:06:31 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5C13561209; Tue, 18 May 2021 09:06:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1621328790; bh=9+8VlIrFfLEmzRoxqWF0ylaXDWsmZt0DQAU8LObraoc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tum/Yu+aKBsznhRuVylQK1gPSXlk4/7f+dqaXzkFCAWeO/0tZdRrJZtzGTM6D28JO kNXoQsHu8pYcBj4X1N6ufEmYx14mMILc9d/2tIvJVWRyafGupktUOVExadKNVYaMGZ llENDa6we67Ooe34Xi2kSQ/P6XCtnqQ5WnnqX9SoyRCkHAwcWOxOdhZTeF86UzVNxL 04embraLt7uvp7lZ/rLgrZ6w2rjJAcQRUn/cTkCXggepKY2CGsNGa+ScXwBTxXyKTs SBvoaM2ND8iIQF2D7E+02+2ciTrM3HEhoMf5yOI0k+bMMe8zfn6o1H8bWgy6toeWHM gbkuHTV/w6DmA== From: Mike Rapoport To: linux-arm-kernel@lists.infradead.org Cc: Andrew Morton , Kefeng Wang , Mike Rapoport , Mike Rapoport , Russell King , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 3/3] arm: extend pfn_valid to take into accound freed memory map alignment Date: Tue, 18 May 2021 12:06:13 +0300 Message-Id: <20210518090613.21519-4-rppt@kernel.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210518090613.21519-1-rppt@kernel.org> References: <20210518090613.21519-1-rppt@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210518_020630_344129_4E035E9D X-CRM114-Status: GOOD ( 15.38 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Mike Rapoport When unused memory map is freed the preserved part of the memory map is extended to match pageblock boundaries because lots of core mm functionality relies on homogeneity of the memory map within pageblock boundaries. Since pfn_valid() is used to check whether there is a valid memory map entry for a PFN, make it return true also for PFNs that have memory map entries even if there is no actual memory populated there. Signed-off-by: Mike Rapoport Tested-by: Kefeng Wang --- arch/arm/mm/init.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c index 9d4744a632c6..bb678c0ba143 100644 --- a/arch/arm/mm/init.c +++ b/arch/arm/mm/init.c @@ -125,11 +125,24 @@ static void __init zone_sizes_init(unsigned long min, unsigned long max_low, int pfn_valid(unsigned long pfn) { phys_addr_t addr = __pfn_to_phys(pfn); + unsigned long pageblock_size = PAGE_SIZE * pageblock_nr_pages; if (__phys_to_pfn(addr) != pfn) return 0; - return memblock_is_map_memory(addr); + if (memblock_is_map_memory(addr)) + return 1; + + /* + * If address less than pageblock_size bytes away from a present + * memory chunk there still will be a memory map entry for it + * because we round freed memory map to the pageblock boundaries + */ + if (memblock_is_map_memory(ALIGN(addr + 1, pageblock_size)) || + memblock_is_map_memory(ALIGN_DOWN(addr, pageblock_size))) + return 1; + + return 0; } EXPORT_SYMBOL(pfn_valid); #endif