Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp559339lqb; Wed, 29 May 2024 04:19:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWYuwQWR7APvPCr5GtCTfs6nmtBt5OsEXeKH5Dm6VEJXGRDUpJHgr7Tl3nm9wyP3tPafe/WueoWiZT3UmhDCojZLOvCxE5cReyPTbUgsA== X-Google-Smtp-Source: AGHT+IGWVZ3d+TAk3TZzSvql2Ga5ssdbVMskNLSJNVqxiV1IVJKZzYAPc6CtnncH7WvAjm6ovh/o X-Received: by 2002:a17:906:c011:b0:a5c:dfc2:7239 with SMTP id a640c23a62f3a-a626525cb05mr1000220766b.66.1716981572174; Wed, 29 May 2024 04:19:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716981572; cv=pass; d=google.com; s=arc-20160816; b=mZHNF5O/QeOtvGosPvrLRG6F5DrJIw0Ajt4nopGR5t9D1VLXktyrD/8WwB1tdwgLLf dYeWkonoV1NBscT7tMrsvAhe8auECGhfe9+E3jqBwKkIhbweqmnC/YIyz6U1Zuy7Kz+o KHU9g2l1Iy0xffPPkkr7kJsnlMfCVZooYzJ9i/Oka99KrCV8CrAA2qpcgzQbSYrYaZN7 shRfXjx55ukvTSSIJgLP3U5uFwFJ4GwdyZCl26Gr3w0qV9Bc3pYztvalEQPW+TE22Pm+ 64wBq1NPepKoE8Ll9pw0DxTTKsIq0jI07ZB8quXFNKuu1PSN4+FO9Yru441+HJPyL1dF 8kfw== 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=eYW6FgG2O6XV/uk9aR1DRrJWoOUkUVwlSfHnXOiWQ04=; fh=4qo2wXwF6+wBmVpKt9nE5vXwAOEbbhXPZvwe/C5tp4o=; b=rENcRMKPCZfAtsK1pnH4f/vOCP3KpGbCq4mGFHsEvVZZQQpd0itEF9f4Z6yF6xhIan C9LWz/9ChB8Lig5zO3znMpKw63SIlG1QsqoFp3lD5+b88g4VMVXUC7iFoUD1E4cRcvoY yQHPak2Rbt2lKwTGn+haJd61/xaA3zqWcoybu+FGJcVlMns0ZTjXXE65pk/tvc45EjVz fvet+R/XbfKhlms8SWYEDneoMKtE7Vo1r+y6KrfLBjpLUWiazPYoOd1KuWF3Bo3tnQYG maTUBJBgKOanxBML6vnQ2NNF7/VgAdwZUkxrdp48kjnppORQylxG+a1P6rRLz2iR3may 5kTw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="R/attSln"; 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-194005-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194005-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a626c9134b8si605097866b.226.2024.05.29.04.19.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 04:19:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194005-linux.lists.archive=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=@redhat.com header.s=mimecast20190719 header.b="R/attSln"; 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-194005-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194005-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 am.mirrors.kernel.org (Postfix) with ESMTPS id B06661F26088 for ; Wed, 29 May 2024 11:19:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3096316A373; Wed, 29 May 2024 11:19:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="R/attSln" 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 9C7B416EBF0 for ; Wed, 29 May 2024 11:19:14 +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=1716981556; cv=none; b=uNJG33ZfW5dnOwPIhxT0bdsIt3xwualbKvG/DRgDzdIc0Z4x06YXSlIvwXmpssGxqv0xZtnVGMsL00iBGQYA/VVRrTaYM1gYONQBw87Ow6/sJisXU4z5VyEfpoyrGFgX0F5g03sXe4GsxxxwvAnANkU1/xQ1va4frBFKRMYjfnM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716981556; c=relaxed/simple; bh=WIyToRVLU5UPSAo+kAbFtG62AOKqZ9vqaCQCkPtTXdk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rqq7rgKGWOSR0d+3zlCagp2pW+6G+5obcS4WA6UyXtuiKK9hj69k39Pmk35EzQGwTFB7pCnSrMeyCo+SqecYeaWjARa3qJ5sAEbt6E1gScpsckV36dzsDJHF3GbWul2/uOklKIOdQHprcbMFJR4SIgN1/OYpnUh8o8wbBE5lVEU= 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=R/attSln; 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=1716981553; 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=eYW6FgG2O6XV/uk9aR1DRrJWoOUkUVwlSfHnXOiWQ04=; b=R/attSlnudsGgZD2A123ebGkVnGtr5iW1IvBDndz5zRJQEV6KosbIhnOaZzoWjk7h7SNPU TdL46oXzx25CeVvqm3QimCZkAJJCS0xHlvfhs7zZSVP5bfDCXQpoKSiQRuJWxfWaTpIv9V FOWyufDMIO2WWcCP8d0lH7U13HGlMkU= 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-228-yxWjoKy1OFGlzWoM2RexRg-1; Wed, 29 May 2024 07:19:10 -0400 X-MC-Unique: yxWjoKy1OFGlzWoM2RexRg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (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 2072480028D; Wed, 29 May 2024 11:19:09 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.193.127]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4B9D6C15BB9; Wed, 29 May 2024 11:19:07 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , "Matthew Wilcox (Oracle)" , Mike Rapoport , Minchan Kim , Sergey Senozhatsky , Hyeonggon Yoo <42.hyeyoo@gmail.com> Subject: [PATCH v2 1/6] mm: update _mapcount and page_type documentation Date: Wed, 29 May 2024 13:18:59 +0200 Message-ID: <20240529111904.2069608-2-david@redhat.com> In-Reply-To: <20240529111904.2069608-1-david@redhat.com> References: <20240529111904.2069608-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.8 Let's make it clearer that _mapcount must no longer be used for own purposes, and how _mapcount and page_type behaves nowadays (also in the context of hugetlb folios, which are typed folios that will be mapped to user space). Move the documentation regarding "-1" over from page_mapcount_reset(), which we will remove next. Move "page_type" before "mapcount", to make it clearer what typed folios are. Signed-off-by: David Hildenbrand --- include/linux/mm.h | 5 ----- include/linux/mm_types.h | 28 +++++++++++++++++----------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 3aa1b6889bccf..eebfce8f58bca 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1206,11 +1206,6 @@ static inline int folio_entire_mapcount(const struct folio *folio) return atomic_read(&folio->_entire_mapcount) + 1; } -/* - * The atomic page->_mapcount, starts from -1: so that transitions - * both from it and to it can be tracked, using atomic_inc_and_test - * and atomic_add_negative(-1). - */ static inline void page_mapcount_reset(struct page *page) { atomic_set(&(page)->_mapcount, -1); diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 24323c7d0bd48..dd2ce1b3ec80e 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -46,9 +46,7 @@ struct mem_cgroup; * which is guaranteed to be aligned. If you use the same storage as * page->mapping, you must restore it to NULL before freeing the page. * - * If your page will not be mapped to userspace, you can also use the four - * bytes in the mapcount union, but you must call page_mapcount_reset() - * before freeing it. + * The mapcount field must not be used for own purposes. * * If you want to use the refcount field, it must be used in such a way * that other CPUs temporarily incrementing and then decrementing the @@ -152,18 +150,26 @@ struct page { union { /* This union is 4 bytes in size. */ /* - * If the page can be mapped to userspace, encodes the number - * of times this page is referenced by a page table. + * For head pages of typed folios, the value stored here + * allows for determining what this page is used for. The + * tail pages of typed folios will not store a type + * (page_type == _mapcount == -1). + * + * See page-flags.h for a list of page types which are currently + * stored here. */ - atomic_t _mapcount; + unsigned int page_type; /* - * If the page is neither PageSlab nor mappable to userspace, - * the value stored here may help determine what this page - * is used for. See page-flags.h for a list of page types - * which are currently stored here. + * For pages that are part of non-typed folios for which mappings + * are tracked via the RMAP, encodes the number of times this page + * is directly referenced by a page table. + * + * Note that the mapcount is always initialized to -1, so that + * transitions both from it and to it can be tracked, using + * atomic_inc_and_test() and atomic_add_negative(-1). */ - unsigned int page_type; + atomic_t _mapcount; }; /* Usage count. *DO NOT USE DIRECTLY*. See page_ref.h */ -- 2.45.1