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 F2488C433FE for ; Wed, 23 Nov 2022 17:18:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3EB9A6B0071; Wed, 23 Nov 2022 12:18:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 39B736B0073; Wed, 23 Nov 2022 12:18:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 262D86B0074; Wed, 23 Nov 2022 12:18:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 150526B0071 for ; Wed, 23 Nov 2022 12:18:22 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id DD69D1C6A77 for ; Wed, 23 Nov 2022 17:18:21 +0000 (UTC) X-FDA: 80165365602.10.EBBED76 Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) by imf21.hostedemail.com (Postfix) with ESMTP id 417531C0009 for ; Wed, 23 Nov 2022 17:18:21 +0000 (UTC) Received: by mail-qk1-f177.google.com with SMTP id k4so12880619qkj.8 for ; Wed, 23 Nov 2022 09:18:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20210112.gappssmtp.com; s=20210112; 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=TwvPiJ/FeIr0Mz9lZfh35WWzSLWvCKU31ofAXU9cKEM=; b=gr6DO3Oh3skW8tb7D2/B9WOQNEtkPRHHjzUdtvmzXPZka6wGY/ceBYbCRSyXSY5AP9 V0vFrXdXO51oP5M9qw+n5uAdYAR51QxT7SFnBDaccuwY2V933/n+FmLYRj8L1Ahk4hmQ 2xH1fYb4CEJKv8BoukY3TDmI1xnM+nOm1yoaEKh5ANXUcap3zZK1+OY7DoE1uvROFHxZ v+9+PzwLsDn/7H5Lnzt4mlH6OFeBxspzcMWWMBUJCKR9XQmHADzkFo/TKhXOuriwKU78 kfDrZ3nlYvYEmmmTzwJWkuExmBQ3uCMJ/zyoDt1SjW4TM58DPZ1lfbKmYWRBgPKX5Q1x X4OQ== 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=TwvPiJ/FeIr0Mz9lZfh35WWzSLWvCKU31ofAXU9cKEM=; b=lNpaxOb9G4ryLtBp0lSOMfjpztFcz9Z0BdOVDxdGR24qlzECGDnBN6Q4SEoNqL4ntT PJ9FluQI+TutrnKSYNM0j5BxcdkF5qrAeB6iPtnWaDhptRQiLypBBwV+aWFIuc92YiNv TYim8+JhERkyXuzWEqbW3HMTsoBnK+ds03ygITGT5BhSmaTp+kyHIESi4wtPbNgNJzY7 DvCxT2ly5POdU6a3zvKDHoxbguc6rP8MCHMuTQM+4i4y4PkjtqfxyitnqcZa9CjkPyiL gpOAVqEv9Xv0TYpKrHAByV67XOr0pxBnsBjZk/ntxpJQ0AArnmNaUte8Lqufr+SGGA9m s9TQ== X-Gm-Message-State: ANoB5pka18n3ASJ2lr0to+mt13mvce43Hm1u0Dh8IrEkYKDu+XDrYV/o 9qlpeyd/hJxG1keexIoeIoseRA== X-Google-Smtp-Source: AA0mqf7xRfTB/UejWMIfr3NInpGb5Rlt1+RLepAPyJ05e/VDNphvwLRHhnkFG3PQr5xRQ8tpVnC/og== X-Received: by 2002:a37:9a15:0:b0:6fb:6221:18a3 with SMTP id c21-20020a379a15000000b006fb622118a3mr26200055qke.230.1669223900337; Wed, 23 Nov 2022 09:18:20 -0800 (PST) Received: from localhost ([2620:10d:c091:480::1:bc4]) by smtp.gmail.com with ESMTPSA id fz10-20020a05622a5a8a00b003a50d92f9b4sm10141541qtb.1.2022.11.23.09.18.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 09:18:19 -0800 (PST) Date: Wed, 23 Nov 2022 12:18:46 -0500 From: Johannes Weiner To: Sergey Senozhatsky Cc: Nhat Pham , akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, minchan@kernel.org, ngupta@vflare.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: ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669223901; a=rsa-sha256; cv=none; b=vVcztuGd/WrNyA4g7NaMaG6/1c7nOCyC/6gort7PraiT0B7fton5C62n+jrIWOie3md33Q IshTjev+V3iq9hRy50IarR5wqaka9hdycPZOa28MoBhcqBBVkKEdFA9B9CBcKmMhTxxDBP CKgCMW80gF5pht1VnUfFgET1yB/VdY0= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=gr6DO3Oh; spf=pass (imf21.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.177 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669223901; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TwvPiJ/FeIr0Mz9lZfh35WWzSLWvCKU31ofAXU9cKEM=; b=0IcK1h3L5dW3a2nnnOrOKDAA3FrCV4DCXjoWrAvWg8IngspPXoJ2yfq6LM39K7s6BINrlG dIOEMKG+hZNNHnD6G8gcpemTO/LSD68S6UGE8fkVsynYgBpWGvKDCctEZGYJfoYZNrniNI KQqRcgRdBHoRLjVm+QpyXbW8kGno/rU= X-Rspam-User: X-Rspamd-Queue-Id: 417531C0009 Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=cmpxchg-org.20210112.gappssmtp.com header.s=20210112 header.b=gr6DO3Oh; spf=pass (imf21.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.222.177 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org X-Stat-Signature: j5hxart7ut4iw7fum89nkjqjn9brsgzb X-Rspamd-Server: rspam10 X-HE-Tag: 1669223901-444005 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: On Tue, Nov 22, 2022 at 03:37:29PM +0900, Sergey Senozhatsky wrote: > 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. Hm, yeah I suppose that could make sense if we try more than one page. We always hold either the pool lock or the page locks, and we probably don't want to schedule with the page locks held. So it would need to actually lockbreak the pool lock. And then somebody can steal the page and empty the LRU under us, so we need to check that on looping, too. Something like this? for (i = 0; i < retries; i++) { spin_lock(&pool->lock); if (list_empty(&pool->lru)) { spin_unlock(&pool->lock); return -EINVAL; } zspage = list_last_entry(&pool->lru, ...); ... putback_zspage(class, zspage); list_add(&zspage->lru, &pool->lru); unlock_zspage(zspage); spin_unlock(&pool->lock); cond_resched(); } return -EAGAIN;