Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6717583rdb; Tue, 2 Jan 2024 10:49:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IEPyaWiUp3pAEpvYXBf8krw0tGP6ShX8IFAnKdhFegbV0HW2cOR3EOE6vcdmcEn/OZkqVq0 X-Received: by 2002:a05:600c:2287:b0:40c:6d4b:2f98 with SMTP id 7-20020a05600c228700b0040c6d4b2f98mr8840087wmf.91.1704221366679; Tue, 02 Jan 2024 10:49:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704221366; cv=none; d=google.com; s=arc-20160816; b=Qm/pcXp2uIqwFDiwQmOiP7hpPfKpqx4o59NXIiQWiClFBOAgVIOsYnOctqFj6LLdqB OqBfb5uLz4g9VN/zwbTtNwoVourr4sf5XUdJzGrd/JCEqGqkExNVaywe5xvsWMLzY7W8 /HfUlaebUQBtHdU+3VRWkmYx+EXnZGcLAcBnRDE3sdZ+OI0Wq37wf3d55DbV9d6V8P7K boR4qNJ/gtp1Qq5PqfRw7S79xBeTC29JgOIuHolhiLeb5tGQGVRQCWltOfMH1qIJltVD r/bIQ1/bQMrq56uZzWdSRwfIalw0DXE/4d6sn/ZnB/lNXyKoQdOEpP625ldx70M9Opfx 4ywQ== ARC-Message-Signature: i=1; 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:cc:to:from:dkim-signature; bh=s9/T5K2ir2OJL/EqmsqvZQ3IpaLcsXDlXwLSIHXyRwY=; fh=cf1wzNgv8Y9vv687wGuXRY2VMl5yvitPBABc44jVg4s=; b=XknnTGMEahip7v23mlB8lBsN/fEC4m6Il05fjjGLjuk6tD+lujv/G0A5UgrTDMxQBK h+WdpJibWr7RhV9xESO/IZmQAQbSlc6MeJPLu2tLtimcTPh83SVLZSk9LXNQeI5wNPSp TN+YLJgmYPlM3ofDH6BX5yQvwm/Y6A0DB4FRkSsrruOA6lhpZZINBpOHBsYgMPM7dtPu VCFh6UUAlaqz9iE6t8saprMQmX7TlhsyrOP+shXR1pXE9xoJmfd7+y7K62jYx+8cr3wO qSwPbRuF+NMrspUdodP1OMG9ErTmPnuQ9/umWrveXxNC+QVpTab3cNA5ZgR6Qrwr99Gy FjMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=QqyNJBaF; spf=pass (google.com: domain of linux-kernel+bounces-14742-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14742-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id gv10-20020a170906f10a00b00a1d1b8a0886si10813018ejb.822.2024.01.02.10.49.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 10:49:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14742-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=QqyNJBaF; spf=pass (google.com: domain of linux-kernel+bounces-14742-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14742-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 5717C1F22F42 for ; Tue, 2 Jan 2024 18:49:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E409B179A6; Tue, 2 Jan 2024 18:47:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QqyNJBaF" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-lf1-f42.google.com (mail-lf1-f42.google.com [209.85.167.42]) (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 9FB861772F for ; Tue, 2 Jan 2024 18:47:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f42.google.com with SMTP id 2adb3069b0e04-50e7be1c65dso6281129e87.3 for ; Tue, 02 Jan 2024 10:47:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704221238; x=1704826038; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=s9/T5K2ir2OJL/EqmsqvZQ3IpaLcsXDlXwLSIHXyRwY=; b=QqyNJBaF17QA4zJWhIzv8GdhcGwy4f1bXtAZCGdk6P7kYdAqHjznYBUttM5nINPnlV GKP1dQVag6KVzs8rClS3ibWcFkC3rGcDaY0TiylGhmIZ9m/4jTN5E3IA94/RQRBGPTwQ e4+q9qSauuA2k6oQf2ZyO750QcK53xwVq2rpf1BzGEUDkJMVHLtFA9xhQmJmKe5AIUha MbHQ8x+yLbXUBZtYFi6tr9/D1wDtFhWrC0lTLiDu5aLD7oeeJqRyB7L+CxvcWMKMNNit xnHuDZjlawjvFqPu6fldmU0o4GNjHjerZUWFrpJJ0d7kCAZhPvHXtH5gmLoGIocDc3Sx wV2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704221238; x=1704826038; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s9/T5K2ir2OJL/EqmsqvZQ3IpaLcsXDlXwLSIHXyRwY=; b=eL9X3sdiw+2PRaxxiga9v6t8jBAcD23Mw1NuYPegMLI8E0pRZ7XPTIqvyoTwUG5exv r615S7va/GgYLvaEs6TCnGtvmEABmnKE8mVyewDXhyGUpKMbPRb+Ta8OwVhu1+fiehW+ oVH/TnBU1ca7uzfBjC8/jl3k56gzO/xKUDnuG1eu6IxkFtEbB4Y/36bn+aow00jmFnPv cpLAo/REq3qKgWpYnoTeUQAMN05N4jl+IFv5Ya90EdpLULbra1OC/bB5sm0Za8YOepBd j1AcrPagFgQwXWVDWqI6tluHVnlmtTBcUb3UTVNK4eJLOsWJM7tiEPoNpe6YBqe0GcJL 2CfQ== X-Gm-Message-State: AOJu0Yz13Es96AYP+CdVEqSmQc6P6VsfFLABt/0qZzSOoZiXi2AQy2qj JgFRgVMddKkMeAI9X0fQqwQ= X-Received: by 2002:ac2:5fae:0:b0:50e:5f99:21f2 with SMTP id s14-20020ac25fae000000b0050e5f9921f2mr6671072lfe.37.1704221237681; Tue, 02 Jan 2024 10:47:17 -0800 (PST) Received: from pc638.lan (host-185-121-47-193.sydskane.nu. [185.121.47.193]) by smtp.gmail.com with ESMTPSA id q1-20020ac246e1000000b0050e7be886d9sm2592656lfo.56.2024.01.02.10.47.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 10:47:17 -0800 (PST) From: "Uladzislau Rezki (Sony)" To: linux-mm@kvack.org, Andrew Morton Cc: LKML , Baoquan He , Lorenzo Stoakes , Christoph Hellwig , Matthew Wilcox , "Liam R . Howlett" , Dave Chinner , "Paul E . McKenney" , Joel Fernandes , Uladzislau Rezki , Oleksiy Avramchenko Subject: [PATCH v3 11/11] mm: vmalloc: Add a shrinker to drain vmap pools Date: Tue, 2 Jan 2024 19:46:33 +0100 Message-Id: <20240102184633.748113-12-urezki@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240102184633.748113-1-urezki@gmail.com> References: <20240102184633.748113-1-urezki@gmail.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 The added shrinker is used to return back current cached VAs into a global vmap space, when a system enters into a low memory mode. Signed-off-by: Uladzislau Rezki (Sony) --- mm/vmalloc.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index ef534c76daef..e30dabf68263 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -4917,8 +4917,37 @@ static void vmap_init_nodes(void) } } +static unsigned long +vmap_node_shrink_count(struct shrinker *shrink, struct shrink_control *sc) +{ + unsigned long count; + struct vmap_node *vn; + int i, j; + + for (count = 0, i = 0; i < nr_vmap_nodes; i++) { + vn = &vmap_nodes[i]; + + for (j = 0; j < MAX_VA_SIZE_PAGES; j++) + count += READ_ONCE(vn->pool[j].len); + } + + return count ? count : SHRINK_EMPTY; +} + +static unsigned long +vmap_node_shrink_scan(struct shrinker *shrink, struct shrink_control *sc) +{ + int i; + + for (i = 0; i < nr_vmap_nodes; i++) + decay_va_pool_node(&vmap_nodes[i], true); + + return SHRINK_STOP; +} + void __init vmalloc_init(void) { + struct shrinker *vmap_node_shrinker; struct vmap_area *va; struct vmap_node *vn; struct vm_struct *tmp; @@ -4966,4 +4995,14 @@ void __init vmalloc_init(void) */ vmap_init_free_space(); vmap_initialized = true; + + vmap_node_shrinker = shrinker_alloc(0, "vmap-node"); + if (!vmap_node_shrinker) { + pr_err("Failed to allocate vmap-node shrinker!\n"); + return; + } + + vmap_node_shrinker->count_objects = vmap_node_shrink_count; + vmap_node_shrinker->scan_objects = vmap_node_shrink_scan; + shrinker_register(vmap_node_shrinker); } -- 2.39.2