From patchwork Mon Mar 16 10:21:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 11440075 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 7F1A86CA for ; Mon, 16 Mar 2020 10:22:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4AE6F2071C for ; Mon, 16 Mar 2020 10:22:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HmdM1Cp4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4AE6F2071C 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 6D1356B0005; Mon, 16 Mar 2020 06:22:06 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6A8276B0007; Mon, 16 Mar 2020 06:22:06 -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 5BE7E6B0008; Mon, 16 Mar 2020 06:22:06 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0156.hostedemail.com [216.40.44.156]) by kanga.kvack.org (Postfix) with ESMTP id 3F4796B0005 for ; Mon, 16 Mar 2020 06:22:06 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 0A6F3824556B for ; Mon, 16 Mar 2020 10:22:06 +0000 (UTC) X-FDA: 76600835052.14.brain16_124b527689529 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:23,LUA_SUMMARY:none X-HE-Tag: brain16_124b527689529 X-Filterd-Recvd-Size: 3893 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Mon, 16 Mar 2020 10:22:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584354125; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc; bh=9AuoExRKnoesKH6vkEtuwhs5DyeCR7/IOYAGKhOXPhw=; b=HmdM1Cp4tS5mspeeCuq/8KkARwMkPO52Iis/+x+gMtemKW+ssePsFfw72vonpqtcJ7X/nh 3klfv9uqN3V8xGk2dvX6S8o2mrApdzJx4EbVS4pvqqkr6MxktnsUyFh7pwiMTfRw3K1SjI OwUmIbL3gGG9KRTut5645fBfOuPwyLg= 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-72-TXJpbww_P46sqjAT3PWRHw-1; Mon, 16 Mar 2020 06:21:59 -0400 X-MC-Unique: TXJpbww_P46sqjAT3PWRHw-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 152C2DBAB; Mon, 16 Mar 2020 10:21:58 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-129.pek2.redhat.com [10.72.12.129]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4AFCD93536; Mon, 16 Mar 2020 10:21:52 +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, willy@infradead.org, richard.weiyang@gmail.com, vbabka@suse.cz, bhe@redhat.com Subject: [PATCH v4 1/2] mm/sparse.c: Use kvmalloc/kvfree to alloc/free memmap for the classic sparse Date: Mon, 16 Mar 2020 18:21:49 +0800 Message-Id: <20200316102150.16487-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 Reviewed-by: David Hildenbrand Acked-by: Michal Hocko Reviewed-by: Pankaj Gupta Reviewed-by: Matthew Wilcox (Oracle) --- v3->v4: Split the old v3 into two patches, to carve out the using 'nid' as preferred node to allocate memmap into a separate patch. This is suggested by Michal, and the carving out is put in patch 2. v2->v3: Remove __GFP_NOWARN and use array_size when calling kvmalloc_node() per Matthew's comments. http://lkml.kernel.org/r/20200312141749.GL27711@MiWiFi-R3L-srv mm/sparse.c | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/mm/sparse.c b/mm/sparse.c index e747a238a860..d01d09cc7d99 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) From patchwork Mon Mar 16 10:21: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: 11440077 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 7751B6CA for ; Mon, 16 Mar 2020 10:22:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 43B4D2071C for ; Mon, 16 Mar 2020 10:22:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RDuLU9Cs" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 43B4D2071C 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 4ADFA6B0007; Mon, 16 Mar 2020 06:22:07 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 486326B0008; Mon, 16 Mar 2020 06:22:07 -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 328236B000A; Mon, 16 Mar 2020 06:22:07 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0227.hostedemail.com [216.40.44.227]) by kanga.kvack.org (Postfix) with ESMTP id 1B6336B0007 for ; Mon, 16 Mar 2020 06:22:07 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id EC64352C1 for ; Mon, 16 Mar 2020 10:22:06 +0000 (UTC) X-FDA: 76600835052.17.truck00_126e3087d0a12 X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,bhe@redhat.com,,RULES_HIT:30054,0,RBL:207.211.31.120:@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:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: truck00_126e3087d0a12 X-Filterd-Recvd-Size: 3276 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by imf47.hostedemail.com (Postfix) with ESMTP for ; Mon, 16 Mar 2020 10:22:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584354126; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=Vv1cQFCqZ1YUMKAqTsznQf04tGJGAJ2S0nm59ugBb9M=; b=RDuLU9CsZLay8jtw/Np1tXxnT8qO3VLDX+3NNlsxkI9SMVxOXUVyhRkcuJVRBD8pXJWTnb diXYO0sv7oGNZL5LIpc3mRB8vUtOqUiXI8LJeiY0xaPL/yH2xEeTzCnCzdPR2TIa8EYUHg SP2H6KCNlOsE/rBUDjJNqaIeHWAyevc= 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-455-JE4Ec69iOQOXSHxLJsY6Rw-1; Mon, 16 Mar 2020 06:22:03 -0400 X-MC-Unique: JE4Ec69iOQOXSHxLJsY6Rw-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 ACBCBDBCB; Mon, 16 Mar 2020 10:22:01 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-129.pek2.redhat.com [10.72.12.129]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F9BF1BC6D; Mon, 16 Mar 2020 10:21:58 +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, willy@infradead.org, richard.weiyang@gmail.com, vbabka@suse.cz, bhe@redhat.com Subject: [PATCH v4 2/2] mm/sparse.c: allocate memmap preferring the given node Date: Mon, 16 Mar 2020 18:21:50 +0800 Message-Id: <20200316102150.16487-2-bhe@redhat.com> In-Reply-To: <20200316102150.16487-1-bhe@redhat.com> References: <20200316102150.16487-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: When allocating memmap for hot added memory with the classic sparse, the specified 'nid' is ignored in populate_section_memmap(). While in allocating memmap for the classic sparse during boot, the node given by 'nid' is preferred. And VMEMMAP prefers the node of 'nid' in both boot stage and memory hot adding. So seems no reason to not respect the node of 'nid' for the classic sparse when hot adding memory. Use kvmalloc_node instead to use the passed in 'nid'. Signed-off-by: Baoquan He Acked-by: Michal Hocko --- mm/sparse.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/sparse.c b/mm/sparse.c index d01d09cc7d99..513d765e8c72 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -719,8 +719,8 @@ 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) { - return kvmalloc(array_size(sizeof(struct page), - PAGES_PER_SECTION), GFP_KERNEL); + return kvmalloc_node(array_size(sizeof(struct page), + PAGES_PER_SECTION), GFP_KERNEL, nid); } static void depopulate_section_memmap(unsigned long pfn, unsigned long nr_pages,