From patchwork Mon Mar 11 16:46:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13589079 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 8459BC54E58 for ; Mon, 11 Mar 2024 16:46:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A50836B00CD; Mon, 11 Mar 2024 12:46:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9AFB06B00CE; Mon, 11 Mar 2024 12:46:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 805B46B00CF; Mon, 11 Mar 2024 12:46:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 5CD966B00CD for ; Mon, 11 Mar 2024 12:46:50 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 2641BA01C3 for ; Mon, 11 Mar 2024 16:46:50 +0000 (UTC) X-FDA: 81885337380.23.2691252 Received: from mail-qk1-f178.google.com (mail-qk1-f178.google.com [209.85.222.178]) by imf06.hostedemail.com (Postfix) with ESMTP id 59AC2180003 for ; Mon, 11 Mar 2024 16:46:48 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=FL5czDVs; spf=pass (imf06.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.178 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710175608; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=RZjnTg3rcm4xEs2wuMm2S2zMsfw/GRvQpvq6ZsCVNYQ=; b=y8SAY9R6pvb0KNUFsKRFSKybAVHJn3+nCATPHu39H7mDy4qhMd2mLxCjNn9tMf2YhixCp9 K5zSTns58VxXx5i4jUudSSLj/nzh3S0fV8yL2prWGFZm11lo6VVY/gLUdoYelUJWzlJiho HLibseHv69yWTJIkCOtzONK1jPIwzjM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710175608; a=rsa-sha256; cv=none; b=I6Lgx7bqsyqu6k7NcOGk66XNTGz2+mLcLVs9OwOKM5kGM5rr/coD73R41VdQ0yging84aC 2nNKkOtli8ZD0gjePANlRxOk/zZ2C9bINUC3KsQ8aiyr3Rvh05n162niP1Mc6WwCZQo8Xo 3Ez6zA3ICKi+X9mltYIqDlZNvF+wLCk= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=FL5czDVs; spf=pass (imf06.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.178 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com Received: by mail-qk1-f178.google.com with SMTP id af79cd13be357-78830bba6a4so170786185a.0 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=kvack.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=FL5czDVscOELNA/+Bv28b8RW5JwhsYtggNhJely3918ZZ3L2XPNzFq7WbFnxXH5oik xPuj5kGTRffTHiDLwNI+WzpTv3CF9w9aKq6Rc/z+jBJrTx5bTx1wzUGL1mnZh47rq4/4 JNHp2/epffrRDUfoM00YGvYuLxJBglZzG346Xm6hIj2yvojPY3cpb5uXXwyeenjR2rOI Pm0dz36iES5d+qnh+j6jbCqLXTcY8dZME6zqyCXkJxB6RPqsXVNUM38Mgsglq8qjlsch RqCzukjHI0APDF76OKOwvDmHFiCA4Uugu46boIKdvemBIRAdV4b8KX/M6FkGwx76fKOX eoQQ== 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=pUSOLPAo5rBJO5aslTAUqpQnq7HGt4gjxElfBZixx/fzLMtDCM7EhG+nb5WHmrg9HQ +vPRTlOplGIz2QJIcULP42Io2aG/SDIbCDkcSKFEiyQBKtORb7Y2ninXWCUAPDTbXK7K oG54qe2xFI/3G1Eb1jge6w1j50T72mOxNswQBzW+v+zdk9vkWev+xR9tok2lD4iWfnpQ lvSUlIBbrMK2nVLa572nhhpaX7InCKwQWM/JhU7VpK3aReFk7rSzorNcAZLbzMYj7fqu m95tWbDLpbBdcghU64wh/pg4szuTL8AJXouvbBaXoTmL0OX9uvMvcLwX8pXuPXLDfId4 +kTQ== X-Forwarded-Encrypted: i=1; AJvYcCV2iT2Cu77TqjrwxZDk3utUiDa/fsYoa2tTKcSBAGqyqXHsXfL5j+sNBChX/TUkzJL5OGWdmRwDDyp3OseYRNk1P4o= X-Gm-Message-State: AOJu0YxoVe0sXxPD5DSae9apEgPdRSNbxfFCgZF/2TmetuMGdM6Tj172 Yv1EQRhYPsu089KpR65ghRU5oPC7HQ2ogBTiPqNqD0TOkQDSCvQi3tG8wE4gwqE= X-Google-Smtp-Source: AGHT+IGK3ZkaISv7/cXUwYINZRSYzKZD81aDWnU5gX/aNi31ERoz+HAdpfJ4DupGmG/DqWHaLyf2Ag== 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> MIME-Version: 1.0 X-Stat-Signature: jzpq4p9okz4s4ec4sej39hj8z6sg5snx X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 59AC2180003 X-Rspam-User: X-HE-Tag: 1710175608-379542 X-HE-Meta: U2FsdGVkX1+tn8l+p8Ivg267MFLwLXz3kNUGb9hy5sI3EHWC0unmVMh4zZu/mmNIf0PXGH75hrXKZkTU+W2oJixC8FGcLW4LSa5SQWPHRankBqFhPsFWz/4upqrukPtVMnNrs2z1rVtn9YMEQkizu1sWcTEN1kW1WSGm5CSB3sxkmvs5hk/zkYPOckDFX1VZB33dLshd0Dm6ZDOFzXVNq/kT/QepdvYvZXTSwUFBbyTtECR1GGu93Dn4rT+VxIF1JTlAxipf38FXFAnAK+lCLqOBucZH2Ru6MVARr+VKA6r95G2HPxoyjdJc+zvcs7SsaZa3+ml3lvl/QGDSMdgM230Ao/O5MudspwkXyQllM3RRSuZNk8SUKnGG56aM3+8kVkwuCog6YG6UByFK1y1OXMppKu+0tcc6hbObTLgdKH8gHwiavalEJkrwzXfspG6g8AFA66nWgLarwcMmPlyPPVjMelV1nGa9Gv4XzpIC1ZmWQ6BmQ4J0ibNJhQXzgaHRu61QDnBVpyN+APB77ZqNNGqjzu0RovCBpqQIsE9y/HsznUQ0GvhdFjPVVPL5eczzCPVjS7IEGkemzKDCN1n7TuJj/UpsmeKrQ4Dutdnd0uKAqAMITyPyVh+8QxYT0uwN+d2iJjJrLZsa2MDVCOws4fFBo4L6TSdj5mZIQMhHimE6Aqk7TOCTfLrz9g5sVLaPZiBtd2prF8JlD/lbLnpiY+sYkgN+oXtzprbg7wDdYolImUC7dhPxm3/cWq3CwtCfRSlZ+Wmpbg6vNjsgBf1aiZSfg9CiMZtTryBQF5PAyDrJi8kyzDVxnY1G/LLTSGZwU7dlfzS6kz/aQRr5CgLKeYoBQAal6vdmd/FBT2DXIJ+hNCwRPlQGGaZSjfAQFcCiCFThI4a8+uDURoWKLfPhPUB8yU3WpOMhdJAEMLx+rONkv6xngdnQG/LiUdEIqQBKWfqy2GsnSfN2DuXEMxV pHxVIHYC nibzuRpHPeGQAkF4KvXRMLKlMHOV+zPTUel0Iho/PoMGhDN7nkFzK0EHJvF0LOvQ84hEynhaz1AN6uFIiYR4TD2jwngfZnjPk8INhENpLTUIDfpBsG/eZM/HC3a69g4T7Jh+u847NJfGkFTlTQ/fEtsTyZuw3hCYwm2bfSrUpnPXVWufRFlCJDoglONj58WHrFcH6/K4mPH4V6sQb+KAoqtMjxe5aiMD7RCNRzatHYTnWQkIJhmw2Q1P9DSGMuTboplAlFNE00MvaCej3QWzNoCj5cWGc04IsylLma+sxR8k2XBYf2ZrF4IBTFad/3OpPsGZ2FyH4HXiZLI6dK3vP6zz8K8GKES/oHwyrLWxYtD/MZoL7niukGPhuXcHUi50uheKMlBjvUbU7Rij5djqhXE9D37lR6g92xi4GU3iVkBj8+2x+0AS+W+Sz0UYWvFV+k4P7zo3IJ1jy4zlr2PttazxQJx+kj2PTvntHH1sl4E67n82EOdQhYe0JIW4IrMT7ayh1 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: 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); } }