From patchwork Tue Dec 11 14:27:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Hocko X-Patchwork-Id: 10723897 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ED3F291E for ; Tue, 11 Dec 2018 14:27:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DDB2C28587 for ; Tue, 11 Dec 2018 14:27:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CED942883D; Tue, 11 Dec 2018 14:27:59 +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 5C1AE28587 for ; Tue, 11 Dec 2018 14:27:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E2BC88E0091; Tue, 11 Dec 2018 09:27:53 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DD9FD8E004D; Tue, 11 Dec 2018 09:27:53 -0500 (EST) 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 CA4B08E0091; Tue, 11 Dec 2018 09:27:53 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by kanga.kvack.org (Postfix) with ESMTP id 6D63D8E004D for ; Tue, 11 Dec 2018 09:27:53 -0500 (EST) Received: by mail-ed1-f71.google.com with SMTP id y35so7044193edb.5 for ; Tue, 11 Dec 2018 06:27:53 -0800 (PST) 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:mime-version :content-transfer-encoding; bh=Q8sh+9FkpWv6DFNlPPgKqUlqTEtJzBvplK2abR1KP7U=; b=muDJiy2BE4yKmBNnC9tqO9CohJgC2EriEqCeJYgKuK71HUu9kv2LaNAjePf8H7hA8L xczgqkcxy47MzdVnjuT98fCdr64dHil2wh5zbyhM5yL+1t2kpIsz9MScqQpO9uvDVyeW TgOLbL0W0LN5JQ2N7x8sceCSUPKVG/N2meEUHR6QnqrkgFUabePfpLXbjXhgjpDW0omM ObuDQBVLNj9sZ0FNM1B93lqTUq/hLZb8gasF14HccgK33z5CBBFgBCBw0Zhl59Pr7Hh1 HwgraJ4yagMNpTf7wVQ3ZB4JAOZt53DoPqxlnllo4BUJJf2SkAQhso+rUrx+mKujRc4Z 6A8Q== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of mstsxfx@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=mstsxfx@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Gm-Message-State: AA+aEWZR3XHwU8gzXwvj0RuXEuS+ui+wCRTqjzKnpGp51yx9JRWRmE4N UAMEnLr4GvyVpwqAdB2hTWlaavD+d7eDqst4YIRyeGxpT9Coozvy8+OGj+q9XJOhkal9yzcrUWd y3hT1iowdtvogOAT7P2BhrEKawbhul4L3X8zmQ2qgzvj8sc6nd6StZwJmu6tHjRpUKxLxyiViCY 7Bof1lYDXXV+W1QebolF+zvtuhfzlSAnULoIuMdwHR/RshGPcWVxbEqKCF0QJSWKJ0XqCgm1WLM +DA42p6IQlrkT06IQWb3XXCkaklr/ls0PxLkW6QkrvzfI63uh/PHHMuB1g01hZvaUuDmtwh5rBP Mp6gbWi1wfsjVAavSNC8h+W57BXdnJRJaXVkuRFaaa7eQNGWX4FUqI6/E9zhZ7rAy4ZoVhTW2Q= = X-Received: by 2002:a50:9226:: with SMTP id i35mr15710252eda.8.1544538472927; Tue, 11 Dec 2018 06:27:52 -0800 (PST) X-Received: by 2002:a50:9226:: with SMTP id i35mr15710206eda.8.1544538472001; Tue, 11 Dec 2018 06:27:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544538471; cv=none; d=google.com; s=arc-20160816; b=Cc4WP/RKq8Di6LhDIieNZz/5F3AhbyPQGKGSpUi9fJBV9OPCVoeAttk4r6CUcstIji x1REztgcpstXs/g51sVz+YEGq+Onc/TLokdfM1IjZ4R0FCqchmAtMkOB8sWfbUenBVSk ww4LSu877K+poVIo3w3jmQZyIyfXwfBk/gf+p/P/JRJ5QYoRKmHNb/0Fz+lObTrjhX4W D3ynzl3i3/3guujaFb64+tdLIzHMTrtVqNbiqt4ODREGe6MwVCHmqYA6vF0F0bJ+Ctgo Xm0np01oGhjPDG7vHsgRuk46fV2lTuPSANx00mxCNPN7apmhH45d/BvPEjCy7pdwNKaD f7fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=Q8sh+9FkpWv6DFNlPPgKqUlqTEtJzBvplK2abR1KP7U=; b=DUcHKHtqg2FaoHdl8t8uitcQP316/kjq9fICv9eTIzcoq1rPe+gw2yTW48WI+xlwxJ 6KVFDf4WlhmcVqZoz4WI5t08eUNtSMgr0pCpwuY7E3GNgyvWHWD2xHYkKGSQPFXp4OYN SuTdzBZ+LmUJfBmQSmAk313nKOEJampyPeyIuKuZNovwbbNyCHVFovOWpJu/Kv8pWKlN Ikd5/KgQF7EWlqSb057v8kxI5JvaSH26sjCHZ8pOGncjB1hciGMp8qNMtpfq7WbRXrui 3cQE2Ahi/rP7Vo7mHkrD/Xpr/1K3UUFL/DOwYKZLfkaD51nxn+07xkuxrzOlsKBhkvqL m42w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of mstsxfx@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=mstsxfx@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id p7-v6sor4051488ejb.30.2018.12.11.06.27.51 for (Google Transport Security); Tue, 11 Dec 2018 06:27:51 -0800 (PST) Received-SPF: pass (google.com: domain of mstsxfx@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; spf=pass (google.com: domain of mstsxfx@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=mstsxfx@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Google-Smtp-Source: AFSGD/Xb/9v/+9EOR4DQqoxgTxgYu4+WFUeAMf/WERoa5tPJYu2EQVJWRavObQF6AqoNGie3Iwhl5g== X-Received: by 2002:a17:906:590a:: with SMTP id h10-v6mr13068100ejq.102.1544538471623; Tue, 11 Dec 2018 06:27:51 -0800 (PST) Received: from tiehlicka.suse.cz (prg-ext-pat.suse.com. [213.151.95.130]) by smtp.gmail.com with ESMTPSA id g31sm4073975eda.96.2018.12.11.06.27.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Dec 2018 06:27:51 -0800 (PST) From: Michal Hocko To: Andrew Morton Cc: , LKML , Michal Hocko , David Hildenbrand , Oscar Salvador Subject: [PATCH 2/3] mm, memory_hotplug: deobfuscate migration part of offlining Date: Tue, 11 Dec 2018 15:27:40 +0100 Message-Id: <20181211142741.2607-3-mhocko@kernel.org> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181211142741.2607-1-mhocko@kernel.org> References: <20181211142741.2607-1-mhocko@kernel.org> MIME-Version: 1.0 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 From: Michal Hocko Memory migration might fail during offlining and we keep retrying in that case. This is currently obfuscate by goto retry loop. The code is hard to follow and as a result it is even suboptimal becase each retry round scans the full range from start_pfn even though we have successfully scanned/migrated [start_pfn, pfn] range already. This is all only because check_pages_isolated failure has to rescan the full range again. De-obfuscate the migration retry loop by promoting it to a real for loop. In fact remove the goto altogether by making it a proper double loop (yeah, gotos are nasty in this specific case). In the end we will get a slightly more optimal code which is better readable. Reviewed-by: David Hildenbrand Reviewed-by: Oscar Salvador Signed-off-by: Michal Hocko --- mm/memory_hotplug.c | 58 ++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 6263c8cd4491..c6c42a7425e5 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1591,38 +1591,38 @@ static int __ref __offline_pages(unsigned long start_pfn, goto failed_removal_isolated; } - pfn = start_pfn; -repeat: - /* start memory hot removal */ - ret = -EINTR; - if (signal_pending(current)) { - reason = "signal backoff"; - goto failed_removal_isolated; - } + do { + for (pfn = start_pfn; pfn;) { + if (signal_pending(current)) { + ret = -EINTR; + reason = "signal backoff"; + goto failed_removal_isolated; + } - cond_resched(); - lru_add_drain_all(); - drain_all_pages(zone); + cond_resched(); + lru_add_drain_all(); + drain_all_pages(zone); - pfn = scan_movable_pages(start_pfn, end_pfn); - if (pfn) { /* We have movable pages */ - ret = do_migrate_range(pfn, end_pfn); - goto repeat; - } + pfn = scan_movable_pages(pfn, end_pfn); + if (pfn) { + /* TODO fatal migration failures should bail out */ + do_migrate_range(pfn, end_pfn); + } + } + + /* + * dissolve free hugepages in the memory block before doing offlining + * actually in order to make hugetlbfs's object counting consistent. + */ + ret = dissolve_free_huge_pages(start_pfn, end_pfn); + if (ret) { + reason = "failure to dissolve huge pages"; + goto failed_removal_isolated; + } + /* check again */ + offlined_pages = check_pages_isolated(start_pfn, end_pfn); + } while (offlined_pages < 0); - /* - * dissolve free hugepages in the memory block before doing offlining - * actually in order to make hugetlbfs's object counting consistent. - */ - ret = dissolve_free_huge_pages(start_pfn, end_pfn); - if (ret) { - reason = "failure to dissolve huge pages"; - goto failed_removal_isolated; - } - /* check again */ - offlined_pages = check_pages_isolated(start_pfn, end_pfn); - if (offlined_pages < 0) - goto repeat; pr_info("Offlined Pages %ld\n", offlined_pages); /* Ok, all of our target is isolated. We cannot do rollback at this point. */