Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp539264lql; Mon, 11 Mar 2024 09:47:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUL+x5w4YjHb0IWdOeoUG1emnqdWbZFaZxi9DqOvvCD9OvYTGSdkvpY7GoEDvps08tgbIybXGKapicEgFO34mqs7WfRHBiLfEAYKiTDvA== X-Google-Smtp-Source: AGHT+IFpvB78Ah3zckSwmqoVdr/ZZE53fPiAgOA7b019BsZ+RckK0HfZeJq0YZ62azM6OfMsRFTU X-Received: by 2002:a05:620a:1359:b0:788:2bcc:6c3d with SMTP id c25-20020a05620a135900b007882bcc6c3dmr7798234qkl.18.1710175656682; Mon, 11 Mar 2024 09:47:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710175656; cv=pass; d=google.com; s=arc-20160816; b=EYZvJMvEgX+KSHDGUV4q4Ez2tV+lMu/gLQM1CX6L4cJD4MkXo+VhayQHyL4KI2kozK 0FCO5iHdHTGVjLthUxl8DdkYCFkWYUqvi5XT1t+1P1GBuxbiZSAoWCNUxsgBZiU1fRCJ cq5fq0giIjdCQYFGzp5wQYaXBm4Upkzb1o5c5NApLtih/kTSMuKaijuoKg0sLahrOXeM OjT4U6f6QAb249W7/v3xd0qMWYVdRPrhkNXIw7bVXD5AKbAetPjTQUBF0KRZUa3tkkEE xHG8AVQesNibm27sc2uk0iXP4P8Um14k4r7N7Ktf/d7Y3jr8VtvIA+cYQP0KRpCQTtEk 35/A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=RZjnTg3rcm4xEs2wuMm2S2zMsfw/GRvQpvq6ZsCVNYQ=; fh=kQiLOTmmTYT/RnYbETsrCCUkzAGxYfMbAVQHF5Hzuqo=; b=QRk2QKu1GsUOPEIF5DVs+z4qdZRbzNVIHm1KVf52UFKaB/ti0l81Hw4s9Ma9m2n60E 5aPhIWY/PajHObuE+TlZVk+6fPC5ukBGCYh2PgheBzG7ab17S4fDU9HGH+qmAzN/igFQ B57FmsgnEnvA7991eNQTy9qx14FIPpUrWYOOPMlm1rBXcGfdt5oYhDy7x3MujtPcyAER KaDriH79f102sxs8ag3BYoSMzWStBrCnRfq1a2tt73yYgmduJ3upLlLTAykb5ForzVET 5sCsbtOWEhvds7Bh1vL7l5ad2+eGLpD4/FtMby5VFhVooOv9U0QAY3jnAHicAiInlE14 R1qQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=q9Di0cQF; arc=pass (i=1 spf=pass spfdomain=soleen.com dkim=pass dkdomain=soleen-com.20230601.gappssmtp.com dmarc=pass fromdomain=soleen.com); spf=pass (google.com: domain of linux-kernel+bounces-99261-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99261-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=soleen.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id u28-20020a05620a085c00b00788686e7a36si3521368qku.176.2024.03.11.09.47.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 09:47:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-99261-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=q9Di0cQF; arc=pass (i=1 spf=pass spfdomain=soleen.com dkim=pass dkdomain=soleen-com.20230601.gappssmtp.com dmarc=pass fromdomain=soleen.com); spf=pass (google.com: domain of linux-kernel+bounces-99261-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99261-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=soleen.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 5B3BE1C21B6D for ; Mon, 11 Mar 2024 16:47:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4D811535D5; Mon, 11 Mar 2024 16:46:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b="q9Di0cQF" Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C7B374AED1 for ; Mon, 11 Mar 2024 16:46:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710175610; cv=none; b=LEnwbILsB8zX69Fg933aDWUHEvtORoiRvO5lZgh0LBexKC8D5es0YTb77c6wy/yM6ZjibyBrjSY4RnDT9TxlWyBQBD1aEZCY0zfOJSIlrNNxjWCOonqTlPc9yfaGtQZxBC7rD3QS/CPBqMOm8sGDamoC4KJi5jf+RAFF2qQyDEU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710175610; c=relaxed/simple; bh=1rbaxunOVQPm7FPgRClladfLQq23xPc2MbtK28dseXQ=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VyzAAD1lS6sCJJnmxTk9sGNi2LEPCwGRxg3X/OXJ14DszkpFsYLW2FiU0kObGVksNAZF5ItxvbI0AqUo9DQbJUvrrHZRmZzATflur6M5MsLpTBHnRqgdiHwVqk/NXZTyro8gx0NwueXxaAplHuu8VrcUEG9M9ZCN4qpeSGe+EOs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com; spf=pass smtp.mailfrom=soleen.com; dkim=pass (2048-bit key) header.d=soleen-com.20230601.gappssmtp.com header.i=@soleen-com.20230601.gappssmtp.com header.b=q9Di0cQF; arc=none smtp.client-ip=209.85.222.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=soleen.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=soleen.com Received: by mail-qk1-f180.google.com with SMTP id af79cd13be357-7884114feb8so119905385a.1 for ; Mon, 11 Mar 2024 09:46:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1710175607; x=1710780407; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=RZjnTg3rcm4xEs2wuMm2S2zMsfw/GRvQpvq6ZsCVNYQ=; b=q9Di0cQFIiTo63gXIxSVQaGOI70w8l37/sKZzk4Af7Uh7nSl+Rx6ztOW/R2b0heH7K CxS9f6ldFRJRtXWZLXifv4jqSUEHtkY+yrVDognppkBJ6Zk17TWRDmdnvx+qUskpwo6O j6qBj1PLHtd2aWkvVwth14JPdOst4Q+LJAs/vtF1jkjueuuAL0xqkQD+hlXdUO5uH/PJ 4o6HmBjqeZ6bixvnWvKujRJszPjgzkyVaHscTs1WSFaWK5h1DbwIU7bpelCnOAHnIAB7 9iV0SSQRHNvVDFXIEWhK4HU1IXkVLDCw8IqjI6QxDuLokK7Y0OfY8vvHNM7xh52M18I0 2kew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710175607; x=1710780407; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RZjnTg3rcm4xEs2wuMm2S2zMsfw/GRvQpvq6ZsCVNYQ=; b=WdMnAFXOaR8Ac5pX6ByVpg3/AgcFWHfBi9JSUD4aWFOn5egrHvc2GeGVdwov/u1//+ 4yK864H1q5SVDOIG17L8hQXD60sc8KLyhrJrgvF6PxIeXGNApRkEAULF4e/OKkterVmd knDGO7ZhdjmFE6U5pPLGGjCx1lbwzDCiamxC7qjLhQZFdOvRHvzc4ZpV8PasK0PZtZWu H/HmtKRY824ruu57tWvCJJ+mnvkAucN0nXpSiHCrdZk72Jlp8THB+k6uBrB3pIyEV89w vHVcHl3/ybg2NMgHWpI9HQl97RcSf3tR7pcRp+qHgWhSHqjQs3PHKRrHOhZncfVTu9uq S+BA== X-Gm-Message-State: AOJu0YzzWcnUu8VVO3zzeziBLmfhG0J6uLE7djB5Ayn03K96FwaiF3jy JoP7EWMPhwijfOGuwuw+nLe30RTVku35IfIf3H4tNTJDxtWuzHbmYqW3kmaJzhA4TtHTHwv6WJ2 WkbY= X-Received: by 2002:a05:620a:3908:b0:788:7507:6e24 with SMTP id qr8-20020a05620a390800b0078875076e24mr1874945qkn.3.1710175607288; Mon, 11 Mar 2024 09:46:47 -0700 (PDT) Received: from soleen.c.googlers.com.com (150.254.86.34.bc.googleusercontent.com. [34.86.254.150]) by smtp.gmail.com with ESMTPSA id d27-20020a05620a137b00b00788228fbe05sm2851589qkl.17.2024.03.11.09.46.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 09:46:47 -0700 (PDT) From: Pasha Tatashin To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, x86@kernel.org, bp@alien8.de, brauner@kernel.org, bristot@redhat.com, bsegall@google.com, dave.hansen@linux.intel.com, dianders@chromium.org, dietmar.eggemann@arm.com, eric.devolder@oracle.com, hca@linux.ibm.com, hch@infradead.org, hpa@zytor.com, jacob.jun.pan@linux.intel.com, jgg@ziepe.ca, jpoimboe@kernel.org, jroedel@suse.de, juri.lelli@redhat.com, kent.overstreet@linux.dev, kinseyho@google.com, kirill.shutemov@linux.intel.com, lstoakes@gmail.com, luto@kernel.org, mgorman@suse.de, mic@digikod.net, michael.christie@oracle.com, mingo@redhat.com, mjguzik@gmail.com, mst@redhat.com, npiggin@gmail.com, peterz@infradead.org, pmladek@suse.com, rick.p.edgecombe@intel.com, rostedt@goodmis.org, surenb@google.com, tglx@linutronix.de, urezki@gmail.com, vincent.guittot@linaro.org, vschneid@redhat.com, pasha.tatashin@soleen.com Subject: [RFC 04/14] fork: Remove assumption that vm_area->nr_pages equals to THREAD_SIZE Date: Mon, 11 Mar 2024 16:46:28 +0000 Message-ID: <20240311164638.2015063-5-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog In-Reply-To: <20240311164638.2015063-1-pasha.tatashin@soleen.com> References: <20240311164638.2015063-1-pasha.tatashin@soleen.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit In many places number of pages in the stack is detremined via (THREAD_SIZE / PAGE_SIZE). There is also a BUG_ON() that ensures that (THREAD_SIZE / PAGE_SIZE) is indeed equals to vm_area->nr_pages. However, with dynamic stacks, the number of pages in vm_area will grow with stack, therefore, use vm_area->nr_pages to determine the actual number of pages allocated in stack. Signed-off-by: Pasha Tatashin --- kernel/fork.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/kernel/fork.c b/kernel/fork.c index 60e812825a7a..a35f4008afa0 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -243,13 +243,11 @@ static int free_vm_stack_cache(unsigned int cpu) static int memcg_charge_kernel_stack(struct vm_struct *vm) { - int i; - int ret; + int i, ret, nr_pages; int nr_charged = 0; - BUG_ON(vm->nr_pages != THREAD_SIZE / PAGE_SIZE); - - for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++) { + nr_pages = vm->nr_pages; + for (i = 0; i < nr_pages; i++) { ret = memcg_kmem_charge_page(vm->pages[i], GFP_KERNEL, 0); if (ret) goto err; @@ -531,9 +529,10 @@ static void account_kernel_stack(struct task_struct *tsk, int account) { if (IS_ENABLED(CONFIG_VMAP_STACK)) { struct vm_struct *vm = task_stack_vm_area(tsk); - int i; + int i, nr_pages; - for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++) + nr_pages = vm->nr_pages; + for (i = 0; i < nr_pages; i++) mod_lruvec_page_state(vm->pages[i], NR_KERNEL_STACK_KB, account * (PAGE_SIZE / 1024)); } else { @@ -551,10 +550,11 @@ void exit_task_stack_account(struct task_struct *tsk) if (IS_ENABLED(CONFIG_VMAP_STACK)) { struct vm_struct *vm; - int i; + int i, nr_pages; vm = task_stack_vm_area(tsk); - for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++) + nr_pages = vm->nr_pages; + for (i = 0; i < nr_pages; i++) memcg_kmem_uncharge_page(vm->pages[i], 0); } } -- 2.44.0.278.ge034bb2e1d-goog