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=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no 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 1E7C7C433ED for ; Thu, 15 Apr 2021 15:30:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 96F396115C for ; Thu, 15 Apr 2021 15:30:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 96F396115C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=techsingularity.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A59FA6B0036; Thu, 15 Apr 2021 11:30:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A314F6B006C; Thu, 15 Apr 2021 11:30:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8D3C06B0070; Thu, 15 Apr 2021 11:30:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0153.hostedemail.com [216.40.44.153]) by kanga.kvack.org (Postfix) with ESMTP id 7357F6B0036 for ; Thu, 15 Apr 2021 11:30:02 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 1767018140B75 for ; Thu, 15 Apr 2021 15:30:02 +0000 (UTC) X-FDA: 78034987044.23.39E49C3 Received: from outbound-smtp09.blacknight.com (outbound-smtp09.blacknight.com [46.22.139.14]) by imf02.hostedemail.com (Postfix) with ESMTP id 46C5140002EB for ; Thu, 15 Apr 2021 15:29:44 +0000 (UTC) Received: from mail.blacknight.com (pemlinmail03.blacknight.ie [81.17.254.16]) by outbound-smtp09.blacknight.com (Postfix) with ESMTPS id CDE571C429D for ; Thu, 15 Apr 2021 16:29:59 +0100 (IST) Received: (qmail 1618 invoked from network); 15 Apr 2021 15:29:59 -0000 Received: from unknown (HELO techsingularity.net) (mgorman@techsingularity.net@[84.203.22.4]) by 81.17.254.9 with ESMTPSA (AES256-SHA encrypted, authenticated); 15 Apr 2021 15:29:59 -0000 Date: Thu, 15 Apr 2021 16:29:58 +0100 From: Mel Gorman To: Vlastimil Babka Cc: Linux-MM , Linux-RT-Users , LKML , Chuck Lever , Jesper Dangaard Brouer , Thomas Gleixner , Peter Zijlstra , Ingo Molnar , Michal Hocko Subject: Re: [PATCH 11/11] mm/page_alloc: Embed per_cpu_pages locking within the per-cpu structure Message-ID: <20210415152958.GL3697@techsingularity.net> References: <20210414133931.4555-1-mgorman@techsingularity.net> <20210414133931.4555-12-mgorman@techsingularity.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 46C5140002EB X-Stat-Signature: jirxr77kxxckgpjj8ekn543zm5ngeahx Received-SPF: none (techsingularity.net>: No applicable sender policy available) receiver=imf02; identity=mailfrom; envelope-from=""; helo=outbound-smtp09.blacknight.com; client-ip=46.22.139.14 X-HE-DKIM-Result: none/none X-HE-Tag: 1618500584-306759 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 Thu, Apr 15, 2021 at 04:53:46PM +0200, Vlastimil Babka wrote: > 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 explanation > > from Peter Ziljstra > > > > The whole thing relies on: > > > > &per_cpu_ptr(msblk->stream, cpu)->lock == per_cpu_ptr(&msblk->stream->lock, cpu) > > > > Which is true because the lhs: > > > > (local_lock_t *)((zone->per_cpu_pages + per_cpu_offset(cpu)) + offsetof(struct per_cpu_pages, lock)) > > > > and the rhs: > > > > (local_lock_t *)((zone->per_cpu_pages + offsetof(struct per_cpu_pages, lock)) + per_cpu_offset(cpu)) > > > > are identical, because addition is associative. > > > > More details are included in mmzone.h. This embedding is not completely > > free for three reasons. > > > > 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. > > > > 2. For PREEMPT_RT and CONFIG_DEBUG_LOCK_ALLOC, local_lock is potentially > > 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 would 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_ALLOC > could perhaps just keep the IRQ's disabled and just note the change of what's > acquired? > A helper could potentially be used but right now, there is only one call-site that needs this type of care so it may be overkill. A helper was proposed that can lookup and lock a per-cpu structure which is generally useful but does not suit the case where different locks need to be 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_RT > > and CONFIG_DEBUG_LOCK_ALLOC is higher. > > But I wonder, is there really a benefit to this increased complexity? Before 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 take 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? > I don't think PREEMPT_RT gets additional parallelism because it's still a per-cpu structure that is being protected. The difference is whether we are protecting the CPU-N index for all per_cpu_pages or just one. The patch exists because it was asked why the lock was not embedded within the structure it's protecting. I initially thought that was unsafe and I was wrong as explained in the changelog. But now that I find it *can* be done but it's a bit ugly so I put it at the end of the series so it can be dropped if necessary. -- Mel Gorman SUSE Labs