From patchwork Thu Mar 12 13:08:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 11434157 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5FA5513B1 for ; Thu, 12 Mar 2020 13:08:38 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2CDD320663 for ; Thu, 12 Mar 2020 13:08:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="cUNxxVa6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2CDD320663 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 495C16B0003; Thu, 12 Mar 2020 09:08:37 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4464C6B0006; Thu, 12 Mar 2020 09:08:37 -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 382C66B0007; Thu, 12 Mar 2020 09:08:37 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0204.hostedemail.com [216.40.44.204]) by kanga.kvack.org (Postfix) with ESMTP id 1EC856B0003 for ; Thu, 12 Mar 2020 09:08:37 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 021B7814D for ; Thu, 12 Mar 2020 13:08:37 +0000 (UTC) X-FDA: 76586739474.26.food04_4b30b65865560 X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,bhe@redhat.com,,RULES_HIT:30054:30070,0,RBL:205.139.110.120:@redhat.com:.lbl8.mailshell.net-62.18.0.100 66.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: food04_4b30b65865560 X-Filterd-Recvd-Size: 3552 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Thu, 12 Mar 2020 13:08:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584018515; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc; bh=S6bzV9J0z/IVD/ibu5hpuBEpz5XNYpk50t3w61vNfkc=; b=cUNxxVa6J/npQT8Lbrm6NDqfOvvHb6etykjtpnpm/HhFCQcchZzugMnpwXQ/++71/G4skr cQYbeIsyhB8cczKBC7V5V79sYTcwX7l5G7qooA4I3Lf42sEXXQA59bmAneZ3O1f3dW9NFh wGfqRVMPDviyMcWWOthIT3pmh6zafYI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-178-nM0-vi0hOVqePh4H10z_BQ-1; Thu, 12 Mar 2020 09:08:30 -0400 X-MC-Unique: nM0-vi0hOVqePh4H10z_BQ-1 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 10F35107ACCA; Thu, 12 Mar 2020 13:08:29 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-43.pek2.redhat.com [10.72.12.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id A678093501; Thu, 12 Mar 2020 13:08:23 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, mhocko@suse.com, akpm@linux-foundation.org, david@redhat.com, richard.weiyang@gmail.com, bhe@redhat.com Subject: [PATCH v2] mm/sparse.c: Use kvmalloc_node/kvfree to alloc/free memmap for the classic sparse Date: Thu, 12 Mar 2020 21:08:22 +0800 Message-Id: <20200312130822.6589-1-bhe@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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: This change makes populate_section_memmap()/depopulate_section_memmap much simpler. Suggested-by: Michal Hocko Signed-off-by: Baoquan He --- v1->v2: The old version only used __get_free_pages() to replace alloc_pages() in populate_section_memmap(). http://lkml.kernel.org/r/20200307084229.28251-8-bhe@redhat.com mm/sparse.c | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/mm/sparse.c b/mm/sparse.c index bf6c00a28045..362018e82e22 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -734,35 +734,14 @@ static void free_map_bootmem(struct page *memmap) struct page * __meminit populate_section_memmap(unsigned long pfn, unsigned long nr_pages, int nid, struct vmem_altmap *altmap) { - struct page *page, *ret; - unsigned long memmap_size = sizeof(struct page) * PAGES_PER_SECTION; - - page = alloc_pages(GFP_KERNEL|__GFP_NOWARN, get_order(memmap_size)); - if (page) - goto got_map_page; - - ret = vmalloc(memmap_size); - if (ret) - goto got_map_ptr; - - return NULL; -got_map_page: - ret = (struct page *)pfn_to_kaddr(page_to_pfn(page)); -got_map_ptr: - - return ret; + return kvmalloc_node(sizeof(struct page) * PAGES_PER_SECTION, + GFP_KERNEL|__GFP_NOWARN, nid); } static void depopulate_section_memmap(unsigned long pfn, unsigned long nr_pages, struct vmem_altmap *altmap) { - struct page *memmap = pfn_to_page(pfn); - - if (is_vmalloc_addr(memmap)) - vfree(memmap); - else - free_pages((unsigned long)memmap, - get_order(sizeof(struct page) * PAGES_PER_SECTION)); + kvfree(pfn_to_page(pfn)); } static void free_map_bootmem(struct page *memmap)