From patchwork Thu Jul 13 04:20:20 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: 13311269 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 396D8EB64DD for ; Thu, 13 Jul 2023 04:21:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B49768D0006; Thu, 13 Jul 2023 00:21:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AD0948D0005; Thu, 13 Jul 2023 00:21:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 924198D0006; Thu, 13 Jul 2023 00:21:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 808C98D0005 for ; Thu, 13 Jul 2023 00:21:11 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5A6138010B for ; Thu, 13 Jul 2023 04:21:11 +0000 (UTC) X-FDA: 81005288742.18.00B2B4B Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by imf19.hostedemail.com (Postfix) with ESMTP id 843411A0010 for ; Thu, 13 Jul 2023 04:21:09 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=Jt6o06lR; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf19.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.210.182 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=1689222069; 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=uhaPI5HZCviIKmkdgH7KFJDdrqT6GNzpynmu4YA1d+4=; b=Zj0M3KJYDiP85bCWX+3yG/x3ckBvfNyyh2jtjdj5P1hChiJ9dp2quD9+PHQEjoF67yqVSy VwAbnAJ3BmTpqR6Q9WP3bvfLSuOhLg46sHJEqtBurk3b5pc7xiDV5XErXNIzXQBCScbWtv a7EIerV3dutnqRksnNh5fAuh9cNjfBc= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=Jt6o06lR; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf19.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.210.182 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689222069; a=rsa-sha256; cv=none; b=pu7PStGRNrNCnToWM0TF7rHyAvfORMhTwrt4+zio24Rf52naTR5iiOeu8yRrJMkP8DU1oH 19nSsucqYD0Tu9o+kepOHLcxmsObQA79cI6XgWa0PeloNMx5LgjDWsQjU+8EbkeJX6v573 8NwyecyZ6S/6hBJ7thCsUFuurqusngY= Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-6686c74183cso322986b3a.1 for ; Wed, 12 Jul 2023 21:21:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689222068; x=1691814068; 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=uhaPI5HZCviIKmkdgH7KFJDdrqT6GNzpynmu4YA1d+4=; b=Jt6o06lRegWfpT6s7u556O96jLXuVWenL3j7rdCJMMEZJSxbKfdLZdvetPddoF/DHX PAMG0XVW/6owS3g4G4hGDuiYl5Weo+v61dNqznEhQrdjvfHaNR0Uz3Xhg37UAFAsNb7U ZH7JKwt8s7tvmf6jfRAoe5445IXGboDowduaXGoJduEmrtA/Gs04jyb+QhdGq2tCblsB VilcMo/Li/bBOTmGNGKEK+fobdvYvHTEEULz0+R5qEX5V9BHphgzBgL0oa3cqLS5uL+S wcdF4m7jBn35fTjxbHwyr18gTW56GA0WU5LMGze94rRKwRwLwPSLNaPW6F1EdVP1tc72 Ad2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689222068; x=1691814068; 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=uhaPI5HZCviIKmkdgH7KFJDdrqT6GNzpynmu4YA1d+4=; b=VxeXsAiOjxSaWCD5J4PnwuKhjf3d/OxXuwax48SU8GdriSjsmCMbwfWQgSWFTQP9f2 +mQbDVOuyhNz2DHv7h6EcO9mcTouGNWnzz4rGqdnG4vNQEEPPIIw0MyM8Wh9BTP9lcPm AB1i8YltTRkHJOVwrV/iAIt1/pMP6kJg4IstMEoqv7yXZLoIFTvxShdzTu0eKAtQA4yP XrNE1R3kQEqmlI2KsEHxM4YKtJuTebVxmRQhvgwMaXRILLLFQ7qYuX08rOfwOd4mzJRd 3NTuDRMJ8NUmP1WcEVYCPHhdPXP2yjrepcLE1Ug28i1qhAYcfVE28WBKYHV+3VTyYjbb I8PQ== X-Gm-Message-State: ABy/qLagop6xAglOre7qjefBnxa6Zxj7Zwz8XAMQgm7dbrpxJ2N5xPgi l4qa5R4gPLBi0IVpVpsmz+E= X-Google-Smtp-Source: APBJJlEe7OIMuJtVjHfXHkehY78DJUMXlwp6taFHwT6PsouXRsh0IpuGtqw7vkbfdP9Ouwmze4dUZA== X-Received: by 2002:a05:6a00:1692:b0:668:6445:8931 with SMTP id k18-20020a056a00169200b0066864458931mr807724pfc.29.1689222068309; Wed, 12 Jul 2023 21:21:08 -0700 (PDT) Received: from fedora.. ([1.245.179.104]) by smtp.gmail.com with ESMTPSA id u18-20020aa78392000000b006827c26f147sm4346601pfm.138.2023.07.12.21.21.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 21:21:07 -0700 (PDT) From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Minchan Kim , Sergey Senozhatsky Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Matthew Wilcox , Mike Rapoport , Hyeonggon Yoo <42.hyeyoo@gmail.com> Subject: [RFC PATCH v2 05/21] mm/zsmalloc: convert {try,}lock_zspage() to use zsdesc Date: Thu, 13 Jul 2023 13:20:20 +0900 Message-ID: <20230713042037.980211-6-42.hyeyoo@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230713042037.980211-1-42.hyeyoo@gmail.com> References: <20230713042037.980211-1-42.hyeyoo@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 843411A0010 X-Stat-Signature: 5pycruam4u64wofqeja6yihs4tjcffqg X-HE-Tag: 1689222069-292798 X-HE-Meta: U2FsdGVkX18Z8gdCtrCngpQp/4X2wRAuFgjowyc4+N6bceba7EAVvoGax/8BIDMDeNLmu96BXYKaJB6EjksnZ/NwjX5ckhH+RtVd6FK/FYv+UrdPys7GLELTX7f3tSRkY32wNRpMNv9za60avQmQZzzw1dDwFpyWRrWAZcTuur1OiPvoZeji2a04Nr9TeT1FMjOPAh7exMGIDRL/Xz8pVMWMfaMJy2bB/69a+hWZ8vKfYbiRC0ElCpP5DtrFg+Pw5rI6dODj1JnY3+X920c2dN/ysBwE0otQTmKHyTIYldC8UZJLHklUOfFStMeb117x7+5XGCh8Y4qMgI3XPZp3jOo9fYUGLsvYlhhXwDYuDAg1wInhXUGIppmbypo//5gr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VLWFReRIZ0saQ70ySA3rgD0Dw9OlJqle+RQXI+vGH20qrKvg9KtJurA+kfIHH9YKHfGRcPLdAYh3wOZJrDROl6OqGNg3cB/nnvFwVyFSsIV6e0bFWoMXwTNrrnpmLSjPw== 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: 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 f44a2d8a36b5..2cce76a19a1e 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -326,6 +326,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)); +} + /* huge object: pages_per_zspage == 1 && maxobj_per_zspage == 1 */ static void SetZsHugePage(struct zspage *zspage) { @@ -911,11 +926,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; } @@ -923,9 +938,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; } @@ -1755,7 +1770,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 @@ -1767,24 +1782,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); } }