Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp659904pxb; Fri, 16 Apr 2021 15:07:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvGuTkAwTFwRY+T7kxE8Sng7VrYx0Ij1WaBw4qxsthRWWwgErScuMOX3D4xPXvVmWoGQiX X-Received: by 2002:a63:5517:: with SMTP id j23mr980799pgb.209.1618610829527; Fri, 16 Apr 2021 15:07:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618610829; cv=none; d=google.com; s=arc-20160816; b=K1J5OOQRInrJ4JVMsqtfZmHgTzlB7Q9/ge/yQQw4VH1JAjcAcXoEvwqCzvqQ8Gyw2f A0JKNpc0D9WGJxbV5x44X5HJGrYYFA63JGGEPLmIIosPb0U7GVPZWVfpajW0wUmUGCqd H2ygE7jgTPcgTPvChyzXW7Fz34+/VXJsDuUmoXwrFkgP4Hi/wz+OFlTHKUV4GvOH+jZZ qsgT2H99kgxC8+yPsPbBzjFCWEZIgDCnCU5dJXjzqk1g+UPue2V/5s9sNsfpbB33wbMI Nx8bk4qNYEQMQ74+wLA7fVkrBHl8K7pI4FR9/r39Z7U8Sn6Yn9/rRc/8FrCi/cjL0xE/ Damg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=EKyEsfbEdP05yBqMIYFaM4FBS/vxypwwn4CFBa3hXxE=; b=CQH9l51f8nBsWp1U/ug89OHQ63nas+gJLgtQL0Zo2i5SB1lYhyTXs9iwv3iVWCnt8o S188QB9cFnANOB49nyL6S+DKwGyQgkraiCOIYTVLSssxKRHTbLURrD/iTAqmdIe5lI5T YHuPPn0DTYDXbH3PZ1YFDFsLRpJEEMJBwA+g/W6sWD8k4kPyDIoMImo6XkZrcLCGeJq3 LNffWU73MEy8KGpXOp5eu6dNlI+qpefIGW1GotTKPE/o9YWjAJCN4gtJrQLOezlWrUsy SZfHFPgmbp2w797AAHLA+Nj1JffjwnqEkkg8EZCJalIxYLsgb+/zFtUwPC01copoSjha NeDQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c4si6333225pjn.76.2021.04.16.15.06.57; Fri, 16 Apr 2021 15:07:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344048AbhDPVHZ (ORCPT + 99 others); Fri, 16 Apr 2021 17:07:25 -0400 Received: from mail-io1-f47.google.com ([209.85.166.47]:33551 "EHLO mail-io1-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343949AbhDPVHZ (ORCPT ); Fri, 16 Apr 2021 17:07:25 -0400 Received: by mail-io1-f47.google.com with SMTP id a11so26913082ioo.0 for ; Fri, 16 Apr 2021 14:06:59 -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=EKyEsfbEdP05yBqMIYFaM4FBS/vxypwwn4CFBa3hXxE=; b=rGMAcyqD0GHTHZY8DsqblUO+zfJcwT2QBposuvlpW5kIDpcEXK1fzdjBd0eQlZezln v29m40uL5HVuI4FF9lfxkmrmSWsPjmrwiatQlIxX8ZYmMcuR82DLkkW8s7acdefcPQXz Fa1jVw4WFDjdB8CbfcNAMEdSfMUfTnTuIawIlXntlUEfwuOcJqLK2cinusFewtAPAYx1 qJspvfFWui2Hgl2chQc6OR1EoX38HJSYPrvmgw06eiailwdrcdrVuv2rr+8sMsLYjqKI HkHnPFJgEVXuiqFZgA+++tLlKG9uvcm2z4gRToULNPO+FwM/QIFCWej/fzboOQp/HUwq 307Q== X-Gm-Message-State: AOAM530TmIMK198OLRz5f/Smq5plcZe1BHNwysRkV7fsriNIcdGaEjzL gZraL5zp3y+Wi7nS5ayo7mo= X-Received: by 2002:a6b:7e0c:: with SMTP id i12mr5107770iom.196.1618607218632; Fri, 16 Apr 2021 14:06:58 -0700 (PDT) Received: from google.com (243.199.238.35.bc.googleusercontent.com. [35.238.199.243]) by smtp.gmail.com with ESMTPSA id m5sm3213345ilg.79.2021.04.16.14.06.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Apr 2021 14:06:58 -0700 (PDT) Date: Fri, 16 Apr 2021 21:06:57 +0000 From: Dennis Zhou To: Roman Gushchin Cc: Tejun Heo , Christoph Lameter , Andrew Morton , Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 2/6] percpu: split __pcpu_balance_workfn() Message-ID: References: <20210408035736.883861-1-guro@fb.com> <20210408035736.883861-3-guro@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210408035736.883861-3-guro@fb.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Wed, Apr 07, 2021 at 08:57:32PM -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 > Reviewed-by: Dennis Zhou > --- > mm/percpu.c | 46 +++++++++++++++++++++++++++++----------------- > 1 file changed, 29 insertions(+), 17 deletions(-) > > diff --git a/mm/percpu.c b/mm/percpu.c > index 2f27123bb489..7e31e1b8725f 100644 > --- a/mm/percpu.c > +++ b/mm/percpu.c > @@ -1933,31 +1933,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) { > @@ -1985,6 +1976,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 > @@ -2054,22 +2064,24 @@ static void __pcpu_balance_workfn(enum pcpu_chunk_type type) > goto retry_pop; > } > } > - > - mutex_unlock(&pcpu_alloc_mutex); > } > > /** > * 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 > > I've applied this to for-5.14. Thanks, Dennis