From patchwork Wed May 23 15:11:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10421753 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CEEDC60224 for ; Wed, 23 May 2018 15:13:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BDD9628F2B for ; Wed, 23 May 2018 15:13:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BC8A328F3C; Wed, 23 May 2018 15:13:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B56942917E for ; Wed, 23 May 2018 15:12:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 94A3B6B02AD; Wed, 23 May 2018 11:12:22 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8F8956B02AE; Wed, 23 May 2018 11:12:22 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D7B76B02AF; Wed, 23 May 2018 11:12:22 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt0-f200.google.com (mail-qt0-f200.google.com [209.85.216.200]) by kanga.kvack.org (Postfix) with ESMTP id 411B16B02AD for ; Wed, 23 May 2018 11:12:22 -0400 (EDT) Received: by mail-qt0-f200.google.com with SMTP id k4-v6so3654071qtm.4 for ; Wed, 23 May 2018 08:12:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=EQ0p5zD1wrTQszvVXnBma/30StiYx8/b/52JX4oWfmw=; b=W/igRvunEi0E5UXNTMFOU+yJyqQcPkamCmuB5xdAz9V0uc7v+uRGu1+UxJMVY5yg8H Q0xfB0oUJ5tJUWNeGPdqk1fCq4dS1MJQ81aC19deSOmCT6eNC1x0rNe3SjlPGJOFPwhr AjBDizW72Di3HlzJCOIzOfhX0eOLsmLxe8HCNLTwwBjikdC9NXoC96Y4QEmHRGCpeTxO ZPKigPbcZvzepsj2XnvUHvI8Os0SsZagNB24nkRm1P1HF+h+8d1qfz/oQKG2Xu2D1Tnl zp1GgHuXkLSBX7WLjx69uQG/yvCfvpfrGIV3bXyUw5m+Gl86cGEKnZR2Rk1Y3TBSYAPe X0Bw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: ALKqPwc/NPBTudoB3Mp9FRpFG3/FSPuwjwNMPxPU6Pht/atBbHZa90j6 4+1Jscdf7ei6RWjTDpRhuJv/+JEMkblzDI8y+1EubFj8Bjqs66PELnUg7MLFbAC6th8xCsWQNX8 8206MCtk0RBFgWWujSMKTAP01wV39yyuadxawlNda8Vdz2OjfZsDV9QUiYEpkTZatZA== X-Received: by 2002:a37:b243:: with SMTP id b64-v6mr2735978qkf.21.1527088342015; Wed, 23 May 2018 08:12:22 -0700 (PDT) X-Google-Smtp-Source: ADUXVKImlOspakzDrlpAHlyKSLacyHVRaBuggFBIx+G/bd9tQ8VJ14PWT+qGcud8Fx4YecKI00f0 X-Received: by 2002:a37:b243:: with SMTP id b64-v6mr2735933qkf.21.1527088341384; Wed, 23 May 2018 08:12:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527088341; cv=none; d=google.com; s=arc-20160816; b=MEQSCmLz79AXilh5Ko2EKLGH+uAFg5Ug5PTebDgz7NDyabQuluwnL5Ztp0doIrpjfY L9C5S1rPVf2kikQF5T3aotzP/XWhkE00NnW0ST8TnoaHtvw47m+8GXue/7YxvY907WAN mIuFqey91N3azyyG54Eb6jQA33Ryz2qgbLOU5vat7GYgrfrWVGRXpvMmRxdqaCZPQjez tBMm5AN7IPgu0YFOeRSHszJodJx46Otzr5Vqp4himHu45QexsqlXeSQIpXj5Zi+0q5p3 enPlru1M8rQpkkQtVYkV46GvLxHDV4C6Wt+rvRl1up0ahvY/7nD31Y9bGIoyGNHaoIpR mtyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=EQ0p5zD1wrTQszvVXnBma/30StiYx8/b/52JX4oWfmw=; b=KzQLure3v+xhfSJXMjxF27majU4t09Y4K5vMGLhxViAjXH07AgCjKVuegbikuIKcu8 8bwFtsL49bw+QuPOA/MG1vsmYoPSNTPiWMsTsCz4ubt1B2sPynCG1lYKo6qVxoNKA01Q fDkF5iQ6GW2jYrJ79dC/Qjt9vC2bJuBDDMyuH4wnBrDIrljGlsruNQPrUgvCqN4R0z0K UVW6/TldSp3cBvU7ZpKzzGKg3f4vOmFnhk9EEvHgKHtJqf/jb61iE0LSu+Whg6gV//Yw tJRzUHVs3MAuhF3A9Eop7JgQsPztJGGC0aQrpPjUkWLsZGqf1nMuSWJO5DEuxySGeGii 6Y1A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx3-rdu2.redhat.com. [66.187.233.73]) by mx.google.com with ESMTPS id w2-v6si2630814qtg.187.2018.05.23.08.12.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 May 2018 08:12:21 -0700 (PDT) Received-SPF: pass (google.com: domain of david@redhat.com designates 66.187.233.73 as permitted sender) client-ip=66.187.233.73; Authentication-Results: mx.google.com; spf=pass (google.com: domain of david@redhat.com designates 66.187.233.73 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0F45940BC04A; Wed, 23 May 2018 15:12:21 +0000 (UTC) Received: from t460s.redhat.com (ovpn-116-112.ams2.redhat.com [10.36.116.112]) by smtp.corp.redhat.com (Postfix) with ESMTP id 32C9E10C564A; Wed, 23 May 2018 15:12:19 +0000 (UTC) From: David Hildenbrand To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, David Hildenbrand , Andrew Morton , Vlastimil Babka , Michal Hocko , Dan Williams , Joonsoo Kim , Greg Kroah-Hartman , Pavel Tatashin , Reza Arbab , Thomas Gleixner Subject: [PATCH v1 05/10] mm/memory_hotplug: limit offline_pages() to sizes we can actually handle Date: Wed, 23 May 2018 17:11:46 +0200 Message-Id: <20180523151151.6730-6-david@redhat.com> In-Reply-To: <20180523151151.6730-1-david@redhat.com> References: <20180523151151.6730-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 23 May 2018 15:12:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 23 May 2018 15:12:21 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'david@redhat.com' RCPT:'' 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: X-Virus-Scanned: ClamAV using ClamSMTP We have to take care of MAX_ORDER. Page blocks might contain references to the next page block. So sometimes a page block cannot be offlined independently. E.g. on x86: page block size is 2MB, MAX_ORDER -1 (10) allows 4MB allocations. E.g. a buddy page could either overlap at the beginning or the end of the range to offline. While the end case could be handled easily (shrink the buddy page), overlaps at the beginning are hard to handle (unknown page order). Let document offline_pages() while at it. Cc: Andrew Morton Cc: Vlastimil Babka Cc: Michal Hocko Cc: Dan Williams Cc: Joonsoo Kim Cc: Greg Kroah-Hartman Cc: Pavel Tatashin Cc: Reza Arbab Cc: Thomas Gleixner Signed-off-by: David Hildenbrand --- include/linux/memory_hotplug.h | 6 ++++++ mm/memory_hotplug.c | 22 ++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index e0e49b5b1ee1..d71829d54360 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -294,6 +294,12 @@ static inline void pgdat_resize_init(struct pglist_data *pgdat) {} #endif /* !(CONFIG_MEMORY_HOTPLUG || CONFIG_DEFERRED_STRUCT_PAGE_INIT) */ #ifdef CONFIG_MEMORY_HOTREMOVE +/* + * Isolation and offlining code cannot deal with pages (e.g. buddy) + * overlapping with the range to be offlined yet. + */ +#define offline_nr_pages max((unsigned long)pageblock_nr_pages, \ + (unsigned long)MAX_ORDER_NR_PAGES) extern bool is_mem_section_removable(unsigned long pfn, unsigned long nr_pages); extern void try_offline_node(int nid); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 7f7bd2acb55b..c971295a1100 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1599,10 +1599,9 @@ static int __ref __offline_pages(unsigned long start_pfn, struct zone *zone; struct memory_notify arg; - /* at least, alignment against pageblock is necessary */ - if (!IS_ALIGNED(start_pfn, pageblock_nr_pages)) + if (!IS_ALIGNED(start_pfn, offline_nr_pages)) return -EINVAL; - if (!IS_ALIGNED(end_pfn, pageblock_nr_pages)) + if (!IS_ALIGNED(end_pfn, offline_nr_pages)) return -EINVAL; /* This makes hotplug much easier...and readable. we assume this for now. .*/ @@ -1700,7 +1699,22 @@ static int __ref __offline_pages(unsigned long start_pfn, return ret; } -/* Must be protected by mem_hotplug_begin() or a device_lock */ +/** + * offline_pages - offline pages in a given range (that are currently online) + * @start_pfn: start pfn of the memory range + * @nr_pages: the number of pages + * + * This function tries to offline the given pages. The alignment/size that + * can be used is given by offline_nr_pages. + * + * Returns 0 if sucessful, -EBUSY if the pages cannot be offlined and + * -EINVAL if start_pfn/nr_pages is not properly aligned or not in a zone. + * -EINTR is returned if interrupted by a signal. + * + * Bad things will happen if pages in the range are already offline. + * + * Must be protected by mem_hotplug_begin() or a device_lock + */ int offline_pages(unsigned long start_pfn, unsigned long nr_pages) { return __offline_pages(start_pfn, start_pfn + nr_pages);