From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ot1-f51.google.com (mail-ot1-f51.google.com [209.85.210.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 795EB2E7378 for ; Fri, 29 May 2026 00:00:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780012804; cv=none; b=A1rLDB9ElaOM2yFKlNSR3EUr2lnDlRzv2hsoNgX7Qmctqk2zVF9KZGrKFMWdV/0xQCxj5UmJtPoofmswUQBaX7z/RMRQB2uW2Z4FUcvxgWdWxSMxKbJca3hKsyCmQMBdkTSqF85IxwNB7smfs2URhpivfq1b6dWsNUeXkmVOv9I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780012804; c=relaxed/simple; bh=EeEFiYGptatbfuz4luiQsZoFr3oKEisAzj/7hOWNUb8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qud6l+4NWSr+2EPdWHCh7CBdbcV7/SynZw6fTIoBf16Gs6nZEFIwOySkqPX7Ji1szcF8k+6E85SHwu8KR8I+fMQy1cOq+wn5ZJhdcVpuOZAm4QM2gcytJ/J1fDZj4bw6/669hli4UQ58O2nMoLsvhtMBsoSTGgHF5zrtd2LS4ns= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Br+tiHlV; arc=none smtp.client-ip=209.85.210.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Br+tiHlV" Received: by mail-ot1-f51.google.com with SMTP id 46e09a7af769-7dcdaf06498so8653065a34.2 for ; Thu, 28 May 2026 17:00:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1780012802; x=1780617602; darn=vger.kernel.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=lWA22sBER7v5Bm8fMESQHwBbc2tnWs5QQVcuwUnnoQ0=; b=Br+tiHlVI9OlRIJ2nnJ8x4B4bD0f11Zvr5R0AiFadra3nDk1aPxQ2wxTeURJPbutIb e6fj8VhfOqGkzu7H0NFqF19viztSREuIErK83n9OPRbp7FdBuynzCjvmuTx5jvJtE/e/ BPt8C0koNG6J1yfbSRwgDVey3PDdPocuCPb0fH6rd/BJMQVG5sZiGb+3Jo78G8JTnYh8 w5wiy9552JeEboCR1/hs3u4Yq078BRd5knYEfeqC5ZPWBTozh+if8zrIpKbi2VW3Vf45 Vd4zicK2y8GTWWCBMKFDT1KTWdxmodcFOve2IBbIzwNp0VRRPw0NVBfDahS7R1LEdKbt gz1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780012802; x=1780617602; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=lWA22sBER7v5Bm8fMESQHwBbc2tnWs5QQVcuwUnnoQ0=; b=kC67eOqe0EGtgobKcLuMtqNssIOYs+KdA9nDt27z4PJ37g6jEcHkg/Dw+jVwHtaL7X irlxmKN25IF7nyHbV9PX1IVRVmdGiQ+0pL5s3ToKq6/aSUYtTmNuiHTed0BnX/PsJ4CE qOWNLwTqk1xawccHLqyWOlxWbN7uI5HbW4zHyZRWV3qMeXOE9SbcIUww/uvF6U+KO5RU SgZLiJ/WtDu0Z9SbjpPATu55k4HerQ5e16MrKhfaEEsilKU+Fz2xmWav6nNFXES36C12 j7A42osAoqUG6gNJVg78iUVs4eMebVYE5XzjA8XyFgAl6am0gT1OTvgJ9l7eCv0TSeF8 aJlA== X-Forwarded-Encrypted: i=1; AFNElJ/auiV9t5+Xyil9hOhXUowvgmwUkuqqPPu03LuCwzshsAcMdxva9fROsSlkZoC+USb5iGFjAeJC8TKbYrw=@vger.kernel.org X-Gm-Message-State: AOJu0Yx+WocbmAT1Fz//j7kr98PX80Zq2RHBqebJgDBCkrBSdpXq9gm2 6k/v1oUWzF5+AL4vHYY/TeW6fXbhaqzW8dwMkMbEkMUOEf20GxupE/H/ X-Gm-Gg: Acq92OHlTx/806k1zMImOGAE8TXy+ZpWb8jgO2X1XQMzNdAXcOxbVV7bGwsDfH4N5ET ohjWehJO0Szd5SY1ngp8ZCZDs5AKJv9MtXHy3kwl2cp1+JwbF0yiP1UDDigEDPp9qceyHzZ5pbF HPmRUioVQGtZFTEuNdnDZPVkpulyyllUR/Yf5m2PYZ7im2uOqpjJN4NgpQgH+1wPokX9f3/OzbW /yuSnTQ+DSSaliWRA/79xhugmPsUlUGIKnCXV9qL8TAOKaCrb2+nUQGridmWVoZlv7xISPI7Y6h SJnUsXWAWAI7TGUXJxD37J2hdApy3e7HMBPu7cOwOnnog6OhXDzxipaVd/eEFXKZTlr5S791CnS hIYkYBdVI1ZGi5JCSBbPbt9ceR40QVdfCsnCOqrv605JQ4hs5CGhPdTYfx3szqjMEi7TKhO7MRM roiAawSyCshONP6gTGsA918/5fL7jnBcKzz+hxLSudn7SCs72LIMMdu36KpPFbqQcG X-Received: by 2002:a05:6830:8285:b0:7d9:f50f:96ad with SMTP id 46e09a7af769-7e694dab86fmr588038a34.24.1780012802437; Thu, 28 May 2026 17:00:02 -0700 (PDT) Received: from localhost ([2a03:2880:10ff:71::]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7e695a1d33dsm349116a34.0.2026.05.28.17.00.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 May 2026 17:00:01 -0700 (PDT) From: Joshua Hahn To: Wenchao Hao Cc: Andrew Morton , Nhat Pham , Yosry Ahmed , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Minchan Kim , Sergey Senozhatsky , Xueyuan Chen , Wenchao Hao Subject: Re: [RFC PATCH v2 3/3] mm/zsmalloc: drop class lock before freeing zspage Date: Thu, 28 May 2026 16:59:57 -0700 Message-ID: <20260529000000.652785-1-joshua.hahnjy@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260527115930.3138213-4-haowenchao@xiaomi.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On Wed, 27 May 2026 19:59:30 +0800 Wenchao Hao wrote: > From: Xueyuan Chen > > Currently in zs_free(), the class->lock is held until the zspage is > completely freed and the counters are updated. However, freeing pages > back to the buddy allocator requires acquiring the zone lock. > > Under heavy memory pressure, zone lock contention can be severe. When > this happens, the CPU holding the class->lock will stall waiting for > the zone lock, thereby blocking all other CPUs attempting to acquire > the same class->lock. > > This patch shrinks the critical section of the class->lock to reduce > lock contention. By moving the actual page freeing process outside the > class->lock, we can improve the concurrency performance of zs_free(). Hello Wenchao and Xueyuan, Thank you for the patch. This is a really cool idea and I think it makes a lot of sense. LGTM aside from a few nits, with those resolved please feel free to add Reviewed-by: Joshua Hahn > fullness = fix_fullness_group(class, zspage); > - if (fullness == ZS_INUSE_RATIO_0) > - free_zspage(pool, class, zspage); > + if (fullness == ZS_INUSE_RATIO_0) { > + if (trylock_zspage(zspage)) { > + remove_zspage(class, zspage); > + class_stat_sub(class, ZS_OBJS_ALLOCATED, > + class->objs_per_zspage); > + zspage_to_free = zspage; > + } else > + kick_deferred_free(pool); NIT: We should probably add opening and closing braces here as well since the if() case is more than one line. > + } > > spin_unlock(&class->lock); Sashiko caught this in [1] and I was confused why the likely() doesn't make sense here, but I finally realized that zspage_to_free is likely to be set when comparing trylock_zspage() success vs. failure, but it's unlikely to enter the ZS_INUSE_RATIO_0 case to begin with, so an unlikely() seems correct here. Thanks again. I hope you have a great day! Joshua > + if (likely(zspage_to_free)) { > + __free_zspage_lockless(pool, zspage_to_free); > + atomic_long_sub(class->pages_per_zspage, &pool->pages_allocated); > + } > cache_free_handle(handle); > } > EXPORT_SYMBOL_GPL(zs_free); [1] https://sashiko.dev/#/patchset/20260527115930.3138213-1-haowenchao%40xiaomi.com