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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06412C3600C for ; Thu, 3 Apr 2025 09:26:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2770A280005; Thu, 3 Apr 2025 05:26:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 224E0280001; Thu, 3 Apr 2025 05:26:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0ED70280005; Thu, 3 Apr 2025 05:26:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E8B74280001 for ; Thu, 3 Apr 2025 05:26:40 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 0716C81F32 for ; Thu, 3 Apr 2025 09:26:41 +0000 (UTC) X-FDA: 83292202602.28.E6A39B1 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf02.hostedemail.com (Postfix) with ESMTP id 7019780012 for ; Thu, 3 Apr 2025 09:26:38 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Go74T+tU; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=Yo5K1YJs; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Go74T+tU; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=Yo5K1YJs; spf=pass (imf02.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1743672399; h=from:from:sender: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:dkim-signature; bh=g5JBiagd/IaphZnNyD5cE9CP+4ou/BNEE11+z/xpLv8=; b=arkLt/QzERtIDOp0hoP5U3xM60nsig+mf5ayRdSIY9FbE1hpi7w469ynk2dXP2YFUjUgEE 1sUSn48U3z8EM6xe8/zgpp9iBkvN24rFy17nUo0D7yggvi0IPh/B2Ym3kx9G5FGeUPgna4 CUdwlybhyAwwuUTqfbQO2SxCqTjsWk8= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Go74T+tU; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=Yo5K1YJs; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Go74T+tU; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=Yo5K1YJs; spf=pass (imf02.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1743672399; a=rsa-sha256; cv=none; b=7vTmlxgkR57H4ckFHYISqUXeJAeATJZI5WgHgtmIS6UmnQeQC9dZOy0BFO0zCOZSVQp+J7 x/lKvh8Lx7g2BisGMtX3cTI+0Urq/VnS2WmvyOXtS1Fkm3B0zq4M+oKSbs9HSjOQmPttr4 l7enEA37P1BRhH745xAgT/XdB9jktp4= Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 3946C2119C; Thu, 3 Apr 2025 09:26:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1743672396; h=from:from:reply-to: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=g5JBiagd/IaphZnNyD5cE9CP+4ou/BNEE11+z/xpLv8=; b=Go74T+tUMTM6OYdgLA37QBOkBLwM+KvGmRKuScprELaI3wS+y+CEE0CAGHNeZpSu42E4HC PS4zr7Qb+kuj+u0fqs7wZGYgJs+8ZJTPubY1mLgqZrdVKHNGouW1eOPXNA83eeDL7OXWaT wz/auDH67aPVt+xsgV9PkVm2z0QNIrQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1743672396; h=from:from:reply-to: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=g5JBiagd/IaphZnNyD5cE9CP+4ou/BNEE11+z/xpLv8=; b=Yo5K1YJsEQjD37r4hoFAPojI/47BnHdlm4EGwH/fr7Ve751Vut4k5R/Mwyg8w3kGQRfuid PkQezbA8/O+1sSCQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1743672396; h=from:from:reply-to: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=g5JBiagd/IaphZnNyD5cE9CP+4ou/BNEE11+z/xpLv8=; b=Go74T+tUMTM6OYdgLA37QBOkBLwM+KvGmRKuScprELaI3wS+y+CEE0CAGHNeZpSu42E4HC PS4zr7Qb+kuj+u0fqs7wZGYgJs+8ZJTPubY1mLgqZrdVKHNGouW1eOPXNA83eeDL7OXWaT wz/auDH67aPVt+xsgV9PkVm2z0QNIrQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1743672396; h=from:from:reply-to: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=g5JBiagd/IaphZnNyD5cE9CP+4ou/BNEE11+z/xpLv8=; b=Yo5K1YJsEQjD37r4hoFAPojI/47BnHdlm4EGwH/fr7Ve751Vut4k5R/Mwyg8w3kGQRfuid PkQezbA8/O+1sSCQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 146AD13A2C; Thu, 3 Apr 2025 09:26:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id JThnBExU7mdkbgAAD6G6ig (envelope-from ); Thu, 03 Apr 2025 09:26:36 +0000 Message-ID: <78c2d3be-aa8e-4bb7-8883-7f144a06f866@suse.cz> Date: Thu, 3 Apr 2025 11:26:35 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] locking/local_lock, mm: Replace localtry_ helpers with local_trylock_t type Content-Language: en-US To: Alexei Starovoitov , Shakeel Butt Cc: Linus Torvalds , bpf , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Andrew Morton , Peter Zijlstra , Sebastian Sewior , Steven Rostedt , Michal Hocko , linux-mm , LKML References: <20250401205245.70838-1-alexei.starovoitov@gmail.com> From: Vlastimil Babka In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 7019780012 X-Rspamd-Server: rspam05 X-Rspam-User: X-Stat-Signature: nisht6wieod6k7cupyjhnhf9o1nju6pi X-HE-Tag: 1743672398-563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zIObOpedCoXudizNgU7Kw+e1Y28MqLZ6MiF+GRNK+doZV3bJoaVhaRAqsmWCRqqheaWjB2mUxUAoqE7W03N0tRHR5Sw0h/G3F8ui0opxdEkiptrX7riqyCv5BCZ0F5tM3S/sKHIsRPSPaou6vZbVHnivU6la4S03r6teoPdT7rhK1MS3MlSZ7/FjPDgdBIIlijM5vyk63X7sDS/8VooBDWg4zowrnbWIipS14WlRdIIhdI1dVgD6Fw54RlaedRjRTybqNbClSCN3vWOEjiZy2U9NJXcptovxBZ8KEbH6kxj5Qd+39u91KiioR8vgV31mnc6bA1OM0RxSYfF0F6A4gbBx97EK4PHx+qel3aC7S7MlDy12unFZ5Y5KC8Q= 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: List-Subscribe: List-Unsubscribe: On 4/2/25 23:40, Alexei Starovoitov wrote: > On Wed, Apr 2, 2025 at 1:56 PM Shakeel Butt wrote: >> >> On Tue, Apr 01, 2025 at 01:52:45PM -0700, Alexei Starovoitov wrote: >> > From: Alexei Starovoitov >> > >> > Partially revert commit 0aaddfb06882 ("locking/local_lock: Introduce localtry_lock_t"). >> > Remove localtry_*() helpers, since localtry_lock() name might >> > be misinterpreted as "try lock". >> > >> > Introduce local_trylock[_irqsave]() helpers that only work >> > with newly introduced local_trylock_t type. >> > Note that attempt to use local_trylock[_irqsave]() with local_lock_t >> > will cause compilation failure. >> > >> > Usage and behavior in !PREEMPT_RT: >> > >> > local_lock_t lock; // sizeof(lock) == 0 >> > local_lock(&lock); // preempt disable >> > local_lock_irqsave(&lock, ...); // irq save >> > if (local_trylock_irqsave(&lock, ...)) // compilation error >> > >> > local_trylock_t lock; // sizeof(lock) == 4 >> >> Is there a reason for this 'acquired' to be int? Can it be uint8_t? No >> need to change anything here but I plan to change it later to compact as >> much as possible within one (or two) cachline for memcg stocks. > > I don't see any issue. I can make it u8 right away. Are you planning to put the lock near other <64bit sized values in memcg stock? Otherwise it will be padded anyway? I hope it won't hurt the performance though, AFAIK at least sub-word atomics are much slower than using a full word. But we use only read/write once for acquired so hopefully it's fine? >> > local_lock(&lock); // preempt disable, acquired = 1 >> > local_lock_irqsave(&lock, ...); // irq save, acquired = 1 >> > if (local_trylock(&lock)) // if (!acquired) preempt disable >> > if (local_trylock_irqsave(&lock, ...)) // if (!acquired) irq save >> >> For above two ", acquired = 1" as well. > > I felt it would be too verbose and not accurate anyway, > since irq save will be done before the check. > It's a pseudo code. > But sure, I can add. > >> >> > >> > The existing local_lock_*() macros can be used either with >> > local_lock_t or local_trylock_t. >> > With local_trylock_t they set acquired = 1 while local_unlock_*() clears it. >> > >> > In !PREEMPT_RT local_lock_irqsave(local_lock_t *) disables interrupts >> > to protect critical section, but it doesn't prevent NMI, so the fully >> > reentrant code cannot use local_lock_irqsave(local_lock_t *) for >> > exclusive access. >> > >> > The local_lock_irqsave(local_trylock_t *) helper disables interrupts >> > and sets acquired=1, so local_trylock_irqsave(local_trylock_t *) from >> > NMI attempting to acquire the same lock will return false. >> > >> > In PREEMPT_RT local_lock_irqsave() maps to preemptible spin_lock(). >> > Map local_trylock_irqsave() to preemptible spin_trylock(). >> > When in hard IRQ or NMI return false right away, since >> > spin_trylock() is not safe due to explicit locking in the underneath >> > rt_spin_trylock() implementation. Removing this explicit locking and >> > attempting only "trylock" is undesired due to PI implications. >> > >> > The local_trylock() without _irqsave can be used to avoid the cost of >> > disabling/enabling interrupts by only disabling preemption, so >> > local_trylock() in an interrupt attempting to acquire the same >> > lock will return false. >> > >> > Note there is no need to use local_inc for acquired variable, >> > since it's a percpu variable with strict nesting scopes. >> > >> > Acked-by: Vlastimil Babka >> > Signed-off-by: Alexei Starovoitov >> >> Reviewed-by: Shakeel Butt > > Thanks!