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=-14.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 19967C433DB for ; Mon, 29 Mar 2021 17:28:38 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6622861968 for ; Mon, 29 Mar 2021 17:28:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6622861968 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D33C16B007B; Mon, 29 Mar 2021 13:28:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D0B2E6B007E; Mon, 29 Mar 2021 13:28:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD2A06B0080; Mon, 29 Mar 2021 13:28:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0196.hostedemail.com [216.40.44.196]) by kanga.kvack.org (Postfix) with ESMTP id 9F7566B007B for ; Mon, 29 Mar 2021 13:28:36 -0400 (EDT) Received: from smtpin03.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 66E21180AD820 for ; Mon, 29 Mar 2021 17:28:36 +0000 (UTC) X-FDA: 77973596232.03.B408968 Received: from mail-io1-f45.google.com (mail-io1-f45.google.com [209.85.166.45]) by imf13.hostedemail.com (Postfix) with ESMTP id 1F5D0E005F20 for ; Mon, 29 Mar 2021 17:28:29 +0000 (UTC) Received: by mail-io1-f45.google.com with SMTP id x16so13572995iob.1 for ; Mon, 29 Mar 2021 10:28:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Nkzt5ca+QTI2PdMNoQrVYUu19ObnRjYQ/LdWspjTQOA=; b=sSzd3Rh6TW8+qEFM0wUu2AHuIOHR9MejCmn5vwzqVtGZTzJ/R1KHjqUpt37qpgO1dz Z3N34mv6ddHwRinV0AECYSoBLTCBC/4jDv5gTdgl34rT6/n/Zi9AozF1YgQT0Ez/5JN2 EunB5ZMj4HPi1yZlzcOoa+zjOgxHe5amRf6t8/NVBhS3GNBvl8xDpExbGtvz25gAJKyG MZxtiWrNQnXY2osTgoKPMAuvFrCLAw1mVBd5PhkBKyqzdGKMPm7oP2LkgtYCPXr8K5D+ a44pR12gOAjXT+pghnBALg+86JeyEGXilrAI06rlH7ruGQaWmjNPEVC3pGdzXWGWW5Jr zFhA== X-Gm-Message-State: AOAM531iVSUP8R+WA2bNrLEvMLDLhGAXUFqNevF+N4j8q6c2G70khXHu Ff4fcw3dW3jthKQUKJhmjvCZ9FEjwrI= X-Google-Smtp-Source: ABdhPJxW6JdM2bXLojdubZTuopcLdyZe28g3PcUDHgAwrq2Vhm7NvakTtgSqMCd/hxKe4m6b5oyPdQ== X-Received: by 2002:a05:6602:2348:: with SMTP id r8mr21193050iot.77.1617038905185; Mon, 29 Mar 2021 10:28:25 -0700 (PDT) Received: from google.com (243.199.238.35.bc.googleusercontent.com. [35.238.199.243]) by smtp.gmail.com with ESMTPSA id z10sm7541252ilq.38.2021.03.29.10.28.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Mar 2021 10:28:24 -0700 (PDT) Date: Mon, 29 Mar 2021 17:28:23 +0000 From: Dennis Zhou To: Roman Gushchin Cc: Tejun Heo , Christoph Lameter , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH rfc 2/4] percpu: split __pcpu_balance_workfn() Message-ID: References: <20210324190626.564297-1-guro@fb.com> <20210324190626.564297-3-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210324190626.564297-3-guro@fb.com> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 1F5D0E005F20 X-Stat-Signature: n78zkcibe687raqktwdmmpufe4hmaqhq Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf13; identity=mailfrom; envelope-from=""; helo=mail-io1-f45.google.com; client-ip=209.85.166.45 X-HE-DKIM-Result: none/none X-HE-Tag: 1617038909-478643 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 Wed, Mar 24, 2021 at 12:06:24PM -0700, Roman Gushchin wrote: > __pcpu_balance_workfn() became fairly big and hard to follow, but in > fact it consists of two fully independent parts, responsible for > the destruction of excessive free chunks and population of necessarily > amount of free pages. > > In order to simplify the code and prepare for adding of a new > functionality, split it in two functions: > > 1) pcpu_balance_free, > 2) pcpu_balance_populated. > > Move the taking/releasing of the pcpu_alloc_mutex to an upper level > to keep the current synchronization in place. > > Signed-off-by: Roman Gushchin > --- > mm/percpu.c | 46 +++++++++++++++++++++++++++++----------------- > 1 file changed, 29 insertions(+), 17 deletions(-) > > diff --git a/mm/percpu.c b/mm/percpu.c > index 78c55c73fa28..015d076893f5 100644 > --- a/mm/percpu.c > +++ b/mm/percpu.c > @@ -1930,31 +1930,22 @@ void __percpu *__alloc_reserved_percpu(size_t size, size_t align) > } > > /** > - * __pcpu_balance_workfn - manage the amount of free chunks and populated pages > + * pcpu_balance_free - manage the amount of free chunks > * @type: chunk type > * > - * Reclaim all fully free chunks except for the first one. This is also > - * responsible for maintaining the pool of empty populated pages. However, > - * it is possible that this is called when physical memory is scarce causing > - * OOM killer to be triggered. We should avoid doing so until an actual > - * allocation causes the failure as it is possible that requests can be > - * serviced from already backed regions. > + * Reclaim all fully free chunks except for the first one. > */ > -static void __pcpu_balance_workfn(enum pcpu_chunk_type type) > +static void pcpu_balance_free(enum pcpu_chunk_type type) > { > - /* gfp flags passed to underlying allocators */ > - const gfp_t gfp = GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN; > LIST_HEAD(to_free); > struct list_head *pcpu_slot = pcpu_chunk_list(type); > struct list_head *free_head = &pcpu_slot[pcpu_nr_slots - 1]; > struct pcpu_chunk *chunk, *next; > - int slot, nr_to_pop, ret; > > /* > * There's no reason to keep around multiple unused chunks and VM > * areas can be scarce. Destroy all free chunks except for one. > */ > - mutex_lock(&pcpu_alloc_mutex); > spin_lock_irq(&pcpu_lock); > > list_for_each_entry_safe(chunk, next, free_head, list) { > @@ -1982,6 +1973,25 @@ static void __pcpu_balance_workfn(enum pcpu_chunk_type type) > pcpu_destroy_chunk(chunk); > cond_resched(); > } > +} > + > +/** > + * pcpu_balance_populated - manage the amount of populated pages > + * @type: chunk type > + * > + * Maintain a certain amount of populated pages to satisfy atomic allocations. > + * It is possible that this is called when physical memory is scarce causing > + * OOM killer to be triggered. We should avoid doing so until an actual > + * allocation causes the failure as it is possible that requests can be > + * serviced from already backed regions. > + */ > +static void pcpu_balance_populated(enum pcpu_chunk_type type) > +{ > + /* gfp flags passed to underlying allocators */ > + const gfp_t gfp = GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN; > + struct list_head *pcpu_slot = pcpu_chunk_list(type); > + struct pcpu_chunk *chunk; > + int slot, nr_to_pop, ret; > > /* > * Ensure there are certain number of free populated pages for > @@ -2051,8 +2061,6 @@ static void __pcpu_balance_workfn(enum pcpu_chunk_type type) > goto retry_pop; > } > } > - > - mutex_unlock(&pcpu_alloc_mutex); > } > > /** > @@ -2149,14 +2157,18 @@ static void pcpu_shrink_populated(enum pcpu_chunk_type type) > * pcpu_balance_workfn - manage the amount of free chunks and populated pages > * @work: unused > * > - * Call __pcpu_balance_workfn() for each chunk type. > + * Call pcpu_balance_free() and pcpu_balance_populated() for each chunk type. > */ > static void pcpu_balance_workfn(struct work_struct *work) > { > enum pcpu_chunk_type type; > > - for (type = 0; type < PCPU_NR_CHUNK_TYPES; type++) > - __pcpu_balance_workfn(type); > + for (type = 0; type < PCPU_NR_CHUNK_TYPES; type++) { > + mutex_lock(&pcpu_alloc_mutex); > + pcpu_balance_free(type); > + pcpu_balance_populated(type); > + mutex_unlock(&pcpu_alloc_mutex); > + } > } > > /** > -- > 2.30.2 > Reviewed-by: Dennis Zhou This makes sense. If you want me to pick this and the last patch up first I can. Otherwise, do you mind moving this to the front of the stack because it is a clean up? Thanks, Dennis