From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDAD0C47256 for ; Fri, 1 May 2020 21:46:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8943E2166E for ; Fri, 1 May 2020 21:46:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8943E2166E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 265A88E0005; Fri, 1 May 2020 17:46:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 214BF8E0001; Fri, 1 May 2020 17:46:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1520E8E0005; Fri, 1 May 2020 17:46:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0089.hostedemail.com [216.40.44.89]) by kanga.kvack.org (Postfix) with ESMTP id F05658E0001 for ; Fri, 1 May 2020 17:46:34 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id AF4D140C0 for ; Fri, 1 May 2020 21:46:34 +0000 (UTC) X-FDA: 76769484708.04.spy40_56739f48e4462 X-HE-Tag: spy40_56739f48e4462 X-Filterd-Recvd-Size: 3099 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Fri, 1 May 2020 21:46:33 +0000 (UTC) IronPort-SDR: bmkFY4rO+9TGMlA0fxDHgLCh1yzszfGySp2qOlTI2dG8T4S8LEgxxxZgjsLBeGu9v40ULizsiF EQ6uvls31RSg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 May 2020 14:46:32 -0700 IronPort-SDR: APjvBuXoDHn2cvvuqaTFzkW4bnzIv2ckBl9UrbjPwTaOG32LjX6/6R80UAf8oYx2P+D8I4JkWh gEGfjESfaKWA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,341,1583222400"; d="scan'208";a="283301037" Received: from schen9-mobl.amr.corp.intel.com ([10.254.53.33]) by fmsmga004.fm.intel.com with ESMTP; 01 May 2020 14:46:32 -0700 Subject: Re: [PATCH 1/3] mm/swap: simplify alloc_swap_slot_cache() To: Zhen Lei , Andrew Morton , linux-mm , linux-kernel References: <20200430061143.450-1-thunder.leizhen@huawei.com> <20200430061143.450-2-thunder.leizhen@huawei.com> From: Tim Chen Message-ID: <34318e00-fd1a-f8d7-14d4-0efa84b151d2@linux.intel.com> Date: Fri, 1 May 2020 14:46:31 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <20200430061143.450-2-thunder.leizhen@huawei.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit 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: On 4/29/20 11:11 PM, Zhen Lei wrote: > Both "slots" and "slots_ret" are only need to be freed when cache already > allocated. Make them closer, seems more clear. > > No functional change. > > Signed-off-by: Zhen Lei > --- > mm/swap_slots.c | 18 +++++++++--------- > 1 file changed, 9 insertions(+), 9 deletions(-) > > diff --git a/mm/swap_slots.c b/mm/swap_slots.c > index 0975adc72253..01609b5f0c55 100644 > --- a/mm/swap_slots.c > +++ b/mm/swap_slots.c > @@ -136,9 +136,16 @@ static int alloc_swap_slot_cache(unsigned int cpu) > > mutex_lock(&swap_slots_cache_mutex); > cache = &per_cpu(swp_slots, cpu); > - if (cache->slots || cache->slots_ret) > + if (cache->slots || cache->slots_ret) { > /* cache already allocated */ > - goto out; > + mutex_unlock(&swap_slots_cache_mutex); > + > + kvfree(slots); > + kvfree(slots_ret); > + > + return 0; > + } > + > if (!cache->lock_initialized) { > mutex_init(&cache->alloc_lock); > spin_lock_init(&cache->free_lock); > @@ -155,15 +162,8 @@ static int alloc_swap_slot_cache(unsigned int cpu) > */ > mb(); > cache->slots = slots; > - slots = NULL; > cache->slots_ret = slots_ret; > - slots_ret = NULL; > -out: > mutex_unlock(&swap_slots_cache_mutex); > - if (slots) > - kvfree(slots); > - if (slots_ret) > - kvfree(slots_ret); > return 0; > } > > Acked-by: Tim Chen