From patchwork Thu Oct 20 21:53:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Berger X-Patchwork-Id: 13014048 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 DAA8EC4332F for ; Thu, 20 Oct 2022 21:54:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 84C1E8E0005; Thu, 20 Oct 2022 17:54:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7FA258E0001; Thu, 20 Oct 2022 17:54:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 69C0A8E0005; Thu, 20 Oct 2022 17:54: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 5C2AD8E0001 for ; Thu, 20 Oct 2022 17:54:25 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 1268AABB53 for ; Thu, 20 Oct 2022 21:54:25 +0000 (UTC) X-FDA: 80042682090.05.8496E36 Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) by imf22.hostedemail.com (Postfix) with ESMTP id BDAEBC0032 for ; Thu, 20 Oct 2022 21:54:24 +0000 (UTC) Received: by mail-qk1-f176.google.com with SMTP id d13so881442qko.5 for ; Thu, 20 Oct 2022 14:54:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BwP9OSSuHG+apHyoqkPAJ44LToseDE0HSDpJZDk5eXs=; b=jNUUsRnWlXrm8JAnuE1Xqa7UyLQ1Ntt7WFErGDBLV2vutQLJ0PQilqL0HL16ioBgaH tfq5WvKTPdO/dJLDa7W8VLb0/wS9gfOFZuMY8jvjjuPVKNIMwy9MVx/MirO3GfRRjL9n LupI3gDdDDnJkGpBaXNyK+SWatGDer0WWzVHCbIfQnp6CFkOKk6e3uHHKYH1dhv9aKUc UA3llhu3zx7UqBkZYqKQEWHaDgpLD1LksEfySU/2dYYUbXhzmBK7FSG2uF/2KLWhBZ9W k2/WpZe9yLC3nkSo4WQVXGo12b2hpsTKZzBu5axXXMLlcPqhKB9lAMVFlgQgm+2vH3RB pXgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version: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=BwP9OSSuHG+apHyoqkPAJ44LToseDE0HSDpJZDk5eXs=; b=5r08MTJ8TqFSI9r0fYLN4r+YpOkK5r38+5jrTKUQPE6j7yga9Peg43O88Pyk/s71fY +4pcPwtAqOvG85ZWu2i9IGxdFkmov3xOroVuaAkZU4Ibt6MEIbLVh/ELg69XGeDWo8fx Ago6iEtCoqEN1BdTt/mxeEByYhsUe96ddrPS3ubqGAPHB7IzwGKrWMIvP2maF+PCyils 2kNFJOlBr0G2KZHKnKbhGfz3wYSV2EtfghJdApp3Nd0q1ky4oWKnCdm/EcqAvUypzZLN QfFtDEHYdLSjc9aehzxfRpylK2mMhIIUr7vCYNMzxcRcotmkr1WnY8a2dVFKMGyfj5i2 MDpA== X-Gm-Message-State: ACrzQf3ecwukXZT0zLvDRyuVj7s9KKql2JF/DhzmUToMXmmI2M12mC7f 30Y10txXgbyhUpR/bS3VUGg= X-Google-Smtp-Source: AMsMyM6u0RdH/aVAaBL4k+8UrNNclWICnDFcnMRVg2Itkr/PEI6FjGGL8fVEwkAtL7Q/FgTRKalRDQ== X-Received: by 2002:a05:620a:150b:b0:6ee:8d04:f70 with SMTP id i11-20020a05620a150b00b006ee8d040f70mr11428999qkk.101.1666302864030; Thu, 20 Oct 2022 14:54:24 -0700 (PDT) Received: from stbirv-lnx-3.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id bj41-20020a05620a192900b006bb29d932e1sm8121067qkb.105.2022.10.20.14.54.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 14:54:23 -0700 (PDT) From: Doug Berger To: Andrew Morton Cc: Jonathan Corbet , Mike Rapoport , Borislav Petkov , "Paul E. McKenney" , Neeraj Upadhyay , Randy Dunlap , Damien Le Moal , Muchun Song , Vlastimil Babka , Johannes Weiner , Michal Hocko , KOSAKI Motohiro , Mel Gorman , Mike Kravetz , Florian Fainelli , David Hildenbrand , Oscar Salvador , Joonsoo Kim , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Doug Berger Subject: [PATCH v3 1/9] lib/show_mem.c: display MovableOnly Date: Thu, 20 Oct 2022 14:53:10 -0700 Message-Id: <20221020215318.4193269-2-opendmb@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221020215318.4193269-1-opendmb@gmail.com> References: <20221020215318.4193269-1-opendmb@gmail.com> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=jNUUsRnW; spf=pass (imf22.hostedemail.com: domain of opendmb@gmail.com designates 209.85.222.176 as permitted sender) smtp.mailfrom=opendmb@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666302864; a=rsa-sha256; cv=none; b=0L+VhbCbNs74dFTtqp0Jhf7uf+DjNgYrcJEjDqeaSqMMuwp9F2l53YuwoenQQaYOkxoqkw fJ0SYmlHb2R8gEXnmx/QOhqN7CeAYf/XIeyrSglBnVTcXhP8J1hprR1S2YGQtc881h/n4f m7TkO16/fdqiIPZlUjYIzzlklg948L4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666302864; h=from:from:sender: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=BwP9OSSuHG+apHyoqkPAJ44LToseDE0HSDpJZDk5eXs=; b=ixj5/Z1/01kJL+Svn8AP7iJLJrxJ7hW8Vrqm2/4Xloz3M0Q/OX1KY0JgA03AFDTmR71cJp woG28prVj0ttAe/k3eXDEV8F31MLT2uOCAXXne09Z0i53H4gnE2jGAyblhZEsU+1PMT63L TZ13b2FYF7oJatVGrao8a3MFUTEPmbs= Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=jNUUsRnW; spf=pass (imf22.hostedemail.com: domain of opendmb@gmail.com designates 209.85.222.176 as permitted sender) smtp.mailfrom=opendmb@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: zpfqr3ayayi3bp5wbo9fq9an94cgbiyq X-Rspamd-Queue-Id: BDAEBC0032 X-Rspamd-Server: rspam02 X-Rspam-User: X-HE-Tag: 1666302864-350002 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: The comment for commit c78e93630d15 ("mm: do not walk all of system memory during show_mem") indicates it "also corrects the reporting of HighMem as HighMem/MovableOnly as ZONE_MOVABLE has similar problems to HighMem with respect to lowmem/highmem exhaustion." Presuming the similar problems are with regard to the general exclusion of kernel allocations from either zone, I believe it makes sense to include all ZONE_MOVABLE memory even on systems without HighMem. To the extent that this was the intent of the original commit I have included a "Fixes" tag, but it seems unnecessary to submit to linux-stable. Fixes: c78e93630d15 ("mm: do not walk all of system memory during show_mem") Signed-off-by: Doug Berger --- lib/show_mem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/show_mem.c b/lib/show_mem.c index 0d7585cde2a6..6a632b0c35c5 100644 --- a/lib/show_mem.c +++ b/lib/show_mem.c @@ -27,7 +27,7 @@ void __show_mem(unsigned int filter, nodemask_t *nodemask, int max_zone_idx) total += zone->present_pages; reserved += zone->present_pages - zone_managed_pages(zone); - if (is_highmem_idx(zoneid)) + if (zoneid == ZONE_MOVABLE || is_highmem_idx(zoneid)) highmem += zone->present_pages; } } From patchwork Thu Oct 20 21:53:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Berger X-Patchwork-Id: 13014049 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 C38DCC4332F for ; Thu, 20 Oct 2022 21:54:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6EAE98E0006; Thu, 20 Oct 2022 17:54:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 69B9F8E0001; Thu, 20 Oct 2022 17:54:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 53C088E0006; Thu, 20 Oct 2022 17:54:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 46D718E0001 for ; Thu, 20 Oct 2022 17:54:28 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1A3451413E0 for ; Thu, 20 Oct 2022 21:54:28 +0000 (UTC) X-FDA: 80042682216.13.3C89ED0 Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) by imf23.hostedemail.com (Postfix) with ESMTP id B9010140010 for ; Thu, 20 Oct 2022 21:54:27 +0000 (UTC) Received: by mail-qv1-f42.google.com with SMTP id e15so493149qvo.4 for ; Thu, 20 Oct 2022 14:54:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ShOyVALLWkkR4pnZbEXjhmF6LOSGNE0eOMv5EosjK40=; b=LmhsWLB5/8ER2JWGrAWt10ivNX62HhMvv1xr1WhLa8oIGbqE6gfaxeCqdv3/yMH1rg rupS1AoSzdDIE3sKhGSRgJ5JtZIE2Z00oJDsRRai1sGmU5SFhOf536G/b4t9VgZqOm8F +8bmWW2eKxJu2t/MLePJJ0YkKGitQ6cHO2DxfYvC2u+IkGry12ZDQ/MP4rOrSu4d0NBa MLgsBVxBgLZaAXLnaneL/ROAKOtw8peTXm6aE7CAIo2L/Hroz4ZJeq4htcoLmT07Awdi EIVo+KmLfCM/6yslbPviiQniqDYINEwRj+mLjivLeu4/7v5eVh8YdXUaSnwxQxIi1Kgy VU6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version: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=ShOyVALLWkkR4pnZbEXjhmF6LOSGNE0eOMv5EosjK40=; b=K7f40De1IYw6dO+prOwk8OIm44P8AJDfGSox61WIQAR1dZ8vcPM/D+gQ1tQ15SAq7J iM+WTLBl18zvuGw+EG/ohOW/6mbRK1pPBdHQCY9e2mbAqrk6KZaCAp8nlRfvQ/YnO2h6 fsw4VBe4eDBJG8YoC2EuwpgmZho9sqSp1h0wVMiTjs2uVebB2t49nWYSUPczJLWIz8X2 g8ISA4vlZQxF5vY/E0RTqJm/3kkT84PCU9I8uw0RySrPXClR7ctRp6bMMBao+Asxq7YU fMWIEX2BuWwSigQ7MUBJH9NVKr5oDVi31GZLhX1gxHTucBsthp+dhgOcZlR5r5UL/U7/ jCQg== X-Gm-Message-State: ACrzQf2B1NFsT9MXzt9COFcYimZYdSxngz5xHvvz8pWT15dG4CciHDRN PanX59EopfS4qo5iyd1KVXU= X-Google-Smtp-Source: AMsMyM4hvvi4L9JYqaXZOTFe/8FS+MJ1R0MvB72qG3wAneUbZ7hAzYBbeQWK/BxtpwbfBfx5iBtOJw== X-Received: by 2002:a05:6214:20a8:b0:4b3:d99f:2588 with SMTP id 8-20020a05621420a800b004b3d99f2588mr13740927qvd.64.1666302867022; Thu, 20 Oct 2022 14:54:27 -0700 (PDT) Received: from stbirv-lnx-3.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id bj41-20020a05620a192900b006bb29d932e1sm8121067qkb.105.2022.10.20.14.54.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 14:54:26 -0700 (PDT) From: Doug Berger To: Andrew Morton Cc: Jonathan Corbet , Mike Rapoport , Borislav Petkov , "Paul E. McKenney" , Neeraj Upadhyay , Randy Dunlap , Damien Le Moal , Muchun Song , Vlastimil Babka , Johannes Weiner , Michal Hocko , KOSAKI Motohiro , Mel Gorman , Mike Kravetz , Florian Fainelli , David Hildenbrand , Oscar Salvador , Joonsoo Kim , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Doug Berger Subject: [PATCH v3 2/9] mm/page_alloc: calculate node_spanned_pages from pfns Date: Thu, 20 Oct 2022 14:53:11 -0700 Message-Id: <20221020215318.4193269-3-opendmb@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221020215318.4193269-1-opendmb@gmail.com> References: <20221020215318.4193269-1-opendmb@gmail.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666302867; a=rsa-sha256; cv=none; b=hL8DRyOfimS3ttKr4AnAE7fBoIMy/Yogy2WhpluJEn0gpViwdK3/cjRMk2ePrsLn+ThNLQ DeUlTb4hWg2IKV+3svXGt8v+JNYPHk3rwWX5A8NH5f7dxxh+win6xBF8wKN2ICT1PpwCGM 2ZsB/8hhyjyCfzT1YVMnACfCO+8uN0I= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=LmhsWLB5; spf=pass (imf23.hostedemail.com: domain of opendmb@gmail.com designates 209.85.219.42 as permitted sender) smtp.mailfrom=opendmb@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=1666302867; h=from:from:sender: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=ShOyVALLWkkR4pnZbEXjhmF6LOSGNE0eOMv5EosjK40=; b=b8Cn2d0aMUUnxTc6pr+jarWyBfQObGz9swghz7dR0vT1tKa22wWlGBeGa2qSwnPLdjapWV KJrUDz7wJYQForrA3AmARGBd9sVkY3As6DrSzszbqnq9HdblomiFIA1M/gUcK1Bg9vdP8g CHCQIteXrxS1P9ZtKwEK7k9EO7n63oc= X-Stat-Signature: j9wniwoi95pisdasbx41pqr1i5iihfxf X-Rspamd-Queue-Id: B9010140010 Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=LmhsWLB5; spf=pass (imf23.hostedemail.com: domain of opendmb@gmail.com designates 209.85.219.42 as permitted sender) smtp.mailfrom=opendmb@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1666302867-420801 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: Since the start and end pfns of the node are passed as arguments to calculate_node_totalpages() they might as well be used to specify the node_spanned_pages value for the node rather than accumulating the spans of member zones. This prevents the need for additional adjustments if zones are allowed to overlap. The realtotalpages name is reverted to just totalpages to reduce the burden of supporting multiple realities. Signed-off-by: Doug Berger --- mm/page_alloc.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index e20ade858e71..92908c51f1c3 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -7542,7 +7542,7 @@ static void __init calculate_node_totalpages(struct pglist_data *pgdat, unsigned long node_start_pfn, unsigned long node_end_pfn) { - unsigned long realtotalpages = 0, totalpages = 0; + unsigned long totalpages = 0; enum zone_type i; for (i = 0; i < MAX_NR_ZONES; i++) { @@ -7573,13 +7573,12 @@ static void __init calculate_node_totalpages(struct pglist_data *pgdat, zone->present_early_pages = real_size; #endif - totalpages += size; - realtotalpages += real_size; + totalpages += real_size; } - pgdat->node_spanned_pages = totalpages; - pgdat->node_present_pages = realtotalpages; - pr_debug("On node %d totalpages: %lu\n", pgdat->node_id, realtotalpages); + pgdat->node_spanned_pages = node_end_pfn - node_start_pfn; + pgdat->node_present_pages = totalpages; + pr_debug("On node %d totalpages: %lu\n", pgdat->node_id, totalpages); } #ifndef CONFIG_SPARSEMEM From patchwork Thu Oct 20 21:53:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Berger X-Patchwork-Id: 13014050 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 97336C4332F for ; Thu, 20 Oct 2022 21:54:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 341538E0007; Thu, 20 Oct 2022 17:54:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2F1B78E0001; Thu, 20 Oct 2022 17:54:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 192D58E0007; Thu, 20 Oct 2022 17:54:31 -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 0C10B8E0001 for ; Thu, 20 Oct 2022 17:54:31 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id DCCB91204E4 for ; Thu, 20 Oct 2022 21:54:30 +0000 (UTC) X-FDA: 80042682300.21.524260E Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) by imf14.hostedemail.com (Postfix) with ESMTP id 8CE20100023 for ; Thu, 20 Oct 2022 21:54:30 +0000 (UTC) Received: by mail-qk1-f181.google.com with SMTP id s17so849611qkj.12 for ; Thu, 20 Oct 2022 14:54:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tvfEueXv3MPyKUTDqbsvcgdPv0lPq1HvhYO0pg1lxgg=; b=ffixkJKdZbTCBgQd/yyyoLEt9enHtHJdBGSffjbahVDco4N7boG7mqHf4g6HNIWDRV TUF2h3/TlW1N88JPvCgjd5FjVNusNzYKuIyp8TGrBY9OXkwOzi7zUpMXlULvLJUWJ8W9 avv5kHbuJnwKwgHuWuDXHdm9QYpgnsiEKcZEFOneAtsv2+MP3U8dOTOOGDD1USkrXOCt Iqv8+KZIqj6eh2vmChJHacuLhyL1e4qs7ooWBZUnlQp/Eb7vo1cQiMKoyTJrkOBKnZSP ZtvvP6oZGVyoOyC7Bt9iXv+x4vQtDi9ovBXsTNzCOqpI7rcL0jEiTpC70OvnjYfdeMAU hhHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version: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=tvfEueXv3MPyKUTDqbsvcgdPv0lPq1HvhYO0pg1lxgg=; b=TOY144V+ulHh0yLGYDMJwP54Fu5jAPBL7R/SBCbmZPbPpsrM7Sk5SkcWaHRR8OyG7B dyXcb7tKGw/WXo9VPEHGIGZhJ6IispxTj70PE2Bq948MnDci67d2phObk+Y9GWfG3AEt JU+egAa17pFRBWnQZUSARZJqIcHhSrXAsr5RkJfuWrkoilhcRWQnWicfEAhmGxmMC43g diSPAAhrcGfGa9oHnuavDvNhG1uwf6DXXJ7OstBW/RlD0Jocjglte1Lc+IgBwA24RWqp bEK2cqs2/GCvMxJDnfMYUAX/+SN0+up8lQ8kALE9CO4hd/ZPf562ysX8ihcWvhHj2pYz 7YSg== X-Gm-Message-State: ACrzQf24uVQLhn2Ve7rGZXqAeGBtBcislZ+Cd1FOPfZGE+lFSwPNmYfb ytiG9xDspeCc0duZ0RQ1Rrw= X-Google-Smtp-Source: AMsMyM5Nmw4C772V70Q+LmwGPXj1++mwiH027m+RB4IR5T/YT15ihOIWJHuJ1fNCaKZtV3P9KumgYA== X-Received: by 2002:a05:620a:2b91:b0:6ee:bc07:24c with SMTP id dz17-20020a05620a2b9100b006eebc07024cmr11239651qkb.64.1666302869881; Thu, 20 Oct 2022 14:54:29 -0700 (PDT) Received: from stbirv-lnx-3.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id bj41-20020a05620a192900b006bb29d932e1sm8121067qkb.105.2022.10.20.14.54.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 14:54:29 -0700 (PDT) From: Doug Berger To: Andrew Morton Cc: Jonathan Corbet , Mike Rapoport , Borislav Petkov , "Paul E. McKenney" , Neeraj Upadhyay , Randy Dunlap , Damien Le Moal , Muchun Song , Vlastimil Babka , Johannes Weiner , Michal Hocko , KOSAKI Motohiro , Mel Gorman , Mike Kravetz , Florian Fainelli , David Hildenbrand , Oscar Salvador , Joonsoo Kim , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Doug Berger Subject: [PATCH v3 3/9] mm/page_alloc: prevent creation of empty zones Date: Thu, 20 Oct 2022 14:53:12 -0700 Message-Id: <20221020215318.4193269-4-opendmb@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221020215318.4193269-1-opendmb@gmail.com> References: <20221020215318.4193269-1-opendmb@gmail.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666302870; a=rsa-sha256; cv=none; b=3v6vkeCaBJd18yBPWtbbJkgyPB2F5b2MUikEx1YwoHyqTzsSf1pg/S5hSAz3dyX6GzjWRs 6/yVE0JWhhujCPWHXAEPzEAkS/YFVx6R7yCzVEAayoIq840T4ABNIFrkNrBdoG0GFO36f/ n6CqQ4BEa4do09XGJXsSlCACc+83RnI= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ffixkJKd; spf=pass (imf14.hostedemail.com: domain of opendmb@gmail.com designates 209.85.222.181 as permitted sender) smtp.mailfrom=opendmb@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=1666302870; h=from:from:sender: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=tvfEueXv3MPyKUTDqbsvcgdPv0lPq1HvhYO0pg1lxgg=; b=Z0Bb5t7ilYLQiKoGH2skh6pYfYvBZsrPC9CLsLBtwBpro6u0kXhSOkndd71r6taJkUs3KM lMIk5w+sMtaq/cMo8gYqwmMDGuffKzS6RTwb3fceuqXTBHv+Bp8k6UI+TfF9jT4CiecZH0 vdxE0LyfjbTnzCW2iMeJ4Uwz0Usep4U= X-Stat-Signature: 9bmc8nng5418k919u7n1sbyetbpxjme5 X-Rspamd-Queue-Id: 8CE20100023 X-Rspam-User: X-Rspamd-Server: rspam03 Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ffixkJKd; spf=pass (imf14.hostedemail.com: domain of opendmb@gmail.com designates 209.85.222.181 as permitted sender) smtp.mailfrom=opendmb@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1666302870-884189 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: If none of the pages a zone spans are present then its start pfn and span should be zeroed to prevent initialization. This prevents the creation of an empty zone if all of its pages are moved to a zone that would overlap it. The real_size name is reverted to just size to reduce the burden of supporting multiple realities. Signed-off-by: Doug Berger --- mm/page_alloc.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 92908c51f1c3..2f7b88d78bc2 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -7548,8 +7548,7 @@ static void __init calculate_node_totalpages(struct pglist_data *pgdat, for (i = 0; i < MAX_NR_ZONES; i++) { struct zone *zone = pgdat->node_zones + i; unsigned long zone_start_pfn, zone_end_pfn; - unsigned long spanned, absent; - unsigned long size, real_size; + unsigned long spanned, absent, size; spanned = zone_spanned_pages_in_node(pgdat->node_id, i, node_start_pfn, @@ -7560,20 +7559,21 @@ static void __init calculate_node_totalpages(struct pglist_data *pgdat, node_start_pfn, node_end_pfn); - size = spanned; - real_size = size - absent; + size = spanned - absent; - if (size) + if (size) { zone->zone_start_pfn = zone_start_pfn; - else + } else { + spanned = 0; zone->zone_start_pfn = 0; - zone->spanned_pages = size; - zone->present_pages = real_size; + } + zone->spanned_pages = spanned; + zone->present_pages = size; #if defined(CONFIG_MEMORY_HOTPLUG) - zone->present_early_pages = real_size; + zone->present_early_pages = size; #endif - totalpages += real_size; + totalpages += size; } pgdat->node_spanned_pages = node_end_pfn - node_start_pfn; From patchwork Thu Oct 20 21:53:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Berger X-Patchwork-Id: 13014051 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 B63FCC4332F for ; Thu, 20 Oct 2022 21:54:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5B2138E0008; Thu, 20 Oct 2022 17:54:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 562C18E0001; Thu, 20 Oct 2022 17:54:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 403768E0008; Thu, 20 Oct 2022 17:54:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 3383F8E0001 for ; Thu, 20 Oct 2022 17:54:34 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id D684581143 for ; Thu, 20 Oct 2022 21:54:33 +0000 (UTC) X-FDA: 80042682426.30.2068675 Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) by imf14.hostedemail.com (Postfix) with ESMTP id 8B6D0100023 for ; Thu, 20 Oct 2022 21:54:33 +0000 (UTC) Received: by mail-qv1-f52.google.com with SMTP id i12so637537qvs.2 for ; Thu, 20 Oct 2022 14:54:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3QVy7NAfSopf+Iij2pw0HKI71t//u6xehpjVOpbyUMY=; b=J+iDN/3M1v4SmMv54h7rTzpz0LCv5/XHzg8ewdpWRJK70RuAF16mbixTaMb/vBat51 /mOQLg5Lg+eWwblMvbeXIjCw6c7NGBNFeD/y4PUno/X8AVsvp3cN9kuMppVqjdsN5kl6 orFfq4ybTrc/U75TOFffbD2FHq/yB8TQdUCF4W5zgxsL4RtZssN3wgMFfKwcAq4UKdf8 F8nDYyOYiinRzsKsyxRooF/HEUiIjI0N0PbTdoyDCvkE5xiCtErgJjWuKYBHcuAzQd0V 2rntUIgntvNQWYugXRMQ7XaB2yU5azO8RSIVC6neC4mThi5qsxjgKAfWCPpzvk9W2R02 HrBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version: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=3QVy7NAfSopf+Iij2pw0HKI71t//u6xehpjVOpbyUMY=; b=dC9x6RmcFUwl+1Uy3yHqEwynatsZ2/zYIdA3eBu8BqU4xImGtmqTeOFhNPvLkeD1uf MCOvxrCQ8GTVIsFSS1DtvuxoZ+lqlhcEuB9DvBpLDUUCsctYNABkbeN8ky2CCsb50yg1 B6Y8NILfXrovtnRmFvBG3blhse4Y91os17x2plOjBYe4N4+2xhHLZ04QXpNvpYfYABfG zCLKcDGRGC4wIrPjz2NuGKwLfFXwdV1CnNhI50PQpeoqwtUphFMd4043obGhVF9mGuvX Hha0t2YKYcftfL6ZHSGzhxl6dJ8/5ApCve3vjQ8HXJfH57uvvwxmz9e3ZUMPpv0jmSmx 0hhw== X-Gm-Message-State: ACrzQf3PQ91GIb1kWuTZgCEwIffFiGNDvXg3mfXFUQ5VxwBZmWqlUNt0 99olLGjuPLUOite0dB1CjXI= X-Google-Smtp-Source: AMsMyM5aXseEnbCth+1erHFOC0l1o/oiEp9CjvS4tO2sP+AMndswz+RDyF7PQHIu1wmG8A/x1Oi+0g== X-Received: by 2002:ad4:5949:0:b0:4b4:8535:97a4 with SMTP id eo9-20020ad45949000000b004b4853597a4mr13776300qvb.101.1666302872827; Thu, 20 Oct 2022 14:54:32 -0700 (PDT) Received: from stbirv-lnx-3.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id bj41-20020a05620a192900b006bb29d932e1sm8121067qkb.105.2022.10.20.14.54.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 14:54:32 -0700 (PDT) From: Doug Berger To: Andrew Morton Cc: Jonathan Corbet , Mike Rapoport , Borislav Petkov , "Paul E. McKenney" , Neeraj Upadhyay , Randy Dunlap , Damien Le Moal , Muchun Song , Vlastimil Babka , Johannes Weiner , Michal Hocko , KOSAKI Motohiro , Mel Gorman , Mike Kravetz , Florian Fainelli , David Hildenbrand , Oscar Salvador , Joonsoo Kim , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Doug Berger Subject: [PATCH v3 4/9] mm/page_alloc.c: allow oversized movablecore Date: Thu, 20 Oct 2022 14:53:13 -0700 Message-Id: <20221020215318.4193269-5-opendmb@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221020215318.4193269-1-opendmb@gmail.com> References: <20221020215318.4193269-1-opendmb@gmail.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666302873; a=rsa-sha256; cv=none; b=cSS3SHNqQk2Fnboq7GQNPSxVJNlbtMqVAvjsg74lOqMQHUe4j1Z15RMOu+TfG0OVWe/ILP GlTknU4pJIArbAwSzhlBtkybMuL6dd/SV/DQ6DJfFeODbDn4nxb9CuSdFt+fWybyQYZvEH +BpI7Hpg1zqFSfhLAFKaSJjARAbUZgM= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="J+iDN/3M"; spf=pass (imf14.hostedemail.com: domain of opendmb@gmail.com designates 209.85.219.52 as permitted sender) smtp.mailfrom=opendmb@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=1666302873; h=from:from:sender: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=3QVy7NAfSopf+Iij2pw0HKI71t//u6xehpjVOpbyUMY=; b=46s1vNgp1GzENJvQ0wOFFObEkI2ffY76M01hqlqKzcgUIOSA90ruaZtNyIemUxOUAcETRv aLqI26nXdRBMXZTYegf/zc7uhs1mOyDXe1KJeheHC6tc+N5wqxtI1JfG7tc2jMU/8cILh+ a9+MI+W+CfxAeDt2lowZuyds1WfP+fw= X-Stat-Signature: owp91k11bsdgxux8qa4n85aocmjtdqga X-Rspamd-Queue-Id: 8B6D0100023 X-Rspam-User: X-Rspamd-Server: rspam03 Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="J+iDN/3M"; spf=pass (imf14.hostedemail.com: domain of opendmb@gmail.com designates 209.85.219.52 as permitted sender) smtp.mailfrom=opendmb@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1666302873-473101 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: Now that the error in computation of corepages has been corrected by commit 9fd745d450e7 ("mm: fix overflow in find_zone_movable_pfns_for_nodes()"), oversized specifications of movablecore will result in a zero value for required_kernelcore if it is not also specified. It is unintuitive for such a request to lead to no ZONE_MOVABLE memory when the kernel parameters are clearly requesting some. The current behavior when requesting an oversized kernelcore is to classify all of the pages in movable_zone as kernelcore. The new behavior when requesting an oversized movablecore (when not also specifying kernelcore) is to similarly classify all of the pages in movable_zone as movablecore. Signed-off-by: Doug Berger --- mm/page_alloc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 2f7b88d78bc2..a4c2c157bacf 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -8121,13 +8121,13 @@ static void __init find_zone_movable_pfns_for_nodes(void) corepages = totalpages - required_movablecore; required_kernelcore = max(required_kernelcore, corepages); + } else if (!required_kernelcore) { + /* If kernelcore was not specified, there is no ZONE_MOVABLE */ + goto out; } - /* - * If kernelcore was not specified or kernelcore size is larger - * than totalpages, there is no ZONE_MOVABLE. - */ - if (!required_kernelcore || required_kernelcore >= totalpages) + /* If kernelcore size exceeds totalpages, there is no ZONE_MOVABLE */ + if (required_kernelcore >= totalpages) goto out; /* usable_startpfn is the lowest possible pfn ZONE_MOVABLE can be at */ From patchwork Thu Oct 20 21:53:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Berger X-Patchwork-Id: 13014052 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 F245CC433FE for ; Thu, 20 Oct 2022 21:54:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 90D1F8E0009; Thu, 20 Oct 2022 17:54:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8BD8C8E0001; Thu, 20 Oct 2022 17:54:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 785DA8E0009; Thu, 20 Oct 2022 17:54:37 -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 6BB538E0001 for ; Thu, 20 Oct 2022 17:54:37 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3A5371204E4 for ; Thu, 20 Oct 2022 21:54:37 +0000 (UTC) X-FDA: 80042682594.06.FBC78F6 Received: from mail-qv1-f51.google.com (mail-qv1-f51.google.com [209.85.219.51]) by imf22.hostedemail.com (Postfix) with ESMTP id E708BC0014 for ; Thu, 20 Oct 2022 21:54:36 +0000 (UTC) Received: by mail-qv1-f51.google.com with SMTP id t16so608981qvm.9 for ; Thu, 20 Oct 2022 14:54:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=D/FIsjw19eZ3OnJAIkw3KCiDeRv2n8mXkgoaXFlI9ro=; b=Jfxyh2ci01RrSPT9NlGFNscPY5PnsXAUGYcYoRSlBmjDz2eJE3LFrmNFqOjrNXF+V7 kH7Xlpre2JSJCWaxUVgT2xDPJMzJX5z+2wD5qUCsUREd0mY/eySZwJWln98Pra1/1gbI fdmxz5E2ZJWa8NubMcYhANwAlL2V5iNmTwIDWbIxEfbqDC8yvhsWJAZ+kFU+7giGU7DC wvFTrJT7YJ0e9wl+7meEo6c8q0ukXsJVNF2a7Z6z4aN61MeappkLjeJyJUo2B5Vqouqn cfqt7nA9MgPPPtx5fwH3bgE+niTxHXdMv3M/Tbp64/fEWFwMqF//10fYVb5EeAksvWUg kHgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version: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/FIsjw19eZ3OnJAIkw3KCiDeRv2n8mXkgoaXFlI9ro=; b=ieHnhrcO+qIvP7U/cEM7qDi0a8H4sNWDqzy7HakHvj6ORt1RLyBpGpCeuGukL/TSww DqE1H+ISrQlUjiUo2VW4Z/mJiS9IOGRXZR38YDPK2SjCbbrxmgOQbHWUlEYOGkAG29ze RZUcaiVkLytNTbpQSN0NhiQr8Glvd28bvQMpqfPlnp09v+iekYmgWYVbL46fuEpPxTGY r4Zt2mMhiXViPsPo9Shkt4oI9KOlErXgC6YKbtEK0VVf4nbstrMDNJu4yWZlvusiepSd HTMWZTUhE0WiooVJDoMlkrYofC452o1hzG5VKtqed6CI2uN2xil/yGYEUJkKOceQpkYI RIlg== X-Gm-Message-State: ACrzQf0JLXhVTASgdo17xoIrL95hFQ/doYuNCnWECV2YYLCz7eweRwUG /ywSmGIijq4crp8lP5Fjlwo= X-Google-Smtp-Source: AMsMyM6pLENQr5vbjvY+6Kql1ESyWRc/dvrXQFOAxarXh38H3a3fK/a5qUu7a9qn0oImRKl027uuPg== X-Received: by 2002:ad4:5968:0:b0:4b4:7d98:7ede with SMTP id eq8-20020ad45968000000b004b47d987edemr13626883qvb.130.1666302876219; Thu, 20 Oct 2022 14:54:36 -0700 (PDT) Received: from stbirv-lnx-3.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id bj41-20020a05620a192900b006bb29d932e1sm8121067qkb.105.2022.10.20.14.54.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 14:54:35 -0700 (PDT) From: Doug Berger To: Andrew Morton Cc: Jonathan Corbet , Mike Rapoport , Borislav Petkov , "Paul E. McKenney" , Neeraj Upadhyay , Randy Dunlap , Damien Le Moal , Muchun Song , Vlastimil Babka , Johannes Weiner , Michal Hocko , KOSAKI Motohiro , Mel Gorman , Mike Kravetz , Florian Fainelli , David Hildenbrand , Oscar Salvador , Joonsoo Kim , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Doug Berger Subject: [PATCH v3 5/9] mm/page_alloc: introduce init_reserved_pageblock() Date: Thu, 20 Oct 2022 14:53:14 -0700 Message-Id: <20221020215318.4193269-6-opendmb@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221020215318.4193269-1-opendmb@gmail.com> References: <20221020215318.4193269-1-opendmb@gmail.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666302876; a=rsa-sha256; cv=none; b=c9WS1MUBiDIVUyP01Bq/3blP45G4vRLnnMOSzeAFQrU665aT1SEDVQz6SbEEkVlV/Rk8hc g6j21Y4WxWhZkTUMZJZ3kFsAV2FFfMHeSl86qlFsq/OZAVhEjUpiXTa/d7kmj/uIYCat48 baDl6B1MGGtf3HNj2AiF8VHntWSXyig= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Jfxyh2ci; spf=pass (imf22.hostedemail.com: domain of opendmb@gmail.com designates 209.85.219.51 as permitted sender) smtp.mailfrom=opendmb@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=1666302876; h=from:from:sender: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=D/FIsjw19eZ3OnJAIkw3KCiDeRv2n8mXkgoaXFlI9ro=; b=ecBECLBVBXTQumX7BW/S77ipIL/Ki2S7jYftDD16JqFjimLQxqabOQ19iLcm7JbZ3AcTNS RDztyktouQ+6FAZTqh6FUEmoJBFc/GzWd+hSJ5umEeGWpdHO9AMlr0OrSU3lsPOI5nekxX voLC++TqDpxGWDq9njz2UOy2VMqyUX4= X-Stat-Signature: dybzbsptkd7fa9kakiyidncwewp54j7t X-Rspamd-Queue-Id: E708BC0014 X-Rspam-User: X-Rspamd-Server: rspam03 Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Jfxyh2ci; spf=pass (imf22.hostedemail.com: domain of opendmb@gmail.com designates 209.85.219.51 as permitted sender) smtp.mailfrom=opendmb@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1666302876-137974 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: Most of the implementation of init_cma_reserved_pageblock() is common to the initialization of any reserved pageblock for use by the page allocator. This commit breaks that functionality out into the new common function init_reserved_pageblock() for use by code other than CMA. The CMA specific code is relocated from page_alloc to the point where init_cma_reserved_pageblock() was invoked and the new function is used there instead. The error path is also updated to use the function to operate on pageblocks rather than pages. Signed-off-by: Doug Berger --- include/linux/gfp.h | 5 +---- mm/cma.c | 15 +++++++++++---- mm/page_alloc.c | 8 ++------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index ef4aea3b356e..6d66193f336d 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -347,9 +347,6 @@ extern struct page *alloc_contig_pages(unsigned long nr_pages, gfp_t gfp_mask, #endif void free_contig_range(unsigned long pfn, unsigned long nr_pages); -#ifdef CONFIG_CMA -/* CMA stuff */ -extern void init_cma_reserved_pageblock(struct page *page); -#endif +extern void init_reserved_pageblock(struct page *page); #endif /* __LINUX_GFP_H */ diff --git a/mm/cma.c b/mm/cma.c index 4a978e09547a..6208a3e1cd9d 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include "cma.h" @@ -116,8 +117,13 @@ static void __init cma_activate_area(struct cma *cma) } for (pfn = base_pfn; pfn < base_pfn + cma->count; - pfn += pageblock_nr_pages) - init_cma_reserved_pageblock(pfn_to_page(pfn)); + pfn += pageblock_nr_pages) { + struct page *page = pfn_to_page(pfn); + + set_pageblock_migratetype(page, MIGRATE_CMA); + init_reserved_pageblock(page); + page_zone(page)->cma_pages += pageblock_nr_pages; + } spin_lock_init(&cma->lock); @@ -133,8 +139,9 @@ static void __init cma_activate_area(struct cma *cma) out_error: /* Expose all pages to the buddy, they are useless for CMA. */ if (!cma->reserve_pages_on_error) { - for (pfn = base_pfn; pfn < base_pfn + cma->count; pfn++) - free_reserved_page(pfn_to_page(pfn)); + for (pfn = base_pfn; pfn < base_pfn + cma->count; + pfn += pageblock_nr_pages) + init_reserved_pageblock(pfn_to_page(pfn)); } totalcma_pages -= cma->count; cma->count = 0; diff --git a/mm/page_alloc.c b/mm/page_alloc.c index a4c2c157bacf..d7a5a05ead4b 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -2308,9 +2308,8 @@ void __init page_alloc_init_late(void) set_zone_contiguous(zone); } -#ifdef CONFIG_CMA -/* Free whole pageblock and set its migration type to MIGRATE_CMA. */ -void __init init_cma_reserved_pageblock(struct page *page) +/* Free whole pageblock */ +void __init init_reserved_pageblock(struct page *page) { unsigned i = pageblock_nr_pages; struct page *p = page; @@ -2320,14 +2319,11 @@ void __init init_cma_reserved_pageblock(struct page *page) set_page_count(p, 0); } while (++p, --i); - set_pageblock_migratetype(page, MIGRATE_CMA); set_page_refcounted(page); __free_pages(page, pageblock_order); adjust_managed_page_count(page, pageblock_nr_pages); - page_zone(page)->cma_pages += pageblock_nr_pages; } -#endif /* * The order of subdivision here is critical for the IO subsystem. From patchwork Thu Oct 20 21:53:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Berger X-Patchwork-Id: 13014053 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 2D817C433FE for ; Thu, 20 Oct 2022 21:54:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C1AAA8E000A; Thu, 20 Oct 2022 17:54:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BCD0D8E0001; Thu, 20 Oct 2022 17:54:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A92EC8E000A; Thu, 20 Oct 2022 17:54:40 -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 9C3AD8E0001 for ; Thu, 20 Oct 2022 17:54:40 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 576831C6C35 for ; Thu, 20 Oct 2022 21:54:40 +0000 (UTC) X-FDA: 80042682720.18.4131AEC Received: from mail-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.46]) by imf02.hostedemail.com (Postfix) with ESMTP id ED9F18003B for ; Thu, 20 Oct 2022 21:54:39 +0000 (UTC) Received: by mail-qv1-f46.google.com with SMTP id h10so614199qvq.7 for ; Thu, 20 Oct 2022 14:54:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=k0ZvpnVNYZiRg/rCuSdzxC9eb6lzs9TieDFdQySZsn8=; b=SZ1PlrYOPpSqmq/vLnLZafqj76vcgQtuklt87DwVjrckcKo++SoYbWCoXH2RuEmcb6 4y4tJhiFfNsKAYGCDqNldMQv8ggfF9el1/DuGHGyFTTgGJTgBB1ub2t8TJn/8VQ/0njh x9PBzyecXTaH7sPHGenWV53OQv2MF6VIv7XIRqYd6awOmsAXwfizyl7Pvu/dtb12NoEI FmlTxSQ26E38t9VXc438mbDPBM+Nsfx1gqnxiKl0224bwHFJKJ36YENdqiT+aCbkxIGU QeFvaN4zOD3HePcbtw0ZaU1yZSvLexZNzQIPkdE25F5wKPOiXAjcD1OSAUZXG39Xan4S LqVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version: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=k0ZvpnVNYZiRg/rCuSdzxC9eb6lzs9TieDFdQySZsn8=; b=Bj2Z2A464jSm78VtIVBMPbC+3bMc5U/SBtOhQIjS3BtXWvkMV17NHxK7wM2umqnHWc NbZBP8a23Ledw41jVYERMrkP490fbSgdeQ9rnUE19wJfwuvBSqxHGrT+eEVlnRzFr5yR Z6//KRLMaxZVdM7CxXIQhq1LDm23JeEHT/NEQWNR+4Rt0NbcJBm94d65ayZSct0EzL3q csxRHUHbM6L9xzzcAs7GyFOen1LoghRihNkZdtpV0vCjaXa/lQeW0NnP9p/O/NnyCpEK 8VsetR4O8Eu7nJldoQ8e4QZpXIo9pC8pgleB6/OpfaArazpKjoIiZhLPaXMUf4GaTmMv bXRw== X-Gm-Message-State: ACrzQf2qgTNOQLBnr1WAGdf5KyCJ+fciDP0fJUc79Cr6RGWdnFr+rox3 NdhkuirP/rc8RXANV7s4Uhc= X-Google-Smtp-Source: AMsMyM7a38TE8ilGlotanmpyp3rhbuPFqLEEes3huL7M5Q8qh4Xm+gSlVT2+xpnn07tUAZEUhQLqSA== X-Received: by 2002:a05:6214:29ef:b0:4b4:5d8c:637c with SMTP id jv15-20020a05621429ef00b004b45d8c637cmr13527095qvb.77.1666302879221; Thu, 20 Oct 2022 14:54:39 -0700 (PDT) Received: from stbirv-lnx-3.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id bj41-20020a05620a192900b006bb29d932e1sm8121067qkb.105.2022.10.20.14.54.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 14:54:38 -0700 (PDT) From: Doug Berger To: Andrew Morton Cc: Jonathan Corbet , Mike Rapoport , Borislav Petkov , "Paul E. McKenney" , Neeraj Upadhyay , Randy Dunlap , Damien Le Moal , Muchun Song , Vlastimil Babka , Johannes Weiner , Michal Hocko , KOSAKI Motohiro , Mel Gorman , Mike Kravetz , Florian Fainelli , David Hildenbrand , Oscar Salvador , Joonsoo Kim , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Doug Berger Subject: [PATCH v3 6/9] memblock: introduce MEMBLOCK_MOVABLE flag Date: Thu, 20 Oct 2022 14:53:15 -0700 Message-Id: <20221020215318.4193269-7-opendmb@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221020215318.4193269-1-opendmb@gmail.com> References: <20221020215318.4193269-1-opendmb@gmail.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666302880; a=rsa-sha256; cv=none; b=xxac02sI3pf4qGSN0WXcjLpX3uBKY8ie6YII2aW6UqFnVD8NA6h2KRKQJ9TQ4rPxs0P9+d 5yNj/lY1zGvtL1W/0PwPcjZmY17b2Bmmkas4RkB40YAXe9ZLFb9YvvZPXUMahSY9Uekm1o O2ZnV6qpTRATTxtXczzneqRaWRH2bFQ= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=SZ1PlrYO; spf=pass (imf02.hostedemail.com: domain of opendmb@gmail.com designates 209.85.219.46 as permitted sender) smtp.mailfrom=opendmb@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=1666302880; h=from:from:sender: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=k0ZvpnVNYZiRg/rCuSdzxC9eb6lzs9TieDFdQySZsn8=; b=Tk9ZpwgPDARDYBaMRBN7J8sycSbVg0fAV9p1Q1ssS+CpJmDsUBGODU3vX79EX/zkdAeFTG JY10Um9WLEZSzfFwk53f1pe8zeAFVaEyLmyvPjva+I75Ex/zuFVLem1B4A7zTSTKn8SYmS Je+diCwl8spUoR6cgwD581QbvLE9K4g= X-Stat-Signature: 1ph413inyid6zmcdpe4ghjfkycxmcesu X-Rspamd-Queue-Id: ED9F18003B Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=SZ1PlrYO; spf=pass (imf02.hostedemail.com: domain of opendmb@gmail.com designates 209.85.219.46 as permitted sender) smtp.mailfrom=opendmb@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1666302879-192275 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: The MEMBLOCK_MOVABLE flag is introduced to designate a memblock as only supporting movable allocations by the page allocator. Signed-off-by: Doug Berger --- include/linux/memblock.h | 8 ++++++++ mm/memblock.c | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 50ad19662a32..8eb3ca32dfa7 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -47,6 +47,7 @@ enum memblock_flags { MEMBLOCK_MIRROR = 0x2, /* mirrored region */ MEMBLOCK_NOMAP = 0x4, /* don't add to kernel direct mapping */ MEMBLOCK_DRIVER_MANAGED = 0x8, /* always detected via a driver */ + MEMBLOCK_MOVABLE = 0x10, /* designated movable block */ }; /** @@ -125,6 +126,8 @@ int memblock_clear_hotplug(phys_addr_t base, phys_addr_t size); int memblock_mark_mirror(phys_addr_t base, phys_addr_t size); int memblock_mark_nomap(phys_addr_t base, phys_addr_t size); int memblock_clear_nomap(phys_addr_t base, phys_addr_t size); +int memblock_mark_movable(phys_addr_t base, phys_addr_t size); +int memblock_clear_movable(phys_addr_t base, phys_addr_t size); void memblock_free_all(void); void memblock_free(void *ptr, size_t size); @@ -265,6 +268,11 @@ static inline bool memblock_is_driver_managed(struct memblock_region *m) return m->flags & MEMBLOCK_DRIVER_MANAGED; } +static inline bool memblock_is_movable(struct memblock_region *m) +{ + return m->flags & MEMBLOCK_MOVABLE; +} + int memblock_search_pfn_nid(unsigned long pfn, unsigned long *start_pfn, unsigned long *end_pfn); void __next_mem_pfn_range(int *idx, int nid, unsigned long *out_start_pfn, diff --git a/mm/memblock.c b/mm/memblock.c index 511d4783dcf1..46a4deb07d92 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -979,6 +979,30 @@ int __init_memblock memblock_clear_nomap(phys_addr_t base, phys_addr_t size) return memblock_setclr_flag(base, size, 0, MEMBLOCK_NOMAP); } +/** + * memblock_mark_movable - Mark designated movable block with MEMBLOCK_MOVABLE. + * @base: the base phys addr of the region + * @size: the size of the region + * + * Return: 0 on success, -errno on failure. + */ +int __init_memblock memblock_mark_movable(phys_addr_t base, phys_addr_t size) +{ + return memblock_setclr_flag(base, size, 1, MEMBLOCK_MOVABLE); +} + +/** + * memblock_clear_movable - Clear flag MEMBLOCK_MOVABLE for a specified region. + * @base: the base phys addr of the region + * @size: the size of the region + * + * Return: 0 on success, -errno on failure. + */ +int __init_memblock memblock_clear_movable(phys_addr_t base, phys_addr_t size) +{ + return memblock_setclr_flag(base, size, 0, MEMBLOCK_MOVABLE); +} + static bool should_skip_region(struct memblock_type *type, struct memblock_region *m, int nid, int flags) From patchwork Thu Oct 20 21:53:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Berger X-Patchwork-Id: 13014054 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 2F946C433FE for ; Thu, 20 Oct 2022 21:54:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C1A658E000B; Thu, 20 Oct 2022 17:54:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BCAFE8E0001; Thu, 20 Oct 2022 17:54:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A450D8E000B; Thu, 20 Oct 2022 17:54:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9653E8E0001 for ; Thu, 20 Oct 2022 17:54:43 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 71F89A11FD for ; Thu, 20 Oct 2022 21:54:43 +0000 (UTC) X-FDA: 80042682846.27.0D2A89A Received: from mail-qt1-f182.google.com (mail-qt1-f182.google.com [209.85.160.182]) by imf23.hostedemail.com (Postfix) with ESMTP id 14848140007 for ; Thu, 20 Oct 2022 21:54:42 +0000 (UTC) Received: by mail-qt1-f182.google.com with SMTP id c23so520588qtw.8 for ; Thu, 20 Oct 2022 14:54:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ON4FfF7RtuDZjsoHxYv/wuBnH0JKvImdT9/cPL7B4E0=; b=XzHIddvgjbn/DEGuAOcP7G4+LhPADOsmHOVPx+eK/tArDp0m1ApsQjdzDRhDWjBjze FV7WvmZ3Z1YIylkFLO79TwLXVHmmpJiiMr4LzhKu5IQtBXgM1BWHrk9NnmQRBxx2R9of wXxEz7cErjAV/icB62wzyIHImPD22fCv2VuRDuHHzJ/eLMTeuoQTBvURVuUU8IuP5i77 Wwvv2l7MRAVvir55myuZNw2HjXsQ/g4bjHDnSPw6oJ4iQFcDR+ET2mGaH38XxNKI72wk jfitbMd/w6o0N3l/Q9xIA/puo4psu3OFDqXj5GIeGkX9Szoh/jdbWQUtBPei4RUXXhmg xH0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version: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=ON4FfF7RtuDZjsoHxYv/wuBnH0JKvImdT9/cPL7B4E0=; b=7L1N+eqdUe0isIp+4dlAZej7zcxlasEcLv1X7okqQQI1FFjn7ulvsBogrMRPJjilVp U/NPTFvaSzFwrXhDOavUm7WYmhgA7awTLNRWkpCxlvoivuamgvFNkV1bAIippZHL8EYw FtJE2YDbmd35XcCKpwdx92WHzp+uME9yB1W6in6mZOgJikN+H5ly0+gs/m9wdBamHm+D gdmuvDXPyIlx3JIoWoMjSFGFE11LTIPafgGLgrFvzgBdLZA9t5wCjlDw7rEzPEJBPwDo S3QZIegysTGgbadSP6hadP5/U6UV6wZ5vkc2nd8XHEXE9q7zY1BH4a8UnqacvnHgjqh3 GQug== X-Gm-Message-State: ACrzQf3cY0YfOGfEDnoJj5f90p5wUkI5J3Ufv84ifd5o+w+ssHDPr1mU nchqRTTYJ2xiRLeV7itg2YY= X-Google-Smtp-Source: AMsMyM605cIOfVk5wCuuu2iSfdA5o6IG3mc3NNxopDZfN9pfYCmZZRzggaTw3fb309wKHReA7jxYoQ== X-Received: by 2002:ac8:7f89:0:b0:39c:e339:3076 with SMTP id z9-20020ac87f89000000b0039ce3393076mr13067224qtj.526.1666302882230; Thu, 20 Oct 2022 14:54:42 -0700 (PDT) Received: from stbirv-lnx-3.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id bj41-20020a05620a192900b006bb29d932e1sm8121067qkb.105.2022.10.20.14.54.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 14:54:41 -0700 (PDT) From: Doug Berger To: Andrew Morton Cc: Jonathan Corbet , Mike Rapoport , Borislav Petkov , "Paul E. McKenney" , Neeraj Upadhyay , Randy Dunlap , Damien Le Moal , Muchun Song , Vlastimil Babka , Johannes Weiner , Michal Hocko , KOSAKI Motohiro , Mel Gorman , Mike Kravetz , Florian Fainelli , David Hildenbrand , Oscar Salvador , Joonsoo Kim , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Doug Berger Subject: [PATCH v3 7/9] mm/dmb: Introduce Designated Movable Blocks Date: Thu, 20 Oct 2022 14:53:16 -0700 Message-Id: <20221020215318.4193269-8-opendmb@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221020215318.4193269-1-opendmb@gmail.com> References: <20221020215318.4193269-1-opendmb@gmail.com> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=XzHIddvg; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of opendmb@gmail.com designates 209.85.160.182 as permitted sender) smtp.mailfrom=opendmb@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666302883; a=rsa-sha256; cv=none; b=SukEQXldAmz0L+CKmyCpbiHs+ENWOWzrAyYxJ41RF0xar52876JTHQsmOCHf5gjo9qJe8V JRV09MJY4d/iV9NL5rT8JVrgK6welbZa8jjx7Sc4rEHfD36X+GGQNg2+c6wZvJ5pI+HOlj shBPFtifZs03wtsw/MOX9mF82j1IYJc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666302883; h=from:from:sender: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=ON4FfF7RtuDZjsoHxYv/wuBnH0JKvImdT9/cPL7B4E0=; b=Qft184BFNg6eEfiW6JPs8zIv1FMjplQ14nqM9q1HXJxxCxHjpqYLxzhfEwtUh7EvsBNzJH SrO7ftW9zyLKGTxS6aLfVbhVzkmjvUpvyrfr9siyGsgDkxn1WKzXcUDZynvDkhnnPfa5ZB R/dmFRzLWUyeCCD+IexmoYMxptXs9qM= Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=XzHIddvg; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of opendmb@gmail.com designates 209.85.160.182 as permitted sender) smtp.mailfrom=opendmb@gmail.com X-Rspam-User: X-Rspamd-Server: rspam06 X-Stat-Signature: 1cud4kye3e4t1nihyxcignhqaksarcdp X-Rspamd-Queue-Id: 14848140007 X-HE-Tag: 1666302882-765780 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: Designated Movable Blocks are blocks of memory that are composed of one or more adjacent memblocks that have the MEMBLOCK_MOVABLE designation. These blocks must be reserved before receiving that designation and will be located in the ZONE_MOVABLE zone rather than any other zone that may span them. Signed-off-by: Doug Berger --- include/linux/dmb.h | 29 ++++++++++++++ mm/Kconfig | 12 ++++++ mm/Makefile | 1 + mm/dmb.c | 91 +++++++++++++++++++++++++++++++++++++++++++ mm/memblock.c | 6 ++- mm/page_alloc.c | 95 ++++++++++++++++++++++++++++++++++++++------- 6 files changed, 220 insertions(+), 14 deletions(-) create mode 100644 include/linux/dmb.h create mode 100644 mm/dmb.c diff --git a/include/linux/dmb.h b/include/linux/dmb.h new file mode 100644 index 000000000000..fa2976c0fa21 --- /dev/null +++ b/include/linux/dmb.h @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __DMB_H__ +#define __DMB_H__ + +#include + +/* + * the buddy -- especially pageblock merging and alloc_contig_range() + * -- can deal with only some pageblocks of a higher-order page being + * MIGRATE_MOVABLE, we can use pageblock_nr_pages. + */ +#define DMB_MIN_ALIGNMENT_PAGES pageblock_nr_pages +#define DMB_MIN_ALIGNMENT_BYTES (PAGE_SIZE * DMB_MIN_ALIGNMENT_PAGES) + +enum { + DMB_DISJOINT = 0, + DMB_INTERSECTS, + DMB_MIXED, +}; + +struct dmb; + +extern int dmb_intersects(unsigned long spfn, unsigned long epfn); + +extern int dmb_reserve(phys_addr_t base, phys_addr_t size, + struct dmb **res_dmb); +extern void dmb_init_region(struct memblock_region *region); + +#endif diff --git a/mm/Kconfig b/mm/Kconfig index 57e1d8c5b505..3a058b34e77e 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -868,6 +868,18 @@ config CMA_AREAS If unsure, leave the default value "7" in UMA and "19" in NUMA. +config DMB_COUNT + int "Maximum count of Designated Movable Blocks" + default 19 if NUMA + default 7 + help + Designated Movable Blocks are blocks of memory that can be used + by the page allocator exclusively for movable pages. They are + managed in ZONE_MOVABLE but may overlap with other zones. This + parameter sets the maximum number of DMBs in the system. + + If unsure, leave the default value "7" in UMA and "19" in NUMA. + config MEM_SOFT_DIRTY bool "Track memory changes" depends on CHECKPOINT_RESTORE && HAVE_ARCH_SOFT_DIRTY && PROC_FS diff --git a/mm/Makefile b/mm/Makefile index 8e105e5b3e29..824be8fb11cd 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -67,6 +67,7 @@ obj-y += page-alloc.o obj-y += init-mm.o obj-y += memblock.o obj-y += $(memory-hotplug-y) +obj-y += dmb.o ifdef CONFIG_MMU obj-$(CONFIG_ADVISE_SYSCALLS) += madvise.o diff --git a/mm/dmb.c b/mm/dmb.c new file mode 100644 index 000000000000..f6c4e2662e0f --- /dev/null +++ b/mm/dmb.c @@ -0,0 +1,91 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Designated Movable Block + */ + +#define pr_fmt(fmt) "dmb: " fmt + +#include + +struct dmb { + unsigned long start_pfn; + unsigned long end_pfn; +}; + +static struct dmb dmb_areas[CONFIG_DMB_COUNT]; +static unsigned int dmb_area_count; + +int dmb_intersects(unsigned long spfn, unsigned long epfn) +{ + int i; + struct dmb *dmb; + + if (spfn >= epfn) + return DMB_DISJOINT; + + for (i = 0; i < dmb_area_count; i++) { + dmb = &dmb_areas[i]; + if (spfn >= dmb->end_pfn) + continue; + if (epfn <= dmb->start_pfn) + return DMB_DISJOINT; + if (spfn >= dmb->start_pfn && epfn <= dmb->end_pfn) + return DMB_INTERSECTS; + else + return DMB_MIXED; + } + + return DMB_DISJOINT; +} +EXPORT_SYMBOL(dmb_intersects); + +int __init dmb_reserve(phys_addr_t base, phys_addr_t size, + struct dmb **res_dmb) +{ + struct dmb *dmb; + + /* Sanity checks */ + if (!size || !memblock_is_region_reserved(base, size)) + return -EINVAL; + + /* ensure minimal alignment required by mm core */ + if (!IS_ALIGNED(base | size, DMB_MIN_ALIGNMENT_BYTES)) + return -EINVAL; + + if (dmb_area_count == ARRAY_SIZE(dmb_areas)) { + pr_warn("Not enough slots for DMB reserved regions!\n"); + return -ENOSPC; + } + + /* + * Each reserved area must be initialised later, when more kernel + * subsystems (like slab allocator) are available. + */ + dmb = &dmb_areas[dmb_area_count++]; + + dmb->start_pfn = PFN_DOWN(base); + dmb->end_pfn = PFN_DOWN(base + size); + if (res_dmb) + *res_dmb = dmb; + + memblock_mark_movable(base, size); + return 0; +} + +void __init dmb_init_region(struct memblock_region *region) +{ + unsigned long pfn; + int i; + + for (pfn = memblock_region_memory_base_pfn(region); + pfn < memblock_region_memory_end_pfn(region); + pfn += pageblock_nr_pages) { + struct page *page = pfn_to_page(pfn); + + for (i = 0; i < pageblock_nr_pages; i++) + set_page_zone(page + i, ZONE_MOVABLE); + + /* free reserved pageblocks to page allocator */ + init_reserved_pageblock(page); + } +} diff --git a/mm/memblock.c b/mm/memblock.c index 46a4deb07d92..2a957337bd8b 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -2090,13 +2091,16 @@ static void __init memmap_init_reserved_pages(void) for_each_reserved_mem_range(i, &start, &end) reserve_bootmem_region(start, end); - /* and also treat struct pages for the NOMAP regions as PageReserved */ for_each_mem_region(region) { + /* treat struct pages for the NOMAP regions as PageReserved */ if (memblock_is_nomap(region)) { start = region->base; end = start + region->size; reserve_bootmem_region(start, end); } + /* move Designated Movable Block pages to ZONE_MOVABLE */ + if (memblock_is_movable(region)) + dmb_init_region(region); } } diff --git a/mm/page_alloc.c b/mm/page_alloc.c index d7a5a05ead4b..82cad751e0b8 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -76,6 +76,7 @@ #include #include #include +#include #include #include #include @@ -434,6 +435,8 @@ static unsigned long required_kernelcore __initdata; static unsigned long required_kernelcore_percent __initdata; static unsigned long required_movablecore __initdata; static unsigned long required_movablecore_percent __initdata; +static unsigned long min_dmb_pfn[MAX_NUMNODES] __initdata; +static unsigned long max_dmb_pfn[MAX_NUMNODES] __initdata; static unsigned long zone_movable_pfn[MAX_NUMNODES] __initdata; bool mirrored_kernelcore __initdata_memblock; @@ -2171,7 +2174,7 @@ static int __init deferred_init_memmap(void *data) } zone_empty: /* Sanity check that the next zone really is unpopulated */ - WARN_ON(++zid < MAX_NR_ZONES && populated_zone(++zone)); + WARN_ON(++zid < ZONE_MOVABLE && populated_zone(++zone)); pr_info("node %d deferred pages initialised in %ums\n", pgdat->node_id, jiffies_to_msecs(jiffies - start)); @@ -6978,6 +6981,10 @@ static void __init memmap_init_zone_range(struct zone *zone, unsigned long zone_end_pfn = zone_start_pfn + zone->spanned_pages; int nid = zone_to_nid(zone), zone_id = zone_idx(zone); + /* Skip overlap of ZONE_MOVABLE */ + if (zone_id == ZONE_MOVABLE && zone_start_pfn < *hole_pfn) + zone_start_pfn = *hole_pfn; + start_pfn = clamp(start_pfn, zone_start_pfn, zone_end_pfn); end_pfn = clamp(end_pfn, zone_start_pfn, zone_end_pfn); @@ -7438,6 +7445,12 @@ static unsigned long __init zone_spanned_pages_in_node(int nid, node_start_pfn, node_end_pfn, zone_start_pfn, zone_end_pfn); + if (zone_type == ZONE_MOVABLE && max_dmb_pfn[nid]) { + if (*zone_start_pfn == *zone_end_pfn) + *zone_end_pfn = max_dmb_pfn[nid]; + *zone_start_pfn = min(*zone_start_pfn, min_dmb_pfn[nid]); + } + /* Check that this node has pages within the zone's required range */ if (*zone_end_pfn < node_start_pfn || *zone_start_pfn > node_end_pfn) return 0; @@ -7506,12 +7519,21 @@ static unsigned long __init zone_absent_pages_in_node(int nid, &zone_start_pfn, &zone_end_pfn); nr_absent = __absent_pages_in_range(nid, zone_start_pfn, zone_end_pfn); + if (zone_type == ZONE_MOVABLE && max_dmb_pfn[nid]) { + if (zone_start_pfn == zone_end_pfn) + zone_end_pfn = max_dmb_pfn[nid]; + else + zone_end_pfn = zone_movable_pfn[nid]; + zone_start_pfn = min(zone_start_pfn, min_dmb_pfn[nid]); + nr_absent += zone_end_pfn - zone_start_pfn; + } + /* * ZONE_MOVABLE handling. - * Treat pages to be ZONE_MOVABLE in ZONE_NORMAL as absent pages + * Treat pages to be ZONE_MOVABLE in other zones as absent pages * and vice versa. */ - if (mirrored_kernelcore && zone_movable_pfn[nid]) { + if (zone_movable_pfn[nid]) { unsigned long start_pfn, end_pfn; struct memblock_region *r; @@ -7521,6 +7543,19 @@ static unsigned long __init zone_absent_pages_in_node(int nid, end_pfn = clamp(memblock_region_memory_end_pfn(r), zone_start_pfn, zone_end_pfn); + if (memblock_is_movable(r)) { + if (zone_type != ZONE_MOVABLE) { + nr_absent += end_pfn - start_pfn; + continue; + } + + nr_absent -= end_pfn - start_pfn; + continue; + } + + if (!mirrored_kernelcore) + continue; + if (zone_type == ZONE_MOVABLE && memblock_is_mirror(r)) nr_absent += end_pfn - start_pfn; @@ -7540,18 +7575,27 @@ static void __init calculate_node_totalpages(struct pglist_data *pgdat, { unsigned long totalpages = 0; enum zone_type i; + int nid = pgdat->node_id; + + /* + * If Designated Movable Blocks are defined on this node, ensure that + * zone_movable_pfn is also defined for this node. + */ + if (max_dmb_pfn[nid] && !zone_movable_pfn[nid]) + zone_movable_pfn[nid] = min(node_end_pfn, + arch_zone_highest_possible_pfn[movable_zone]); for (i = 0; i < MAX_NR_ZONES; i++) { struct zone *zone = pgdat->node_zones + i; unsigned long zone_start_pfn, zone_end_pfn; unsigned long spanned, absent, size; - spanned = zone_spanned_pages_in_node(pgdat->node_id, i, + spanned = zone_spanned_pages_in_node(nid, i, node_start_pfn, node_end_pfn, &zone_start_pfn, &zone_end_pfn); - absent = zone_absent_pages_in_node(pgdat->node_id, i, + absent = zone_absent_pages_in_node(nid, i, node_start_pfn, node_end_pfn); @@ -8002,15 +8046,27 @@ unsigned long __init node_map_pfn_alignment(void) static unsigned long __init early_calculate_totalpages(void) { unsigned long totalpages = 0; - unsigned long start_pfn, end_pfn; - int i, nid; + struct memblock_region *r; - for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, &nid) { - unsigned long pages = end_pfn - start_pfn; + for_each_mem_region(r) { + unsigned long start_pfn, end_pfn, pages; + int nid; + + nid = memblock_get_region_node(r); + start_pfn = memblock_region_memory_base_pfn(r); + end_pfn = memblock_region_memory_end_pfn(r); - totalpages += pages; - if (pages) + pages = end_pfn - start_pfn; + if (pages) { + totalpages += pages; node_set_state(nid, N_MEMORY); + if (memblock_is_movable(r)) { + if (start_pfn < min_dmb_pfn[nid]) + min_dmb_pfn[nid] = start_pfn; + if (end_pfn > max_dmb_pfn[nid]) + max_dmb_pfn[nid] = end_pfn; + } + } } return totalpages; } @@ -8023,7 +8079,7 @@ static unsigned long __init early_calculate_totalpages(void) */ static void __init find_zone_movable_pfns_for_nodes(void) { - int i, nid; + int nid; unsigned long usable_startpfn; unsigned long kernelcore_node, kernelcore_remaining; /* save the state before borrow the nodemask */ @@ -8151,13 +8207,24 @@ static void __init find_zone_movable_pfns_for_nodes(void) kernelcore_remaining = kernelcore_node; /* Go through each range of PFNs within this node */ - for_each_mem_pfn_range(i, nid, &start_pfn, &end_pfn, NULL) { + for_each_mem_region(r) { unsigned long size_pages; + if (memblock_get_region_node(r) != nid) + continue; + + start_pfn = memblock_region_memory_base_pfn(r); + end_pfn = memblock_region_memory_end_pfn(r); start_pfn = max(start_pfn, zone_movable_pfn[nid]); if (start_pfn >= end_pfn) continue; + /* Skip over Designated Movable Blocks */ + if (memblock_is_movable(r)) { + zone_movable_pfn[nid] = end_pfn; + continue; + } + /* Account for what is only usable for kernelcore */ if (start_pfn < usable_startpfn) { unsigned long kernel_pages; @@ -8306,6 +8373,8 @@ void __init free_area_init(unsigned long *max_zone_pfn) } /* Find the PFNs that ZONE_MOVABLE begins at in each node */ + memset(min_dmb_pfn, 0xff, sizeof(min_dmb_pfn)); + memset(max_dmb_pfn, 0, sizeof(max_dmb_pfn)); memset(zone_movable_pfn, 0, sizeof(zone_movable_pfn)); find_zone_movable_pfns_for_nodes(); From patchwork Thu Oct 20 21:53:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Berger X-Patchwork-Id: 13014055 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 126DFC4332F for ; Thu, 20 Oct 2022 21:54:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A6D6E8E000C; Thu, 20 Oct 2022 17:54:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A1D618E0001; Thu, 20 Oct 2022 17:54:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8BE2C8E000C; Thu, 20 Oct 2022 17:54:46 -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 7EAF98E0001 for ; Thu, 20 Oct 2022 17:54:46 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 6308AA11FD for ; Thu, 20 Oct 2022 21:54:46 +0000 (UTC) X-FDA: 80042682972.03.E49D048 Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) by imf11.hostedemail.com (Postfix) with ESMTP id F189C40004 for ; Thu, 20 Oct 2022 21:54:45 +0000 (UTC) Received: by mail-qk1-f180.google.com with SMTP id a18so925120qko.0 for ; Thu, 20 Oct 2022 14:54:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cizdPvmJ1B17OrSNKxRqtl13qIriognWBTeBRaDyut8=; b=KB+L2mJLWgHCBesUojexARn3KfzhK2H8uBHU+VHa8RVf7cVaGNVrwuXj5H0u/3lYNt wcRhSDne7ByyOYLA9cvoYeZ3VkJnXDvSNYrN7WLs2Y8egIdBuC1tsxWHa8GuimGAILbi HpD84Z7bldzP6/kQGQaZBJtwCmr8b/q3S10e3mNdrpXjva2ZtAfgkTBffc6/iyI1nZh8 Dkvb6WhFlo7oG5GjOPlOEGO7jqBEgByfJJkRI0qvYtt0VrUgU2wXlz0p4gbq6SsQ+iYg B0OQZMc70gmWoyH7TxZ9cLUl4CmQ26VS1NmykgFEz179lNiZQ6BbQaEEdltfzN3ILZRT GG9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version: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=cizdPvmJ1B17OrSNKxRqtl13qIriognWBTeBRaDyut8=; b=dAUmHeK2/36AUQnq6+8RnW1gbfcfpN1/qHFBeTQ+hNFKBeFjCtR4XPghL1cDG5aRQr +piTnm9yUxePj3BPwOvUElf4ix//pthcUFv5vbvVIu97CiNCInok7XaJvA7LM/1K2Q0K 09vQjqJW5jpPuym8YCi+K5C+++nYXxwGg45XBuu+R741ENibBWyjtxxmv6Sa4TBUDZ3V afQvfKNeBBMqttX/XQMJUdmEW/IfkEnxFEOkLKNlv/bpxVUzgVfGHGP80cPhpf27qlCP qnqO1CXU2C2uI596PvQ/owM9tjta5EYl1QdD5K4kq5WFK389LPvMgS6AZJw+eUVbLd5i UgPw== X-Gm-Message-State: ACrzQf0/dd3XUC+wZLQ7lFqsFoiB41GqieByACcFpE4qjLKaef2BEl8d yRejDJ4lVdzvV9FV10BP06c= X-Google-Smtp-Source: AMsMyM4TfR3bYlmhEQVS3hRsR8tGQaHhGxaCz70N0D3SiJn/URFTRu7Q8Q87qGF4C+fS2BQtoGIQDg== X-Received: by 2002:a05:620a:4510:b0:6ee:e598:a185 with SMTP id t16-20020a05620a451000b006eee598a185mr10499940qkp.765.1666302885214; Thu, 20 Oct 2022 14:54:45 -0700 (PDT) Received: from stbirv-lnx-3.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id bj41-20020a05620a192900b006bb29d932e1sm8121067qkb.105.2022.10.20.14.54.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 14:54:44 -0700 (PDT) From: Doug Berger To: Andrew Morton Cc: Jonathan Corbet , Mike Rapoport , Borislav Petkov , "Paul E. McKenney" , Neeraj Upadhyay , Randy Dunlap , Damien Le Moal , Muchun Song , Vlastimil Babka , Johannes Weiner , Michal Hocko , KOSAKI Motohiro , Mel Gorman , Mike Kravetz , Florian Fainelli , David Hildenbrand , Oscar Salvador , Joonsoo Kim , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Doug Berger Subject: [PATCH v3 8/9] mm/page_alloc: make alloc_contig_pages DMB aware Date: Thu, 20 Oct 2022 14:53:17 -0700 Message-Id: <20221020215318.4193269-9-opendmb@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221020215318.4193269-1-opendmb@gmail.com> References: <20221020215318.4193269-1-opendmb@gmail.com> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=KB+L2mJL; spf=pass (imf11.hostedemail.com: domain of opendmb@gmail.com designates 209.85.222.180 as permitted sender) smtp.mailfrom=opendmb@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666302886; a=rsa-sha256; cv=none; b=tjvY9gcxcZXBnWxvcMygGVMisgsgA0BOsme80LQsgkW82GImlKFgdI5f4qJuN973O3zWrb dqy9dmY1t1Hb09Sg1uEFNpbMcA+q4hXu4fnmJGdDiYvUjjs12rK9iLiKQ5oTKhlEiLeyp+ gB8NeKMe4Q2q1B1MmVAvA7jW2aF5Yg0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666302886; h=from:from:sender: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=cizdPvmJ1B17OrSNKxRqtl13qIriognWBTeBRaDyut8=; b=aJGwi52oqCRYZi6ngdiA0GX+1oAHky6fciYzgeUY3NZisT90y6P2BzPJqziFIsTyTjZ/G/ JkeY6hW3VVZ3mEGHWaRNlRJevNElcFWBQk0BDlCcWgqTZW9XBNqGx02kC3FbEEoyL5k/Xl CTHQS44DY9P/COVxkwPCm3+/QgmvEVE= Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=KB+L2mJL; spf=pass (imf11.hostedemail.com: domain of opendmb@gmail.com designates 209.85.222.180 as permitted sender) smtp.mailfrom=opendmb@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: 7y1scdbhyd7xn45m414w86zzjhsorrzc X-Rspamd-Queue-Id: F189C40004 X-Rspamd-Server: rspam02 X-Rspam-User: X-HE-Tag: 1666302885-864937 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: Designated Movable Blocks are skipped when attempting to allocate contiguous pages. Doing per page validation across all spanned pages within a zone can be extra inefficient when Designated Movable Blocks create large overlaps between zones. Use dmb_intersects() within pfn_range_valid_contig as an early check to signal the range is not valid. The zone_movable_pfn array which represents the start of non- overlapped ZONE_MOVABLE on the node is now preserved to be used at runtime to skip over any DMB-only portion of the zone. Signed-off-by: Doug Berger --- mm/page_alloc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 82cad751e0b8..a39eca3bc01b 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -437,7 +437,7 @@ static unsigned long required_movablecore __initdata; static unsigned long required_movablecore_percent __initdata; static unsigned long min_dmb_pfn[MAX_NUMNODES] __initdata; static unsigned long max_dmb_pfn[MAX_NUMNODES] __initdata; -static unsigned long zone_movable_pfn[MAX_NUMNODES] __initdata; +static unsigned long zone_movable_pfn[MAX_NUMNODES]; bool mirrored_kernelcore __initdata_memblock; /* movable_zone is the "real" zone pages in ZONE_MOVABLE are taken from */ @@ -9460,6 +9460,9 @@ static bool pfn_range_valid_contig(struct zone *z, unsigned long start_pfn, unsigned long i, end_pfn = start_pfn + nr_pages; struct page *page; + if (dmb_intersects(start_pfn, end_pfn)) + return false; + for (i = start_pfn; i < end_pfn; i++) { page = pfn_to_online_page(i); if (!page) @@ -9516,7 +9519,10 @@ struct page *alloc_contig_pages(unsigned long nr_pages, gfp_t gfp_mask, gfp_zone(gfp_mask), nodemask) { spin_lock_irqsave(&zone->lock, flags); - pfn = ALIGN(zone->zone_start_pfn, nr_pages); + if (zone_idx(zone) == ZONE_MOVABLE && zone_movable_pfn[nid]) + pfn = ALIGN(zone_movable_pfn[nid], nr_pages); + else + pfn = ALIGN(zone->zone_start_pfn, nr_pages); while (zone_spans_last_pfn(zone, pfn, nr_pages)) { if (pfn_range_valid_contig(zone, pfn, nr_pages)) { /* From patchwork Thu Oct 20 21:53:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Berger X-Patchwork-Id: 13014056 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 AF2D6C4332F for ; Thu, 20 Oct 2022 21:54:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 406E88E000D; Thu, 20 Oct 2022 17:54:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3B4E88E0001; Thu, 20 Oct 2022 17:54:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 255B58E000D; Thu, 20 Oct 2022 17:54:49 -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 187478E0001 for ; Thu, 20 Oct 2022 17:54:49 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E96E016014C for ; Thu, 20 Oct 2022 21:54:48 +0000 (UTC) X-FDA: 80042683056.11.948449B Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) by imf11.hostedemail.com (Postfix) with ESMTP id 9711D40004 for ; Thu, 20 Oct 2022 21:54:48 +0000 (UTC) Received: by mail-qk1-f180.google.com with SMTP id a18so925192qko.0 for ; Thu, 20 Oct 2022 14:54:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ea/3nCCOnpBrAub9VWj+VXkTFR+eMwl9pcvHopG8Sl4=; b=jHO9VXRMOgdapG/UgLZpqe+Gt5pAn7UO5fZglesQLnrsJyUhoJnB3qHY4gaLpiyFOy bUH75Aj62S7L5f3ngX4qS9txpVrLZd93mjdMBZQ0U7flk0sQPbYTCS7mQ7RIXxkvnq+x jZEhV0P3om90L4r12ay7KkkDquUuCss1I8xiwWwxRyQvMekR87gzk1POzYfJyWllelOY t3uQ+y3KkAhEZ1RY6johTUnoMIIbx77+Xuo9N2Y/I+jQ6VcUfI2jAsKkEsTB9FyFs08b ORM6yLBHqPM6zcCt7XPaHUmhLZp0rubUzkkslI1uggLXAFRo3Mk+qOGm9V0JvNMvR1uL F9Aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version: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=Ea/3nCCOnpBrAub9VWj+VXkTFR+eMwl9pcvHopG8Sl4=; b=Cik7lDpU/5voswfGjGCauC3ECHbHCOM/ljK3UEey2FpLcesQ0kdyb7bztFauawei6Y H8mCkLFwtFe8tEBL9P4/twXl1ZA3XCucgtzoIP3Ul7hNMPemUCSOKFQwkrlY6hOBE2Mj n0EPCiyIbRNQ7D2tQ6qAc1tURTeDZtnt3X8S5n8dMFHTdtTEON583FPVtCp3YWz9btop bjisMr275nK18zcpQ5UN9btXbjX+Y5GfAmdwy5tttSrUhCH2Qnpg5A8vG5UWtgXGjyqp opJ8YHBt05R/sdECJeDFXC3fvm+X8MPO3HbaNDnKQfvCwbU6mR4fq+kP+vNpiSi0emOh di3Q== X-Gm-Message-State: ACrzQf3K1wOMRpv2FmUBneSvmBc3HydW7vxuZ8iZ6DvccbbxbgOl9xeH fVy5GKieTK3aaFtIzW/Q4dg= X-Google-Smtp-Source: AMsMyM4pzFRAGr5Df27Tt7JSy+ztbl+cUDOBbNs8UPvLwkFRB8ksm3avZsXosGl3xlV877vJr3B/0g== X-Received: by 2002:a05:620a:4250:b0:6cf:a822:7c7e with SMTP id w16-20020a05620a425000b006cfa8227c7emr11637421qko.503.1666302888216; Thu, 20 Oct 2022 14:54:48 -0700 (PDT) Received: from stbirv-lnx-3.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id bj41-20020a05620a192900b006bb29d932e1sm8121067qkb.105.2022.10.20.14.54.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 14:54:47 -0700 (PDT) From: Doug Berger To: Andrew Morton Cc: Jonathan Corbet , Mike Rapoport , Borislav Petkov , "Paul E. McKenney" , Neeraj Upadhyay , Randy Dunlap , Damien Le Moal , Muchun Song , Vlastimil Babka , Johannes Weiner , Michal Hocko , KOSAKI Motohiro , Mel Gorman , Mike Kravetz , Florian Fainelli , David Hildenbrand , Oscar Salvador , Joonsoo Kim , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Doug Berger Subject: [PATCH v3 9/9] mm/page_alloc: allow base for movablecore Date: Thu, 20 Oct 2022 14:53:18 -0700 Message-Id: <20221020215318.4193269-10-opendmb@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221020215318.4193269-1-opendmb@gmail.com> References: <20221020215318.4193269-1-opendmb@gmail.com> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=jHO9VXRM; spf=pass (imf11.hostedemail.com: domain of opendmb@gmail.com designates 209.85.222.180 as permitted sender) smtp.mailfrom=opendmb@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666302888; a=rsa-sha256; cv=none; b=M9IoB8S/dKJ6ypWWjJsAzdQrb6KM0WLJTGHoPiyO6cZm5dXVfNfoAegjaRCcMhVA9BwlJV 0PwXmjLzVnX1uP7R02k8QIhVjS4sXKB7wtM4yXxwJYgSHngBJ/3Ij1EZzvDd0be1W4CNaX zRDeTqPN8D17fUR7v2063SBeKMCRoKY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666302888; h=from:from:sender: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=Ea/3nCCOnpBrAub9VWj+VXkTFR+eMwl9pcvHopG8Sl4=; b=p6czictytRxrAzVywohU3vyDMq4XeI2zVQFxkZi7048jOukZ38LavI2RmHHJ16/8fgtUxP Pw5HxDy8w6EX91c30SWeOLGzaES3gBcLvawjyHriIGinvE6m/Kb/X14q0WhRayzRVuXjx2 wE97Y5jfzuG8P28Bwz81sKAAws/AvpE= Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=jHO9VXRM; spf=pass (imf11.hostedemail.com: domain of opendmb@gmail.com designates 209.85.222.180 as permitted sender) smtp.mailfrom=opendmb@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: 7z39wcrgzuzqnigomr4y84r4niqqo35a X-Rspamd-Queue-Id: 9711D40004 X-Rspamd-Server: rspam02 X-Rspam-User: X-HE-Tag: 1666302888-818955 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: A Designated Movable Block can be created by including the base address of the block when specifying a movablecore range on the kernel command line. Signed-off-by: Doug Berger --- .../admin-guide/kernel-parameters.txt | 14 ++++++- mm/page_alloc.c | 38 ++++++++++++++++--- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index a465d5242774..f4f783cd683e 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -3325,7 +3325,7 @@ reporting absolute coordinates, such as tablets movablecore= [KNL,X86,IA-64,PPC] - Format: nn[KMGTPE] | nn% + Format: nn[KMGTPE] | nn[KMGTPE]@ss[KMGTPE] | nn% This parameter is the complement to kernelcore=, it specifies the amount of memory used for migratable allocations. If both kernelcore and movablecore is @@ -3335,6 +3335,18 @@ that the amount of memory usable for all allocations is not too small. + If @ss[KMGTPE] is included, memory within the region + from ss to ss+nn will be designated as a movable block + and included in ZONE_MOVABLE. Designated Movable Blocks + must be aligned to pageblock_order. Designated Movable + Blocks take priority over values of kernelcore= and are + considered part of any memory specified by more general + movablecore= values. + Multiple Designated Movable Blocks may be specified, + comma delimited. + Example: + movablecore=100M@2G,100M@3G,1G@1024G + movable_node [KNL] Boot-time switch to make hotplugable memory NUMA nodes to be movable. This means that the memory of such nodes will be usable only for movable diff --git a/mm/page_alloc.c b/mm/page_alloc.c index a39eca3bc01b..385fc9082945 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -8461,9 +8461,9 @@ void __init free_area_init(unsigned long *max_zone_pfn) } static int __init cmdline_parse_core(char *p, unsigned long *core, - unsigned long *percent) + unsigned long *percent, bool movable) { - unsigned long long coremem; + unsigned long long coremem, address; char *endptr; if (!p) @@ -8478,6 +8478,17 @@ static int __init cmdline_parse_core(char *p, unsigned long *core, *percent = coremem; } else { coremem = memparse(p, &p); + if (movable && *p == '@') { + address = memparse(++p, &p); + if (*p != '\0' || + !memblock_is_region_memory(address, coremem) || + memblock_is_region_reserved(address, coremem)) + return -EINVAL; + memblock_reserve(address, coremem); + return dmb_reserve(address, coremem, NULL); + } else if (*p != '\0') { + return -EINVAL; + } /* Paranoid check that UL is enough for the coremem value */ WARN_ON((coremem >> PAGE_SHIFT) > ULONG_MAX); @@ -8500,17 +8511,32 @@ static int __init cmdline_parse_kernelcore(char *p) } return cmdline_parse_core(p, &required_kernelcore, - &required_kernelcore_percent); + &required_kernelcore_percent, false); } /* * movablecore=size sets the amount of memory for use for allocations that - * can be reclaimed or migrated. + * can be reclaimed or migrated. movablecore=size@base defines a Designated + * Movable Block. */ static int __init cmdline_parse_movablecore(char *p) { - return cmdline_parse_core(p, &required_movablecore, - &required_movablecore_percent); + int ret = -EINVAL; + + while (p) { + char *k = strchr(p, ','); + + if (k) + *k++ = 0; + + ret = cmdline_parse_core(p, &required_movablecore, + &required_movablecore_percent, true); + if (ret) + break; + p = k; + } + + return ret; } early_param("kernelcore", cmdline_parse_kernelcore);