From patchwork Tue Nov 8 19:32:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 13036776 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 6BEFAC43217 for ; Tue, 8 Nov 2022 19:32:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4DC508E0006; Tue, 8 Nov 2022 14:32:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 415F68E0001; Tue, 8 Nov 2022 14:32:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2B57D8E0006; Tue, 8 Nov 2022 14:32:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 146EE8E0001 for ; Tue, 8 Nov 2022 14:32:15 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A3D85C0938 for ; Tue, 8 Nov 2022 19:32:14 +0000 (UTC) X-FDA: 80111270988.16.E604F25 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) by imf25.hostedemail.com (Postfix) with ESMTP id 48318A0004 for ; Tue, 8 Nov 2022 19:32:14 +0000 (UTC) Received: by mail-pg1-f177.google.com with SMTP id b62so14279304pgc.0 for ; Tue, 08 Nov 2022 11:32:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=NcRGiok93yrAI7cvzhwIp5D29F3AFI0/ULm3Nt1q2VU=; b=fqWVAbjdw/fNyqUE/etLKdBoXVwrp6pKlcFnwPGKLcOfZBud1HZCf6BK53gHrYdV4g IGtamwQbgzqDFuKM78ggN/XUx84npKmZFw7VBbsZ9GFU4jvRffJ7QeuBgCY26lk/XZfJ Fo0/BYnSR0oQQHgW7jb+qeC2N6tS06hg+ewVnR12TCYRT2I2Eon1Q03flOwqrDoZx7C1 0KDKAtbrovbnna4a5n5LUYeCM48kjQQceWfwPa/IuPCChs6JWTSuWBLITjyRGa5wBu0V Q0VJr/FlETrNwTiE0In3eUtKGNy2RX9SPuh38w4ZsTDemlolYpXZVDVjeZbQw4BLUMp1 f8rA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=NcRGiok93yrAI7cvzhwIp5D29F3AFI0/ULm3Nt1q2VU=; b=liIrHCxtqMdUV1toUy9VLhjHQ7jTONIRel55uxyRz9zWQ7gniMDmLOv/sNBvtwEib4 LirasY2sg9EVeyMBHLAYOotyloDHHP0Zrqe117t6xwvX0OedFRCbmSFNxVTasymvgqEs GyfMXc+nQVC2EW2NhA4BrNjZF114qY9owOXSxms1OdRzZ7BAV1Yq+o4Y5fhCLGhAaPBE nxuaenJgssL0rCRg2ONoYj5CTBGJBKzEwUfU6TqnEKMTVcbXCgOoU5k2AtfFK4LlCjhU QMa5fIE7PGVIcq6NKohSiykNqc0A16mrzheGrlb17kg76hQXn0rsgyJF92NCJTR9nRKp KVEg== X-Gm-Message-State: ANoB5pmpqznEQLEzO5K/KKKRWXRINZwkBwnTcUzV+18TB0lTuEO7tINC fp1Kumx4vIB9GCilcFheYd239oRCz2Q1aw== X-Google-Smtp-Source: AA0mqf6iiFu5zDZOHd3n6s6iM4xfMmMFKoWMGjMEb6APqnthOimT7tHF15pQHafzLwYbBJRleC1A4w== X-Received: by 2002:a05:6a00:1689:b0:56e:d7f4:3aca with SMTP id k9-20020a056a00168900b0056ed7f43acamr18175224pfc.55.1667935933322; Tue, 08 Nov 2022 11:32:13 -0800 (PST) Received: from localhost (fwdproxy-prn-002.fbsv.net. [2a03:2880:ff:2::face:b00c]) by smtp.gmail.com with ESMTPSA id j21-20020a170902c3d500b00186c9d17af2sm7336166plj.17.2022.11.08.11.32.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 11:32:12 -0800 (PST) From: Nhat Pham To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, minchan@kernel.org, ngupta@vflare.org, senozhatsky@chromium.org, sjenning@redhat.com, ddstreet@ieee.org, vitaly.wool@konsulko.com Subject: [PATCH v3 4/5] zsmalloc: Add ops fields to zs_pool to store evict handlers Date: Tue, 8 Nov 2022 11:32:06 -0800 Message-Id: <20221108193207.3297327-5-nphamcs@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221108193207.3297327-1-nphamcs@gmail.com> References: <20221108193207.3297327-1-nphamcs@gmail.com> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=fqWVAbjd; spf=pass (imf25.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.215.177 as permitted sender) smtp.mailfrom=nphamcs@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667935934; a=rsa-sha256; cv=none; b=4WF5OPYmPszuNM6d0VtYHXzJbYfRJYAAdo0C5kHqjGdY53/vLO157oFroqWL/Tm28CpVCn eZ7pGG1euzi9NENmcjy8V5V99YNe5tD1BpGW4+KeUMlCafBvT+W+A608I29MKN+tvYt5U3 aV8VdOHLDVH3rBeR33OsToe80zyhbqU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667935934; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NcRGiok93yrAI7cvzhwIp5D29F3AFI0/ULm3Nt1q2VU=; b=L3U9SQ8pzCUJsv9pD1NrNj/Kbu/OdIp0qbIrtngUx0RB2ZHGvee/XkawynvbJ26vR2vwDF rXOR4CFsiyby4HfMZiuVCwuo/1b2EQx8dJpYTdTcccd5yb8tuEki8ckv2iVX6aHWA8Dcr1 GBu8m7ihQVXS7krMg4MndkuAoyulItU= X-Stat-Signature: 7u3nyfjpuopkttfaxgqm89wcr8mrwgky X-Rspamd-Queue-Id: 48318A0004 Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=fqWVAbjd; spf=pass (imf25.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.215.177 as permitted sender) smtp.mailfrom=nphamcs@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1667935934-893768 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: This adds fields to zs_pool to store evict handlers for writeback, analogous to the zbud allocator. Signed-off-by: Nhat Pham --- mm/zsmalloc.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) -- 2.30.2 diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 600c40121544..ac86cffa62cd 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -225,6 +225,12 @@ struct link_free { }; }; +struct zs_pool; + +struct zs_ops { + int (*evict)(struct zs_pool *pool, unsigned long handle); +}; + struct zs_pool { const char *name; @@ -242,6 +248,12 @@ struct zs_pool { /* List tracking the zspages in LRU order by most recently added object */ struct list_head lru; +#ifdef CONFIG_ZPOOL + const struct zs_ops *ops; + struct zpool *zpool; + const struct zpool_ops *zpool_ops; +#endif + #ifdef CONFIG_ZSMALLOC_STAT struct dentry *stat_dentry; #endif @@ -379,6 +391,18 @@ static void record_obj(unsigned long handle, unsigned long obj) #ifdef CONFIG_ZPOOL +static int zs_zpool_evict(struct zs_pool *pool, unsigned long handle) +{ + if (pool->zpool && pool->zpool_ops && pool->zpool_ops->evict) + return pool->zpool_ops->evict(pool->zpool, handle); + else + return -ENOENT; +} + +static const struct zs_ops zs_zpool_ops = { + .evict = zs_zpool_evict +}; + static void *zs_zpool_create(const char *name, gfp_t gfp, const struct zpool_ops *zpool_ops, struct zpool *zpool) @@ -388,7 +412,19 @@ static void *zs_zpool_create(const char *name, gfp_t gfp, * different contexts and its caller must provide a valid * gfp mask. */ - return zs_create_pool(name); + struct zs_pool *pool = zs_create_pool(name); + + if (pool) { + pool->zpool = zpool; + pool->zpool_ops = zpool_ops; + + if (zpool_ops) + pool->ops = &zs_zpool_ops; + else + pool->ops = NULL; + } + + return pool; } static void zs_zpool_destroy(void *pool)