Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp5420169rwb; Mon, 21 Nov 2022 22:55:36 -0800 (PST) X-Google-Smtp-Source: AA0mqf5MIa/mAlT9t2jmK0D3mHZr5NPg6VWvEdmQ4x9dg4YbNJbyv0DTiN/xY0e8QawchU5t0QHU X-Received: by 2002:a17:906:404:b0:781:f54c:1947 with SMTP id d4-20020a170906040400b00781f54c1947mr5224570eja.69.1669100136681; Mon, 21 Nov 2022 22:55:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669100136; cv=none; d=google.com; s=arc-20160816; b=eQCRh2MCsK1XBWS52doJK8CxGOnPrQBvFPTPh7xSzKu2c0nC2dFNKYTVPkkP+9d+T0 TPT4K2G3VOdfcXEFlPqmk0Tc1qrc4IHxD2wxjPb7m5jDR4zdsfBCAsVClhEJK7su4Hdt z6xdRZ9HvQazJF5BgngifvSkRxGHtWX9waG0XFwL+YMZW2peqxbAqgRi8cN7I/iX5TXP XISvtRulBsV2edsvHN+bLzYiDi7CBQWWSSnPFfJbeO1T1ZHt+4BFTGU8FMGabdLZk3Z1 EqRjeCQ01pTJj9/eykoPRXBWhLLsQxj0o9xvnSRXh2KZxqLXC17zbU0fCQ/2oOQUN14m x4Hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=c6nEzvRMqkEoaAWST80S3Bt5GCknL1xuC4oMibyvkh8=; b=OAY8Bf5LRWb7RJqHAFlHguimDrpCx/DHp3tUtwZUx7SW4y95CMqy/cQ/MTopOgD7g/ NXfC2/n8CngyQa6ngf/6S5ENYCCVBqhUYONSX8IOONLOsUH+o1tpG3DzdbFlBV7j/nb1 A1gYmjWkf3G6bUj8EHjsjNFmEPgCp7ryq8+lfJspEI1c/ER41gxseEXNBTMVG39QYIjm A0QBPypsy7kxEkx31D6IsZ6NlDPF9GuvSe256tH4ZoftGC6wgwUGimWlvjUcbDFv++1F nMb3kxHXvm4N3C2/sta3pBSTeiCx3CRrtcvy4OAg2AzbR3LZhuu0uF9QNw4/5z0yAhUP H8xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=X8lz3R6K; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qb3-20020a1709077e8300b0078df3bd80b9si12918676ejc.46.2022.11.21.22.55.14; Mon, 21 Nov 2022 22:55:36 -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=@chromium.org header.s=google header.b=X8lz3R6K; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230377AbiKVGhk (ORCPT + 91 others); Tue, 22 Nov 2022 01:37:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbiKVGhi (ORCPT ); Tue, 22 Nov 2022 01:37:38 -0500 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98BA56356 for ; Mon, 21 Nov 2022 22:37:35 -0800 (PST) Received: by mail-pl1-x62c.google.com with SMTP id y4so12736891plb.2 for ; Mon, 21 Nov 2022 22:37:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=c6nEzvRMqkEoaAWST80S3Bt5GCknL1xuC4oMibyvkh8=; b=X8lz3R6KuIPbAa9xJs09TMxgQ67PyPXHpxyQt3ICa55h+zNm7zl05/tkdJRImGv/dL AVeZUbNJzJ6NESVqnv14Qv5DIZubGpQiWvsiHE5yQzyX1xD+NqxeuLzyp32PlzSSveC1 MVGKwaGwz8lIgKvTgt8VXiHh1W4vhEqnQ9Lqo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=c6nEzvRMqkEoaAWST80S3Bt5GCknL1xuC4oMibyvkh8=; b=QlEjMub3rmcejvOQ9dhQkrVWuvh5egiyG+3ZEirZkkccSbAPLLSNVjJGIkqIBICpoo PeWHDzKMhw+XB2uZU7aeDqKJbKUVcdFlChfjueSzN0RwTSda3H3N0PLGoHbAOifmnPJ9 q3P5hsKffBI20bfFhpJY9j2sNNFe59Qy0HTn7PZKW8og2+wHSCUBlp6S5CpeLAD3o3Iz 8p3XUaArRhAAFmOwm7bAsUUjeUmsq+aCN7E+srQYwOYuVdUNVuWFek9OLtOsG2vpyBZa gpaqFz1ZyaouiW1lq5wQDKprSVt6CWCkBq1gyXvJH27OK/2LpLp30X/LqIhIAY5XNDSp 44tQ== X-Gm-Message-State: ANoB5pkluRMBDsgjZs/sJLYfAZqCnmpaWC0JwBkRaIHJYwmJIlp2kQzq Xa1T/PgZdwGWQLZC2m5zSPLjsA== X-Received: by 2002:a17:90b:1282:b0:214:1804:d96b with SMTP id fw2-20020a17090b128200b002141804d96bmr23650840pjb.90.1669099055073; Mon, 21 Nov 2022 22:37:35 -0800 (PST) Received: from google.com ([240f:75:7537:3187:e258:71ac:37b7:2d52]) by smtp.gmail.com with ESMTPSA id y65-20020a626444000000b0056d73ef41fdsm9809385pfb.75.2022.11.21.22.37.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Nov 2022 22:37:34 -0800 (PST) Date: Tue, 22 Nov 2022 15:37:29 +0900 From: Sergey Senozhatsky To: Nhat Pham Cc: akpm@linux-foundation.org, 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: Re: [PATCH v6 6/6] zsmalloc: Implement writeback mechanism for zsmalloc Message-ID: References: <20221119001536.2086599-1-nphamcs@gmail.com> <20221119001536.2086599-7-nphamcs@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221119001536.2086599-7-nphamcs@gmail.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 On (22/11/18 16:15), Nhat Pham wrote: [..] > +static int zs_reclaim_page(struct zs_pool *pool, unsigned int retries) > +{ > + int i, obj_idx, ret = 0; > + unsigned long handle; > + struct zspage *zspage; > + struct page *page; > + enum fullness_group fullness; > + > + /* Lock LRU and fullness list */ > + spin_lock(&pool->lock); > + if (list_empty(&pool->lru)) { > + spin_unlock(&pool->lock); > + return -EINVAL; > + } > + > + for (i = 0; i < retries; i++) { > + struct size_class *class; > + > + zspage = list_last_entry(&pool->lru, struct zspage, lru); > + list_del(&zspage->lru); > + > + /* zs_free may free objects, but not the zspage and handles */ > + zspage->under_reclaim = true; > + > + class = zspage_class(pool, zspage); > + fullness = get_fullness_group(class, zspage); > + > + /* Lock out object allocations and object compaction */ > + remove_zspage(class, zspage, fullness); > + > + spin_unlock(&pool->lock); > + > + /* Lock backing pages into place */ > + lock_zspage(zspage); > + > + obj_idx = 0; > + page = zspage->first_page; > + while (1) { > + handle = find_alloced_obj(class, page, &obj_idx); > + if (!handle) { > + page = get_next_page(page); > + if (!page) > + break; > + obj_idx = 0; > + continue; > + } > + > + /* > + * This will write the object and call zs_free. > + * > + * zs_free will free the object, but the > + * under_reclaim flag prevents it from freeing > + * the zspage altogether. This is necessary so > + * that we can continue working with the > + * zspage potentially after the last object > + * has been freed. > + */ > + ret = pool->zpool_ops->evict(pool->zpool, handle); > + if (ret) > + goto next; > + > + obj_idx++; > + } > + > +next: > + /* For freeing the zspage, or putting it back in the pool and LRU list. */ > + spin_lock(&pool->lock); > + zspage->under_reclaim = false; > + > + if (!get_zspage_inuse(zspage)) { > + /* > + * Fullness went stale as zs_free() won't touch it > + * while the page is removed from the pool. Fix it > + * up for the check in __free_zspage(). > + */ > + zspage->fullness = ZS_EMPTY; > + > + __free_zspage(pool, class, zspage); > + spin_unlock(&pool->lock); > + return 0; > + } > + > + putback_zspage(class, zspage); > + list_add(&zspage->lru, &pool->lru); > + unlock_zspage(zspage); We probably better to cond_resched() somewhere here. Or in zs_zpool_shrink() loop. > + } > + > + spin_unlock(&pool->lock); > + return -EAGAIN; > +}