Received: by 2002:a05:7208:31d3:b0:81:e143:7c29 with SMTP id v19csp2633316rbd; Tue, 9 Apr 2024 12:25:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUBHDIn1RgEVftDwxwW/Bf+LT024YsJEftg7TYZJaTzXJAmNeQrJj+P4e9hlDQPLKL8N/cI7iRn50FS/EB3Z+8QBeyJcuxvT0eKCpehHQ== X-Google-Smtp-Source: AGHT+IHwzqY8eW+kWmsFyRCq7Ve4oWhlA2B5kZD9K1rkYqPEGXO+fgMu0/LcC0NdpMMDYz2OgmTe X-Received: by 2002:a05:6a20:da9f:b0:1a7:74e4:efa5 with SMTP id iy31-20020a056a20da9f00b001a774e4efa5mr927347pzb.2.1712690720329; Tue, 09 Apr 2024 12:25:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712690720; cv=pass; d=google.com; s=arc-20160816; b=ArzVU48Jy636wE4FIBpbKxUBNw0dBZAk2sXZKnam4eyFQDRrXMORQR8w6RIIDj0bp/ n1FFfaedl7lxffiweKewnsiwVxRs7k/r4ZukvQY69AVjbiG3zAJYc9dHUKghQtv28xzQ tM1sGzNeGUTrxGoTWaa6iZj5laNY4A7dIgNiPAN8kBZ+8QxdFCIHra8o7lTW7nk8dJIP 5nL5POSQmhWEC2SzjiTIFbusrT+HhRd/rnOH8wLce5e9jdIr9oDoNKC7Dl1VmENAoN1q g8JSXNEsn8/abIRfBT5ULb7JoQNMhzCOhhjhgddl4Irhb7wds2aUFN/dqcigg2KIqSJj S/0Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=DanfdMkK2y8X/5UQWi5wxydKuxMzBBZcoNekt2NzNQo=; fh=6UXOkRl8PLWnLRlJFkZ1FKxRpZrfO06mwvecZ/lFyqY=; b=SKNsPsPCzdXCN/yZzC52x8gZ/O1o7xuNWCM/UAvMxVWB1FNze9NdknLWZrONx8Wd6q fSI+xXajM/eZABcYIy9sctNdsYChxUPCvHlQQr/n2KqSFQBU3xjslkFVqz0QZWaDub9k dzejrtdCUmEjBLeUSdeiXnHh3pcm2YhhjhlDKwi6CJQilj7V40t88bWvxRHJFkvqhZ9x b3KXc5hP5zxuvqxmJNQCFBsixTSxxtOsm+mFJm4hXtEiS3knnluoxQnIChpkyNw/iuDw bsVWHGRHishgBF3ylpp8sSzToOu62UrExF5v1+Mqs61of21GudDurmKsk3ruzA778np8 LhMg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Fi6bZy47; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-137519-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137519-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id gj9-20020a17090b108900b002a557ec4174si3042944pjb.82.2024.04.09.12.25.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 12:25:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-137519-linux.lists.archive=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=@redhat.com header.s=mimecast20190719 header.b=Fi6bZy47; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-137519-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-137519-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com 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 134A4284A2F for ; Tue, 9 Apr 2024 19:24:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C4CB1157E7E; Tue, 9 Apr 2024 19:24:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Fi6bZy47" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 6CE70157A75 for ; Tue, 9 Apr 2024 19:24:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712690653; cv=none; b=BbMm8RLmZGsXEhoCHn3gavcIdyNBqHgcdjhCfr5q3xQ4EJ+T0srISuVGASiSW9C25srfhZ9uJZzoDr8Jm3aK4JKvmmwlVnCGUJEOClB6TC3Zd7+vv/RJVKXU0deATxcudDTFbS2DRZMPZAWTCy74n4W6QUOscSmTeRrNrXsZTQQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712690653; c=relaxed/simple; bh=A67TbDz2qCguWtpXjavdA9CUCuXT3t/vnWxh8asQyzo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BPvxbTKRC/D+JPgUyPPO4wbHExif5eY5N5DakkhNOqaCqqbiTSuYoqVai6B3rf2wPqgvKVIb4ybd4PjNvmTi0QIK9ZlvsGPCTs9HSPoAD21OQ2Qvk+ljR/NLs8ZzWtr9+UZe83vGswzrYXiKdkcyXklsHTcoUMx1wuEV1eMAbs4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Fi6bZy47; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712690651; 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=DanfdMkK2y8X/5UQWi5wxydKuxMzBBZcoNekt2NzNQo=; b=Fi6bZy47nGOs56Cal9c8pHL4W4LzICBjqtqUX99MWdQvINFjtD7vEO2OyPkf2tBaRD3UDA yUJp0XHsc+B9XPy/+zLhemDNPZqREmZjebGI29czrCJRYKPd7yxafc0L03WGRWvQTKA/1j 5oSwC5dxdEtji0QjTIpq+oOEGGVhVc4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-140-eJSj8LVjMUGt1dEE8jgGSA-1; Tue, 09 Apr 2024 15:24:08 -0400 X-MC-Unique: eJSj8LVjMUGt1dEE8jgGSA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E743E806604; Tue, 9 Apr 2024 19:24:06 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.106]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3CAAC40B4982; Tue, 9 Apr 2024 19:24:00 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org, cgroups@vger.kernel.org, linux-sh@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Peter Xu , Ryan Roberts , Yin Fengwei , Yang Shi , Zi Yan , Jonathan Corbet , Hugh Dickins , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , Chris Zankel , Max Filippov , Muchun Song , Miaohe Lin , Naoya Horiguchi , Richard Chang Subject: [PATCH v1 03/18] mm/rmap: add fast-path for small folios when adding/removing/duplicating Date: Tue, 9 Apr 2024 21:22:46 +0200 Message-ID: <20240409192301.907377-4-david@redhat.com> In-Reply-To: <20240409192301.907377-1-david@redhat.com> References: <20240409192301.907377-1-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 Let's add a fast-path for small folios to all relevant rmap functions. Note that only RMAP_LEVEL_PTE applies. This is a preparation for tracking the mapcount of large folios in a single value. Signed-off-by: David Hildenbrand --- include/linux/rmap.h | 13 +++++++++++++ mm/rmap.c | 26 ++++++++++++++++---------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index 9549d78928bb..327f1ca5a487 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -322,6 +322,11 @@ static __always_inline void __folio_dup_file_rmap(struct folio *folio, switch (level) { case RMAP_LEVEL_PTE: + if (!folio_test_large(folio)) { + atomic_inc(&page->_mapcount); + break; + } + do { atomic_inc(&page->_mapcount); } while (page++, --nr_pages > 0); @@ -405,6 +410,14 @@ static __always_inline int __folio_try_dup_anon_rmap(struct folio *folio, if (PageAnonExclusive(page + i)) return -EBUSY; } + + if (!folio_test_large(folio)) { + if (PageAnonExclusive(page)) + ClearPageAnonExclusive(page); + atomic_inc(&page->_mapcount); + break; + } + do { if (PageAnonExclusive(page)) ClearPageAnonExclusive(page); diff --git a/mm/rmap.c b/mm/rmap.c index 56b313aa2ebf..4bde6d60db6c 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1172,15 +1172,18 @@ static __always_inline unsigned int __folio_add_rmap(struct folio *folio, switch (level) { case RMAP_LEVEL_PTE: + if (!folio_test_large(folio)) { + nr = atomic_inc_and_test(&page->_mapcount); + break; + } + do { first = atomic_inc_and_test(&page->_mapcount); - if (first && folio_test_large(folio)) { + if (first) { first = atomic_inc_return_relaxed(mapped); - first = (first < ENTIRELY_MAPPED); + if (first < ENTIRELY_MAPPED) + nr++; } - - if (first) - nr++; } while (page++, --nr_pages > 0); break; case RMAP_LEVEL_PMD: @@ -1514,15 +1517,18 @@ static __always_inline void __folio_remove_rmap(struct folio *folio, switch (level) { case RMAP_LEVEL_PTE: + if (!folio_test_large(folio)) { + nr = atomic_add_negative(-1, &page->_mapcount); + break; + } + do { last = atomic_add_negative(-1, &page->_mapcount); - if (last && folio_test_large(folio)) { + if (last) { last = atomic_dec_return_relaxed(mapped); - last = (last < ENTIRELY_MAPPED); + if (last < ENTIRELY_MAPPED) + nr++; } - - if (last) - nr++; } while (page++, --nr_pages > 0); break; case RMAP_LEVEL_PMD: -- 2.44.0