From patchwork Thu Nov 30 10:12:28 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: 13474204 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 8D114C4167B for ; Thu, 30 Nov 2023 10:13:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1EC796B0462; Thu, 30 Nov 2023 05:13:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 19F7B6B0463; Thu, 30 Nov 2023 05:13:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 015AE6B0464; Thu, 30 Nov 2023 05:13:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E08146B0462 for ; Thu, 30 Nov 2023 05:13:23 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B8581C014C for ; Thu, 30 Nov 2023 10:13:23 +0000 (UTC) X-FDA: 81514208286.30.526D941 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) by imf10.hostedemail.com (Postfix) with ESMTP id DD969C000B for ; Thu, 30 Nov 2023 10:13:21 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Zj6XWtEm; spf=pass (imf10.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.215.172 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701339201; a=rsa-sha256; cv=none; b=WUuxItBpWWrpE5U1EJokPPf3MyAnHBzi7IffRD0/7Rp8goXLCjCDYSWiYa9F1JQfrUzv9I n5gBzMKyCAuPgRgdzR5+WfgJfyQdI/vw8sHfFkC8sUsgyeKQy49veQBE27bgvNy0u/3Yqy 5X5uuhq9LNKBh+7/CtizRmEuVltDPTE= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Zj6XWtEm; spf=pass (imf10.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.215.172 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701339201; 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=sN9WK9gt3M9tH0088FFqUlWMS1+EeVFdkh7yWGn+zTA=; b=ECGk3/LXurwwtpZNHGT/MZG3zZ5pRJMWjnxPoKt3ZS5GMRCvwwjjP6bODEEHdvQ3/y+eIf JpK4KnDRs+krivBrF2nAoFZCzxSdZbD578glybNzcvhMwM2z9DFArJbhstWWHr+oWQGvWU qxNPQXNWTS5607BmH45jkubItoL7TLw= Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-5c5f0e325a6so627358a12.1 for ; Thu, 30 Nov 2023 02:13:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701339201; x=1701944001; 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=sN9WK9gt3M9tH0088FFqUlWMS1+EeVFdkh7yWGn+zTA=; b=Zj6XWtEmjziQGJFOaUvnkkomWgW6VcupulW2LOrc2Zok3FAwxuRBwtN/tf3Q+JBxGV MxwEstd4ebUEUi7m9KkuccLE0fBSwMdD2gVAkj6V+O9lGRgKfLxV+cEEdgqoCpDtXKYn Z+FLUrD0YltCevVuJ53n3Y5ZLhmUhxYgGXHhQ5Nn6D04kHxgROnI0Ba1N1R0/OjeKJ3I JzDGKFyphBU0GRGsrQORP7ZVTkD+SPLcDyhKdN3SfegrFvCegU8c3OB30amiA8Qve5Vz Zl7S/+CFUh6T7g23vDK1WobjLXhhlpNMhcOlnixXfMtVw/s860QWCkwXmmJVkvyi7n0G WYzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701339201; x=1701944001; 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=sN9WK9gt3M9tH0088FFqUlWMS1+EeVFdkh7yWGn+zTA=; b=lIkcCRgHyxZkeP23aEIC89ry311+QbG2BBSse3MspeUngewmv32VdU1Cl+oLxQyUKG jJGzA0czfyx+X2yKG2z2O+B25Agf3QQbNG1ltbajqDtALFuRvabHS+Yd3StWxf+Q2/07 1QAcn/FYRq3u/OPqa1SOOXh7jXxvu2MRBEGIcQi+0jitVvr8cFPpz+JkoLjo1JKXq/w4 WBX2Hi7ciErFgI43EzlN3DMinREqywgoqzLNGs34OXHycKFUfsjzRcsHy3yS1Tl1oH6G SIZTGpeWt78Oo8v/FNq+7ETxX5OPfdGItbRiyNJ7TZCCNpri/AFkQxGhxvMgmEgUcPbE Cfzg== X-Gm-Message-State: AOJu0YzSZ6dDynp39iV+OVo/Zo/JUgEbq/Fo2JjhY1rz3fjb+7XX4vV2 CSOj1XythlyBK3+7hJ8i9kw= X-Google-Smtp-Source: AGHT+IEwFMzcf5tYd6FjYnBLPQh0f175hnZdLkui0O9Bmt3oQnmtyBpIi2tN4qbWfiJCd0Rr+uiMgQ== X-Received: by 2002:a05:6a20:d48e:b0:187:3b1f:219c with SMTP id im14-20020a056a20d48e00b001873b1f219cmr25710613pzb.10.1701339200517; Thu, 30 Nov 2023 02:13:20 -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.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 02:13:19 -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 07/21] mm/zsmalloc: convert obj_to_location() and its users to use zsdesc Date: Thu, 30 Nov 2023 19:12:28 +0900 Message-Id: <20231130101242.2590384-8-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-Server: rspam08 X-Rspamd-Queue-Id: DD969C000B X-Stat-Signature: uii3phmryuke138ftupcb49o51o5e831 X-Rspam-User: X-HE-Tag: 1701339201-545139 X-HE-Meta: U2FsdGVkX18hqKEojBBwwZkVoIlaeqQwTNxcU7Y9takoEV7GQryERTRSzIDP7E46DmAn51yuMcCw07m8JoX0MIC8V1Vnsnz/IrtNUzYYTlG37+3uESyk7OZ3fezqMjMIMuERiB5kdLQfWFV7JM25KWvFSv4WgjBbB4BU4CsoK02K84GIeKpaehe5BeEihDXW9d6fQ4trTgBTMQSLe4KXMCWBZ2RceAX6xteJocCxFvv/uR6oTIZQuS4Rh91SJlc5bVw6Bt3umgSuAdYJ1tr3uhhj3AkGCMzMZ1JjtswMPbK4E6OZA52V9Tt0PBNt5ley14UuL5zkIlEM4CE5UcygcSG7rL5EKc2DzxUeqv1CE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0s1g3HXJubOoxGIfJpjeehqddfcx6dG6D8PYdKY/uL5lNKqp95U6ricPtnMnU0R0e3K+sNAqr52bruUYzH0uifGuQBUSo+rQY3STAtJhCRKJhRoLeprgSul7KyWDahttIGS0oMmWAYBgrJKqmSiat78o2ng== 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: List-Subscribe: List-Unsubscribe: Convert obj_to_location() to take zsdesc and also convert its users to use zsdesc. Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> --- mm/zsmalloc.c | 75 ++++++++++++++++++++++++++------------------------- 1 file changed, 38 insertions(+), 37 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index be3b8734bdf2..f5a20c20ec19 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -864,16 +864,16 @@ static __maybe_unused struct zsdesc *get_next_zsdesc(struct zsdesc *zsdesc) } /** - * obj_to_location - get (, ) from encoded object value + * obj_to_location - get (, ) from encoded object value * @obj: the encoded object value - * @page: page object resides in zspage + * @zsdesc: zsdesc object resides in zspage * @obj_idx: object index */ -static void obj_to_location(unsigned long obj, struct page **page, +static void obj_to_location(unsigned long obj, struct zsdesc **zsdesc, unsigned int *obj_idx) { obj >>= OBJ_TAG_BITS; - *page = pfn_to_page(obj >> OBJ_INDEX_BITS); + *zsdesc = pfn_zsdesc(obj >> OBJ_INDEX_BITS); *obj_idx = (obj & OBJ_INDEX_MASK); } @@ -1302,13 +1302,13 @@ void *zs_map_object(struct zs_pool *pool, unsigned long handle, enum zs_mapmode mm) { struct zspage *zspage; - struct page *page; + struct zsdesc *zsdesc; unsigned long obj, off; unsigned int obj_idx; struct size_class *class; struct mapping_area *area; - struct page *pages[2]; + struct zsdesc *zsdescs[2]; void *ret; /* @@ -1321,8 +1321,8 @@ void *zs_map_object(struct zs_pool *pool, unsigned long handle, /* It guarantees it can get zspage from handle safely */ spin_lock(&pool->lock); obj = handle_to_obj(handle); - obj_to_location(obj, &page, &obj_idx); - zspage = get_zspage(page); + obj_to_location(obj, &zsdesc, &obj_idx); + zspage = get_zspage(zsdesc_page(zsdesc)); /* * migration cannot move any zpages in this zspage. Here, pool->lock @@ -1341,17 +1341,17 @@ void *zs_map_object(struct zs_pool *pool, unsigned long handle, area->vm_mm = mm; if (off + class->size <= PAGE_SIZE) { /* this object is contained entirely within a page */ - area->vm_addr = kmap_atomic(page); + area->vm_addr = zsdesc_kmap_atomic(zsdesc); ret = area->vm_addr + off; goto out; } /* this object spans two pages */ - pages[0] = page; - pages[1] = get_next_page(page); - BUG_ON(!pages[1]); + zsdescs[0] = zsdesc; + zsdescs[1] = get_next_zsdesc(zsdesc); + BUG_ON(!zsdescs[1]); - ret = __zs_map_object(area, (struct zsdesc **)pages, off, class->size); + ret = __zs_map_object(area, zsdescs, off, class->size); out: if (likely(!ZsHugePage(zspage))) ret += ZS_HANDLE_SIZE; @@ -1363,7 +1363,7 @@ EXPORT_SYMBOL_GPL(zs_map_object); void zs_unmap_object(struct zs_pool *pool, unsigned long handle) { struct zspage *zspage; - struct page *page; + struct zsdesc *zsdesc; unsigned long obj, off; unsigned int obj_idx; @@ -1371,8 +1371,8 @@ void zs_unmap_object(struct zs_pool *pool, unsigned long handle) struct mapping_area *area; obj = handle_to_obj(handle); - obj_to_location(obj, &page, &obj_idx); - zspage = get_zspage(page); + obj_to_location(obj, &zsdesc, &obj_idx); + zspage = get_zspage(zsdesc_page(zsdesc)); class = zspage_class(pool, zspage); off = offset_in_page(class->size * obj_idx); @@ -1380,13 +1380,13 @@ void zs_unmap_object(struct zs_pool *pool, unsigned long handle) if (off + class->size <= PAGE_SIZE) kunmap_atomic(area->vm_addr); else { - struct page *pages[2]; + struct zsdesc *zsdescs[2]; - pages[0] = page; - pages[1] = get_next_page(page); - BUG_ON(!pages[1]); + zsdescs[0] = zsdesc; + zsdescs[1] = get_next_zsdesc(zsdesc); + BUG_ON(!zsdescs[1]); - __zs_unmap_object(area, (struct zsdesc **)pages, off, class->size); + __zs_unmap_object(area, zsdescs, off, class->size); } local_unlock(&zs_map_area.lock); @@ -1528,23 +1528,24 @@ static void obj_free(int class_size, unsigned long obj) { struct link_free *link; struct zspage *zspage; - struct page *f_page; + struct zsdesc *f_zsdesc; unsigned long f_offset; unsigned int f_objidx; void *vaddr; - obj_to_location(obj, &f_page, &f_objidx); + + obj_to_location(obj, &f_zsdesc, &f_objidx); f_offset = offset_in_page(class_size * f_objidx); - zspage = get_zspage(f_page); + zspage = get_zspage(zsdesc_page(f_zsdesc)); - vaddr = kmap_atomic(f_page); + vaddr = zsdesc_kmap_atomic(f_zsdesc); link = (struct link_free *)(vaddr + f_offset); /* Insert this object in containing zspage's freelist */ if (likely(!ZsHugePage(zspage))) link->next = get_freeobj(zspage) << OBJ_TAG_BITS; else - f_page->index = 0; + f_zsdesc->next = NULL; set_freeobj(zspage, f_objidx); kunmap_atomic(vaddr); @@ -1587,7 +1588,7 @@ EXPORT_SYMBOL_GPL(zs_free); static void zs_object_copy(struct size_class *class, unsigned long dst, unsigned long src) { - struct page *s_page, *d_page; + struct zsdesc *s_zsdesc, *d_zsdesc; unsigned int s_objidx, d_objidx; unsigned long s_off, d_off; void *s_addr, *d_addr; @@ -1596,8 +1597,8 @@ static void zs_object_copy(struct size_class *class, unsigned long dst, s_size = d_size = class->size; - obj_to_location(src, &s_page, &s_objidx); - obj_to_location(dst, &d_page, &d_objidx); + obj_to_location(src, &s_zsdesc, &s_objidx); + obj_to_location(dst, &d_zsdesc, &d_objidx); s_off = offset_in_page(class->size * s_objidx); d_off = offset_in_page(class->size * d_objidx); @@ -1608,8 +1609,8 @@ static void zs_object_copy(struct size_class *class, unsigned long dst, if (d_off + class->size > PAGE_SIZE) d_size = PAGE_SIZE - d_off; - s_addr = kmap_atomic(s_page); - d_addr = kmap_atomic(d_page); + s_addr = zsdesc_kmap_atomic(s_zsdesc); + d_addr = zsdesc_kmap_atomic(d_zsdesc); while (1) { size = min(s_size, d_size); @@ -1634,17 +1635,17 @@ static void zs_object_copy(struct size_class *class, unsigned long dst, if (s_off >= PAGE_SIZE) { kunmap_atomic(d_addr); kunmap_atomic(s_addr); - s_page = get_next_page(s_page); - s_addr = kmap_atomic(s_page); - d_addr = kmap_atomic(d_page); + s_zsdesc = get_next_zsdesc(s_zsdesc); + s_addr = zsdesc_kmap_atomic(s_zsdesc); + d_addr = zsdesc_kmap_atomic(d_zsdesc); s_size = class->size - written; s_off = 0; } if (d_off >= PAGE_SIZE) { kunmap_atomic(d_addr); - d_page = get_next_page(d_page); - d_addr = kmap_atomic(d_page); + d_zsdesc = get_next_zsdesc(d_zsdesc); + d_addr = zsdesc_kmap_atomic(d_zsdesc); d_size = class->size - written; d_off = 0; } @@ -1910,7 +1911,7 @@ static int zs_page_migrate(struct page *newpage, struct page *page, struct zs_pool *pool; struct size_class *class; struct zspage *zspage; - struct page *dummy; + struct zsdesc *dummy; void *s_addr, *d_addr, *addr; unsigned int offset; unsigned long handle;