From patchwork Thu Nov 17 16:38:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 21831 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp508902wrr; Thu, 17 Nov 2022 08:58:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf526lDDj0nPuIerfFmaTvoJWJHNaZ7vTOyyJa1EKAJH+7IqfNNpLVDXDFudkx7RAODnGRWN X-Received: by 2002:a63:1015:0:b0:470:5f22:1496 with SMTP id f21-20020a631015000000b004705f221496mr2679267pgl.585.1668704294939; Thu, 17 Nov 2022 08:58:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668704294; cv=none; d=google.com; s=arc-20160816; b=ae9MSqQINpFoQhZv3jdCUfky54UslCHVLPPIq/Lnt8WXdsz4E/uW8/o+KSXO+gDo8s 9E/j9i/zAz4UcvlD3KRbAmKGUwLPVY6wXACqVLdV0p17pVdUTiwF58xHnRO7pCDpdRN7 oThOXk3QgOi3uoT4ERUCgdfP7yY0of8Tl0n7EfoDydkjKml6q/HJY/IRe4DL3MQK0Xcs 7qZNiPOQ7/u03eh2cmZ3BsIaNXER3l3A4VfKpfsvig+TCkTib7nd2EAPso2YSWOR8L4B Tejot6Pq7W45FFBQGwLshHcNHEpB8+yaCX0kwZxFbunOC0LpyHa6nEGbVmn76mnF11gX bwaw== 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=8Nqg4Xt8lGKthWB+nE04XmQsPpZUs65jb+qHOq4Cr/k=; b=x/3fkL2kIlHEKD3C2mA+KN1xm5bFgcZgp7vgEoqkL4WRz52wEh94nIhQj5hlob3rj5 AEcyqFYxmmfbVZ/XprqOmz5jiPR3yv0S5DTuskVIk0WKoZT+2CwmjxF0aC9OXvaxFTmB dTNQOV0J2vfFHirMzvQk0dSvjKSc3qF4ObrPfpKxSCqLyA8OatU6Gyxpj7a+BET2KWQF /Igp7ILQnMk+Ik+I4z4vDQy3Uf2813mRF4tYYc9i5VPr+RidbLkoqa62sxCa0ST+P454 PtwlpdFTJydZryViY7pQ2Ky2fzqztPIaLQ1+47D8X8QOpwTwIJwHXn95njTzQ/APOQcX hQ0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PRXwfJiP; 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 l17-20020a170903121100b00186f9d4400esi1588515plh.346.2022.11.17.08.58.00; Thu, 17 Nov 2022 08:58:14 -0800 (PST) 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=PRXwfJiP; 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 S240510AbiKQQj0 (ORCPT + 99 others); Thu, 17 Nov 2022 11:39:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233679AbiKQQi4 (ORCPT ); Thu, 17 Nov 2022 11:38:56 -0500 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DF5E7C011 for ; Thu, 17 Nov 2022 08:38:47 -0800 (PST) Received: by mail-pj1-x1036.google.com with SMTP id r61-20020a17090a43c300b00212f4e9cccdso5875119pjg.5 for ; Thu, 17 Nov 2022 08:38:47 -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=8Nqg4Xt8lGKthWB+nE04XmQsPpZUs65jb+qHOq4Cr/k=; b=PRXwfJiPmdnJffoazkBjUBN8ZE3gBH/hkNy/65kEe1ygSQwxKpmoEIjZkvNBkBd3d4 UAcN7kr2yQiixORgoPBvpXxN27IMZ+QOmLa8coD8Fa9cMn2Khspr0MSgul60p0CoPc9S V+hm8qNojAxVS77NWN/UxmzX/5B2ujehMRzWW57FsYBMYCh65oPMx5O2EkKMzdJq8OIs wz9RkshLbCfjuOFy8mofp+9SYbllP0P65SoImEnn29027zUuKntQn2uac4eQxrdzBN7W n57wczZSCztTlEVXxl8d3ExlLHHiz5qAxdv8Y9hE3J/YV9vEgMNrMQKQ3YdiJzgniV/Z VWpw== 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=8Nqg4Xt8lGKthWB+nE04XmQsPpZUs65jb+qHOq4Cr/k=; b=yPrBJXPszLxGdSpBb3CPSD85IfpiYH2H31FrnITV4zsuRvfwDJjCVH/WQ9Xyp3rz+Q obfV7ot8cLemyiPz2HYMaBdQVSxM8daOlPQxT3B+An7f1ORnmPjElh56emLmb9es//7B qxopPOaNW0zhs9Dkiy83y5twGQ1pBoZ3raovOzzh8pk4hEsSX1Jz7omiRPWtRLnL6Pv9 YGWnGvzgDYc4hER3n+/dBi1R9hAjnZF3JkLA+VXzjmFl2EU8jfbGEQYISU4ydqjG0NTw sPV+C1tMOf/g+Mli38Mgrqyfptbnx2/iVKIxN5MBMxfdc8F5dMhxBG19aFxz9oFy/WWm WkrQ== X-Gm-Message-State: ANoB5pkzoP31++w4J9lQbWW2PXVfcSqBXkXNK2YiX/xafn47hRbHB/ay UpCq5djHN8AbKVvy3IjwlSDHdMMGuSOUlw== X-Received: by 2002:a17:90a:bc4b:b0:212:d796:d30f with SMTP id t11-20020a17090abc4b00b00212d796d30fmr3699709pjv.9.1668703126784; Thu, 17 Nov 2022 08:38:46 -0800 (PST) Received: from localhost (fwdproxy-prn-001.fbsv.net. [2a03:2880:ff:1::face:b00c]) by smtp.gmail.com with ESMTPSA id y4-20020a17090322c400b0016f196209c9sm1645420plg.123.2022.11.17.08.38.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Nov 2022 08:38:46 -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 v4 4/5] zsmalloc: Add ops fields to zs_pool to store evict handlers Date: Thu, 17 Nov 2022 08:38:38 -0800 Message-Id: <20221117163839.230900-5-nphamcs@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221117163839.230900-1-nphamcs@gmail.com> References: <20221117163839.230900-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?1749763275133262537?= X-GMAIL-MSGID: =?utf-8?q?1749763275133262537?= This adds fields to zs_pool to store evict handlers for writeback, analogous to the zbud allocator. Signed-off-by: Nhat Pham Signed-off-by: Johannes Weiner Signed-off-by: Johannes Weiner --- mm/zsmalloc.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) -- 2.30.2 diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 2557b55ec767..776d0e15a401 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,9 @@ struct zs_pool { #ifdef CONFIG_ZPOOL /* List tracking the zspages in LRU order by most recently added object */ struct list_head lru; + const struct zs_ops *ops; + struct zpool *zpool; + const struct zpool_ops *zpool_ops; #endif #ifdef CONFIG_ZSMALLOC_STAT @@ -385,6 +394,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) @@ -394,7 +415,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)