From patchwork Fri Jun 23 04:40:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13289966 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 67C63EB64D7 for ; Fri, 23 Jun 2023 04:40:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DA4178D0003; Fri, 23 Jun 2023 00:40:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D51C98D0001; Fri, 23 Jun 2023 00:40:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BCB9E8D0003; Fri, 23 Jun 2023 00:40:36 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id AD6708D0001 for ; Fri, 23 Jun 2023 00:40:36 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 6AF29B074E for ; Fri, 23 Jun 2023 04:40:36 +0000 (UTC) X-FDA: 80932761672.11.F2B6675 Received: from mail-ot1-f52.google.com (mail-ot1-f52.google.com [209.85.210.52]) by imf09.hostedemail.com (Postfix) with ESMTP id A824C14000C for ; Fri, 23 Jun 2023 04:40:34 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Cbp1e0QD; spf=pass (imf09.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.210.52 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687495234; a=rsa-sha256; cv=none; b=1HtiJEbWwKKvPM9OBEeV3+NQWrCLKd3jliw9tAey4f3t/s/FtVkONavo4EUZBugUgecNzp Wd09yB5MuH2GERjsKvtEG6vgqLEcxjzGvcrJcjc4iFYZDO/cDdF0AvUsINk5hwl3+VCsCm XEAYJh4BYNYDhqwf/tqeV9k1GcubOnA= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Cbp1e0QD; spf=pass (imf09.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.210.52 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687495234; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=A39gdokmxlm4U38P/Zql/B/dp1bRrgyGGMBd2ncXVBo=; b=ZhbcLK5Ux3qnjGov5wrkfG+bW+u61l+Yw7KodFRE+GskkILE/BmrEMlwn9psDeHEXbTY0z +2GNjJB+58M6B5DnyeHKDsdWj4MKGE0X3QqOcdfzutvFcBo9/GqgsoblaGc2HKIj4jiSst 2XUw/JoCxLNQUn54AZXf7cs8/+IlVwg= Received: by mail-ot1-f52.google.com with SMTP id 46e09a7af769-6b5d7e60015so296598a34.0 for ; Thu, 22 Jun 2023 21:40:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1687495233; x=1690087233; 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=A39gdokmxlm4U38P/Zql/B/dp1bRrgyGGMBd2ncXVBo=; b=Cbp1e0QDlBoMFSQUoDU44b/Cu4zloKVkubwfpVG0voArrICkUtyxlHNDLJm7uQaPWs yMtq2C3UOdpl3PwFBZ6fbcJm75BISUhsaIgsCU5qiVlrVsBW+skGS0Karwa520O8DOTP ScA5bFfNO0Evz3c7RIm+D6tZD1CBxKd0YmmyQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687495233; x=1690087233; 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=A39gdokmxlm4U38P/Zql/B/dp1bRrgyGGMBd2ncXVBo=; b=Tbrmufb9ppJJge0KQqYSH4T3n2ezFASkyQ+shH0RD4xMWn2ebdnzDDHGeWS1O5jWYb CiXDOqXka26+6RVdIcM2vhDIgeby+WpKRVDNXWc2LbEEC+guLvS7HZlMKE3d6aDFg30E NY/ZLgyq5jyP4oF6rLlzYFqfnhj8sbe2f9ZpfZ9UHRXRsSBiDlvXyaeCFrVE9Vwy0wD0 s8PGTnQhx2fDPkLeiS3G1xjmcM11zpPsTslJHxQr3RLmqJajsyjixem52BJGqP2Rl8gK kmKEL4PUXbXs9V2shRdC6X5zgfeaI9rmOwGtcc+l2PzZImzqt5dsHxPUuV1kkxjcXhpK Tyxw== X-Gm-Message-State: AC+VfDzJB1GY4EP1TSR0LLxcOuM40FdzV3xUdcgBq2KrB4CFNUGTZJ1N 4TaQkZ15VSJi7RT6TS3+1hJ84w== X-Google-Smtp-Source: ACHHUZ40SAmzVB3zyhbJ6Kmva/XRtgJ/rNm6Czlb8EAz6WtSXnsypo+QCnvyyJ2uHG4IQuWlO/8oRA== X-Received: by 2002:a05:6358:edc:b0:12b:c378:b090 with SMTP id 28-20020a0563580edc00b0012bc378b090mr14548296rwh.26.1687495233523; Thu, 22 Jun 2023 21:40:33 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:3383:b451:fa2:1538]) by smtp.gmail.com with ESMTPSA id q25-20020a62ae19000000b00666e17004a4sm4237350pff.58.2023.06.22.21.40.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jun 2023 21:40:33 -0700 (PDT) From: Sergey Senozhatsky To: Minchan Kim , Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Sergey Senozhatsky , Alexey Romanov Subject: [PATCH 1/2] zsmalloc: do not scan for allocated objects in empty zspage Date: Fri, 23 Jun 2023 13:40:01 +0900 Message-ID: <20230623044016.366793-2-senozhatsky@chromium.org> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog In-Reply-To: <20230623044016.366793-1-senozhatsky@chromium.org> References: <20230623044016.366793-1-senozhatsky@chromium.org> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: A824C14000C X-Stat-Signature: p8pwipei1unfiw91d6m3b1yqb8cdu84o X-Rspam-User: X-HE-Tag: 1687495234-672011 X-HE-Meta: U2FsdGVkX1+BTufaORp4Zv1RWFufrkYtzt+bQo7eZwASWlXVFX5R33NFKPf20fMDbeHyPdbHwYUemlxHB3WdqkBqJeSdKNJobKtIBPmtNeT/1SJDjTJiAAdgDgGUXhcz0tnfCr+fOf1lz5LbzYya4mQk2Td9srW+TuwkN9oAsf7BkmIJYnMN6fxMmZutfD4omHIOf08sk36/gJ/ONVF7VUxmuzq3nw8mtpSAS78dGOUYdkbah5kFzqIkHvVStRRJvg3WyblK+jBxhpJ6nQ428yXhwd46gsKRs+s6DLijwr8fkNU8/VUsciDT1Vgk3eOwqvaAXCOl2SQFlcwBrFqOQZXm1oJQJp0O+ZG+LM/uqwaJ7hMpa1YtQGZTslU+cs6VNnnZARNoos+g7soedUucO+xnNJ26rGUFhc5ZRDYY+p1sWWb9Hg2QmAVTVFFW7znneyOUu9vc1hoDorFKUOXNaoLfNiR2WnEUHRcRYEthhrwFdqwKgtt2HWnSzF8ZnOGzmWI6HWPu19ldphODARfwCSyAmI6a8iZU8oOH0wCWzTXY4Y1YUxdEg8QsTMXF886e6BBMajkg4lAKVIlGMZtKCYsDmCrE/V3ksn7ieWpHgbB9BAUDzQBLxUM2reYDSc0NGfREZE7mbM8DOFS6XpLKRjPyyPw/jE169MfmEH9OGN3MAkG9Zmc+CJogf6Kkq6NfcAc2XQJy6TXNmkA8QFWWKS/dKV3sI8q9B1vmwSCeKwSOn+JDT6cu00US2tdqjE6C0RWR9n+Hx5vZCKSbCEXpvAcDygcu06hojc4FqPu1Fyf+AlSwDuQd8wbBCZdpwTY6Spfi3T8jQrXs9zTVwQIzwKmsYg3DBJ8Dcn6+ZhKHewVgo5YPrRBNvFKj+3YKNI1ZpE2jJWAw4kQDiyVwYjeZFlajgGsvqpGYGximy1pS7o6MwTLlUD5Z/iB8EImRR7Z/ClEMe4eehKYPWHeAcAE brI1cxmr b50XdI+XxZ++mGNoKzIdOYKJ1U6cKxPx4rZdKR8Jo3XfZ8rDHdqwrst/qRd3sJVEodfjQEaD5JKkJFgF6RoPNIXiJV9cig7E0PCtt/RD2NxOjdyXePE67ELJmlcvgpaXaw7JrdhaqcuI9JB0CIVf07YWbCo4DR10mqF5dTnHil9gJI40Hbpz0yHrxSkfng8j/c25sy213jDkkj9jhnv7nUdfsEhe3y4XO8kVLFIkLr5FGTqLfvlE94v5U6gRuz0esAQEiZ9AxVz0T4MOXUoUFYgmv0B7WULJgGfLuzEc/dvBIhMUtF97zDHoGDaoDh28vBszOG7Bsqxdk8LBj+je4FSz7wQtyMhB4VN9VjaMjm+6vKnLIlh6TqnIy2wwPjEnOr1D4gWpsH5ekw946AkwL/3YLLvgIAzIT6Erbmw+C04AQZ295pHetrKQyYfo24wnbGTqzjEzFz/utpthOBAHPVcbmpQ== 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: zspage migration can terminate as soon as it moves the last allocated object from the source zspage. Add a simple helper zspage_empty() that tests zspage ->inuse on each migration iteration. Suggested-by: Alexey Romanov Signed-off-by: Sergey Senozhatsky --- mm/zsmalloc.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 3f057970504e..5d60eaedc3b7 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -1147,6 +1147,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. @@ -1625,6 +1630,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); + + /* Stop if there are no more objects to migrate */ + if (zspage_empty(get_zspage(s_page))) + break; } /* Remember last position in this iteration */