Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2976552ybp; Sun, 6 Oct 2019 02:01:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqxdoTCL9g8QryKRX6h480KGpn8z9cNnJmhKdKrWxBJSLdJlAqxkfW9HWos55wh+/W0pj38u X-Received: by 2002:aa7:ce88:: with SMTP id y8mr24300905edv.145.1570352492444; Sun, 06 Oct 2019 02:01:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570352492; cv=none; d=google.com; s=arc-20160816; b=eoaAEOePnjYXLAVpC6YuBA2WCRzWplgc9GMl9ulJprN2mhT4MkQnAZ3OoaMqp2gLHO l7B2m455nIR7u1LLyrl5ERwY4HEOJqTxFCif7TS+gxB43l5aVBuIUh8jirecAyWbATUe TJdMpW4b59J70KB0+kzf4SHXCtLhGtKJvJkSAQxQeKlZ7zrkBlISQlGNFSMahknwAgtd sD3EaCkozQKnEmtq1LO3rutBN/hWUGJmK4mHQ8yucUkZQtNi7x9rhbVK9y+W14xR6Zlr UeaPWB1o2M1yuXKup0/59NtzBhyAWTvk7ZMxqo1YmMK5++Bqhw/MMjfeMSGjY2r9DLHM 3VXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=brJsYYGr8WMFIRHqUDhS8hQek8BYw/18DXtVFi18L94=; b=liz/kL0jxXAuDIV++/POyQRANERHj7x4dcJupUj3knruHxDvHzL4CLwbndbcvkm7V2 XFwhqvAoAcqWq28gNzoxHb1yGfgKJhKsMr6ptE0DCe+Jo55m7uqLKisBTOd9UuNg+3Kp tAriH6geTtxK5nufrRCBPsHay9VZUR8VkMQp8BOPmGDuH4X4lc/wxo36vwZTBPAeXOEt 5glgP9M0Gq3hVqLiAgn8NKZYIYs3pqUpk6pHb1KlV2+MCplxV2E6Q2KXKX3dJyVO379d 4PulxJyNLWLPQrFB7sOdylSrnNzQw2lqt3hplQT6WHxnoLZFDXhCJhrfVz9BtF86aAIl nuig== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y2si6594617eds.98.2019.10.06.02.01.08; Sun, 06 Oct 2019 02:01:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726548AbfJFI5r (ORCPT + 99 others); Sun, 6 Oct 2019 04:57:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52152 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726185AbfJFI5p (ORCPT ); Sun, 6 Oct 2019 04:57:45 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 75465368CF; Sun, 6 Oct 2019 08:57:45 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-58.ams2.redhat.com [10.36.116.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id ABE055EE1D; Sun, 6 Oct 2019 08:57:42 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, x86@kernel.org, David Hildenbrand , Andrew Morton , Oscar Salvador , Michal Hocko , Pavel Tatashin , Dan Williams , Wei Yang Subject: [PATCH v6 10/10] mm/memory_hotplug: Cleanup __remove_pages() Date: Sun, 6 Oct 2019 10:56:46 +0200 Message-Id: <20191006085646.5768-11-david@redhat.com> In-Reply-To: <20191006085646.5768-1-david@redhat.com> References: <20191006085646.5768-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sun, 06 Oct 2019 08:57:45 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Let's drop the basically unused section stuff and simplify. Also, let's use a shorter variant to calculate the number of pages to the next section boundary. Cc: Andrew Morton Cc: Oscar Salvador Cc: Michal Hocko Cc: Pavel Tatashin Cc: Dan Williams Cc: Wei Yang Signed-off-by: David Hildenbrand --- mm/memory_hotplug.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 843481bd507d..2275240cfa10 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -490,25 +490,20 @@ static void __remove_section(unsigned long pfn, unsigned long nr_pages, void __remove_pages(unsigned long pfn, unsigned long nr_pages, struct vmem_altmap *altmap) { + const unsigned long end_pfn = pfn + nr_pages; + unsigned long cur_nr_pages; unsigned long map_offset = 0; - unsigned long nr, start_sec, end_sec; map_offset = vmem_altmap_offset(altmap); if (check_pfn_span(pfn, nr_pages, "remove")) return; - start_sec = pfn_to_section_nr(pfn); - end_sec = pfn_to_section_nr(pfn + nr_pages - 1); - for (nr = start_sec; nr <= end_sec; nr++) { - unsigned long pfns; - + for (; pfn < end_pfn; pfn += cur_nr_pages) { cond_resched(); - pfns = min(nr_pages, PAGES_PER_SECTION - - (pfn & ~PAGE_SECTION_MASK)); - __remove_section(pfn, pfns, map_offset, altmap); - pfn += pfns; - nr_pages -= pfns; + /* Select all remaining pages up to the next section boundary */ + cur_nr_pages = min(end_pfn - pfn, -(pfn | PAGE_SECTION_MASK)); + __remove_section(pfn, cur_nr_pages, map_offset, altmap); map_offset = 0; } } -- 2.21.0