From patchwork Wed Mar 20 07:35:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 10860953 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 B39BC1390 for ; Wed, 20 Mar 2019 07:36:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9863029A38 for ; Wed, 20 Mar 2019 07:36:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C14429A43; Wed, 20 Mar 2019 07:36:01 +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 2D25529A38 for ; Wed, 20 Mar 2019 07:36:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DD7336B0006; Wed, 20 Mar 2019 03:35:59 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D93E76B0007; Wed, 20 Mar 2019 03:35:59 -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 C76276B0008; Wed, 20 Mar 2019 03:35:59 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by kanga.kvack.org (Postfix) with ESMTP id 9DCB66B0006 for ; Wed, 20 Mar 2019 03:35:59 -0400 (EDT) Received: by mail-qt1-f200.google.com with SMTP id e1so1480938qth.23 for ; Wed, 20 Mar 2019 00:35:59 -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=w9cFJm+HEeCHcX9JqiAPkwlfm2xd5GqjMiIlH+9+Qg0=; b=o+pp9NGNKeQgICH5SZFTgptCUA2AacjhdtLYrA67CjmT7V4vrUNoRSjlne5/zD4Mn0 mZEUoioJc3Exrca5foS3DgY+UlQloab/Hvn7zSTY4PW+oakv7nVtzQIJIpY8gbcqkOwO jHM4WK3LDDE+VpfHDsOaWAX0FW/04octvmjf9ZqgNd0Ib63Kj8eMwZV7NCenEuTrIoV3 rWXtV3bB9exijQfrLywbLP1O4bKkwLkr0+itEyhYeXzIXiMITzWupclm7VckpHYnugcF ITx625gYBOjPsA8CMsCE9bNc/30TIMIO2HCuwfnj4wsx+ok44dycCMFrpp8bSzGM214T xJag== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of bhe@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APjAAAWBxeloQbNd6fdEgRE0ZrtEAzpU/AdbeD4LUNf7v4XJCZSgGTy5 fFnZVgR7dn2LU2xG7PsEUMysRvUr4WGpYse0ENlTHqNPG8fiECLgvrQRTysiW3Id5AMMK+KDOf5 QBWZ4YdAA76Gl+yAYn+oEBUmoUKNpzzTZ0JAvmZuh2rlMnehoNKVIE2dt1K+2dch/Hw== X-Received: by 2002:a0c:b756:: with SMTP id q22mr5323707qve.29.1553067359454; Wed, 20 Mar 2019 00:35:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqx1y47ZmSYVi1vB1k/kERkKHwoDTlClk0FG8sM1b8KI91zqyFzmT2YnZwWjBJQ2+aZGX+AD X-Received: by 2002:a0c:b756:: with SMTP id q22mr5323666qve.29.1553067358418; Wed, 20 Mar 2019 00:35:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553067358; cv=none; d=google.com; s=arc-20160816; b=ucmJox63D5fruFocblvCiLebkKMmVB+o8PmgKN+gB3GI0rFY9cQhV6fJTpBzK24/Xs zMjlQcJo5AYo91EE/fMeu3Gq1mJWM1OC9/kz2hnArEYFW0+8XSZde+I8zV+tQ6GIJzJp O5mh4b3956QvkPCv6Xyjy3ShlMxRuR31cqOgeweMSo3p8duSFlrDBqH2jGqHxXWxYZYi Fk3u3Wv9Fwqz3VwSXevoT+0gdqMiCiBPq+XWuL2xHAWNuHuMKcLEzNU3IGfBuBrNcUZQ WKqOy5J4pneokKjDrUIAxR151ABGza2p0jPVU7vEKJyQuOJab1w40Q9mPgckls8MuRbp 4LWA== 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; bh=w9cFJm+HEeCHcX9JqiAPkwlfm2xd5GqjMiIlH+9+Qg0=; b=LRUi5K+wUvxzJNQsBnEGHvTEVsI+4484XachMlRJklGNrrvb0Ni27tfvW0IIJY4b4a UHub1RUzOscraQrCydJx9Y3L6gEcorUEGwzwzmNo8ano7wU6x+Wf7ZSz1qwJWmWfMsW4 81QTU1YpPt8QKvIcCd19OGRGU2uX0TvsLZVd1m5xX4q5ZLBYp+k5nym9QGERmcA77gMr Aua6SHSv4PBkQxlh+FdyyQQWYlqvF0nap+sgKARTmCOpWGb04f5Cd1NiBiLc+lhOmuML EyrlvfQO+fdjYhUQ/0murD95h8QDmzb3Vm1B7zxhMmY205DzFdRWbWpWu/6Fnv0Rzs8z fF2w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of bhe@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id l37si733250qte.317.2019.03.20.00.35.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Mar 2019 00:35:58 -0700 (PDT) Received-SPF: pass (google.com: domain of bhe@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of bhe@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9578D31688EB; Wed, 20 Mar 2019 07:35:57 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-38.pek2.redhat.com [10.72.12.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id C8C4F60CD3; Wed, 20 Mar 2019 07:35:54 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: akpm@linux-foundation.org, pasha.tatashin@oracle.com, mhocko@suse.com, rppt@linux.vnet.ibm.com, richard.weiyang@gmail.com, linux-mm@kvack.org, Baoquan He Subject: [PATCH 2/3] mm/sparse: Optimize sparse_add_one_section() Date: Wed, 20 Mar 2019 15:35:39 +0800 Message-Id: <20190320073540.12866-2-bhe@redhat.com> In-Reply-To: <20190320073540.12866-1-bhe@redhat.com> References: <20190320073540.12866-1-bhe@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 20 Mar 2019 07:35:57 +0000 (UTC) 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 Reorder the allocation of usemap and memmap since usemap allocation is much smaller and simpler. Otherwise hard work is done to make memmap ready, then have to rollback just because of usemap allocation failure. Signed-off-by: Baoquan He Signed-off-by: Baoquan He --- mm/sparse.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mm/sparse.c b/mm/sparse.c index 0a0f82c5d969..054b99f74181 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -697,16 +697,17 @@ int __meminit sparse_add_one_section(int nid, unsigned long start_pfn, ret = sparse_index_init(section_nr, nid); if (ret < 0 && ret != -EEXIST) return ret; - ret = 0; - memmap = kmalloc_section_memmap(section_nr, nid, altmap); - if (!memmap) - return -ENOMEM; + usemap = __kmalloc_section_usemap(); - if (!usemap) { - __kfree_section_memmap(memmap, altmap); + if (!usemap) + return -ENOMEM; + memmap = kmalloc_section_memmap(section_nr, nid, altmap); + if (!memmap) { + kfree(usemap); return -ENOMEM; } + ret = 0; ms = __pfn_to_section(start_pfn); if (ms->section_mem_map & SECTION_MARKED_PRESENT) { ret = -EEXIST;