From patchwork Mon Mar 16 12:54:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 11440339 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 D5B7B139A for ; Mon, 16 Mar 2020 12:55:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 976CA20658 for ; Mon, 16 Mar 2020 12:55:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="aTIpRPPA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 976CA20658 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 CED686B0003; Mon, 16 Mar 2020 08:55:03 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C9DED6B0005; Mon, 16 Mar 2020 08:55:03 -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 BB2966B0007; Mon, 16 Mar 2020 08:55:03 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0007.hostedemail.com [216.40.44.7]) by kanga.kvack.org (Postfix) with ESMTP id A5E426B0003 for ; Mon, 16 Mar 2020 08:55:03 -0400 (EDT) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id EC60A125C for ; Mon, 16 Mar 2020 12:55:02 +0000 (UTC) X-FDA: 76601220444.30.blood36_2c0c9a7c0e860 X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,bhe@redhat.com,,RULES_HIT:30054:30070,0,RBL:207.211.31.81:@redhat.com:.lbl8.mailshell.net-66.10.201.10 62.18.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: blood36_2c0c9a7c0e860 X-Filterd-Recvd-Size: 3930 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by imf36.hostedemail.com (Postfix) with ESMTP for ; Mon, 16 Mar 2020 12:55:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584363302; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=P4Qyb2MdN0LHuNYPnyEAGuni/fmEz9gabyL6ZPulh44=; b=aTIpRPPAVAgsG2vCtoJMeo9QH9xVvyWYGvv5BAOFtJkZN5ZPGYUghmOMUgONYCc4xgxgCI ousyGuLx+TCWUocaABxz7t7FW4ExtmG8Q7zPngUOWatI9KrPCoIAU0h5FzkgK6/JBlkN4B 0rM89P73HzYnDcEJaHVLwGaBfhieLKI= 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-243-38hwzJ6MMqqjkEIByTaYYQ-1; Mon, 16 Mar 2020 08:54:58 -0400 X-MC-Unique: 38hwzJ6MMqqjkEIByTaYYQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E9953DB70; Mon, 16 Mar 2020 12:54:56 +0000 (UTC) Received: from localhost (ovpn-12-129.pek2.redhat.com [10.72.12.129]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C98EC19C4F; Mon, 16 Mar 2020 12:54:53 +0000 (UTC) Date: Mon, 16 Mar 2020 20:54:50 +0800 From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, mhocko@suse.com, akpm@linux-foundation.org, david@redhat.com, willy@infradead.org, richard.weiyang@gmail.com, vbabka@suse.cz Subject: [PATCH v5 1/2] mm/sparse.c: Use kvmalloc/kvfree to alloc/free memmap for the classic sparse Message-ID: <20200316125450.GG3486@MiWiFi-R3L-srv> References: <20200316102150.16487-1-bhe@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200316102150.16487-1-bhe@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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 Reviewed-by: David Hildenbrand Acked-by: Michal Hocko Reviewed-by: Pankaj Gupta Reviewed-by: Matthew Wilcox (Oracle) Reviewed-by: Wei Yang --- mm/sparse.c | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/mm/sparse.c b/mm/sparse.c index e747a238a860..3fa407d7f70a 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -719,35 +719,14 @@ static int fill_subsection_map(unsigned long pfn, unsigned long nr_pages) 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(array_size(sizeof(struct page), + PAGES_PER_SECTION), GFP_KERNEL); } 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)