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 B25D6C3ABBC for ; Tue, 6 May 2025 18:05:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 579DB6B000A; Tue, 6 May 2025 14:05:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5022F6B0082; Tue, 6 May 2025 14:05:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A4226B0085; Tue, 6 May 2025 14:05:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 166B06B000A for ; Tue, 6 May 2025 14:05:34 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 86FFD805E5 for ; Tue, 6 May 2025 18:05:35 +0000 (UTC) X-FDA: 83413260630.30.F803D57 Received: from out-182.mta1.migadu.com (out-182.mta1.migadu.com [95.215.58.182]) by imf07.hostedemail.com (Postfix) with ESMTP id 810E340005 for ; Tue, 6 May 2025 18:05:33 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=gkfsChz4; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf07.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.182 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1746554733; a=rsa-sha256; cv=none; b=17om04D9x+7vITAeERXCGw1mVZTCoA3m+ODfE2kx8j3k593H9wuq8ZPHugPKThiqVJq0Qo 3Q32YNJ5kRW3DEXz/t+dia3ouu0/p7VYqoEBS9llSZ2C+3yCeILfS2r+k/Qwcs4rjM9ckN 1RHuQbIvpY2qYGbPQ0YnOdrszdECh3w= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=gkfsChz4; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf07.hostedemail.com: domain of shakeel.butt@linux.dev designates 95.215.58.182 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1746554733; 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=8WXuUeFYcJkDDXEdT17Uj8ovL8NdXcFWCwoHDW6hsVg=; b=4hvJBMrmlqtsVN9fDny9iw2l5mWqx+MMfJy6/PcG2225oRltCZFxnQ0cRRpYlV5tEshfvc UnUNXXB+NIDbtxyD+9PCepcHlWUjmApM59JypVbHgJ5Uz4M8FsZ2d+LF4juNkc3j6V2xkd Ybs9CNk3rs+f6CV43wYl6usto8NIjMQ= Date: Tue, 6 May 2025 11:05:23 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1746554731; 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=8WXuUeFYcJkDDXEdT17Uj8ovL8NdXcFWCwoHDW6hsVg=; b=gkfsChz47hWo4rBNxGAPUQZQBuSRf7SWb6Fnn4uuOmiv7Devgy0Dg8vFxQM94kDBocO8i6 fVFxfkjQwh5VlBn+M1TPnwBNCE043auZxyzrPb8lw7dV87YYNhQ7PFeBTBVCNXbuV9K2iQ bwxHA76yB8kck5hxZGuNa2aS7JNrs34= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Alexei Starovoitov Cc: bpf , linux-mm , Vlastimil Babka , Harry Yoo , Michal Hocko , Sebastian Sewior , Andrii Nakryiko , Kumar Kartikeya Dwivedi , Andrew Morton , Peter Zijlstra , Steven Rostedt , Johannes Weiner , Matthew Wilcox Subject: Re: [PATCH 6/6] slab: Introduce kmalloc_nolock() and kfree_nolock(). Message-ID: <4j5rqzw5lulawbggh22e5b2enqgvwhmuwvw2hljcj6fxngnbt7@6hbeyck7255g> References: <20250501032718.65476-1-alexei.starovoitov@gmail.com> <20250501032718.65476-7-alexei.starovoitov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 810E340005 X-Stat-Signature: w571r5ptjs3694usz4utfhepc7is8atk X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1746554733-931411 X-HE-Meta: U2FsdGVkX1+9EsYdjFWQxLB+ZyAbXC0C9dRPaz6MusNA8/UaSovCfGuWSp2uKjW3hel8wYD6K+HKzUV+cIoUjjOgizscPGOwF5XaAkDaxORAp8l9pnWNcZvuZqEDxU9H3Vq3tCg0GdA82dMlbjQx6NfCHR3g2saH9LwJQY31xsoZqUTD7cFvz4cf3wIpmtkc6bNPkUc0UzrTHv3b0t1YepHC2fXhptccMO4et0KHhK9u1bqPeubAmVFa4bmwhbOpfYBuE51mNLY6y5IIpj19fHw5VnnP2NvVECAc9eCB/9LCsz7dn+jbwwt2Ppc19DFKHLNY/ZAXfVfnYmzrctJIwn4ZZEmGaLhRrEO07ZhyyToR0QbiEaal7zISZV+jYIbsqu0G3r/moVw10C4BRM5vKVwwNR6jISqx7U2TCM2uFaHwmvY6mBpJ6OEqZS33u0+b3WJJwucsYRJxXFCXHqvuL2ERqQDvTOCzNA9+sDJCBps79THu7velU+h+Z5+cbB7AJC4r5AEQHEdxCeWi2vDapyNJ/6tX/tStg4RDcj826M342de+6PRT5zava8wACZ86tCeSBruEn24fh6jVEBrVXHGk+MxRzvgcbrPWCxQTIkxI9pnpjl26LzCzhrHvV9i127wZifqZQQs9/OHnR84FDUcS0VYDhN1cdTjn9nbFhQZ2vQDin5oIAfkRR+v4UK1wcRqyZhbbyJHWmaqmnVSSRmjZBdpdQvGuSgWsniSCWtBari5H0jzF1o8LGOpFi6DN4pwzfd/0bf11mfQ+Ql7cgjrETVHAERdulV/FVWceFvaE++xlZgQJZllciob6Wc3POMU+gD9Myerul4cJSz3om4WFe+AcqnJO31IXly/6773l4s3lqgccYc7YE2S+fz3kjUQTnBUHJBaljQV/nRTbrKniCuNQW5I0L2pT5zmMt44c3rJW+cyVhWBoRo4fXfFpqgr/g8DeFzHsU5LcHQg VpKtyj+J LDqS19dX1F2okVApQV8TzL4AMT7tmSHlSDH6cK0/1x4xFVwG9i59e7eSKyj7opHuuA3FZB25azVAzTpeqoBBSiYCORku9UgE0RH2AsiiqtRdSUcRxrsAE5AdhTMqXg7sSsOfa2w+S2ppef0+2V6NkTQjx1ZFqQhrOSN2EkY7vjDHtaDMFexk6pfPeKICkiypS+RtsLTpDhVzN/bjEtUZxk4TokNxkMg9i2MZZw2jklsi1IhR+Sn63wRV8wghk3iq+dqn8vR+ElHLP02aXbRzRfDhtjWvxYBs3pRyt0FnFj0JNY7433aGh6yhxtyywgrztNvPE 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 Mon, May 05, 2025 at 06:51:28PM -0700, Alexei Starovoitov wrote: > On Mon, May 5, 2025 at 6:25 PM Shakeel Butt wrote: > > > > > > > obj_exts[off].objcg = NULL; > > > > > - refill_obj_stock(objcg, obj_size, true, -obj_size, > > > > > - slab_pgdat(slab), cache_vmstat_idx(s)); > > > > > + if (unlikely(lock_held)) { > > > > > + atomic_add(obj_size, &objcg->nr_charged_bytes); > > > > > > > > objcg->nr_charged_bytes is stats ignorant and the relevant stats need to > > > > be updated before putting stuff into it. > > > > > > I'm not following. > > > It's functionally equivalent to refill_obj_stock() without > > > __account_obj_stock(). > > > And the stats are not ignored. > > > The next __memcg_slab_free_hook() from good context will update > > > them. It's only a tiny delay in update. > > > I don't see why it's an issue. > > > > For the slab object of size obj_size which is being freed here, we need > > to update NR_SLAB_RECLAIMABLE_B or NR_SLAB_UNRECLAIMABLE_B stat for the > > corresponding objcg by the amount of obj_size. If we don't call > > __account_obj_stock() here we will loose the context and information to > > update these stats later. > > Lose context? > pgdat has to match objcg, so I don't think we lose anything. > Later refill_obj_stock() will take objcg->nr_charged_bytes and > apply to appropriate NR_SLAB_[UN]RECLAIMABLE_B. refill_obj_stock() will not apply objcg->nr_charged_bytes to NR_SLAB_[UN]RECLAIMABLE_B. This is confusing because per-cpu objcg stock has two distinct functions i.e. (1) byte level charge cache and (2) slab stats cache, though both of them happen to share objcg (this will change when I add multi-objcg support). Let me explain this with an example. Let's say in the task context, Job-A frees a charged slab object on CPU-i and also assume CPU-i's memcg_stock has Job-A's objcg cached. Next let's assume while CPU-i was in refill_obj_stock(), it got interrupted by a nmi and within nmi there is a slab object charged to Job-B got freed. In the above scenario and with this patch, the kernel will put the obj_size of the Job-B's freed slab object to Job-B's objcg->nr_charged_bytes and just return. Please note that CPU-i still has Job-A's objcg (charge and stats) cached. When CPU-i's memcg_stock get drained later, it will update stats of Job-A which were cached on it. We have lost the stat updates for Job-B's freed slab object.