From mboxrd@z Thu Jan 1 00:00:00 1970 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01E0BC433F5 for ; Fri, 12 Nov 2021 07:33:17 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6686660E75 for ; Fri, 12 Nov 2021 07:33:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 6686660E75 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linutronix.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id E8ED96B0074; Fri, 12 Nov 2021 02:33:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E3F4B6B0078; Fri, 12 Nov 2021 02:33:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D2D556B007B; Fri, 12 Nov 2021 02:33:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0160.hostedemail.com [216.40.44.160]) by kanga.kvack.org (Postfix) with ESMTP id C3C216B0074 for ; Fri, 12 Nov 2021 02:33:16 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 8718174CF1 for ; Fri, 12 Nov 2021 07:33:16 +0000 (UTC) X-FDA: 78799462392.09.06EC8F6 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf03.hostedemail.com (Postfix) with ESMTP id 0EBCB3001A29 for ; Fri, 12 Nov 2021 07:31:50 +0000 (UTC) Date: Fri, 12 Nov 2021 08:31:57 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1636702318; 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=FmctTGPPY3978fNx+yJNpeXyGTZTCVxHye6mnLNSbPY=; b=Evbx9UC5rQY5iGcizp4aBU9FqjME6ijAQaeu1lCCV+sgHrEPGCJtVJ4gbpOmwm2R/JKoT1 kNJI8v135W084bGS8/5g1B6Uhebpqji1U1tQs2k3KRCw8JoiFGISYwmjNC1XXOy3YnETXY 06h1sJz9mog8BK72dVyuRlSCmUYPidE16nYUti1sJja9AwzKJ0GvMvF4zSGui+RdiH+oWt b1obUp1AkhEUVD6A4mVoNw0qvS/w5DSa7lYRnsA/gkcptXW5+Z/5KmUyCim3cXOHlzjctE ZfRt4JSHLaPdUa+vyCdLRHQlC6/8XBJNnQj2ZZlJkg6M+bYHNF5Prm9OJsCA1g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1636702318; 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=FmctTGPPY3978fNx+yJNpeXyGTZTCVxHye6mnLNSbPY=; b=SQ1TkrnghdwrwPRBuOaNW2ad4fAyMjmd3bUhYSivX+sdlQ8PrUeItpgtm6C2HXjbDxcLmw bMatLW+8krDR+HAg== From: Sebastian Andrzej Siewior To: Minchan Kim Cc: Andrew Morton , Sergey Senozhatsky , linux-mm , Thomas Gleixner Subject: Re: [PATCH 7/8] zsmalloc: replace per zpage lock with pool->migrate_lock Message-ID: <20211112073157.bfdfo2dzur4c5oqn@linutronix.de> References: <20211110185433.1981097-1-minchan@kernel.org> <20211110185433.1981097-8-minchan@kernel.org> <20211111090727.eq67hxfpux23dagd@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 0EBCB3001A29 X-Stat-Signature: f71sn55e7ziq3uybrnd5ptbu35695pw6 Authentication-Results: imf03.hostedemail.com; dkim=temperror ("DNS error when getting key") header.d=linutronix.de header.s=2020 header.b=Evbx9UC5; dkim=temperror ("DNS error when getting key") header.d=linutronix.de header.s=2020e header.b=SQ1Tkrng; spf=temperror (imf03.hostedemail.com: error in processing during lookup of bigeasy@linutronix.de: DNS error) smtp.mailfrom=bigeasy@linutronix.de X-HE-Tag: 1636702310-528465 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: On 2021-11-11 15:11:34 [-0800], Minchan Kim wrote: > > > @@ -2077,8 +2043,13 @@ static unsigned long __zs_compact(struct zs_po= ol *pool, > > > struct zspage *dst_zspage =3D NULL; > > > unsigned long pages_freed =3D 0; > > > =20 > > > + /* protect the race between zpage migration and zs_free */ > > > + write_lock(&pool->migrate_lock); > > > + /* protect zpage allocation/free */ > > > spin_lock(&class->lock); > > > while ((src_zspage =3D isolate_zspage(class, true))) { > > > + /* protect someone accessing the zspage(i.e., zs_map_object) */ > > > + migrate_write_lock(src_zspage); > > > =20 > > > if (!zs_can_compact(class)) > > > break; > > > @@ -2087,6 +2058,8 @@ static unsigned long __zs_compact(struct zs_poo= l *pool, > > > cc.s_page =3D get_first_page(src_zspage); > > > =20 > > > while ((dst_zspage =3D isolate_zspage(class, false))) { > > > + migrate_write_lock_nested(dst_zspage); > > > + > > > cc.d_page =3D get_first_page(dst_zspage); > > > /* > > > * If there is no more space in dst_page, resched > >=20 > > Looking at the these two chunks, the page here comes from a list, you > > remove that page from that list and this ensures that you can't lock the > > very same pages in reverse order as in: > >=20 > > migrate_write_lock(dst_zspage); > > =E2=80=A6 > > migrate_write_lock(src_zspage); > >=20 > > right? >=20 > Sure. Out of curiosity: why do you need to lock it then if you grab it from the list and there is no other reference to it? Is it because the page might be referenced by other means but only by a reader? Sebastian