From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754025AbcI2HKC (ORCPT ); Thu, 29 Sep 2016 03:10:02 -0400 Received: from out0-151.mail.aliyun.com ([140.205.0.151]:53499 "EHLO out0-151.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932170AbcI2HJx (ORCPT ); Thu, 29 Sep 2016 03:09:53 -0400 X-Greylist: delayed 317 seconds by postgrey-1.27 at vger.kernel.org; Thu, 29 Sep 2016 03:09:53 EDT X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R341e4;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e02c03305;MF=hillf.zj@alibaba-inc.com;NM=1;PH=DS;RN=17;SR=0;TI=SMTPD_---.70-qmFg_1475132644; Reply-To: "Hillf Danton" From: "Hillf Danton" To: , "'Andrew Morton'" Cc: , , , , , "'Huang Ying'" , "'Hugh Dickins'" , "'Shaohua Li'" , "'Minchan Kim'" , "'Rik van Riel'" , "'Andrea Arcangeli'" , "'Kirill A . Shutemov'" , "'Vladimir Davydov'" , "'Johannes Weiner'" , "'Michal Hocko'" References: <20160927171858.GA17943@linux.intel.com> In-Reply-To: <20160927171858.GA17943@linux.intel.com> Subject: Re: [PATCH 7/8] mm/swap: Add cache for swap slots allocation Date: Thu, 29 Sep 2016 15:04:03 +0800 Message-ID: <008401d21a1f$aa29a510$fe7cef30$@alibaba-inc.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQGFS04DUSwt+PV4TdsmDTCPbR0TV6EppY0g Content-Language: zh-cn Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wednesday, September 28, 2016 1:19 AM Tim Chen wrote [...] > + > +static int alloc_swap_slot_cache(int cpu) > +{ > + struct swap_slots_cache *cache; > + > + cache = &per_cpu(swp_slots, cpu); > + mutex_init(&cache->alloc_lock); > + spin_lock_init(&cache->free_lock); > + cache->nr = 0; > + cache->cur = 0; > + cache->n_ret = 0; > + cache->slots = vzalloc(sizeof(swp_entry_t) * SWAP_SLOTS_CACHE_SIZE); > + if (!cache->slots) { > + swap_slot_cache_enabled = false; > + return -ENOMEM; > + } > + cache->slots_ret = vzalloc(sizeof(swp_entry_t) * SWAP_SLOTS_CACHE_SIZE); > + if (!cache->slots_ret) { > + vfree(cache->slots); > + swap_slot_cache_enabled = false; > + return -ENOMEM; > + } > + return 0; > +} > + [...] > + > +static void free_slot_cache(int cpu) > +{ > + struct swap_slots_cache *cache; > + > + mutex_lock(&swap_slots_cache_mutex); > + drain_slots_cache_cpu(cpu, SLOTS_CACHE | SLOTS_CACHE_RET); > + cache = &per_cpu(swp_slots, cpu); > + cache->nr = 0; > + cache->cur = 0; > + cache->n_ret = 0; > + vfree(cache->slots); Also free cache->slots_ret? Or fold the relevant two allocations into one? > + mutex_unlock(&swap_slots_cache_mutex); > +} > thanks Hillf