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 AFCACD637A6 for ; Wed, 13 Nov 2024 18:41:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4AEB46B007B; Wed, 13 Nov 2024 13:41:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 45EBF6B0082; Wed, 13 Nov 2024 13:41:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 300606B0096; Wed, 13 Nov 2024 13:41:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1016B6B007B for ; Wed, 13 Nov 2024 13:41:13 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id ABBCD1A0D14 for ; Wed, 13 Nov 2024 18:41:12 +0000 (UTC) X-FDA: 82781938428.11.6DA0037 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf22.hostedemail.com (Postfix) with ESMTP id 899B2C0023 for ; Wed, 13 Nov 2024 18:40:16 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=fcK7xueT; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=RDWUaPX8; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=fcK7xueT; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=RDWUaPX8; dmarc=none; spf=pass (imf22.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731523207; a=rsa-sha256; cv=none; b=tvHlRKTyE3aYuPk+3CpJBtAhVYXzGKuP5gQi1rMvCX6daCMkN+qWMeoYEtU7N/J0Kuutd6 eA8Mvu7G3pVTtOJ2S4mrpg1yPdgD9KVgX9U9WXxGmkN4nL7kx9U5bkS0ke61aGfKOqL8m0 ndct2y0uERSAwc6xMwMWxhsZXoKC0Cc= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=fcK7xueT; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=RDWUaPX8; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=fcK7xueT; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=RDWUaPX8; dmarc=none; spf=pass (imf22.hostedemail.com: domain of vbabka@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1731523207; 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=8sUM0M8V19GhSGnm250+NhsypvBxJkhxWwffbG/Q0pg=; b=t8cs5Rd9UoLWi5DMfUmJJU4HvfpPC5aVrGM/Qqym2lWM1xAa3kYrvrX8txO0dtxUPk0VYt LjarIyVMKXncu7Wkg0MLCQaQTlp+GCwXk8zQ1MG6mQTGuuPnd2G6/g/t6wZZ+k6y4PcHo9 Lou+L1IbV/kIhAp4kI7hKm95ETQERZg= 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-out2.suse.de (Postfix) with ESMTPS id 8A30A1F395; Wed, 13 Nov 2024 18:41:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1731523268; 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=8sUM0M8V19GhSGnm250+NhsypvBxJkhxWwffbG/Q0pg=; b=fcK7xueTJ0PuKs90qHioaV8SFjsyS1jXkPgG5HYQhJw96gVskquKLeRY7AouPnGZavmrsN 6A8u731/DlZWdmbaHLEVKEXF8Uji6kOu7okB/he0y/AE0K8EJ/BKotqA0Oqrph2Kyxcu+/ GDvflev2fG96kuSLHAzAHD1HR6R0fPM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1731523268; 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=8sUM0M8V19GhSGnm250+NhsypvBxJkhxWwffbG/Q0pg=; b=RDWUaPX8u4XZ41JjLp3RxA2x1CXg0+3bqlW4ra9Drs8mSvnezJfrcETk31RcRboVWTjilk 809HjqOTE0dqDuCw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1731523268; 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=8sUM0M8V19GhSGnm250+NhsypvBxJkhxWwffbG/Q0pg=; b=fcK7xueTJ0PuKs90qHioaV8SFjsyS1jXkPgG5HYQhJw96gVskquKLeRY7AouPnGZavmrsN 6A8u731/DlZWdmbaHLEVKEXF8Uji6kOu7okB/he0y/AE0K8EJ/BKotqA0Oqrph2Kyxcu+/ GDvflev2fG96kuSLHAzAHD1HR6R0fPM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1731523268; 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=8sUM0M8V19GhSGnm250+NhsypvBxJkhxWwffbG/Q0pg=; b=RDWUaPX8u4XZ41JjLp3RxA2x1CXg0+3bqlW4ra9Drs8mSvnezJfrcETk31RcRboVWTjilk 809HjqOTE0dqDuCw== 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 67D7213A6E; Wed, 13 Nov 2024 18:41:08 +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 uV/zGMTyNGfXXgAAD6G6ig (envelope-from ); Wed, 13 Nov 2024 18:41:08 +0000 Message-ID: <82e15a21-c5ee-45a4-add6-fcb94c6fcc71@suse.cz> Date: Wed, 13 Nov 2024 19:41:08 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/1] sched/numa: Fix memory leak due to the overwritten vma->numab_state Content-Language: en-US To: Adrian Huang , raghavendra.kt@amd.com Cc: ahuang12@lenovo.com, akpm@linux-foundation.org, bsegall@google.com, dietmar.eggemann@arm.com, juri.lelli@redhat.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, mgorman@suse.de, mingo@redhat.com, peterz@infradead.org, rostedt@goodmis.org, sunjw10@lenovo.com, vincent.guittot@linaro.org, vschneid@redhat.com References: <1794be3c-358c-4cdc-a43d-a1f841d91ef7@amd.com> <20241111100809.20527-1-ahuang12@lenovo.com> From: Vlastimil Babka In-Reply-To: <20241111100809.20527-1-ahuang12@lenovo.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Queue-Id: 899B2C0023 X-Rspamd-Server: rspam11 X-Stat-Signature: 7c5mab5gn8okeiurgpj7cp7uihrftruh X-HE-Tag: 1731523216-113736 X-HE-Meta: U2FsdGVkX1+q36VPPxKnV9/2ikZmNe8iwdIb5c37fc0u/0MBPiOCLODZc14zpdEVW5SAXw9QMkIhY0EqUjWdZcPxMlKHrDgvsD3w2pgPpDFXr4QApwvU8XxIeDIFQhZaK/ryvKs19zU5XznJCA2dNBWV3xQfMhBb6D9XzUOlMHQkxY+3GLMC3bLGeDTayFPz9NFzqyzFCwnoDT7MqBGP34rO0PNKwFhbOia/UZGUkzEYmEYYw5HnCuuBWp9+MZy/OthOult7wv0t0+L3w6Q7J9F5Lh4wZB+PTnLLCSN9dGDGfCEeCvMnasMhUIoLrAJIGT7KTOfpNa3zWEDjM84bldaAQkYng0qn06WmymgRmlEP8/jMxfazObNxK8wMnRtfDxV3msrJ/AF9xE9zo4l4S/DWNAXE0fODSjabVfcRI5Ga+1sej6zF4y0lTGZZTBWCNXXeletNEUKhjIXQbslePTTDniiVZ6JikUokn9Jqn7FZ7heen0+YidFP9F+S8mT0oO6/lS48FkArSRbzrbcuX7bjetqUeCj2m2ub/OctchUn1T2xk9cQtgtwZWTADgRjRcA7EIbiM1rFPDinkK6YsvOuNXndlOpYjz9LxM8ed6BaJmIoa3XcomeFZlavF4LGSen2HxzUoZhPRpe3dQqvj8LFBJMT4wA6HwiZNfqjCrjzTMU9fHKcdPraeIhTKvTXupEywgsNRyrjUy6KKSYu9lHnuRaroHs2ulGMTdy5Nvgv2+UGBa6i49hjW/tdQbpiJtoS85XSG9Ubeg0r26Qpn1T/I16B2IIH8CyosFZJ9Eg1NIMFvKL4a97NCXFbOjzT/vJmFFIZFroCfUxVR/7GZecZWyAPGrKsKvOn/MxTQb44wr2elo1X1CHMt3mOQRhRt2T4YRwWS3n4DSOFe0VY6NW0myBtF+VQjOIznRnhTNI4QM9oM63pQV90kaRx/vJWr59FaAgYVUsbqmeZe0n 11dLbVYN U4WQDaFYkuUfbJBE5/6oKgQNbS7nVL1xPU9UqL12+8HNuSzqd0ZpIHv1LYYhAA0yxdynU0PhgA9E5O8I+DAnL0OHUWczdH5GYbx5z1t4v2ejsyod+XPH3zP7Uhe4+ZP+bJNmbKLVTEvEJHDqoPAk+iDfYLID/FuFQBjfiocLITojfsmD4XgW8O+gv13PlUtftLWbjitwtWIoOYAZOY5EIRdcntOZQ//CHhuhewQDuknqSe5aZQIlrM1G6d/E/6ryLYZXFbYoeCDMKHpzPqJekB86CpwyMlDTwZkBAQrgJsB49e+IRVBtKQP742AvacjxzSKx0nUQak1qU4mXZopruh7JYCw== 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 11/11/24 11:08, Adrian Huang wrote: > >>However since there are 800 threads, I see there might be an opportunity >>for another thread to enter in the next 'numa_scan_period' while >>we have not gotten till numab_state allocation. >> >>There should be simpler ways to overcome like Vlastimil already pointed >>in the other thread, and having lock is an overkill. >> >>for e.g., >>numab_state = kzalloc(..) >> >>if we see that some other thread able to successfully assign >>vma->numab_state with their allocation (with cmpxchg), simply >>free your allocation. >> >>Can you please check if my understanding is correct? > > Thanks for Vlastimil's and Raghu's reviews and comments. > > Yes, your understanding is correct. Before submitting this patch, > I had two internal proposals: lock and cmpxchg. Here is the my cmpxchg > version (Test passed). If you're ok with this cmpxchg version, may I have > your reviewed-by? I'll send a v2 then. Yeah much better, thanks! Reviewed-by: Vlastimil Babka > --- > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 3356315d7e64..7f99df294583 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -3399,10 +3399,16 @@ static void task_numa_work(struct callback_head *work) > > /* Initialise new per-VMA NUMAB state. */ > if (!vma->numab_state) { > - vma->numab_state = kzalloc(sizeof(struct vma_numab_state), > - GFP_KERNEL); > - if (!vma->numab_state) > + struct vma_numab_state *ptr; > + > + ptr = kzalloc(sizeof(*ptr), GFP_KERNEL); > + if (!ptr) > + continue; > + > + if (cmpxchg(&vma->numab_state, NULL, ptr)) { > + kfree(ptr); > continue; > + } > > vma->numab_state->start_scan_seq = mm->numa_scan_seq; > >