Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp9384911rwd; Wed, 21 Jun 2023 06:53:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6hrBamxsVU54d0Iqbbm7eu3EPR54Jqy+vLvlI0up6aHv9LHGOMk2TwP3E1UWbJrMBSNq7o X-Received: by 2002:a05:6a20:158a:b0:114:7637:3451 with SMTP id h10-20020a056a20158a00b0011476373451mr11985768pzj.37.1687355631784; Wed, 21 Jun 2023 06:53:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687355631; cv=none; d=google.com; s=arc-20160816; b=pcD+k5hLOBfJZLfTufe4c/w+WxtjITFI9XF2twRlN9JOdmyyAQkIDR2v1UpMbemsdi 8psyHliYv18RmMsUSJ8n8HiFMo4Jw/194k58LWPHyCqe1gt5FC3Rz60qCWRKi/SDbCBw o4a6NZDAZ7NsBpm5Yv/5ljvy/tWKYtUg+62Nw30MRmT6Nd/kNw86GUgg53ujTsL96nX7 8CvwvIVxlL3LUblcuHlOfzYNxrnYr+MGoPdz7YqT00fvlTaCtK6K2Kz4vgeisdBjeHPy fSYz5YxyNLKSwV60882Rv2Hps03e3bC1h6UfRdSRN2iTzC7EGbYxWTLbuEPXPmE+eLiE 7RdQ== 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=fveJ7t6dKInkV6jkCt7drrsyoXqW38rNIYDTeWubez4=; b=VIja0yXUtOBLLo8CYKrduT+O2nSku5J4m1opG5x1W6q7aULK2yVpNHs7Y+lBfYVcw+ 0nZrDARVaFLIUOrK78r6Cl/Uu4ow/hmMlwuaqK/WianxzXh91GLzy9cGNNqCo6QVduvW zxGCOtdDHj9+6qjsDglkEhwgLHZ+TtvxSwOffnGVFdbsRdZ4d+x2XxzubG9WSMgYEN0u p2PDoF+9HUN6qpd0IncAq6rXBxUxZAzGPMo75TyuC0+MKc2/mxZUa/GmdMqRwq0Kot3O bFpicQyhtxK5R/4+0WoxbolkhlhhysFsL3JRKi8Dk8/apF66ZrPwzcFUGxHUa1ZeVbNd 7IXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=E5HvcT69; 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 a202-20020a621ad3000000b0065d56d5e7a9si4108492pfa.123.2023.06.21.06.53.39; Wed, 21 Jun 2023 06:53:51 -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=@chromium.org header.s=google header.b=E5HvcT69; 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 S231839AbjFUNRY (ORCPT + 99 others); Wed, 21 Jun 2023 09:17:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230220AbjFUNRX (ORCPT ); Wed, 21 Jun 2023 09:17:23 -0400 Received: from mail-oi1-x229.google.com (mail-oi1-x229.google.com [IPv6:2607:f8b0:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4508310C1 for ; Wed, 21 Jun 2023 06:17:22 -0700 (PDT) Received: by mail-oi1-x229.google.com with SMTP id 5614622812f47-39eab4bbe8aso3855301b6e.1 for ; Wed, 21 Jun 2023 06:17:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1687353441; x=1689945441; 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=fveJ7t6dKInkV6jkCt7drrsyoXqW38rNIYDTeWubez4=; b=E5HvcT690zg+3SJvbU2ye/7aCf3qOHKmVyWxSZ8zZFFCLcVymtvrkKamjL7GOEDwIF W5p00yU/aYFHwRrAYv08KgzzdbAHMwxmFf/QkHGs3VXRTjepf1PAkD6xWULRRCOj3kfJ nncOnnlGuNfdUacAr4Xub0PoYo1811vMIVkOA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687353441; x=1689945441; 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=fveJ7t6dKInkV6jkCt7drrsyoXqW38rNIYDTeWubez4=; b=FWCkQDQYQmp+Uo6kUZcou8Xe/bQ3eG3AXZFissjZisw/T8YDMiup6UkSexoYHYc1iH GCr4FDxo1H1acBVhQk9iytRAmh5yo21Cgmy6RpQZrn0ftZ4kmc0bryPCudNgFYGgqyjC jCyIEhWeg0Lxrj9YiYFUdJ8CL707KGmbOUx6815EAw/WArtd/Uy8lxDxeXv7LYifa8az qBfc5O0MCx/Et0zot4mK8ejlM9NsNRs2GKolvQKA5UW9C0tBGfwlYP39ziNzE4vVTvk2 SdN1dYqDRqao/7p9ihslfpKq2o1rAoBMk+D+kI9ax/4chYAtRX05nskqD95W/1hoMXxV CWxg== X-Gm-Message-State: AC+VfDzQtAGPPvCHobZ39EWB079z84zzrYJdrC26+TjzUtBSTeGRdFtf Io7VLJCa9kyffFq8EBlLUTeR7A== X-Received: by 2002:a54:4518:0:b0:39e:de8b:54a2 with SMTP id l24-20020a544518000000b0039ede8b54a2mr8097176oil.29.1687353441344; Wed, 21 Jun 2023 06:17:21 -0700 (PDT) Received: from google.com (KD124209188001.ppp-bb.dion.ne.jp. [124.209.188.1]) by smtp.gmail.com with ESMTPSA id fr3-20020a17090ae2c300b0024de39e8746sm8952526pjb.11.2023.06.21.06.17.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Jun 2023 06:17:20 -0700 (PDT) Date: Wed, 21 Jun 2023 22:17:16 +0900 From: Sergey Senozhatsky To: Alexey Romanov , Minchan Kim Cc: Sergey Senozhatsky , "akpm@linux-foundation.org" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , kernel Subject: Re: [PATCH v1 1/2] zsmalloc: add allocated objects counter for subpage Message-ID: <20230621131716.GC2934656@google.com> References: <20230619143506.45253-1-avromanov@sberdevices.ru> <20230619143506.45253-2-avromanov@sberdevices.ru> <20230620103629.GA42985@google.com> <20230620111635.gztldehfzvuzkdnj@cab-wsm-0029881> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230620111635.gztldehfzvuzkdnj@cab-wsm-0029881> 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,FSL_HELO_FAKE, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED 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 (23/06/20 11:16), Alexey Romanov wrote: > If sizeof(unsigned int) >= 32 bits the this will be enough for us. > Of course, in rare cases this will not be the case. But it seems that > zram and kernel already has similiar places. For example, if page size > is 256 Kb and sizeof(unsigned int) = 16 bits (2 byte), zram will not > wotk on such system, because we can't store offset. But such case is > very rare, most systems have unsigned int over 32 bits. > > Therefore, I think that my idea is still applicable, we just need to > change the counter type. What do you think? My gut feeling is that we better avoid mixing in architecture specific magic into generic code. It works fine until it doesn't. May be Minchan will have a different opinion tho. There can be other ways to avoid linear scan of empty sub-pages. For instance, something like below probably can cover less cases than your patch 0002, but on the other hand is rather generic, trivial and doesn't contain any assumptions on the architecture specifics. (composed/edited in mail client, so likely is broken, but outlines the idea) ==================================================================== mm/zsmalloc: do not scan empty zspages We already stop zspage migration when we detect that target zspage has no space left for any new objects. There is one more thing we can do in order to avoid doing useless work: stop scanning for allocated objects in sub-pages when we have migrated the last inuse object from the zspage in question. diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 02f7f414aade..2875152e6497 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -1263,6 +1263,11 @@ static bool zspage_full(struct size_class *class, struct zspage *zspage) return get_zspage_inuse(zspage) == class->objs_per_zspage; } +static bool zspage_empty(struct zspage *zspage) +{ + return get_zspage_inuse(zspage) == 0; +} + /** * zs_lookup_class_index() - Returns index of the zsmalloc &size_class * that hold objects of the provided size. @@ -1787,6 +1792,10 @@ static void migrate_zspage(struct zs_pool *pool, struct size_class *class, obj_idx++; record_obj(handle, free_obj); obj_free(class->size, used_obj, NULL); + + /* Stop if there are no more objects to migrate */ + if (zspage_empty(get_zspage(s_page))) + break; }