From nobody Sun Feb 8 06:49:35 2026 Received: from out-172.mta1.migadu.com (out-172.mta1.migadu.com [95.215.58.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0EDC01DE2C1 for ; Wed, 5 Mar 2025 06:11:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741155117; cv=none; b=ibjg0IXPWXIRF2KHkBW+tljXXx43OX2Vrq3W3UfGQNKtTgs8ly/qzR4OjUr42SYbF6qZ/Yst8+v5sqcvBQrV7TQrK9iJ4Me7GI7TWThCo8rX1Ct7EPEQPQ45bFePQEglfOGzIWDqIAEvMqnMtSoEkEBr0XS/zq2pk5FtsnyR3zU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741155117; c=relaxed/simple; bh=4dy+m/XxTgeCzQ7zVcCdW+/Lm2thUR9Kdc8yM1twUBo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OIp6V17rBAnnayQpMbRuI6MF6E7Rrt4Mqb4HuGJGz7PRli0Qce4jzUTTneQyRQo13xxYSPSTsBOpT0gG5QQqWF75ZYUYm3Jd4QKFn7P1/ezpE9u3cTFK1TZyYs9JZyCuGshbqk43SU9POYkqh4/KtwbhHfW374unBzteexfV/TI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=tK8A0eF3; arc=none smtp.client-ip=95.215.58.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="tK8A0eF3" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1741155112; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WoO6FUy5jZ5BOBiD7+tifxnzM0sl78f3lOIy/v/d1Yo=; b=tK8A0eF3Xlefw6CMLjm18bHwmIKhLt12hIUd+n5xuMqL3BbtRIYg5Gaj8g5jd+DEaWgwwz /Bwog36MMW0mCFIHU/kOoYr9xP/Xz/kmzC90sgmkI3tV66KzlJIjgoPnnqSrOz/5v/3rAn Y1ADaz2vPlUZexNOEZegHZGBkvOqNkw= From: Yosry Ahmed To: Andrew Morton Cc: Johannes Weiner , Nhat Pham , Chengming Zhou , Minchan Kim , Sergey Senozhatsky , Herbert Xu , Thomas Gleixner , Peter Zijlstra , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [PATCH mm-unstable 1/5] mm: zpool: Add interfaces for object read/write APIs Date: Wed, 5 Mar 2025 06:11:29 +0000 Message-ID: <20250305061134.4105762-2-yosry.ahmed@linux.dev> In-Reply-To: <20250305061134.4105762-1-yosry.ahmed@linux.dev> References: <20250305061134.4105762-1-yosry.ahmed@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Zsmalloc introduce new APIs to read/write objects besides mapping them. Add the necessary zpool interfaces. Signed-off-by: Yosry Ahmed Acked-by: Johannes Weiner Acked-by: Nhat Pham Reviewed-by: Sergey Senozhatsky --- include/linux/zpool.h | 17 +++++++++++++++ mm/zpool.c | 48 +++++++++++++++++++++++++++++++++++++++++++ mm/zsmalloc.c | 21 +++++++++++++++++++ 3 files changed, 86 insertions(+) diff --git a/include/linux/zpool.h b/include/linux/zpool.h index 5e6dc46b8cc4c..1784e735ee049 100644 --- a/include/linux/zpool.h +++ b/include/linux/zpool.h @@ -52,6 +52,16 @@ void *zpool_map_handle(struct zpool *pool, unsigned long= handle, =20 void zpool_unmap_handle(struct zpool *pool, unsigned long handle); =20 + +void *zpool_obj_read_begin(struct zpool *zpool, unsigned long handle, + void *local_copy); + +void zpool_obj_read_end(struct zpool *zpool, unsigned long handle, + void *handle_mem); + +void zpool_obj_write(struct zpool *zpool, unsigned long handle, + void *handle_mem, size_t mem_len); + u64 zpool_get_total_pages(struct zpool *pool); =20 =20 @@ -90,6 +100,13 @@ struct zpool_driver { enum zpool_mapmode mm); void (*unmap)(void *pool, unsigned long handle); =20 + void *(*obj_read_begin)(void *pool, unsigned long handle, + void *local_copy); + void (*obj_read_end)(void *pool, unsigned long handle, + void *handle_mem); + void (*obj_write)(void *pool, unsigned long handle, + void *handle_mem, size_t mem_len); + u64 (*total_pages)(void *pool); }; =20 diff --git a/mm/zpool.c b/mm/zpool.c index 4bbd12d4b6599..378c2d1e5638f 100644 --- a/mm/zpool.c +++ b/mm/zpool.c @@ -320,6 +320,54 @@ void zpool_unmap_handle(struct zpool *zpool, unsigned = long handle) zpool->driver->unmap(zpool->pool, handle); } =20 +/** + * zpool_obj_read_begin() - Start reading from a previously allocated hand= le. + * @zpool: The zpool that the handle was allocated from + * @handle: The handle to read from + * @local_copy: A local buffer to use if needed. + * + * This starts a read operation of a previously allocated handle. The pass= ed + * @local_copy buffer may be used if needed by copying the memory into. + * zpool_obj_read_end() MUST be called after the read is completed to undo= any + * actions taken (e.g. release locks). + * + * Returns: A pointer to the handle memory to be read, if @local_copy is u= sed, + * the returned pointer is @local_copy. + */ +void *zpool_obj_read_begin(struct zpool *zpool, unsigned long handle, + void *local_copy) +{ + return zpool->driver->obj_read_begin(zpool->pool, handle, local_copy); +} + +/** + * zpool_obj_read_end() - Finish reading from a previously allocated handl= e. + * @zpool: The zpool that the handle was allocated from + * @handle: The handle to read from + * @handle_mem: The pointer returned by zpool_obj_read_begin() + * + * Finishes a read operation previously started by zpool_obj_read_begin(). + */ +void zpool_obj_read_end(struct zpool *zpool, unsigned long handle, + void *handle_mem) +{ + zpool->driver->obj_read_end(zpool->pool, handle, handle_mem); +} + +/** + * zpool_obj_write() - Write to a previously allocated handle. + * @zpool: The zpool that the handle was allocated from + * @handle: The handle to read from + * @handle_mem: The memory to copy from into the handle. + * @mem_len: The length of memory to be written. + * + */ +void zpool_obj_write(struct zpool *zpool, unsigned long handle, + void *handle_mem, size_t mem_len) +{ + zpool->driver->obj_write(zpool->pool, handle, handle_mem, mem_len); +} + /** * zpool_get_total_pages() - The total size of the pool * @zpool: The zpool to check diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 63c99db71dc1f..d84b300db64e7 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -507,6 +507,24 @@ static void zs_zpool_unmap(void *pool, unsigned long h= andle) zs_unmap_object(pool, handle); } =20 +static void *zs_zpool_obj_read_begin(void *pool, unsigned long handle, + void *local_copy) +{ + return zs_obj_read_begin(pool, handle, local_copy); +} + +static void zs_zpool_obj_read_end(void *pool, unsigned long handle, + void *handle_mem) +{ + zs_obj_read_end(pool, handle, handle_mem); +} + +static void zs_zpool_obj_write(void *pool, unsigned long handle, + void *handle_mem, size_t mem_len) +{ + zs_obj_write(pool, handle, handle_mem, mem_len); +} + static u64 zs_zpool_total_pages(void *pool) { return zs_get_total_pages(pool); @@ -522,6 +540,9 @@ static struct zpool_driver zs_zpool_driver =3D { .free =3D zs_zpool_free, .map =3D zs_zpool_map, .unmap =3D zs_zpool_unmap, + .obj_read_begin =3D zs_zpool_obj_read_begin, + .obj_read_end =3D zs_zpool_obj_read_end, + .obj_write =3D zs_zpool_obj_write, .total_pages =3D zs_zpool_total_pages, }; =20 --=20 2.48.1.711.g2feabab25a-goog From nobody Sun Feb 8 06:49:35 2026 Received: from out-175.mta1.migadu.com (out-175.mta1.migadu.com [95.215.58.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 91AC01D5159 for ; Wed, 5 Mar 2025 06:11:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741155119; cv=none; b=mKabpE4ADgUgJknk3e1U4FEfx/ACsl0k+JVU4JAJ9OpnXhCkkEuDTnEwaE6FUYOpb+AJyCWaHYiLSfX2/r+2ofhzs3nVcerVSxF3ucAFvJ2txstgmTInb+aSOG410Gs4M8mD6w7PUaotRe/T/iDapARsnEIj3gMuvOgz2xaaeUc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741155119; c=relaxed/simple; bh=3vDhgAAJC9AGnwTh0lEEl6+JTyqM2vOXcT2aPBYg3M0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G8QFiZRBrixomKnoZ2H5smkYCq0+IVKO0+Pk7c+QnKBF0NQNLLf0LVGOSQF3Pd6x+wBYLk3snNHMV60zEKMSKtQUsZhYwe+6A4RO+7QOvTrSCeHFx/RpEHFKZIkMFTQC1RumIefrNC5/UVsmafiCljl2GhLuXpwmy7G2Lcxxwt0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=cifFrb0J; arc=none smtp.client-ip=95.215.58.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="cifFrb0J" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1741155115; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UHSh+fRW+hK9gv2DRy9l80+ev7l5Ymp5fdm86lOdRKo=; b=cifFrb0JgHRG/57JZ+Mr7M1biLTy24E8MBJu0NSeL4yBba2WzMq9kV83VyVoa8v8fO66+K xYm4fDL+06wlMYNY2zJY/bfIQyNjq1a3UXkuU0ff/RacIWMgjkcl+bSYrX1S3zl27OPYWh KucFgxjj3j3khybeKNnjCvbaqXJ2d3c= From: Yosry Ahmed To: Andrew Morton Cc: Johannes Weiner , Nhat Pham , Chengming Zhou , Minchan Kim , Sergey Senozhatsky , Herbert Xu , Thomas Gleixner , Peter Zijlstra , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [PATCH mm-unstable 2/5] mm: zswap: Use object read/write APIs instead of object mapping APIs Date: Wed, 5 Mar 2025 06:11:30 +0000 Message-ID: <20250305061134.4105762-3-yosry.ahmed@linux.dev> In-Reply-To: <20250305061134.4105762-1-yosry.ahmed@linux.dev> References: <20250305061134.4105762-1-yosry.ahmed@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Use the new object read/write APIs instead of mapping APIs. On compress side, zpool_obj_write() is more concise and provides exactly what zswap needs to write the compressed object to the zpool, instead of map->copy->unmap. On the decompress side, zpool_obj_read_begin() is sleepable, which allows avoiding the memcpy() for zsmalloc and slightly simplifying the code by: - Avoiding checking if the zpool driver is sleepable, reducing special cases and shrinking the huge comment. - Having a single zpool_obj_read_end() call rather than multiple conditional zpool_unmap_handle() calls. The !virt_addr_valid() case can be removed in the future if the crypto API supports kmap addresses or by using kmap_to_page(), completely eliminating the memcpy() path in zswap_decompress(). This a step toward that. In that spirit, opportunistically make the comment more specific about the kmap case instead of generic non-linear addresses. This is the only case that needs to be handled in practice, and the generic comment makes it seem like a bigger problem that it actually is. Signed-off-by: Yosry Ahmed Acked-by: Johannes Weiner Acked-by: Nhat Pham --- Herbert, I think we can completely get rid of the memcpy() in zswap_decompress() if we can pass a highmem address to sg and crypto. I believe your new virtual address API may be used here for this? --- mm/zswap.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 10f2a16e75869..4c474b692828d 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -930,7 +930,6 @@ static bool zswap_compress(struct page *page, struct zs= wap_entry *entry, unsigned int dlen =3D PAGE_SIZE; unsigned long handle; struct zpool *zpool; - char *buf; gfp_t gfp; u8 *dst; =20 @@ -972,10 +971,7 @@ static bool zswap_compress(struct page *page, struct z= swap_entry *entry, if (alloc_ret) goto unlock; =20 - buf =3D zpool_map_handle(zpool, handle, ZPOOL_MM_WO); - memcpy(buf, dst, dlen); - zpool_unmap_handle(zpool, handle); - + zpool_obj_write(zpool, handle, dst, dlen); entry->handle =3D handle; entry->length =3D dlen; =20 @@ -996,24 +992,22 @@ static void zswap_decompress(struct zswap_entry *entr= y, struct folio *folio) struct zpool *zpool =3D entry->pool->zpool; struct scatterlist input, output; struct crypto_acomp_ctx *acomp_ctx; - u8 *src; + u8 *src, *obj; =20 acomp_ctx =3D acomp_ctx_get_cpu_lock(entry->pool); - src =3D zpool_map_handle(zpool, entry->handle, ZPOOL_MM_RO); + obj =3D zpool_obj_read_begin(zpool, entry->handle, acomp_ctx->buffer); + /* - * If zpool_map_handle is atomic, we cannot reliably utilize its mapped b= uffer - * to do crypto_acomp_decompress() which might sleep. In such cases, we m= ust - * resort to copying the buffer to a temporary one. - * Meanwhile, zpool_map_handle() might return a non-linearly mapped buffe= r, - * such as a kmap address of high memory or even ever a vmap address. - * However, sg_init_one is only equipped to handle linearly mapped low me= mory. - * In such cases, we also must copy the buffer to a temporary and lowmem = one. + * zpool_obj_read_begin() might return a kmap address of highmem when + * acomp_ctx->buffer is not used. However, sg_init_one() does not + * handle highmem addresses, so copy the object to acomp_ctx->buffer. */ - if ((acomp_ctx->is_sleepable && !zpool_can_sleep_mapped(zpool)) || - !virt_addr_valid(src)) { - memcpy(acomp_ctx->buffer, src, entry->length); + if (virt_addr_valid(obj)) { + src =3D obj; + } else { + WARN_ON_ONCE(obj =3D=3D acomp_ctx->buffer); + memcpy(acomp_ctx->buffer, obj, entry->length); src =3D acomp_ctx->buffer; - zpool_unmap_handle(zpool, entry->handle); } =20 sg_init_one(&input, src, entry->length); @@ -1023,8 +1017,7 @@ static void zswap_decompress(struct zswap_entry *entr= y, struct folio *folio) BUG_ON(crypto_wait_req(crypto_acomp_decompress(acomp_ctx->req), &acomp_ct= x->wait)); BUG_ON(acomp_ctx->req->dlen !=3D PAGE_SIZE); =20 - if (src !=3D acomp_ctx->buffer) - zpool_unmap_handle(zpool, entry->handle); + zpool_obj_read_end(zpool, entry->handle, obj); acomp_ctx_put_unlock(acomp_ctx); } =20 --=20 2.48.1.711.g2feabab25a-goog From nobody Sun Feb 8 06:49:35 2026 Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F16D51E5B91 for ; Wed, 5 Mar 2025 06:11:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741155121; cv=none; b=SmDnBqrwaFi5VpQ4YmLWTJlGhUsDkgKs/beZbvBbndi7HY9/ycGySMePZ9mL4SHsFqcjh5mvZu6woycIFCrT8ArBbpagnNF70V0JMBfDxVbk2VNM9bQcSeFlEaBnxpDqD3/Eh9JTKrPxwMXNNgkvZxSVaOdjNf4fPTNsSggsMtA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741155121; c=relaxed/simple; bh=iRStbOpLVIAApdbemlh9RwFlXe/MGEHVpH8/IZ4iju0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p4e9BInpvWFMCLtVFw0K//CadSw1Ag0bGQ4zeJrGSmUJgPfT304vtz5IP5JMjMgB1gZpxywgh1j4uETNGJ6CUiXB0QDH1cjL0vnvFywk7i54UD260XQxs5cWt3IA2eVgfr3uAT0O4WjE5s/uGAoU+ZpGQZ1QWYtgHgUjbuQcL1k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=NqpAebb+; arc=none smtp.client-ip=95.215.58.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="NqpAebb+" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1741155118; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+8Bqfcz7PgVEFtBp+cmFfADLG6mXxpRGvGVC/yYU2bs=; b=NqpAebb+VPXqgePqnox4fJ1VPtXsFc4mX0lvtiEvRaIO7un0c0kK81tIPtimYMIf0mHt5I qBouqrSMQGWWnETMPaO7V3U4BGHWZdo8lGyRML8GKKWHuk+6zj4LtNG8zbeurpCtpJT2RJ 1+YQeUtblKbQzHmBW0/C243DqnMvGhY= From: Yosry Ahmed To: Andrew Morton Cc: Johannes Weiner , Nhat Pham , Chengming Zhou , Minchan Kim , Sergey Senozhatsky , Herbert Xu , Thomas Gleixner , Peter Zijlstra , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [PATCH mm-unstable 3/5] mm: zpool: Remove object mapping APIs Date: Wed, 5 Mar 2025 06:11:31 +0000 Message-ID: <20250305061134.4105762-4-yosry.ahmed@linux.dev> In-Reply-To: <20250305061134.4105762-1-yosry.ahmed@linux.dev> References: <20250305061134.4105762-1-yosry.ahmed@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" zpool_map_handle(), zpool_unmap_handle(), and zpool_can_sleep_mapped() are no longer used. Remove them with the underlying driver callbacks. Signed-off-by: Yosry Ahmed Acked-by: Johannes Weiner Acked-by: Nhat Pham Reviewed-by: Sergey Senozhatsky --- include/linux/zpool.h | 30 --------------------- mm/zpool.c | 61 ------------------------------------------- mm/zsmalloc.c | 27 ------------------- 3 files changed, 118 deletions(-) diff --git a/include/linux/zpool.h b/include/linux/zpool.h index 1784e735ee049..2c8a9d2654f6f 100644 --- a/include/linux/zpool.h +++ b/include/linux/zpool.h @@ -13,25 +13,6 @@ =20 struct zpool; =20 -/* - * Control how a handle is mapped. It will be ignored if the - * implementation does not support it. Its use is optional. - * Note that this does not refer to memory protection, it - * refers to how the memory will be copied in/out if copying - * is necessary during mapping; read-write is the safest as - * it copies the existing memory in on map, and copies the - * changed memory back out on unmap. Write-only does not copy - * in the memory and should only be used for initialization. - * If in doubt, use ZPOOL_MM_DEFAULT which is read-write. - */ -enum zpool_mapmode { - ZPOOL_MM_RW, /* normal read-write mapping */ - ZPOOL_MM_RO, /* read-only (no copy-out at unmap time) */ - ZPOOL_MM_WO, /* write-only (no copy-in at map time) */ - - ZPOOL_MM_DEFAULT =3D ZPOOL_MM_RW -}; - bool zpool_has_pool(char *type); =20 struct zpool *zpool_create_pool(const char *type, const char *name, gfp_t = gfp); @@ -47,12 +28,6 @@ int zpool_malloc(struct zpool *pool, size_t size, gfp_t = gfp, =20 void zpool_free(struct zpool *pool, unsigned long handle); =20 -void *zpool_map_handle(struct zpool *pool, unsigned long handle, - enum zpool_mapmode mm); - -void zpool_unmap_handle(struct zpool *pool, unsigned long handle); - - void *zpool_obj_read_begin(struct zpool *zpool, unsigned long handle, void *local_copy); =20 @@ -95,11 +70,6 @@ struct zpool_driver { unsigned long *handle); void (*free)(void *pool, unsigned long handle); =20 - bool sleep_mapped; - void *(*map)(void *pool, unsigned long handle, - enum zpool_mapmode mm); - void (*unmap)(void *pool, unsigned long handle); - void *(*obj_read_begin)(void *pool, unsigned long handle, void *local_copy); void (*obj_read_end)(void *pool, unsigned long handle, diff --git a/mm/zpool.c b/mm/zpool.c index 378c2d1e5638f..4fc665b42f5e9 100644 --- a/mm/zpool.c +++ b/mm/zpool.c @@ -277,49 +277,6 @@ void zpool_free(struct zpool *zpool, unsigned long han= dle) zpool->driver->free(zpool->pool, handle); } =20 -/** - * zpool_map_handle() - Map a previously allocated handle into memory - * @zpool: The zpool that the handle was allocated from - * @handle: The handle to map - * @mapmode: How the memory should be mapped - * - * This maps a previously allocated handle into memory. The @mapmode - * param indicates to the implementation how the memory will be - * used, i.e. read-only, write-only, read-write. If the - * implementation does not support it, the memory will be treated - * as read-write. - * - * This may hold locks, disable interrupts, and/or preemption, - * and the zpool_unmap_handle() must be called to undo those - * actions. The code that uses the mapped handle should complete - * its operations on the mapped handle memory quickly and unmap - * as soon as possible. As the implementation may use per-cpu - * data, multiple handles should not be mapped concurrently on - * any cpu. - * - * Returns: A pointer to the handle's mapped memory area. - */ -void *zpool_map_handle(struct zpool *zpool, unsigned long handle, - enum zpool_mapmode mapmode) -{ - return zpool->driver->map(zpool->pool, handle, mapmode); -} - -/** - * zpool_unmap_handle() - Unmap a previously mapped handle - * @zpool: The zpool that the handle was allocated from - * @handle: The handle to unmap - * - * This unmaps a previously mapped handle. Any locks or other - * actions that the implementation took in zpool_map_handle() - * will be undone here. The memory area returned from - * zpool_map_handle() should no longer be used after this. - */ -void zpool_unmap_handle(struct zpool *zpool, unsigned long handle) -{ - zpool->driver->unmap(zpool->pool, handle); -} - /** * zpool_obj_read_begin() - Start reading from a previously allocated hand= le. * @zpool: The zpool that the handle was allocated from @@ -381,23 +338,5 @@ u64 zpool_get_total_pages(struct zpool *zpool) return zpool->driver->total_pages(zpool->pool); } =20 -/** - * zpool_can_sleep_mapped - Test if zpool can sleep when do mapped. - * @zpool: The zpool to test - * - * Some allocators enter non-preemptible context in ->map() callback (e.g. - * disable pagefaults) and exit that context in ->unmap(), which limits wh= at - * we can do with the mapped object. For instance, we cannot wait for - * asynchronous crypto API to decompress such an object or take mutexes - * since those will call into the scheduler. This function tells us whether - * we use such an allocator. - * - * Returns: true if zpool can sleep; false otherwise. - */ -bool zpool_can_sleep_mapped(struct zpool *zpool) -{ - return zpool->driver->sleep_mapped; -} - MODULE_AUTHOR("Dan Streetman "); MODULE_DESCRIPTION("Common API for compressed memory storage"); diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index d84b300db64e7..56d6ed5c675b2 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -482,31 +482,6 @@ static void zs_zpool_free(void *pool, unsigned long ha= ndle) zs_free(pool, handle); } =20 -static void *zs_zpool_map(void *pool, unsigned long handle, - enum zpool_mapmode mm) -{ - enum zs_mapmode zs_mm; - - switch (mm) { - case ZPOOL_MM_RO: - zs_mm =3D ZS_MM_RO; - break; - case ZPOOL_MM_WO: - zs_mm =3D ZS_MM_WO; - break; - case ZPOOL_MM_RW: - default: - zs_mm =3D ZS_MM_RW; - break; - } - - return zs_map_object(pool, handle, zs_mm); -} -static void zs_zpool_unmap(void *pool, unsigned long handle) -{ - zs_unmap_object(pool, handle); -} - static void *zs_zpool_obj_read_begin(void *pool, unsigned long handle, void *local_copy) { @@ -538,8 +513,6 @@ static struct zpool_driver zs_zpool_driver =3D { .malloc_support_movable =3D true, .malloc =3D zs_zpool_malloc, .free =3D zs_zpool_free, - .map =3D zs_zpool_map, - .unmap =3D zs_zpool_unmap, .obj_read_begin =3D zs_zpool_obj_read_begin, .obj_read_end =3D zs_zpool_obj_read_end, .obj_write =3D zs_zpool_obj_write, --=20 2.48.1.711.g2feabab25a-goog From nobody Sun Feb 8 06:49:35 2026 Received: from out-180.mta1.migadu.com (out-180.mta1.migadu.com [95.215.58.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D89681EB5E2 for ; Wed, 5 Mar 2025 06:12:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741155125; cv=none; b=Jak38rJ0MogCtseuqRmlVnVgP8dGdBTeI95Qfd6eLbXQFpWmUGdBMCmqKhDmhJVQsGygH6pakpXHxiMpoJnCtyNHBrqnitZsziv0sER+63XcL0kpxtLM7bydV7BUW0y0exsKWIdcownbhrQnTtcR0/8NiR+lsBfAn80gJj14JNI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741155125; c=relaxed/simple; bh=rahTlPA4fhyOL+7WCtjNfdiNljfZiTw4NJF1j/mtp6M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nNsQrU71kOHGumggfwiYRSzXq1VNd7i6H1TsA03nR4bNZ1rrcqQv2K9nsTfv1RCzOc/1k3j40YeXhId+TrmlltuNmH99yfLFsS+kkOvPrQH/6jzfA2m5X3xCfu0SZtBPPnrccuhwsOR+K64MT7/3lGOj7h5Pxd1X/Dx6vZxFuzg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=DPgCSaJ/; arc=none smtp.client-ip=95.215.58.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="DPgCSaJ/" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1741155120; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UhZJAb1vZBDPQY5aPuGxl/Pfa74mD9bb2pPv2uBSEcA=; b=DPgCSaJ/EaFB1ZPc4t8mnBIpN7oy4lyB/ivsJgKQV4J6SBrrL1VJ2bzJKbPWx7oEYaAdAP AvVxq2FW40CADY65HpTsCGZ2pmHpSN7reiPmd3wmk5mJ5NFTrsrdZiXnZAnAugXiQjRho0 YuH9Xb3Uy2bVT7lqBMekm5VcHRL+QnE= From: Yosry Ahmed To: Andrew Morton Cc: Johannes Weiner , Nhat Pham , Chengming Zhou , Minchan Kim , Sergey Senozhatsky , Herbert Xu , Thomas Gleixner , Peter Zijlstra , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [PATCH mm-unstable 4/5] mm: zsmalloc: Remove object mapping APIs and per-CPU map areas Date: Wed, 5 Mar 2025 06:11:32 +0000 Message-ID: <20250305061134.4105762-5-yosry.ahmed@linux.dev> In-Reply-To: <20250305061134.4105762-1-yosry.ahmed@linux.dev> References: <20250305061134.4105762-1-yosry.ahmed@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" zs_map_object() and zs_unmap_object() are no longer used, remove them. Since these are the only users of per-CPU mapping_areas, remove them and the associated CPU hotplug callbacks too. Signed-off-by: Yosry Ahmed Acked-by: Johannes Weiner Acked-by: Nhat Pham Acked-by: Sergey Senozhatsky --- include/linux/cpuhotplug.h | 1 - include/linux/zsmalloc.h | 21 ---- mm/zsmalloc.c | 226 +------------------------------------ 3 files changed, 1 insertion(+), 247 deletions(-) diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h index 6cc5e484547c1..1987400000b41 100644 --- a/include/linux/cpuhotplug.h +++ b/include/linux/cpuhotplug.h @@ -116,7 +116,6 @@ enum cpuhp_state { CPUHP_NET_IUCV_PREPARE, CPUHP_ARM_BL_PREPARE, CPUHP_TRACE_RB_PREPARE, - CPUHP_MM_ZS_PREPARE, CPUHP_MM_ZSWP_POOL_PREPARE, CPUHP_KVM_PPC_BOOK3S_PREPARE, CPUHP_ZCOMP_PREPARE, diff --git a/include/linux/zsmalloc.h b/include/linux/zsmalloc.h index 7d70983cf3980..c26baf9fb331b 100644 --- a/include/linux/zsmalloc.h +++ b/include/linux/zsmalloc.h @@ -16,23 +16,6 @@ =20 #include =20 -/* - * zsmalloc mapping modes - * - * NOTE: These only make a difference when a mapped object spans pages. - */ -enum zs_mapmode { - ZS_MM_RW, /* normal read-write mapping */ - ZS_MM_RO, /* read-only (no copy-out at unmap time) */ - ZS_MM_WO /* write-only (no copy-in at map time) */ - /* - * NOTE: ZS_MM_WO should only be used for initializing new - * (uninitialized) allocations. Partial writes to already - * initialized allocations should use ZS_MM_RW to preserve the - * existing data. - */ -}; - struct zs_pool_stats { /* How many pages were migrated (freed) */ atomic_long_t pages_compacted; @@ -48,10 +31,6 @@ void zs_free(struct zs_pool *pool, unsigned long obj); =20 size_t zs_huge_class_size(struct zs_pool *pool); =20 -void *zs_map_object(struct zs_pool *pool, unsigned long handle, - enum zs_mapmode mm); -void zs_unmap_object(struct zs_pool *pool, unsigned long handle); - unsigned long zs_get_total_pages(struct zs_pool *pool); unsigned long zs_compact(struct zs_pool *pool); =20 diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 56d6ed5c675b2..cd1c2a8ffef05 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -281,13 +281,6 @@ struct zspage { struct zspage_lock zsl; }; =20 -struct mapping_area { - local_lock_t lock; - char *vm_buf; /* copy buffer for objects that span pages */ - char *vm_addr; /* address of kmap_local_page()'ed pages */ - enum zs_mapmode vm_mm; /* mapping mode */ -}; - static void zspage_lock_init(struct zspage *zspage) { static struct lock_class_key __key; @@ -522,11 +515,6 @@ static struct zpool_driver zs_zpool_driver =3D { MODULE_ALIAS("zpool-zsmalloc"); #endif /* CONFIG_ZPOOL */ =20 -/* per-cpu VM mapping areas for zspage accesses that cross page boundaries= */ -static DEFINE_PER_CPU(struct mapping_area, zs_map_area) =3D { - .lock =3D INIT_LOCAL_LOCK(lock), -}; - static inline bool __maybe_unused is_first_zpdesc(struct zpdesc *zpdesc) { return PagePrivate(zpdesc_page(zpdesc)); @@ -1111,93 +1099,6 @@ static struct zspage *find_get_zspage(struct size_cl= ass *class) return zspage; } =20 -static inline int __zs_cpu_up(struct mapping_area *area) -{ - /* - * Make sure we don't leak memory if a cpu UP notification - * and zs_init() race and both call zs_cpu_up() on the same cpu - */ - if (area->vm_buf) - return 0; - area->vm_buf =3D kmalloc(ZS_MAX_ALLOC_SIZE, GFP_KERNEL); - if (!area->vm_buf) - return -ENOMEM; - return 0; -} - -static inline void __zs_cpu_down(struct mapping_area *area) -{ - kfree(area->vm_buf); - area->vm_buf =3D NULL; -} - -static void *__zs_map_object(struct mapping_area *area, - struct zpdesc *zpdescs[2], int off, int size) -{ - size_t sizes[2]; - char *buf =3D area->vm_buf; - - /* disable page faults to match kmap_local_page() return conditions */ - pagefault_disable(); - - /* no read fastpath */ - if (area->vm_mm =3D=3D ZS_MM_WO) - goto out; - - sizes[0] =3D PAGE_SIZE - off; - sizes[1] =3D size - sizes[0]; - - /* copy object to per-cpu buffer */ - memcpy_from_page(buf, zpdesc_page(zpdescs[0]), off, sizes[0]); - memcpy_from_page(buf + sizes[0], zpdesc_page(zpdescs[1]), 0, sizes[1]); -out: - return area->vm_buf; -} - -static void __zs_unmap_object(struct mapping_area *area, - struct zpdesc *zpdescs[2], int off, int size) -{ - size_t sizes[2]; - char *buf; - - /* no write fastpath */ - if (area->vm_mm =3D=3D ZS_MM_RO) - goto out; - - buf =3D area->vm_buf; - buf =3D buf + ZS_HANDLE_SIZE; - size -=3D ZS_HANDLE_SIZE; - off +=3D ZS_HANDLE_SIZE; - - sizes[0] =3D PAGE_SIZE - off; - sizes[1] =3D size - sizes[0]; - - /* copy per-cpu buffer to object */ - memcpy_to_page(zpdesc_page(zpdescs[0]), off, buf, sizes[0]); - memcpy_to_page(zpdesc_page(zpdescs[1]), 0, buf + sizes[0], sizes[1]); - -out: - /* enable page faults to match kunmap_local() return conditions */ - pagefault_enable(); -} - -static int zs_cpu_prepare(unsigned int cpu) -{ - struct mapping_area *area; - - area =3D &per_cpu(zs_map_area, cpu); - return __zs_cpu_up(area); -} - -static int zs_cpu_dead(unsigned int cpu) -{ - struct mapping_area *area; - - area =3D &per_cpu(zs_map_area, cpu); - __zs_cpu_down(area); - return 0; -} - static bool can_merge(struct size_class *prev, int pages_per_zspage, int objs_per_zspage) { @@ -1245,117 +1146,6 @@ unsigned long zs_get_total_pages(struct zs_pool *po= ol) } EXPORT_SYMBOL_GPL(zs_get_total_pages); =20 -/** - * zs_map_object - get address of allocated object from handle. - * @pool: pool from which the object was allocated - * @handle: handle returned from zs_malloc - * @mm: mapping mode to use - * - * Before using an object allocated from zs_malloc, it must be mapped using - * this function. When done with the object, it must be unmapped using - * zs_unmap_object. - * - * Only one object can be mapped per cpu at a time. There is no protection - * against nested mappings. - * - * This function returns with preemption and page faults disabled. - */ -void *zs_map_object(struct zs_pool *pool, unsigned long handle, - enum zs_mapmode mm) -{ - struct zspage *zspage; - struct zpdesc *zpdesc; - unsigned long obj, off; - unsigned int obj_idx; - - struct size_class *class; - struct mapping_area *area; - struct zpdesc *zpdescs[2]; - void *ret; - - /* - * Because we use per-cpu mapping areas shared among the - * pools/users, we can't allow mapping in interrupt context - * because it can corrupt another users mappings. - */ - BUG_ON(in_interrupt()); - - /* It guarantees it can get zspage from handle safely */ - read_lock(&pool->lock); - obj =3D handle_to_obj(handle); - obj_to_location(obj, &zpdesc, &obj_idx); - zspage =3D get_zspage(zpdesc); - - /* - * migration cannot move any zpages in this zspage. Here, class->lock - * is too heavy since callers would take some time until they calls - * zs_unmap_object API so delegate the locking from class to zspage - * which is smaller granularity. - */ - zspage_read_lock(zspage); - read_unlock(&pool->lock); - - class =3D zspage_class(pool, zspage); - off =3D offset_in_page(class->size * obj_idx); - - local_lock(&zs_map_area.lock); - area =3D this_cpu_ptr(&zs_map_area); - area->vm_mm =3D mm; - if (off + class->size <=3D PAGE_SIZE) { - /* this object is contained entirely within a page */ - area->vm_addr =3D kmap_local_zpdesc(zpdesc); - ret =3D area->vm_addr + off; - goto out; - } - - /* this object spans two pages */ - zpdescs[0] =3D zpdesc; - zpdescs[1] =3D get_next_zpdesc(zpdesc); - BUG_ON(!zpdescs[1]); - - ret =3D __zs_map_object(area, zpdescs, off, class->size); -out: - if (likely(!ZsHugePage(zspage))) - ret +=3D ZS_HANDLE_SIZE; - - return ret; -} -EXPORT_SYMBOL_GPL(zs_map_object); - -void zs_unmap_object(struct zs_pool *pool, unsigned long handle) -{ - struct zspage *zspage; - struct zpdesc *zpdesc; - unsigned long obj, off; - unsigned int obj_idx; - - struct size_class *class; - struct mapping_area *area; - - obj =3D handle_to_obj(handle); - obj_to_location(obj, &zpdesc, &obj_idx); - zspage =3D get_zspage(zpdesc); - class =3D zspage_class(pool, zspage); - off =3D offset_in_page(class->size * obj_idx); - - area =3D this_cpu_ptr(&zs_map_area); - if (off + class->size <=3D PAGE_SIZE) - kunmap_local(area->vm_addr); - else { - struct zpdesc *zpdescs[2]; - - zpdescs[0] =3D zpdesc; - zpdescs[1] =3D get_next_zpdesc(zpdesc); - BUG_ON(!zpdescs[1]); - - __zs_unmap_object(area, zpdescs, off, class->size); - } - local_unlock(&zs_map_area.lock); - - zspage_read_unlock(zspage); -} -EXPORT_SYMBOL_GPL(zs_unmap_object); - void *zs_obj_read_begin(struct zs_pool *pool, unsigned long handle, void *local_copy) { @@ -1975,7 +1765,7 @@ static int zs_page_migrate(struct page *newpage, stru= ct page *page, * the class lock protects zpage alloc/free in the zspage. */ spin_lock(&class->lock); - /* the zspage write_lock protects zpage access via zs_map_object */ + /* the zspage write_lock protects zpage access via zs_obj_read/write() */ if (!zspage_write_trylock(zspage)) { spin_unlock(&class->lock); write_unlock(&pool->lock); @@ -2459,23 +2249,11 @@ EXPORT_SYMBOL_GPL(zs_destroy_pool); =20 static int __init zs_init(void) { - int ret; - - ret =3D cpuhp_setup_state(CPUHP_MM_ZS_PREPARE, "mm/zsmalloc:prepare", - zs_cpu_prepare, zs_cpu_dead); - if (ret) - goto out; - #ifdef CONFIG_ZPOOL zpool_register_driver(&zs_zpool_driver); #endif - zs_stat_init(); - return 0; - -out: - return ret; } =20 static void __exit zs_exit(void) @@ -2483,8 +2261,6 @@ static void __exit zs_exit(void) #ifdef CONFIG_ZPOOL zpool_unregister_driver(&zs_zpool_driver); #endif - cpuhp_remove_state(CPUHP_MM_ZS_PREPARE); - zs_stat_exit(); } =20 --=20 2.48.1.711.g2feabab25a-goog From nobody Sun Feb 8 06:49:35 2026 Received: from out-174.mta1.migadu.com (out-174.mta1.migadu.com [95.215.58.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE4511EEA4E for ; Wed, 5 Mar 2025 06:12:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741155129; cv=none; b=jrSuLC/9KfuiH6zxc93lPubAt6sRhGZr0Sk87aAe58Bz4Vi2p5RWTMkLca9xZJpsNsED29DGF2BqZZx9SgR9DAbnSGxarhGjjXQNbwRcdHwnn06mCWEV5Y0rzFYG45Mi48gIRy4jI/WdHE9WJF2A7niETduF+zcuF+4ECmt/8MA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741155129; c=relaxed/simple; bh=1QAFUlkYxX/Tklmd9ajQ/kSRC1rOe18Q6iFJn5NEU1A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bzgQlT/mq/zDakG1FYaAtFQg3LiTT93R67PnGM2vv3pu7IunumSMqex+hLmOl41sNw9EL935d68sj0OUhLCa7J0IcuGS1rHVe6DxrAlTZNymzmklbMqGd7uzkzYCBILzM2Ya6bykLXvVuawTOOjOCXE8DVrDMXeKDiaEUfLiA4w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ozyCJOAF; arc=none smtp.client-ip=95.215.58.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ozyCJOAF" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1741155124; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VdDtOHvnm2EdaYulJZ60u1Fa0OrG84atgPrUT7g6aEw=; b=ozyCJOAFVQ+Nj7hdVEjapmmpRc/yILNSg+asLJmivfnQbe0r7mlmBhAfvkGYGIIsMqKhxY NLWVcMHJVaFpc9N7qkZlz2xZGUOcUpXCLilpMemMKftlWVS8i2Ha5Ny8xG/vdmiX2JfxBT xivQEpxxLKZIZFu9RF4irEUJT/E8fQU= From: Yosry Ahmed To: Andrew Morton Cc: Johannes Weiner , Nhat Pham , Chengming Zhou , Minchan Kim , Sergey Senozhatsky , Herbert Xu , Thomas Gleixner , Peter Zijlstra , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [PATCH mm-unstable 5/5] mm: zpool: Remove zpool_malloc_support_movable() Date: Wed, 5 Mar 2025 06:11:33 +0000 Message-ID: <20250305061134.4105762-6-yosry.ahmed@linux.dev> In-Reply-To: <20250305061134.4105762-1-yosry.ahmed@linux.dev> References: <20250305061134.4105762-1-yosry.ahmed@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" zpool_malloc_support_movable() always returns true for zsmalloc, the only remaining zpool driver. Remove it and set the gfp flags in zswap_compress() accordingly. Opportunistically use GFP_NOWAIT instead of __GFP_NOWARN | __GFP_KSWAPD_RECLAIM for conciseness as they are equivalent. Signed-off-by: Yosry Ahmed Acked-by: Johannes Weiner Acked-by: Nhat Pham Reviewed-by: Sergey Senozhatsky --- include/linux/zpool.h | 3 --- mm/zpool.c | 16 ---------------- mm/zsmalloc.c | 1 - mm/zswap.c | 4 +--- 4 files changed, 1 insertion(+), 23 deletions(-) diff --git a/include/linux/zpool.h b/include/linux/zpool.h index 2c8a9d2654f6f..52f30e526607f 100644 --- a/include/linux/zpool.h +++ b/include/linux/zpool.h @@ -21,8 +21,6 @@ const char *zpool_get_type(struct zpool *pool); =20 void zpool_destroy_pool(struct zpool *pool); =20 -bool zpool_malloc_support_movable(struct zpool *pool); - int zpool_malloc(struct zpool *pool, size_t size, gfp_t gfp, unsigned long *handle); =20 @@ -65,7 +63,6 @@ struct zpool_driver { void *(*create)(const char *name, gfp_t gfp); void (*destroy)(void *pool); =20 - bool malloc_support_movable; int (*malloc)(void *pool, size_t size, gfp_t gfp, unsigned long *handle); void (*free)(void *pool, unsigned long handle); diff --git a/mm/zpool.c b/mm/zpool.c index 4fc665b42f5e9..6d6d889309324 100644 --- a/mm/zpool.c +++ b/mm/zpool.c @@ -220,22 +220,6 @@ const char *zpool_get_type(struct zpool *zpool) return zpool->driver->type; } =20 -/** - * zpool_malloc_support_movable() - Check if the zpool supports - * allocating movable memory - * @zpool: The zpool to check - * - * This returns if the zpool supports allocating movable memory. - * - * Implementations must guarantee this to be thread-safe. - * - * Returns: true if the zpool supports allocating movable memory, false if= not - */ -bool zpool_malloc_support_movable(struct zpool *zpool) -{ - return zpool->driver->malloc_support_movable; -} - /** * zpool_malloc() - Allocate memory * @zpool: The zpool to allocate from. diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index cd1c2a8ffef05..961b270f023c2 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -503,7 +503,6 @@ static struct zpool_driver zs_zpool_driver =3D { .owner =3D THIS_MODULE, .create =3D zs_zpool_create, .destroy =3D zs_zpool_destroy, - .malloc_support_movable =3D true, .malloc =3D zs_zpool_malloc, .free =3D zs_zpool_free, .obj_read_begin =3D zs_zpool_obj_read_begin, diff --git a/mm/zswap.c b/mm/zswap.c index 4c474b692828d..138b50ba832b8 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -964,9 +964,7 @@ static bool zswap_compress(struct page *page, struct zs= wap_entry *entry, goto unlock; =20 zpool =3D pool->zpool; - gfp =3D __GFP_NORETRY | __GFP_NOWARN | __GFP_KSWAPD_RECLAIM; - if (zpool_malloc_support_movable(zpool)) - gfp |=3D __GFP_HIGHMEM | __GFP_MOVABLE; + gfp =3D GFP_NOWAIT | __GFP_NORETRY | __GFP_HIGHMEM | __GFP_MOVABLE; alloc_ret =3D zpool_malloc(zpool, dlen, gfp, &handle); if (alloc_ret) goto unlock; --=20 2.48.1.711.g2feabab25a-goog