Message ID | 20221024081435.204970-3-bhe@redhat.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp318325wru; Mon, 24 Oct 2022 01:21:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4fS6yknUPqih3unjjuoUsxcIIjMhi+I7joOIRy8Mwp0GLWAYTp+W1LZPZeMbh4oqZX5uRX X-Received: by 2002:a17:907:72cb:b0:793:30b3:7f89 with SMTP id du11-20020a17090772cb00b0079330b37f89mr20932727ejc.259.1666599709669; Mon, 24 Oct 2022 01:21:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666599709; cv=none; d=google.com; s=arc-20160816; b=iBHhpsTIvEFu+hHWyeLONCqQkQcBo1TEBLcvDhuj1i/2K43Txhdc2LTrNsKX4GZMRi KLp0JBSUCdO/gku7p704gV+miqBC2iZ+wuCRLqwKoxLW6EzqmfB7hM85IcxjC1h3VNvW F55P63zuxDfHa2uj1g4Y42jbqwgG8RwbvKAu15vXr2MaGRmNWycr6ajO33EzxaJ2Www0 tDQwZxpvj+YHkevretxjovSl8Fh9MicyP++tax5ObPZ2ESFjnThWtrgzEpRd8rIRR7iJ GUwSX2AketUmPJrz9J/9jCvuWrt60WaQthBT1qKspphYkdZKkwXWV6/SDGoZjc5g9y8R Q63A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=II9JgjXmJ1/1u2CpjGXaWwKe+WW1rdQe/wCmpKMP6aM=; b=iBnPqctQfcAAvyF5pm+3FonctFkGsg1qCkaHcYKkjrSMz9dWlAGU0L5HoRN1gs1lMJ onfueoGQuj8JkI868BqWCmp2u6ZGgXjWYSRaA5y4+1vf8Ej7MTzRKT0s7Am9lgCSsjCK wtRUKVv7t8tqlsRyh2L3CnpcAJR6NE8DMW5YFNt+6nhDY71NKKyzzZcMqBiz6PHnrFpw CVlKgEmlUMbT3jJzrkafOfq0hIxAsobjDI6VZB9VijnQTT4c91yBvbEgHPSIygzCFxli TovhEmbEIg4+E0cwGqBJV015zAPXGnj4Rgg4vIznHoPVLbh/fLw+bZ2H/wMM6v6bXEVl Z8cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JgrF9Eyj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hg7-20020a1709072cc700b0078e1216fb07si13917055ejc.558.2022.10.24.01.21.25; Mon, 24 Oct 2022 01:21:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JgrF9Eyj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229491AbiJXIQJ (ORCPT <rfc822;pwkd43@gmail.com> + 99 others); Mon, 24 Oct 2022 04:16:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230268AbiJXIP1 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 24 Oct 2022 04:15:27 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 923B83FA01 for <linux-kernel@vger.kernel.org>; Mon, 24 Oct 2022 01:14:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666599294; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=II9JgjXmJ1/1u2CpjGXaWwKe+WW1rdQe/wCmpKMP6aM=; b=JgrF9EyjNHEJYlFJAZ32Xx6VvsLY3n8VobP5XITfLLJZmikEcJL11kJVSrtnTcT2K01il5 r06xEUWyTbtgNUBBl0QlQBsEdPCdXi9Z/9cUiB5ur5A+tzm4tIplBZ64HqcV6v95kLLZwr /zSJCa84e6AcV3FgeLOKIHg/l+N5WVg= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-465-bJGbBwAUPae4Iz-zpeIZZw-1; Mon, 24 Oct 2022 04:14:51 -0400 X-MC-Unique: bJGbBwAUPae4Iz-zpeIZZw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AC69F3C10147; Mon, 24 Oct 2022 08:14:50 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-35.pek2.redhat.com [10.72.12.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 546C940C94EB; Mon, 24 Oct 2022 08:14:47 +0000 (UTC) From: Baoquan He <bhe@redhat.com> To: linux-kernel@vger.kernel.org Cc: Dennis Zhou <dennis@kernel.org>, Tejun Heo <tj@kernel.org>, Christoph Lameter <cl@linux.com>, Andrew Morton <akpm@linux-foundation.org>, linux-mm@kvack.org, Baoquan He <bhe@redhat.com> Subject: [PATCH 2/8] mm/percpu: use list_first_entry_or_null in pcpu_reclaim_populated() Date: Mon, 24 Oct 2022 16:14:29 +0800 Message-Id: <20221024081435.204970-3-bhe@redhat.com> In-Reply-To: <20221024081435.204970-1-bhe@redhat.com> References: <20221024081435.204970-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747556457101901127?= X-GMAIL-MSGID: =?utf-8?q?1747556457101901127?= |
Series |
Cleanup and optimization patches for percpu
|
|
Commit Message
Baoquan He
Oct. 24, 2022, 8:14 a.m. UTC
To replace list_empty()/list_first_entry() pair to simplify code.
Signed-off-by: Baoquan He <bhe@redhat.com>
---
mm/percpu.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
Comments
Hi Baoquan, I love your patch! Perhaps something to improve: [auto build test WARNING on vbabka-slab/for-next] [also build test WARNING on akpm-mm/mm-everything linus/master v6.1-rc2 next-20221024] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Baoquan-He/Cleanup-and-optimization-patches-for-percpu/20221024-161636 base: git://git.kernel.org/pub/scm/linux/kernel/git/vbabka/slab.git for-next patch link: https://lore.kernel.org/r/20221024081435.204970-3-bhe%40redhat.com patch subject: [PATCH 2/8] mm/percpu: use list_first_entry_or_null in pcpu_reclaim_populated() config: um-i386_defconfig compiler: gcc-11 (Debian 11.3.0-8) 11.3.0 reproduce (this is a W=1 build): # https://github.com/intel-lab-lkp/linux/commit/75b290e1aa943a113526ab78c22b38d07bf7a462 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Baoquan-He/Cleanup-and-optimization-patches-for-percpu/20221024-161636 git checkout 75b290e1aa943a113526ab78c22b38d07bf7a462 # save the config file mkdir build_dir && cp config build_dir/.config make W=1 O=build_dir ARCH=um SUBARCH=i386 SHELL=/bin/bash If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> All warnings (new ones prefixed by >>): mm/percpu.c: In function 'pcpu_reclaim_populated': >> mm/percpu.c:2146:16: warning: suggest parentheses around assignment used as truth value [-Wparentheses] 2146 | while (chunk = list_first_entry_or_null( | ^~~~~ vim +2146 mm/percpu.c 2114 2115 /** 2116 * pcpu_reclaim_populated - scan over to_depopulate chunks and free empty pages 2117 * 2118 * Scan over chunks in the depopulate list and try to release unused populated 2119 * pages back to the system. Depopulated chunks are sidelined to prevent 2120 * repopulating these pages unless required. Fully free chunks are reintegrated 2121 * and freed accordingly (1 is kept around). If we drop below the empty 2122 * populated pages threshold, reintegrate the chunk if it has empty free pages. 2123 * Each chunk is scanned in the reverse order to keep populated pages close to 2124 * the beginning of the chunk. 2125 * 2126 * CONTEXT: 2127 * pcpu_lock (can be dropped temporarily) 2128 * 2129 */ 2130 static void pcpu_reclaim_populated(void) 2131 { 2132 struct pcpu_chunk *chunk; 2133 struct pcpu_block_md *block; 2134 int freed_page_start, freed_page_end; 2135 int i, end; 2136 bool reintegrate; 2137 2138 lockdep_assert_held(&pcpu_lock); 2139 2140 /* 2141 * Once a chunk is isolated to the to_depopulate list, the chunk is no 2142 * longer discoverable to allocations whom may populate pages. The only 2143 * other accessor is the free path which only returns area back to the 2144 * allocator not touching the populated bitmap. 2145 */ > 2146 while (chunk = list_first_entry_or_null( 2147 &pcpu_chunk_lists[pcpu_to_depopulate_slot], 2148 struct pcpu_chunk, list)) { 2149 WARN_ON(chunk->immutable); 2150 2151 /* 2152 * Scan chunk's pages in the reverse order to keep populated 2153 * pages close to the beginning of the chunk. 2154 */ 2155 freed_page_start = chunk->nr_pages; 2156 freed_page_end = 0; 2157 reintegrate = false; 2158 for (i = chunk->nr_pages - 1, end = -1; i >= 0; i--) { 2159 /* no more work to do */ 2160 if (chunk->nr_empty_pop_pages == 0) 2161 break; 2162 2163 /* reintegrate chunk to prevent atomic alloc failures */ 2164 if (pcpu_nr_empty_pop_pages < PCPU_EMPTY_POP_PAGES_HIGH) { 2165 reintegrate = true; 2166 goto end_chunk; 2167 } 2168 2169 /* 2170 * If the page is empty and populated, start or 2171 * extend the (i, end) range. If i == 0, decrease 2172 * i and perform the depopulation to cover the last 2173 * (first) page in the chunk. 2174 */ 2175 block = chunk->md_blocks + i; 2176 if (block->contig_hint == PCPU_BITMAP_BLOCK_BITS && 2177 test_bit(i, chunk->populated)) { 2178 if (end == -1) 2179 end = i; 2180 if (i > 0) 2181 continue; 2182 i--; 2183 } 2184 2185 /* depopulate if there is an active range */ 2186 if (end == -1) 2187 continue; 2188 2189 spin_unlock_irq(&pcpu_lock); 2190 pcpu_depopulate_chunk(chunk, i + 1, end + 1); 2191 cond_resched(); 2192 spin_lock_irq(&pcpu_lock); 2193 2194 pcpu_chunk_depopulated(chunk, i + 1, end + 1); 2195 freed_page_start = min(freed_page_start, i + 1); 2196 freed_page_end = max(freed_page_end, end + 1); 2197 2198 /* reset the range and continue */ 2199 end = -1; 2200 } 2201 2202 end_chunk: 2203 /* batch tlb flush per chunk to amortize cost */ 2204 if (freed_page_start < freed_page_end) { 2205 spin_unlock_irq(&pcpu_lock); 2206 pcpu_post_unmap_tlb_flush(chunk, 2207 freed_page_start, 2208 freed_page_end); 2209 cond_resched(); 2210 spin_lock_irq(&pcpu_lock); 2211 } 2212 2213 if (reintegrate || chunk->free_bytes == pcpu_unit_size) 2214 pcpu_reintegrate_chunk(chunk); 2215 else 2216 list_move_tail(&chunk->list, 2217 &pcpu_chunk_lists[pcpu_sidelined_slot]); 2218 } 2219 } 2220
On Mon, Oct 24, 2022 at 04:14:29PM +0800, Baoquan He wrote: > To replace list_empty()/list_first_entry() pair to simplify code. > > Signed-off-by: Baoquan He <bhe@redhat.com> > --- > mm/percpu.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/mm/percpu.c b/mm/percpu.c > index 26d8cd2ca323..a3fde4ac03a4 100644 > --- a/mm/percpu.c > +++ b/mm/percpu.c > @@ -2143,9 +2143,9 @@ static void pcpu_reclaim_populated(void) > * other accessor is the free path which only returns area back to the > * allocator not touching the populated bitmap. > */ > - while (!list_empty(&pcpu_chunk_lists[pcpu_to_depopulate_slot])) { > - chunk = list_first_entry(&pcpu_chunk_lists[pcpu_to_depopulate_slot], > - struct pcpu_chunk, list); > + while (chunk = list_first_entry_or_null( > + &pcpu_chunk_lists[pcpu_to_depopulate_slot], > + struct pcpu_chunk, list)) { > WARN_ON(chunk->immutable); > > /* > -- > 2.34.1 > With added parenthesis, Acked-by: Dennis Zhou <dennis@kernel.org> Thanks, Dennis
diff --git a/mm/percpu.c b/mm/percpu.c index 26d8cd2ca323..a3fde4ac03a4 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -2143,9 +2143,9 @@ static void pcpu_reclaim_populated(void) * other accessor is the free path which only returns area back to the * allocator not touching the populated bitmap. */ - while (!list_empty(&pcpu_chunk_lists[pcpu_to_depopulate_slot])) { - chunk = list_first_entry(&pcpu_chunk_lists[pcpu_to_depopulate_slot], - struct pcpu_chunk, list); + while (chunk = list_first_entry_or_null( + &pcpu_chunk_lists[pcpu_to_depopulate_slot], + struct pcpu_chunk, list)) { WARN_ON(chunk->immutable); /*