From patchwork Thu Nov 30 10:12:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hyeonggon Yoo <42.hyeyoo@gmail.com> X-Patchwork-Id: 13474202 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 BB6A5C4167B for ; Thu, 30 Nov 2023 10:13:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F85D6B045E; Thu, 30 Nov 2023 05:13:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4A8506B045F; Thu, 30 Nov 2023 05:13:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2FBCE6B0460; Thu, 30 Nov 2023 05:13:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 1902E6B045E for ; Thu, 30 Nov 2023 05:13:18 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E1A7D12011F for ; Thu, 30 Nov 2023 10:13:17 +0000 (UTC) X-FDA: 81514208034.05.2C77847 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) by imf16.hostedemail.com (Postfix) with ESMTP id 1ED33180026 for ; Thu, 30 Nov 2023 10:13:15 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=GZZZJEfe; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.210.173 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701339196; 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=efBNSdYQOC9rF9V+LwGnExMI9wJh+dms2ODwKHp/3kI=; b=F5lP6gv/uYMC8sbNkWwm3kQKRfaMLFmDqnodAMNdchPqKNOQkmWXAA64eAlmDPsv8R+N57 4kjY+iUaDg0Hz2hh04aqXnoOEQbEuvu0JDiwOyy6XZW6rjofsYh1s4kmjZ3WUY9yg0A4Gr 7lL7W3KNZ7zCwlVebhjM88DokDhd6KU= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=GZZZJEfe; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.210.173 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701339196; a=rsa-sha256; cv=none; b=B+id3rT5zdPZxFsbuUUxg69YsMCUOFpqoJOKkcpWZsFs12eoDeASnNvIvhBOSm9FU/mC3S m5h1k9d6mxVFIRMza4GgU8himv9I4CjJ5K6aga0V0yDd0Ox0NsoEfZ0SU/qZa48Hc2c3lK yvvv/uThRL51LlG6XLNik2x+cDq/Xo4= Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-6cddc148285so753451b3a.2 for ; Thu, 30 Nov 2023 02:13:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701339195; x=1701943995; darn=kvack.org; 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=efBNSdYQOC9rF9V+LwGnExMI9wJh+dms2ODwKHp/3kI=; b=GZZZJEfebKf8G6ppUFKQum5n7AmhC3GDSRHTqLWE4KfDzRYytQtWdmzOkWYY2PYxc9 9M1nwhy666iPVklcGLfjz9KcWcHFuaq6LlPJJoCbj4bYbmCiygfXFD4LaOVIPQDQJ2h7 1xhaarUEsqP3UiWtz6xB7AJqkHVIALbqx5gZkKiudkWDh9sYNhSVv+IXn2LeFiIRuwQM JDccycaQ2c1H8QHhcHSUZAzKzSP+vhckIihFBzeM3tGMTZV0uy5aZtncMiBuvPcCFzpF 3NzSUsX+Mk0qSpBjjSSMqvLHaBO39lBNbM6namFUCLXR5w5CawIZGf+6EVyDis+Dk2Ag IMdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701339195; x=1701943995; 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=efBNSdYQOC9rF9V+LwGnExMI9wJh+dms2ODwKHp/3kI=; b=RozYefgW1mUm2waMcK/a/zH6rHEor+Qyy3+N+PSB8LKjodpqQeAvFzTTYHL8cJdMlP 9px3TMkVMGzyO/Vsfl+fXwTcWaDENB65HqaNXnMOzzYoV6SXHvNGl2t19Q769/W60lPk VIMRbky3GedaBVzF2g58BQVz48Z9sz5AZja5US1XkNcYeVGp+lWTCIAnkMVjszJiW69o 9T9y8GyHIrf44k+vK8jtfc1RBjydjKhbMwTHo0JltQ1V/0IJqJSaav8tjiElLBdjPlS3 Tq0+w7Je+gCcYpu5iXbu1yssKIEudcUw6RzDUOwaa1kQZ7aw2ZLSGv3FyZZQMhcC8z7J 7yHw== X-Gm-Message-State: AOJu0YwJiJ9rHkBj/2JqanU30s1HgO7toItZi3YgcEpvS6dtBopzLHa/ ACt7f1VYO+fR5XzVvyOew1Y= X-Google-Smtp-Source: AGHT+IFzrTweuqjiYF7pKKdE9kfOSMjO+2vK+G1yRQBKcPwB9oDlie0JFqMh8xM5rAD5uaonO93oNw== X-Received: by 2002:a05:6a20:12d3:b0:18b:d3db:7048 with SMTP id v19-20020a056a2012d300b0018bd3db7048mr25946917pzg.23.1701339194873; Thu, 30 Nov 2023 02:13:14 -0800 (PST) Received: from localhost.localdomain ([1.245.180.67]) by smtp.gmail.com with ESMTPSA id r27-20020aa78b9b000000b006900cb919b8sm841402pfd.53.2023.11.30.02.13.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 02:13:14 -0800 (PST) From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Minchan Kim , Sergey Senozhatsky Cc: Matthew Wilcox , Mike Rapoport , Yosry Ahmed , linux-mm@kvack.org, Hyeonggon Yoo <42.hyeyoo@gmail.com> Subject: [RFC PATCH v3 05/21] mm/zsmalloc: convert {try,}lock_zspage() to use zsdesc Date: Thu, 30 Nov 2023 19:12:26 +0900 Message-Id: <20231130101242.2590384-6-42.hyeyoo@gmail.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231130101242.2590384-1-42.hyeyoo@gmail.com> References: <20231130101242.2590384-1-42.hyeyoo@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 1ED33180026 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: o5p4z1wuyo1ydbppxuqtb6czxhobwc73 X-HE-Tag: 1701339195-151028 X-HE-Meta: U2FsdGVkX1+o6EJiE8WG7Rh8o4O3PXWnU1RN/C6C5u6LkeIYxbxjuXk/Jch0Ot/xRrjopQi11axKg6rbMWyFUJ1eRsdx+oFQxzcOjnXyH6u1qs/qwUSK9gsP81CkCqXwzkrsdWp6DeLFX8m2stPRITF/OAdjlzAM7vrPvHR2lzrrO8gDzYYvVkmhncYAxxU/x20LRRV4FP5M681sCFnsm/dUFmtHZOMIOnwuYskFa7eAQDsoN1JVYEZjUdlxeFvkF7b/OhLdD3kxjKugIxLvHo77ywRG2PDOzgkflN6DWwWf8yLjwlqJnbaFifd0aerGZujTSsUzQeo1Q6QUZQGO3F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ZL3WNZ/kEzsKDTMzSQek7iZF1XLuDYKrg7ejsWJBGShmC0vYOWZLWdDssrRXT9HVxzicslMoUemsw0XnSXxQ5kUncA8hcnVuaeYsF0uNaRNmqiV0zXXUcba8s3I/BPI3kclipTFTqJBqm7L5AaE+TZ5CeCHjUiXPVIveVV++gWGYQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Introduce trylock_zsdesc(), unlock_zsdesc(), wait_on_zsdesc_locked() and convert trylock_zspage() and lock_zspage() to use zsdesc. Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- mm/zsmalloc.c | 55 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index c511539bee8c..91fccc67185b 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -307,6 +307,21 @@ static inline void zsdesc_put(struct zsdesc *zsdesc) folio_put(folio); } +static inline int trylock_zsdesc(struct zsdesc *zsdesc) +{ + return trylock_page(zsdesc_page(zsdesc)); +} + +static inline void unlock_zsdesc(struct zsdesc *zsdesc) +{ + unlock_page(zsdesc_page(zsdesc)); +} + +static inline void wait_on_zsdesc_locked(struct zsdesc *zsdesc) +{ + wait_on_page_locked(zsdesc_page(zsdesc)); +} + struct zspage { struct { unsigned int huge:HUGE_BITS; @@ -915,11 +930,11 @@ static void reset_page(struct page *page) static int trylock_zspage(struct zspage *zspage) { - struct page *cursor, *fail; + struct zsdesc *cursor, *fail; - for (cursor = get_first_page(zspage); cursor != NULL; cursor = - get_next_page(cursor)) { - if (!trylock_page(cursor)) { + for (cursor = get_first_zsdesc(zspage); cursor != NULL; cursor = + get_next_zsdesc(cursor)) { + if (!trylock_zsdesc(cursor)) { fail = cursor; goto unlock; } @@ -927,9 +942,9 @@ static int trylock_zspage(struct zspage *zspage) return 1; unlock: - for (cursor = get_first_page(zspage); cursor != fail; cursor = - get_next_page(cursor)) - unlock_page(cursor); + for (cursor = get_first_zsdesc(zspage); cursor != fail; cursor = + get_next_zsdesc(cursor)) + unlock_zsdesc(cursor); return 0; } @@ -1759,7 +1774,7 @@ static int putback_zspage(struct size_class *class, struct zspage *zspage) */ static void lock_zspage(struct zspage *zspage) { - struct page *curr_page, *page; + struct zsdesc *curr_zsdesc, *zsdesc; /* * Pages we haven't locked yet can be migrated off the list while we're @@ -1771,24 +1786,24 @@ static void lock_zspage(struct zspage *zspage) */ while (1) { migrate_read_lock(zspage); - page = get_first_page(zspage); - if (trylock_page(page)) + zsdesc = get_first_zsdesc(zspage); + if (trylock_zsdesc(zsdesc)) break; - get_page(page); + zsdesc_get(zsdesc); migrate_read_unlock(zspage); - wait_on_page_locked(page); - put_page(page); + wait_on_zsdesc_locked(zsdesc); + zsdesc_put(zsdesc); } - curr_page = page; - while ((page = get_next_page(curr_page))) { - if (trylock_page(page)) { - curr_page = page; + curr_zsdesc = zsdesc; + while ((zsdesc = get_next_zsdesc(curr_zsdesc))) { + if (trylock_zsdesc(zsdesc)) { + curr_zsdesc = zsdesc; } else { - get_page(page); + zsdesc_get(zsdesc); migrate_read_unlock(zspage); - wait_on_page_locked(page); - put_page(page); + wait_on_zsdesc_locked(zsdesc); + zsdesc_put(zsdesc); migrate_read_lock(zspage); } }