From patchwork Thu Dec 5 17:49:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13895896 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 BCBECE77179 for ; Thu, 5 Dec 2024 17:50:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 687B66B016B; Thu, 5 Dec 2024 12:50:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 047136B00BB; Thu, 5 Dec 2024 12:50:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B244C6B0185; Thu, 5 Dec 2024 12:50:08 -0500 (EST) 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 ED37E6B017C for ; Thu, 5 Dec 2024 12:50:07 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 87D161C8698 for ; Thu, 5 Dec 2024 17:50:06 +0000 (UTC) X-FDA: 82861643256.19.D90FF47 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf23.hostedemail.com (Postfix) with ESMTP id F1B45140009 for ; Thu, 5 Dec 2024 17:49:53 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=ck+h9ETu; spf=none (imf23.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1733420997; 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=6IwBfvloigEVpr0LprokmasSm5zXiqgw0uLRSU20BAA=; b=5XEYZgZzz5AqV7+UObjJIAyYlV6EIYSuBRTxQOWsl6RLNBas2trHvXznqJuf9dSbOfHwMO KNZ9/dmqhGPNsJ3Qua3eoyROuXbdkUJO1h572HkCzEfc/0F3Wm1CJnMXFQinTU9BZevF1L 4q+mD8zZaHkZFReImuK2F/eagJLsbz0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1733420997; a=rsa-sha256; cv=none; b=XHbA2ist2DWsUJuzXUnN/qBCqtFah9V2ACJ6HWgVmSs1TgYVuToH4RFaaf7/xlKjBzjqjD JpKQDT6yxAvX02YFlvz3H+LaG78DhEgHH+jfGY0dLvL0cfu93Zd/jDvbzeeBE1ZJPHIqPA HJKpapCR4hUSNOw5fG4GYwvNJjX3wQY= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=ck+h9ETu; spf=none (imf23.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=6IwBfvloigEVpr0LprokmasSm5zXiqgw0uLRSU20BAA=; b=ck+h9ETuPIRtaQqvp9uF81QHYr pbzfbYVdsdPylfS5KFSt03D/q5ApCAe6qykLqQH3tbm9DH8xe8jNGjNaY8IyL8GIwG0zkXhpMAphP 9BrBCneLK5efP8+fLEMsiNKlmmMF0gRFGq3YX4ALfJaiIsbGP5twx3DW/DXikEmvAG9jUGwWl5xbG /3MCjheT8iyO70zDrxX33yfv8KOJUjfqAViDWR3k9uiQivk65TpltXC9E6O0WpTAT7LtkHjmdAseH GVOA6nsIr3VWVytP0yijmjSKCasUaf5Ps5cpPbI0kk4YDmzEfExp4mkZgWHpWKtW/XrYd3B82ucyP wCosQAaQ==; Received: from willy by casper.infradead.org with local (Exim 4.98 #2 (Red Hat Linux)) id 1tJFzG-0000000DN7P-30UE; Thu, 05 Dec 2024 17:50:02 +0000 From: "Matthew Wilcox (Oracle)" To: Minchan Kim , Sergey Senozhatsky Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org, Alex Shi Subject: [PATCH v8 04/21] mm/zsmalloc: add and use pfn/zpdesc seeking funcs Date: Thu, 5 Dec 2024 17:49:41 +0000 Message-ID: <20241205175000.3187069-5-willy@infradead.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241205175000.3187069-1-willy@infradead.org> References: <20241205175000.3187069-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: F1B45140009 X-Stat-Signature: hye8xcf9dcpri3yowptxackzp9phbtky X-Rspam-User: X-HE-Tag: 1733420993-522173 X-HE-Meta: U2FsdGVkX1+6id2h9gq7/hGDO/i3zpnxVhVVEFfoRfmPmUuUnx/899SFvEcwPeD0UmIbs6CGclhD6DapvePB1hec/ogY69dJqaZm1kZ9+4uy1rVVcycsp9c13k6Gf7rZhTQm84AgjAKtDJbkTDf8dfOlIwjuOac399Ss+yUXljLBG3VUs4aoQvJwLkYJG2BZNdZejaIbvmCbqizZc42k6KbCH5ShM68l0sInxTtsgx+b9euiF9XBqmE6/cAZk30VqIb03FFZtk5SWkR2xQx9OO/zWYOCf+NnQfjEFTtk9+u5aSA9OOMUYbYqyKBT6t9UBd9m6lc9yQ8JPn+wye7mwpXFhPAvv/N/ZB6mM9Fp6oVGtZR059ziFDa9b2r+FH/kQvRC1aGuhp7wg9bDkAEPb9GluKnkS2o0ZH/sv7hbC/CWzFMrbrvJzbdRdFb7fZnC+7ETdmRwjIccYHYXmk1AdbvAKYYYh2DB+WB7G1w7Yc8Wr+BlBpK78PBlDSV0P4HSgUQfBs003N8s0lgdldukytEUHAbrN7RvjFIybTN40UhM3Mo00rxuGRxzfEygEqcVpuesL1VwZbMRHQp8NzWxmWlqytudorOz7T0iFV+v7vMq6U481aJn7QAcvB6MXclTe37A7/ldol7KRK9Ns9RYJeAR+WwpV+aC5Nh7cNLbgk9PrJLtzLuNhdOCaILd+bUKyAMnn9eMcyfBoIHryu596d4PhB4d4DUYgYjIAcSYCfVhbZwjkERCblLdhjwytEAN1+lJEVmWQ2Ja3E0e8y6WN2f2l5yVRjNwM9hCTapBZZbtjSdH5H87y5FWt3WRDxL8EipkC4JLf2VR1wl6WXAR6oESR9t1aYqHWzS7pS6yzmN4N4ECG9ZaeUSsukQG3WjVU74tA7zLG2I9RzuI1LffvOzXmya3qO92ciPJfCtjSqYSx506TDSs7igzGeZ9lkfOTIwo9wVl9WvqlO4BveI W8ZzQ4gX 3an6+G/KDnIOxXryECBs2ZEFWBdA+FJ7OOshaN+bDMynEWOakpzHObqSsDCqAhjYQbG2D0XTk9QgCgwKfSDVgYdZxW939gUQYD5M85Uzwq1k3AzBtunNbHP1nt2vsc7xDKGOX/lmAIPH0mRQx8qU9RmT9Qf/DyHH+vzhsNyXeDja2l6HJG+XUMyQKTeSd1+JEs+LhTFFYjBAMrK7O0ugtQXVFGqX0Cxpm5UFGP935WJsztgGfYhDMsLMmpksO9fhl7r2Hkhw237cGtNusDmyoCf1/jCA3HmlbAlUC9jBY0etqybg= 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: From: Hyeonggon Yoo <42.hyeyoo@gmail.com> Add pfn_zpdesc(), pfn_zpdesc() and kmap_local_zpdesc(). Convert obj_to_location() to take zpdesc and also convert its users to use zpdesc. Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com> Signed-off-by: Alex Shi --- mm/zpdesc.h | 14 ++++++++++ mm/zsmalloc.c | 75 ++++++++++++++++++++++++++------------------------- 2 files changed, 52 insertions(+), 37 deletions(-) diff --git a/mm/zpdesc.h b/mm/zpdesc.h index 4c7feee5ef1a..937de815a4ac 100644 --- a/mm/zpdesc.h +++ b/mm/zpdesc.h @@ -96,4 +96,18 @@ static inline void zpdesc_put(struct zpdesc *zpdesc) folio_put(zpdesc_folio(zpdesc)); } +static inline void *kmap_local_zpdesc(struct zpdesc *zpdesc) +{ + return kmap_local_page(zpdesc_page(zpdesc)); +} + +static inline unsigned long zpdesc_pfn(struct zpdesc *zpdesc) +{ + return page_to_pfn(zpdesc_page(zpdesc)); +} + +static inline struct zpdesc *pfn_zpdesc(unsigned long pfn) +{ + return page_zpdesc(pfn_to_page(pfn)); +} #endif diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 5e6467c10757..03b77690c616 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -775,15 +775,15 @@ static struct zpdesc *get_next_zpdesc(struct zpdesc *zpdesc) } /** - * 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 + * @zpdesc: zpdesc 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 zpdesc **zpdesc, unsigned int *obj_idx) { - *page = pfn_to_page(obj >> OBJ_INDEX_BITS); + *zpdesc = pfn_zpdesc(obj >> OBJ_INDEX_BITS); *obj_idx = (obj & OBJ_INDEX_MASK); } @@ -1199,13 +1199,13 @@ void *zs_map_object(struct zs_pool *pool, unsigned long handle, enum zs_mapmode mm) { struct zspage *zspage; - struct page *page; + struct zpdesc *zpdesc; unsigned long obj, off; unsigned int obj_idx; struct size_class *class; struct mapping_area *area; - struct page *pages[2]; + struct zpdesc *zpdescs[2]; void *ret; /* @@ -1218,8 +1218,8 @@ void *zs_map_object(struct zs_pool *pool, unsigned long handle, /* It guarantees it can get zspage from handle safely */ read_lock(&pool->migrate_lock); obj = handle_to_obj(handle); - obj_to_location(obj, &page, &obj_idx); - zspage = get_zspage(page); + obj_to_location(obj, &zpdesc, &obj_idx); + zspage = get_zspage(zpdesc_page(zpdesc)); /* * migration cannot move any zpages in this zspage. Here, class->lock @@ -1238,17 +1238,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_local_page(page); + area->vm_addr = kmap_local_zpdesc(zpdesc); 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]); + zpdescs[0] = zpdesc; + zpdescs[1] = get_next_zpdesc(zpdesc); + BUG_ON(!zpdescs[1]); - ret = __zs_map_object(area, (struct zpdesc **)pages, off, class->size); + ret = __zs_map_object(area, zpdescs, off, class->size); out: if (likely(!ZsHugePage(zspage))) ret += ZS_HANDLE_SIZE; @@ -1260,7 +1260,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 zpdesc *zpdesc; unsigned long obj, off; unsigned int obj_idx; @@ -1268,8 +1268,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, &zpdesc, &obj_idx); + zspage = get_zspage(zpdesc_page(zpdesc)); class = zspage_class(pool, zspage); off = offset_in_page(class->size * obj_idx); @@ -1277,13 +1277,13 @@ void zs_unmap_object(struct zs_pool *pool, unsigned long handle) if (off + class->size <= PAGE_SIZE) kunmap_local(area->vm_addr); else { - struct page *pages[2]; + struct zpdesc *zpdescs[2]; - pages[0] = page; - pages[1] = get_next_page(page); - BUG_ON(!pages[1]); + zpdescs[0] = zpdesc; + zpdescs[1] = get_next_zpdesc(zpdesc); + BUG_ON(!zpdescs[1]); - __zs_unmap_object(area, (struct zpdesc **)pages, off, class->size); + __zs_unmap_object(area, zpdescs, off, class->size); } local_unlock(&zs_map_area.lock); @@ -1425,23 +1425,24 @@ static void obj_free(int class_size, unsigned long obj) { struct link_free *link; struct zspage *zspage; - struct page *f_page; + struct zpdesc *f_zpdesc; unsigned long f_offset; unsigned int f_objidx; void *vaddr; - obj_to_location(obj, &f_page, &f_objidx); + + obj_to_location(obj, &f_zpdesc, &f_objidx); f_offset = offset_in_page(class_size * f_objidx); - zspage = get_zspage(f_page); + zspage = get_zspage(zpdesc_page(f_zpdesc)); - vaddr = kmap_local_page(f_page); + vaddr = kmap_local_zpdesc(f_zpdesc); 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_zpdesc->next = NULL; set_freeobj(zspage, f_objidx); kunmap_local(vaddr); @@ -1486,7 +1487,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 zpdesc *s_zpdesc, *d_zpdesc; unsigned int s_objidx, d_objidx; unsigned long s_off, d_off; void *s_addr, *d_addr; @@ -1495,8 +1496,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_zpdesc, &s_objidx); + obj_to_location(dst, &d_zpdesc, &d_objidx); s_off = offset_in_page(class->size * s_objidx); d_off = offset_in_page(class->size * d_objidx); @@ -1507,8 +1508,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_local_page(s_page); - d_addr = kmap_local_page(d_page); + s_addr = kmap_local_zpdesc(s_zpdesc); + d_addr = kmap_local_zpdesc(d_zpdesc); while (1) { size = min(s_size, d_size); @@ -1533,17 +1534,17 @@ static void zs_object_copy(struct size_class *class, unsigned long dst, if (s_off >= PAGE_SIZE) { kunmap_local(d_addr); kunmap_local(s_addr); - s_page = get_next_page(s_page); - s_addr = kmap_local_page(s_page); - d_addr = kmap_local_page(d_page); + s_zpdesc = get_next_zpdesc(s_zpdesc); + s_addr = kmap_local_zpdesc(s_zpdesc); + d_addr = kmap_local_zpdesc(d_zpdesc); s_size = class->size - written; s_off = 0; } if (d_off >= PAGE_SIZE) { kunmap_local(d_addr); - d_page = get_next_page(d_page); - d_addr = kmap_local_page(d_page); + d_zpdesc = get_next_zpdesc(d_zpdesc); + d_addr = kmap_local_zpdesc(d_zpdesc); d_size = class->size - written; d_off = 0; } @@ -1782,7 +1783,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 zpdesc *dummy; void *s_addr, *d_addr, *addr; unsigned int offset; unsigned long handle;