Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp471593img; Wed, 20 Mar 2019 04:41:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqyl20Ug9zLVrl9cnwVJkax7fc7U+y6SOnk2p43Tf1a/LlH/FbIYPBWTeDOOEq/IQSmFS1Al X-Received: by 2002:a62:1b84:: with SMTP id b126mr7086320pfb.225.1553082073738; Wed, 20 Mar 2019 04:41:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553082073; cv=none; d=google.com; s=arc-20160816; b=pjVZG7n4l6IEoWZz9M+NY1ICthaGVzO301CZWjqO7h3pUuMbfv8YqY4pvhboEmM8vY W2vGKBnDLbSz1/zbeeyzYRJo3NilHHG3ZEuX7bRvn80X3S6P7ty71ivU65WFDB4MRNOY wdunNTuS8TWjAFwZSkUOmK9zALBPQ5oRCrvocAf1yrvc7PR/oYLYADze/2AoHsbbGbYk RpuAU8yGOae+mXYXD1rv+C2vbmqoN23Kyrr1awvXNnE1fbwAVd+DIpvCJvji/WkAHpFi 546X5cg1HZJJJW+36nYtZ4VquW5m6+a3lFWj/im1oNgS4+TyHw6NbjKgcV2eR90vfcFm 9kjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:subject:cc:to:from:date; bh=pYSjs7e2eySqyy+daAVFrdFDJUBtLJ61uA7Bj+SinYU=; b=v9+rPauR7QkmL+tJWmJDay1+ZPrDBIT5G7Gb4lzg759Y2l9clsPLUUjPQ59gAffwpZ eO9o2BvmkCIaXDMabpt5m1aomNJHF1bhnyLhg7Z6giemf59a6vy1hJeKo2Gpv8f15zHt sFBtifJhncuvP285KGjrq04kwtS43/nDjTI/fMIa7MJaw3dQ7k2G9opvxZa9Hf1WwwJk sZfe3uwLdC2Lso4X3vYUIEdOIcktQCpT4G2rDHS2VxqJOFYXIM8bKPEbaQuwqTwrfLkE 1+bsW6P/a/OYq7ckH4NDABNE0A5dNiBxLMXr4cNd4CVDtmJj/uYP2o2ZBkSS5X5NwT6P RgEQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y24si1736259plp.98.2019.03.20.04.40.57; Wed, 20 Mar 2019 04:41:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727805AbfCTL1k (ORCPT + 99 others); Wed, 20 Mar 2019 07:27:40 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:43072 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727154AbfCTL1k (ORCPT ); Wed, 20 Mar 2019 07:27:40 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x2KBJW3A136000 for ; Wed, 20 Mar 2019 07:27:39 -0400 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0a-001b2d01.pphosted.com with ESMTP id 2rbkbemtar-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 20 Mar 2019 07:27:38 -0400 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 20 Mar 2019 11:27:30 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp04.uk.ibm.com (192.168.101.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 20 Mar 2019 11:27:28 -0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x2KBRXLT42729566 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Mar 2019 11:27:33 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 40EB84C05A; Wed, 20 Mar 2019 11:27:33 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8F7704C062; Wed, 20 Mar 2019 11:27:32 +0000 (GMT) Received: from rapoport-lnx (unknown [9.148.8.84]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Wed, 20 Mar 2019 11:27:32 +0000 (GMT) Date: Wed, 20 Mar 2019 13:27:30 +0200 From: Mike Rapoport To: Baoquan He Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org, pasha.tatashin@oracle.com, mhocko@suse.com, rppt@linux.vnet.ibm.com, richard.weiyang@gmail.com, linux-mm@kvack.org Subject: Re: [PATCH 2/3] mm/sparse: Optimize sparse_add_one_section() References: <20190320073540.12866-1-bhe@redhat.com> <20190320073540.12866-2-bhe@redhat.com> <20190320075649.GC13626@rapoport-lnx> <20190320101318.GP18740@MiWiFi-R3L-srv> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190320101318.GP18740@MiWiFi-R3L-srv> User-Agent: Mutt/1.5.24 (2015-08-30) X-TM-AS-GCONF: 00 x-cbid: 19032011-0016-0000-0000-000002651946 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19032011-0017-0000-0000-000032C0329E Message-Id: <20190320112730.GE13626@rapoport-lnx> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-03-20_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903200090 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 20, 2019 at 06:13:18PM +0800, Baoquan He wrote: > Hi Mike, > > On 03/20/19 at 09:56am, Mike Rapoport wrote: > > @@ -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); > > > > If you are anyway changing this why not to switch to goto's for error > > handling? > > I update code change as below, could you check if it's OK to you? > > Thanks > Baoquan > > From 39b679b6f34f6acbc05351be8569d23bae3c0458 Mon Sep 17 00:00:00 2001 > From: Baoquan He > Date: Fri, 15 Mar 2019 16:03:52 +0800 > Subject: [PATCH] mm/sparse: Optimize sparse_add_one_section() > > 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. > > Meanwhile update the error handler to cover usemap allocation failure > too. > > Signed-off-by: Baoquan He > --- > mm/sparse.c | 23 ++++++++++++----------- > 1 file changed, 12 insertions(+), 11 deletions(-) > > diff --git a/mm/sparse.c b/mm/sparse.c > index a99e0b253927..0e842b924be6 100644 > --- a/mm/sparse.c > +++ b/mm/sparse.c > @@ -699,20 +699,21 @@ 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) { > + ret = -ENOMEM; > + goto out2; I'd name the label out_free_usemap. > } > > + ret = 0; > ms = __pfn_to_section(start_pfn); > if (ms->section_mem_map & SECTION_MARKED_PRESENT) { > ret = -EEXIST; > - goto out; > + goto out2; > } I've missed this previously, but it seems that this check can be moved before the allocations, which simplifies the code a bit more. > > /* > @@ -724,11 +725,11 @@ int __meminit sparse_add_one_section(int nid, unsigned long start_pfn, > section_mark_present(ms); > sparse_init_one_section(ms, section_nr, memmap, usemap); > > + return ret; > out: > - if (ret < 0) { > - kfree(usemap); > - __kfree_section_memmap(memmap, altmap); > - } > + __kfree_section_memmap(memmap, altmap); > +out2: > + kfree(usemap); > return ret; > } > > -- > 2.17.2 > -- Sincerely yours, Mike.