From patchwork Tue Feb 20 11:36:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 203566 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp336749dyc; Tue, 20 Feb 2024 03:37:54 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXAaYsRoPN7FeFIJnD4sQQWEPh0Z0cH05+hLkgsrB6NgNOBmNQFbb6CRmojiQC4V/uM46M1fJQUVxShKz5iBSeLGmOBfA== X-Google-Smtp-Source: AGHT+IFNE1CvjYKnpzkpj1htvMmrCH5NWHxl4aKb4WdVJz5WAqyM/cXTzpBgEgm1Iddw79GNVnJ5 X-Received: by 2002:a17:906:1305:b0:a3e:d450:d3dc with SMTP id w5-20020a170906130500b00a3ed450d3dcmr2461372ejb.35.1708429073699; Tue, 20 Feb 2024 03:37:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708429073; cv=pass; d=google.com; s=arc-20160816; b=daVl9NhjizFV/8OViLVfwhuODPJuXAWt0fGGD5jCHDAyMchhOV/w+8LjPTfh5j07Ym 9bJK3nF5Y5UiGx1pO3+G3/pHC/uIsxvccbT470sM2XKOpPz1i5wL+NSUZifGHG5an4a2 048rGNKXmK+FL+MGyrFbg8NU5LegxfPimnnkpNXtiCqZwnhHsPqH8VIBeMtWjI+gcdpi KM0qfza476iaqeN7vV6PNL2MbemkCQ5Hv9TskdjKmSGP2YzC63r9F1EPRys/TMyb6g/4 fcTNEq24yBFTsZBOgz34tCx/icTyNEkAyn8wR7wj3CYXjJK4lh4KT7G7PEszQHuGkKwI 4KPA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=kzQqWreho0C7h7BUSKhkqs4L21k4ROBRD+6NpEqJHvk=; fh=936sdtmrkpSY5xs0isw6wBUcmfCvGttdxKwiAOV5ysg=; b=fa8mdaiS5MxTEfO440f+D8Dq4oN9dwzncfdtcSLAjave6wRFmqCcp+K5+dcM59F9vz 2vl+2kkY8lOHL00iU8ly14d2u3Ez4fZ/TRaJcL66Mt9ruryBNjALx7hyi0Qc6k3WLxaZ 9/R+8q2f+Yga8nbhEmK0GMz/hPwRXAcESR1bZOp4EuxAw814V2N3IL5Ek3wvbCu50NLZ wE70ipM6T8P9yhlgZtzCfV26SKw1TE8lf6AlCIEr+puo04os56N86eEcinT9/fyMXvdR xK890gqNj4Qiou3lHrGq61U4Fto0BEU9LGx7e4Z8Jf7LZSR+ooNd5hWqE/o7UaqImu6O wxHg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=hx+4yBZK; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-72920-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72920-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id l11-20020a1709061c4b00b00a3e5327b750si2473937ejg.10.2024.02.20.03.37.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 03:37:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72920-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=hx+4yBZK; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-72920-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72920-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 52EA41F21F1D for ; Tue, 20 Feb 2024 11:37:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8748C67E9B; Tue, 20 Feb 2024 11:37:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="hx+4yBZK" Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (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 EECA867E63 for ; Tue, 20 Feb 2024 11:37:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708429051; cv=none; b=iItn5yb8Q4/NHhsWZWkhCWr+y/pb7guT3CShhnUMNuw8FVkNDLmZh+6vNvZGukzRssC8oCxmcnBqiCQUGBoCQg7O64uC8M7PqFa2Hn5JBVatsbsrZ5jvtL/Sds9Cs4dqIG4R98UkS/1ZodrheEJhONkfBEJoBBSlketTVaJHQBk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708429051; c=relaxed/simple; bh=uHWg+XOhrK0zRFBt8wOq8bp9H9v8n5Lcorw+sL8Z3+E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mUNfXNj6RSVKWFKA6tNWLg5dN0v8jN85/NQMRlVESATL8B/eoSqakM+UeyZwJqtHGfoamevkoAsl+ANOGZSpgQTfpvITwV8XtJCs+oEtKV9I8xiPkDEMQmEPjh8vXdS9yjYvLnYwrN9jTFJV9oUDvnXV1t5nzNSjci30Q10graI= 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=hx+4yBZK; arc=none smtp.client-ip=91.218.175.171 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 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=1708429047; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kzQqWreho0C7h7BUSKhkqs4L21k4ROBRD+6NpEqJHvk=; b=hx+4yBZK6F1f+K+KobCMKspcH9mU4c02Ya7/2WJ8h1KS2L4WAHusTpcx6exILhAFInTUL7 SjK2RjNlhSZnKKiORgS17ixwOUfDdrDWC12dFCue+HGWSq6lKKLAGf7WKDev6RYIaevBYL y+iI/Zos7kTYfT5NxuryApctqyk8JNc= From: Chengming Zhou Date: Tue, 20 Feb 2024 11:36:58 +0000 Subject: [PATCH RESEND 1/3] mm/zsmalloc: fix migrate_write_lock() when !CONFIG_COMPACTION Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240219-b4-szmalloc-migrate-v1-1-fc21039bed7b@linux.dev> References: <20240219-b4-szmalloc-migrate-v1-0-fc21039bed7b@linux.dev> In-Reply-To: <20240219-b4-szmalloc-migrate-v1-0-fc21039bed7b@linux.dev> To: hannes@cmpxchg.org, Sergey Senozhatsky , Minchan Kim , Andrew Morton , nphamcs@gmail.com, yosryahmed@google.com Cc: linux-mm@kvack.org, Chengming Zhou , linux-kernel@vger.kernel.org X-Developer-Signature: v=1; a=ed25519-sha256; t=1708429041; l=2263; i=chengming.zhou@linux.dev; s=20240220; h=from:subject:message-id; bh=UHSVodPnpBiivncRsTV1Arftl0WePz5UFf9WpjK+7+4=; b=163nW1R+RMQ+orBAqT5aCtZHUFeStvc1n+OYnymxXb76UYU7LE63Rfti+6qmooU5Daaopmvrh ZVuF8XTU4yRCV6oUXqz5lv+X9XhHDAJCUFRaebMIpUHJhvKi7iKCv4M X-Developer-Key: i=chengming.zhou@linux.dev; a=ed25519; pk=5+68Wfci+T30FoQos5RH+hfToF6SlC+S9LMPSPBFWuw= X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791417724611260695 X-GMAIL-MSGID: 1791417724611260695 From: Chengming Zhou migrate_write_lock() is a empty function when !CONFIG_COMPACTION, in which case zs_compact() can be triggered from shrinker reclaim context. (Maybe it's better to rename it to zs_shrink()?) And zspage map object users rely on this migrate_read_lock() so object won't be migrated elsewhere. Fix it by always implementing the migrate_write_lock() related functions. Signed-off-by: Chengming Zhou Reviewed-by: Sergey Senozhatsky --- mm/zsmalloc.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index c937635e0ad1..64d5533fa5d8 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -278,18 +278,15 @@ static bool ZsHugePage(struct zspage *zspage) static void migrate_lock_init(struct zspage *zspage); static void migrate_read_lock(struct zspage *zspage); static void migrate_read_unlock(struct zspage *zspage); - -#ifdef CONFIG_COMPACTION static void migrate_write_lock(struct zspage *zspage); static void migrate_write_lock_nested(struct zspage *zspage); static void migrate_write_unlock(struct zspage *zspage); + +#ifdef CONFIG_COMPACTION static void kick_deferred_free(struct zs_pool *pool); static void init_deferred_free(struct zs_pool *pool); static void SetZsPageMovable(struct zs_pool *pool, struct zspage *zspage); #else -static void migrate_write_lock(struct zspage *zspage) {} -static void migrate_write_lock_nested(struct zspage *zspage) {} -static void migrate_write_unlock(struct zspage *zspage) {} static void kick_deferred_free(struct zs_pool *pool) {} static void init_deferred_free(struct zs_pool *pool) {} static void SetZsPageMovable(struct zs_pool *pool, struct zspage *zspage) {} @@ -1725,7 +1722,6 @@ static void migrate_read_unlock(struct zspage *zspage) __releases(&zspage->lock) read_unlock(&zspage->lock); } -#ifdef CONFIG_COMPACTION static void migrate_write_lock(struct zspage *zspage) { write_lock(&zspage->lock); @@ -1741,6 +1737,7 @@ static void migrate_write_unlock(struct zspage *zspage) write_unlock(&zspage->lock); } +#ifdef CONFIG_COMPACTION /* Number of isolated subpage for *page migration* in this zspage */ static void inc_zspage_isolation(struct zspage *zspage) { From patchwork Tue Feb 20 11:36:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 203567 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp336804dyc; Tue, 20 Feb 2024 03:38:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVmNbY6G1HCzVA1BTQzLaZ7jH2TqL81sY358Jf49uUSRHVDnsZlkRG4vCBsSWk/WB205Vya2YU7ebQ7HdLP5F0h506Ipw== X-Google-Smtp-Source: AGHT+IFxbB9EIpF9+5Qfu3rJ1Px0KxZUwPMCMz33IFHfJtu752pxNS2eDghwSKYCSRk/NnrY8dDk X-Received: by 2002:a9d:6e8e:0:b0:6e2:e982:5bd7 with SMTP id a14-20020a9d6e8e000000b006e2e9825bd7mr15747674otr.31.1708429083503; Tue, 20 Feb 2024 03:38:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708429083; cv=pass; d=google.com; s=arc-20160816; b=cQRsptJRqrQCqh8+sr6Nt4z70rqRxjymFZ56RlnZ8gsWJ71V3c6QEGMtQdxApR17Gv P6YfPRxwhbh1eS9BTT9BQPT9tiwAnmww8IJtDVQL9QSBf1j1uPoDvjvpbwFASNKdYREI M6Q7hhgZNsnutIZvOw13zO3dsUsnguQ+L12keEvtuqcWPfZFS3zM69/bqdFV3IlUbowJ ZXnieFWGD+Rr/ibT9unFJ+2JuFbCqmPcxYNmPL/4/gBN0J6W/JxjsYS0od9LUi5Zm29B cLlVriP59sv/2RUf/L+sVuqGh9bwO8IsZcxBe5B5jJkkH0QWCplovl+rxOsE8iAcBTxV 3LoA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=92Vtmk4shKGDy68G7cvQyAOzVy7wB5PQ3z9H0ogo7j8=; fh=936sdtmrkpSY5xs0isw6wBUcmfCvGttdxKwiAOV5ysg=; b=lgNq9+hU7jTzoE+5gDKER0wPv5SHazp0kVwfTaO9HS0pwnMdluadijKhOHtfAQ2aMD 5UZabf7uyDZQCkv+md7laH6Qt0Z7S/kvGa8HPYKcXfpTWUZL0Gnm7TmkXpMe337RtCV7 s0N2qOFhiLB4aITNl4h1pNzI1wE5A+1djvgqfPAvVuKWam42difvIo1p83W+xrXNpbQr bZcQWCtllI0kuPF1VJbjSqhuB6fJWH8YLIj9jCG9VflYWtMz6DF/SsQa8OBFv4pgylwi HuvnNKNem63Z4lsX+odPa9Ch7hnFJD8k+KnxIUpOaxDRCVfaqhrbxn2V6b35oaQL8O4A UDBA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=oPjn6G6S; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-72921-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72921-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id k192-20020a633dc9000000b005dc4912432csi6002021pga.577.2024.02.20.03.38.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 03:38:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72921-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=oPjn6G6S; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-72921-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72921-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 507A728229A for ; Tue, 20 Feb 2024 11:38:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 599B569302; Tue, 20 Feb 2024 11:37:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="oPjn6G6S" Received: from out-177.mta0.migadu.com (out-177.mta0.migadu.com [91.218.175.177]) (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 A584C67E89 for ; Tue, 20 Feb 2024 11:37:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708429054; cv=none; b=NV/0ucRMBhhRjnHY4kmaW+gTrZUobYjjlYJiNhp5/gbXdcocYDd1l+bd8vcxjJceiVI2uMnobpQR+11IfOy9dbCusfVU6THel06xVRqeCRofZJTh3cUn6SVdVzfoRXMzu1pAGLg5hBg8NOMNdR6k/tHDZuN0/RPMcFF9w2nmkeY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708429054; c=relaxed/simple; bh=4heB2Ziqn7TJxtytS2+rZO3pE9/2o+DwcPf5a+meqjo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QlDuC/0pMHZPqCP29x7MK4tklJKe2SkSYP8qekWCtVWvpl1xQKgXNIIJGdE9tXbQ5VGcEs1Rldc9aeV96iDkZnEMq3YVW/xEkkQG3gh8dOm0ve5f/Phv+SkM41g7fM+4Sdy+PV60lRURfEEJkbtM2ogUfXubB0nt6H30TxSsfcU= 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=oPjn6G6S; arc=none smtp.client-ip=91.218.175.177 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 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=1708429051; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=92Vtmk4shKGDy68G7cvQyAOzVy7wB5PQ3z9H0ogo7j8=; b=oPjn6G6Sm/vrC4om3sEOub6fZmmj5FSnVFKEkEH7SgYTvgp/jDUgGz84ktCIkpOeFOxDM1 aaZVmFQv4ip0oB8UG+ursJb5tM3HpMRXVGwjdzGBrp+dMoxzHmx+32D3PswWnuc04qd5BZ vjKroKX4jLtlQRmCUe7EaIrZA9EktAs= From: Chengming Zhou Date: Tue, 20 Feb 2024 11:36:59 +0000 Subject: [PATCH RESEND 2/3] mm/zsmalloc: remove migrate_write_lock_nested() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240219-b4-szmalloc-migrate-v1-2-fc21039bed7b@linux.dev> References: <20240219-b4-szmalloc-migrate-v1-0-fc21039bed7b@linux.dev> In-Reply-To: <20240219-b4-szmalloc-migrate-v1-0-fc21039bed7b@linux.dev> To: hannes@cmpxchg.org, Sergey Senozhatsky , Minchan Kim , Andrew Morton , nphamcs@gmail.com, yosryahmed@google.com Cc: linux-mm@kvack.org, Chengming Zhou , linux-kernel@vger.kernel.org X-Developer-Signature: v=1; a=ed25519-sha256; t=1708429041; l=2959; i=chengming.zhou@linux.dev; s=20240220; h=from:subject:message-id; bh=OUia51YESybtl45fp4ZaNAosIUgwtCmJ4/X7GVIhXhM=; b=8ijbXFuBVbIAfmOXcNTVodntrXfcwjB4acsw5QXCN052rSsXXdYpcn6HbsyCIPUDL5ekuERGC VMk9bAuraaKBIadh21NRdWVdE5N/IMKOvjmOxFePXE7syuPQng8VanC X-Developer-Key: i=chengming.zhou@linux.dev; a=ed25519; pk=5+68Wfci+T30FoQos5RH+hfToF6SlC+S9LMPSPBFWuw= X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791417734451017815 X-GMAIL-MSGID: 1791417734451017815 From: Chengming Zhou The migrate write lock is to protect the race between zspage migration and zspage objects' map users. We only need to lock out the map users of src zspage, not dst zspage, which is safe to map by users concurrently, since we only need to do obj_malloc() from dst zspage. So we can remove the migrate_write_lock_nested() use case. As we are here, cleanup the __zs_compact() by moving putback_zspage() outside of migrate_write_unlock since we hold pool lock, no malloc or free users can come in. Signed-off-by: Chengming Zhou Reviewed-by: Sergey Senozhatsky --- mm/zsmalloc.c | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 64d5533fa5d8..f2ae7d4c6f21 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -279,7 +279,6 @@ static void migrate_lock_init(struct zspage *zspage); static void migrate_read_lock(struct zspage *zspage); static void migrate_read_unlock(struct zspage *zspage); static void migrate_write_lock(struct zspage *zspage); -static void migrate_write_lock_nested(struct zspage *zspage); static void migrate_write_unlock(struct zspage *zspage); #ifdef CONFIG_COMPACTION @@ -1727,11 +1726,6 @@ static void migrate_write_lock(struct zspage *zspage) write_lock(&zspage->lock); } -static void migrate_write_lock_nested(struct zspage *zspage) -{ - write_lock_nested(&zspage->lock, SINGLE_DEPTH_NESTING); -} - static void migrate_write_unlock(struct zspage *zspage) { write_unlock(&zspage->lock); @@ -2003,19 +1997,17 @@ static unsigned long __zs_compact(struct zs_pool *pool, dst_zspage = isolate_dst_zspage(class); if (!dst_zspage) break; - migrate_write_lock(dst_zspage); } src_zspage = isolate_src_zspage(class); if (!src_zspage) break; - migrate_write_lock_nested(src_zspage); - + migrate_write_lock(src_zspage); migrate_zspage(pool, src_zspage, dst_zspage); - fg = putback_zspage(class, src_zspage); migrate_write_unlock(src_zspage); + fg = putback_zspage(class, src_zspage); if (fg == ZS_INUSE_RATIO_0) { free_zspage(pool, class, src_zspage); pages_freed += class->pages_per_zspage; @@ -2025,7 +2017,6 @@ static unsigned long __zs_compact(struct zs_pool *pool, if (get_fullness_group(class, dst_zspage) == ZS_INUSE_RATIO_100 || spin_is_contended(&pool->lock)) { putback_zspage(class, dst_zspage); - migrate_write_unlock(dst_zspage); dst_zspage = NULL; spin_unlock(&pool->lock); @@ -2034,15 +2025,12 @@ static unsigned long __zs_compact(struct zs_pool *pool, } } - if (src_zspage) { + if (src_zspage) putback_zspage(class, src_zspage); - migrate_write_unlock(src_zspage); - } - if (dst_zspage) { + if (dst_zspage) putback_zspage(class, dst_zspage); - migrate_write_unlock(dst_zspage); - } + spin_unlock(&pool->lock); return pages_freed; From patchwork Tue Feb 20 11:37:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 203568 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp336884dyc; Tue, 20 Feb 2024 03:38:14 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW0VM6/ZfuhHGwOU5xcwwUdTns0vGKiiFnMPsse2hv69HI29hZkoHViFAU+CwdR56R1mxjNY3Fzu8q6Dq4OPM+Z6a+llQ== X-Google-Smtp-Source: AGHT+IGdqkHyYETEOQVPpgTF3TYVpIFk5lKBmyZnUXa9v/QVl9TmTmDcCQjw3kc7NVX278cVeQ+o X-Received: by 2002:a9d:6d86:0:b0:6e2:e627:333c with SMTP id x6-20020a9d6d86000000b006e2e627333cmr16323961otp.23.1708429094754; Tue, 20 Feb 2024 03:38:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708429094; cv=pass; d=google.com; s=arc-20160816; b=Bthva1TCMMaDAz6HpD5OZtneZoMtsIBP0tPYcKBJulqtg4H+PEYUAmcEwfRPbbYnz0 AimtNa1X6tByNll00XKezQUgWp8MPUQ6Ar5Y66WEh/UQ+9kZ2VyyRdo8h+Sa5mQroGnW twZ7GikVS8/M1DvLQjfToIft07iMZoJbu7flssI9MymgWpicOU5JeL+wzmtZHgu1PhxB ZEe1JoL9f4DGE79PnnGQyyKuSa9rYnzpVwqncyF58QDXT1Cg6K/1s5yq5SHZt2z59BG3 bRBy2rihMKajZzVqLMm9X1dHOrRT0EuRjSBxwxlGsWW857unOq9RO8yPuV6EypE6P5hW sFxA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=Y+Zlu/jyffC3tcPYynjlrJGPDukZUfRAC+HVlLoluho=; fh=936sdtmrkpSY5xs0isw6wBUcmfCvGttdxKwiAOV5ysg=; b=MgBhBqoqhoWk6MlDnV55li3Wgg5xZL+aTNMoV01yW5TWVh/vANvyfd99r6rmGF7n9G XxyUfR9ai7b2Gb3U32jKfPWsY6GfYS2ws3G/UEzAHPUQJ7Htg5SmtxsJR1QpAk5HXukX Kmid9fSr2DBJhM9R/PPSbsftZXjHECDwhq/Hn2ux2itk2CbZFzAuYUD1jvgksN51QLok m0r+abWLlq7m1Us/XbDByNhpwTP6ZY+bqHR44HmPx0Ua718URJspYAB7uzitM8lDIp5a DTJmV+GbZ72ZwP88Yia+Cf7E7MIL5a55wFlXt69/3gZEsrHp/2jRA9r48c3aK50TskD0 MhQQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=rw7EWm1j; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-72922-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72922-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id fc23-20020a056a002e1700b006e0735501c5si6157608pfb.316.2024.02.20.03.38.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Feb 2024 03:38:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72922-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=rw7EWm1j; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-72922-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72922-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 8D4B1283A92 for ; Tue, 20 Feb 2024 11:38:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 850EE6931E; Tue, 20 Feb 2024 11:37:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="rw7EWm1j" Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (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 77D86692F6 for ; Tue, 20 Feb 2024 11:37:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708429058; cv=none; b=mb5W3SOX/TovIJx2qeRb5Ij4UQoOBFUA53E3MLo7dSrCu/0+r4O+ZzFjBbhCI5Sz1RvwraH8GI6DkLhc/Wt2L9DSQbOZvPokuoFRN/sQYzhMxTsciBR4aQzEWCgFhqQ5aVGXrpV8EH0k8gLhrScEvoWjfebZXsdx66MOVgUNVmY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708429058; c=relaxed/simple; bh=6InzT0zOMfVSMMUoPS5SFnvU1MpP5NB5EaOK+7nKFWM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=OL0uyn/OCHrncDp8cYTcOXlSWr9DgIxH/tQ7Mcdy9968IuYceOZiM1tf4nzpSzmMEo03SgeUoLmSm6Gh17/QWrOC0dSrTkFNd8TGazgCm1sIEr4C84tkHLPu/CrdAs8Mp2g2ZGDS0x6WqqptuFafAY1w5zIwdy91L0wwJ5Fcwzk= 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=rw7EWm1j; arc=none smtp.client-ip=91.218.175.188 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 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=1708429054; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y+Zlu/jyffC3tcPYynjlrJGPDukZUfRAC+HVlLoluho=; b=rw7EWm1jRAZ0ejyR0syJMxY+LC8andr9N4hT/S2TcsUdJVzr5zpj1ve+7DC0aFKLOP6Zh+ oQAbX4OcdcWxRXxp0WVl9onzMqu+Bu4Srq5jwKDUIbVPErTVJ6F3iLf7W+N/3VP2mgkjg8 CojlsKYsoHjEm5Q7HClBNZpzfqtRCIk= From: Chengming Zhou Date: Tue, 20 Feb 2024 11:37:00 +0000 Subject: [PATCH RESEND 3/3] mm/zsmalloc: remove unused zspage->isolated Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240219-b4-szmalloc-migrate-v1-3-fc21039bed7b@linux.dev> References: <20240219-b4-szmalloc-migrate-v1-0-fc21039bed7b@linux.dev> In-Reply-To: <20240219-b4-szmalloc-migrate-v1-0-fc21039bed7b@linux.dev> To: hannes@cmpxchg.org, Sergey Senozhatsky , Minchan Kim , Andrew Morton , nphamcs@gmail.com, yosryahmed@google.com Cc: linux-mm@kvack.org, Chengming Zhou , linux-kernel@vger.kernel.org X-Developer-Signature: v=1; a=ed25519-sha256; t=1708429041; l=2725; i=chengming.zhou@linux.dev; s=20240220; h=from:subject:message-id; bh=4NV6DsrM5S+/h7ppU/k8FOJs/bnqzH3nRRreQTC9eDs=; b=kFZpk3aIR7kadOlGiYlEg29vShKRkOcKdJVmvW0zBNOCVbMMCVgKRPWfv2u+eEVnktHzunOZC ngUBXQ3+ObdCLuVC2DKsIPzNqJKn3UcHHx0R9m/63qvgYW0ar4p5gkN X-Developer-Key: i=chengming.zhou@linux.dev; a=ed25519; pk=5+68Wfci+T30FoQos5RH+hfToF6SlC+S9LMPSPBFWuw= X-Migadu-Flow: FLOW_OUT X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791417746367827347 X-GMAIL-MSGID: 1791417746367827347 From: Chengming Zhou The zspage->isolated is not used anywhere, we don't need to maintain it, which needs to hold the heavy pool lock to update it, so just remove it. Signed-off-by: Chengming Zhou Reviewed-by: Sergey Senozhatsky --- mm/zsmalloc.c | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index f2ae7d4c6f21..a48f4651d143 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -116,7 +116,6 @@ #define HUGE_BITS 1 #define FULLNESS_BITS 4 #define CLASS_BITS 8 -#define ISOLATED_BITS 5 #define MAGIC_VAL_BITS 8 #define MAX(a, b) ((a) >= (b) ? (a) : (b)) @@ -246,7 +245,6 @@ struct zspage { unsigned int huge:HUGE_BITS; unsigned int fullness:FULLNESS_BITS; unsigned int class:CLASS_BITS + 1; - unsigned int isolated:ISOLATED_BITS; unsigned int magic:MAGIC_VAL_BITS; }; unsigned int inuse; @@ -1732,17 +1730,6 @@ static void migrate_write_unlock(struct zspage *zspage) } #ifdef CONFIG_COMPACTION -/* Number of isolated subpage for *page migration* in this zspage */ -static void inc_zspage_isolation(struct zspage *zspage) -{ - zspage->isolated++; -} - -static void dec_zspage_isolation(struct zspage *zspage) -{ - VM_BUG_ON(zspage->isolated == 0); - zspage->isolated--; -} static const struct movable_operations zsmalloc_mops; @@ -1771,21 +1758,12 @@ static void replace_sub_page(struct size_class *class, struct zspage *zspage, static bool zs_page_isolate(struct page *page, isolate_mode_t mode) { - struct zs_pool *pool; - struct zspage *zspage; - /* * Page is locked so zspage couldn't be destroyed. For detail, look at * lock_zspage in free_zspage. */ VM_BUG_ON_PAGE(PageIsolated(page), page); - zspage = get_zspage(page); - pool = zspage->pool; - spin_lock(&pool->lock); - inc_zspage_isolation(zspage); - spin_unlock(&pool->lock); - return true; } @@ -1850,7 +1828,6 @@ static int zs_page_migrate(struct page *newpage, struct page *page, kunmap_atomic(s_addr); replace_sub_page(class, zspage, newpage, page); - dec_zspage_isolation(zspage); /* * Since we complete the data copy and set up new zspage structure, * it's okay to release the pool's lock. @@ -1872,16 +1849,7 @@ static int zs_page_migrate(struct page *newpage, struct page *page, static void zs_page_putback(struct page *page) { - struct zs_pool *pool; - struct zspage *zspage; - VM_BUG_ON_PAGE(!PageIsolated(page), page); - - zspage = get_zspage(page); - pool = zspage->pool; - spin_lock(&pool->lock); - dec_zspage_isolation(zspage); - spin_unlock(&pool->lock); } static const struct movable_operations zsmalloc_mops = {