From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (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 16BD317E0 for ; Mon, 6 Jan 2025 03:17:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736133444; cv=none; b=gsF8oNtWxaympFyXneSU/0SjtJ2NYJR4iw0szsYa/RCuxai+cvgQnjX8MTszr6ta58D1xcxR7EuACtlFczNKTGNIcSiKKJClPnr7PuIXqEDCANfcT8tzlqKWDsmS/SjDvf47u7Hv1AFFL0eigvUEPUI/em0PFSqzbiTnB4nTgPo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736133444; c=relaxed/simple; bh=ChbDWxJWissWvid7iV6hIjzvlIzJKUm6hVvuhgGBJ4I=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=cg9PfZKGs6UwKHOlQmdhkg1GLqZ2xKfpQFmSPmcosIhCcGDn6Vj63jp0Xo8jB1XJfw7MzuWIaSzaSj5uMvpqypTVTtaV7wGRuTs4BiBux14UM892yUDVlN3CqgH8+dvKXCndqrCDjBPWwlc70rKGdsJy6eOJ3qj6b2U1tvLPuU0= 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=luyGyyDs; arc=none smtp.client-ip=209.85.216.41 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="luyGyyDs" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2ee50ffcf14so17676468a91.0 for ; Sun, 05 Jan 2025 19:17:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736133442; x=1736738242; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=HH3ED89tsTdnsw+rE9QWfbTCRTEYg4GmdA47cOVplWg=; b=luyGyyDsIpPxVeNz2T4mJm9ajpSFVtpK4RI4IIt+Kmxn4uWYE87lNjG7NalPXj7+gx Il3rQqTv8UYymw+Y8WL+KvPBTnGk8kMUacgMWSZZk5h7vzQX7z7GuW4ihQxouRR9HQfL ku/keHzF5OF29vzIDSOsQpg0mpARJ+9ocSJC74F+Y2iUnT838UJx6UxGzdMvedXkZe5V tqox431mRTGvvQRL5w3yd9oPjK1tTz/j13fcE7akhYT9pRdn74sUQ0d9svXf69pQ2yQ2 fByJ1r5LHibWSKzh4+jyQHm+DuEKmJlAfLbaQXMixaCN+tuqsi7gd3idEcgLmkqlMMIL YeXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736133442; x=1736738242; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=HH3ED89tsTdnsw+rE9QWfbTCRTEYg4GmdA47cOVplWg=; b=YSSn1gXD/+De60e6kP2/bsLhyAdlHS/HTVdZT+AT/nK8SBdSVBXgrWlG/kXivlSBO5 Ucx5ubiGgdjwku21UG0lqowcYwngQKzPm89yrsigx5+RSem9nw3+p6D0tWJHpIzmjj3t qsh/AR8ZCYGDsfT0HsIj5+NmOQkSZAra0Ss8BbXlWyfVNujG4JSgOGBE2GkaxaGdV0BD Dlj1+zZCBVg3D7gvCeCAzqK5dSFuNti/GGsS0qVOat/JThF6q0qVXC8fYABnSwgOCKtw d1nsdfhjy/deT09KYVjBQWGk6FuNs3m7hXRDVaeBYkFPUCzei9j5QpdY/o27mFLXxCBZ YTiA== X-Forwarded-Encrypted: i=1; AJvYcCUTPgy8u4LlihIXNuti6tirmscbSBDiMvLzEyYFkERJsLPyJBqqnUX6KFZhexmwvbhZWg92DymqgbUOxss=@vger.kernel.org X-Gm-Message-State: AOJu0YwCY1dsP0nPbIH+CBazpWiQWBMD47qGbASjne3ZA3Iu4aCQgX0l XW+3Xs68z0KJppcXIHQTmhF40Ff0jA5+Wfx4VeX8TqqyMvgu4YHN X-Gm-Gg: ASbGnctBsJOz+A7bddukfv8/AmOdvtgyLMzPtZaHNGelV3UrUK6ri5xoZ1+jNLqBGVM AXkDUVS5j5xFpJHQkBUiKzOxlaN+JothzH1wzl76vYkrEdLWFciEvlzQsw1B8OmIv0SQUlHlClN XD53rggOF7f9DIMTuwrcc+D8lPxpqnmj06y/q4Wye8dLZVWShH3Sw14sdaAIq3VIV86NVDrYkdy DHYn8vhfcXJQt9KLLG4Wuqr0L9Ul2lNa36e5nbAvFx2+bXMx16NVMm8p/v9HROIqr5dg6nlKhHS VxBmBwgO X-Google-Smtp-Source: AGHT+IHJsZoBMBkLol8NRyoMUhyLk6Yxfu4EjG4wqDyWD6EwH7i2BeNlGm0Phl+st/gLUAqxALBIPg== X-Received: by 2002:a17:90b:2b83:b0:2ef:9dbc:38d1 with SMTP id 98e67ed59e1d1-2f4435ad5e6mr82526493a91.5.1736133442245; Sun, 05 Jan 2025 19:17:22 -0800 (PST) Received: from Barrys-MBP.hub ([2407:7000:af65:8200:a54c:5ad3:ad27:edb7]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f2ed62cde6sm38471399a91.13.2025.01.05.19.17.17 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 05 Jan 2025 19:17:21 -0800 (PST) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: linux-arm-kernel@lists.infradead.org, x86@kernel.org, linux-kernel@vger.kernel.org, ioworker0@gmail.com, david@redhat.com, ryan.roberts@arm.com, zhengtangquan@oppo.com, ying.huang@intel.com, kasong@tencent.com, chrisl@kernel.org, baolin.wang@linux.alibaba.com, Barry Song Subject: [PATCH 0/3] mm: batched unmap lazyfree large folios during reclamation Date: Mon, 6 Jan 2025 16:17:08 +1300 Message-Id: <20250106031711.82855-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Barry Song Commit 735ecdfaf4e80 ("mm/vmscan: avoid splitting lazyfree THP during shrink_folio_list()") prevents the splitting of MADV_FREE'd THP in madvise.c. However, those folios are still added to the deferred_split list in try_to_unmap_one() because we are unmapping PTEs and removing rmap entries one by one. This approach is not only slow but also increases the risk of a race condition where lazyfree folios are incorrectly set back to swapbacked, as a speculative folio_get may occur in the shrinker's callback. This patchset addresses the issue by only marking truly dirty folios as swapbacked as suggested by David and shifting to batched unmapping of the entire folio in try_to_unmap_one(). As a result, we've observed deferred_split dropping to zero and significant performance improvements in memory reclamation. Barry Song (3): mm: set folio swapbacked iff folios are dirty in try_to_unmap_one mm: Support tlbbatch flush for a range of PTEs mm: Support batched unmap for lazyfree large folios during reclamation arch/arm64/include/asm/tlbflush.h | 26 ++++---- arch/arm64/mm/contpte.c | 2 +- arch/x86/include/asm/tlbflush.h | 3 +- mm/rmap.c | 103 ++++++++++++++++++++---------- 4 files changed, 85 insertions(+), 49 deletions(-) -- 2.39.3 (Apple Git-146)