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=-10.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 12F33C433ED for ; Thu, 15 Apr 2021 14:53:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9EEEE613C1 for ; Thu, 15 Apr 2021 14:53:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9EEEE613C1 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2E3636B0036; Thu, 15 Apr 2021 10:53:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 292306B006C; Thu, 15 Apr 2021 10:53:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 135E16B0070; Thu, 15 Apr 2021 10:53:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0026.hostedemail.com [216.40.44.26]) by kanga.kvack.org (Postfix) with ESMTP id EC1B96B0036 for ; Thu, 15 Apr 2021 10:53:48 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id A0D3145A8 for ; Thu, 15 Apr 2021 14:53:48 +0000 (UTC) X-FDA: 78034895736.25.38AC114 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf28.hostedemail.com (Postfix) with ESMTP id 956632000271 for ; Thu, 15 Apr 2021 14:53:49 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id CDC45AFE6; Thu, 15 Apr 2021 14:53:46 +0000 (UTC) To: Mel Gorman , Linux-MM , Linux-RT-Users Cc: LKML , Chuck Lever , Jesper Dangaard Brouer , Thomas Gleixner , Peter Zijlstra , Ingo Molnar , Michal Hocko References: <20210414133931.4555-1-mgorman@techsingularity.net> <20210414133931.4555-12-mgorman@techsingularity.net> From: Vlastimil Babka Subject: Re: [PATCH 11/11] mm/page_alloc: Embed per_cpu_pages locking within the per-cpu structure Message-ID: Date: Thu, 15 Apr 2021 16:53:46 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: <20210414133931.4555-12-mgorman@techsingularity.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 956632000271 X-Stat-Signature: p7sinwe9q5my6s3sn69yp5hdh6u3p1s4 Received-SPF: none (suse.cz>: No applicable sender policy available) receiver=imf28; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: none/none X-HE-Tag: 1618498429-689520 Content-Transfer-Encoding: quoted-printable 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/14/21 3:39 PM, Mel Gorman wrote: > struct per_cpu_pages is protected by the pagesets lock but it can be > embedded within struct per_cpu_pages at a minor cost. This is possible > because per-cpu lookups are based on offsets. Paraphrasing an explanati= on > from Peter Ziljstra >=20 > The whole thing relies on: >=20 > &per_cpu_ptr(msblk->stream, cpu)->lock =3D=3D per_cpu_ptr(&msblk->s= tream->lock, cpu) >=20 > Which is true because the lhs: >=20 > (local_lock_t *)((zone->per_cpu_pages + per_cpu_offset(cpu)) + offs= etof(struct per_cpu_pages, lock)) >=20 > and the rhs: >=20 > (local_lock_t *)((zone->per_cpu_pages + offsetof(struct per_cpu_pag= es, lock)) + per_cpu_offset(cpu)) >=20 > are identical, because addition is associative. >=20 > More details are included in mmzone.h. This embedding is not completely > free for three reasons. >=20 > 1. As local_lock does not return a per-cpu structure, the PCP has to > be looked up twice -- first to acquire the lock and again to get the > PCP pointer. >=20 > 2. For PREEMPT_RT and CONFIG_DEBUG_LOCK_ALLOC, local_lock is potentiall= y > a spinlock or has lock-specific tracking. In both cases, it becomes > necessary to release/acquire different locks when freeing a list of > pages in free_unref_page_list. Looks like this pattern could benefit from a local_lock API helper that w= ould do the right thing? It probably couldn't optimize much the CONFIG_PREEMPT_RT= case which would need to be unlock/lock in any case, but CONFIG_DEBUG_LOCK_ALL= OC could perhaps just keep the IRQ's disabled and just note the change of wh= at's acquired? > 3. For most kernel configurations, local_lock_t is empty and no storage= is > required. By embedding the lock, the memory consumption on PREEMPT_R= T > and CONFIG_DEBUG_LOCK_ALLOC is higher. But I wonder, is there really a benefit to this increased complexity? Bef= ore the patch we had "pagesets" - a local_lock that protects all zones' pcplists.= Now each zone's pcplists have own local_lock. On !PREEMPT_RT we will never ta= ke the locks of multiple zones from the same CPU in parallel, because we use local_lock_irqsave(). Can that parallelism happen on PREEMPT_RT, because = that could perhaps justify the change? > Suggested-by: Peter Zijlstra > Signed-off-by: Mel Gorman > ---