From patchwork Wed Oct 26 20:06:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 11436 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp463000wru; Wed, 26 Oct 2022 13:09:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6jCxc0Kp2jGvDLkKi6q8ba5dLMZ8v2Bq8rZ2EV7bEMsnR+yOimyNbhteyPnHbWAuOBaqJe X-Received: by 2002:a17:90a:6e4c:b0:213:2058:f456 with SMTP id s12-20020a17090a6e4c00b002132058f456mr6098291pjm.186.1666814984456; Wed, 26 Oct 2022 13:09:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666814984; cv=none; d=google.com; s=arc-20160816; b=EZwJMhn3mK75mSyIpzJEoAmF+/eAr8I2mHglAyaAOEpVFxilHQO6SgoQVfIHRLfDfH +o9tcxTfIPVx0PLBJGOglw55QfNpd/Ob4lvzyLPo9oS6/xoD3QuvEzxKS/osWLaQ45pw j+eTSehxGz+IjplY/+0AOy5QTPsA2A2tQtiXf9/azG5YbNr0v5uSlVYiEpeIYoOj16Zd w99ylnudQKFZvbBE2khc8Pv9yQIHDq4CFYBHGfXGzjrEGR3s07RZTmuW3eXMQc3gJE+Y GbvITjE5GLUrNexLmFNMA8+9QihVK7/de2DziSg0KoO5cDb10UYEg17pxskhHNXWr/Qt OrCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HSvm1OVp5HfWSmnERqwnki4xcSgkSWyRsvH49QuFnfE=; b=DFgsyoAnMitkIbs58p6ikoh5PqnUr4LWidIoa/PepZba1ZJueEvPSyvT05o0ZgLTAt LZWIONgbbNEsewm6ZqfS1tKXHMfnO1S7X1vvmDLxILUa7EU+y6KrrwzYty20Ux7jhhRB 2Yfrfue66Unj8+9KJXKCk7srb1iXS6F0YRdAscREq4D7ArgCNP7mgnXCQZ1HMMeXawt+ jAafr892jwVW3kCwRsXC/yElNNvOIYl07noOFCqjIYrS3++OmWBR7SCLWdCsU2qvmgi1 yLeFp1DsEW8kcb//gPFozZNOJpVRTzF9Po27OMIEbjMzsgUbIpUhmU7c3zgPYOVwFrt6 ixuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=M6ji8O15; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jb14-20020a170903258e00b00184000a834dsi6413457plb.455.2022.10.26.13.09.30; Wed, 26 Oct 2022 13:09:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=M6ji8O15; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233992AbiJZUHA (ORCPT + 99 others); Wed, 26 Oct 2022 16:07:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235115AbiJZUGW (ORCPT ); Wed, 26 Oct 2022 16:06:22 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C12D895AF5 for ; Wed, 26 Oct 2022 13:06:19 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id l6so11527361pjj.0 for ; Wed, 26 Oct 2022 13:06:19 -0700 (PDT) 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=HSvm1OVp5HfWSmnERqwnki4xcSgkSWyRsvH49QuFnfE=; b=M6ji8O15HzhOwy1jXWvAOlfmKQUeVoW/EbKvR9LcvTBC2x5En6d987HkhhRKanDnDV SFN0WzFT4ZC2IsTIbJT5za3RFvKWWLefUJFkXiy61PQEpN2Fz4H37MdsGumYX9eWk1OO +HWsUn9490Xsf9bxh5xgwAintd2PGJAmexI6ec0NZ4gFb2byWvu1AHzmsOmg2jfPs6E6 P90BnIAzYLyBAzAd7BTeGB5jkonOtk6qNosTYS54/+1/I0O53P9Jib8/1rTtg6vrPmRC ptPQUtnCiSrt2ARsE37QJsrbwBaiZRkzXYx1XNw/Jk7Ms0ycWP/g3fFmzFKmA5GSJXhG KNRw== 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=HSvm1OVp5HfWSmnERqwnki4xcSgkSWyRsvH49QuFnfE=; b=osIFDripWQ80NtYEftNCDlYdaQ95lzAWHMIqUC3h/tV60628KJNkoohf31IOVzjfey 7Cxo65u/92Yp6izlscsUP3UlAwNZFnTwSWI1BrZvUY4IHUXuuK80JH8wuAX2gedcHZvV gONTKw+tPBBQK3/BUQtQPdA5WnmyWXB8vxV0QO6XFZ9zuBEMfaZZ1tHtaQ335kfIdY/C ZZ60c1J16+99GqeDObrqfCzMdlmL+LhH2hyJo9O9qsTRJyIx9/Dsuw4aBjmwHL6XuJLP 8BE3eEwwUEj4LJ26I9IVbsEgXpuI2ar9JMS4m/vyuvbwpuRER/kMBf4ZBAMTSBcixO1C /YHg== X-Gm-Message-State: ACrzQf3VWjavHy0ykFakxqNnlYLla9JgJDhJGdoaHk6tEyORGSBoKzgi kS2ICfbxFg5rBEyMj95kF4s= X-Received: by 2002:a17:902:be0b:b0:182:fd6:1293 with SMTP id r11-20020a170902be0b00b001820fd61293mr46049794pls.146.1666814779269; Wed, 26 Oct 2022 13:06:19 -0700 (PDT) Received: from localhost (fwdproxy-prn-023.fbsv.net. [2a03:2880:ff:17::face:b00c]) by smtp.gmail.com with ESMTPSA id 126-20020a620484000000b0056c349f5c70sm2565942pfe.79.2022.10.26.13.06.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 13:06:18 -0700 (PDT) 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 4/5] zsmalloc: Add ops fields to zs_pool to store evict handlers Date: Wed, 26 Oct 2022 13:06:12 -0700 Message-Id: <20221026200613.1031261-5-nphamcs@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221026200613.1031261-1-nphamcs@gmail.com> References: <20221026200613.1031261-1-nphamcs@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747782189131322262?= X-GMAIL-MSGID: =?utf-8?q?1747782189131322262?= This adds fields to zs_pool to store evict handlers for writeback, analogous to the zbud allocator. Signed-off-by: Nhat Pham Acked-by: Johannes Weiner --- mm/zsmalloc.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 600c40121544..76ff2ed839d0 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,17 @@ 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; + } + + return pool; } static void zs_zpool_destroy(void *pool)