Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2086583lqb; Mon, 27 May 2024 07:28:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVn63Q6R7BDHnvN4siedZAIRdP7h+yT+0tWsAW4UtL5Pc7CDtmTwOC1VMWY983KGayNxAPhDKg57bvjdTv4clX3E/R8jBktpxV6X9Rt3w== X-Google-Smtp-Source: AGHT+IHMIP1D9LegVvDfAwdqNZ/KKdKja1mwtxg5jW89Esfw3FODzYsPEDCqk+2/4FOlZ7eh5kRS X-Received: by 2002:a05:6214:4188:b0:6ab:7270:fcbe with SMTP id 6a1803df08f44-6abcd19e32fmr97990786d6.58.1716820119025; Mon, 27 May 2024 07:28:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716820119; cv=pass; d=google.com; s=arc-20160816; b=BsR+O3wmgglDff0a0+ggod2rdiUD1EjQVcEjnbfoeMRBFclTWVIwWQqs1gYus/YimH pajJJ83c7k0Wfv+FjpkR5K8+qdPXDrxjeu70yTpOCrFmj2f5m+VhojdIDwpWfnEhD95B 7FwgXh/MEkoqiN7Rk1S5tH6zr7Re7m5JtAKjqTfsfWF3lVMBxWSPJIse8OsJbR8KBJxV BxsGZ4NurVSdmF/QaGXb4/+OL5cSP8hiszYot/RLq4C0OY3TvemrCUSPR4lCBloVcD3D nR6Xb5jmJLkvqIXqFu8iD2Z62nxV6ubefU5RcOocyXwrD4tTf0LVL6ezgLi845JryvFR gJag== 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=fI7k3N6P8qJ4FuS4bDw6lNsnGteHRLAJN+b2iNRt+tE=; fh=4qo2wXwF6+wBmVpKt9nE5vXwAOEbbhXPZvwe/C5tp4o=; b=jl5QhUfkUCLfB8hFo/HtWW/gPfhgStHKzam1B47CW0G51/TmzzqtucAjvzAMD1BSfe PWjZikj+eWQ/OpqsqBVV9pIv/anFe9iW1IK2jzkHqcQusSHmdsVhTycXgN9Aoe7XOcyx A+utViETiX9mam/mH6HCs3BVqosX2GvWOuibvhM983PS7WN8nY/jZ+oU+SKo1Nam+Lax 09IQb76skM3rpkyhXobbsZ5QBaaUgy+M6yuH9FxrSJvlaBT4Z7mcJ1PQ4bK7VZviJP4R oJwE17NrCNu4p+uVnQrrJsr1Z+cRPCJ1SWPtQ1HoWGP62aUopeqtc1yhfdCI4ZYLp+kT H/uA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BaxaNOqm; 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-190860-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190860-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6ac162bbda8si81134436d6.527.2024.05.27.07.28.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 07:28:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190860-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BaxaNOqm; 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-190860-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190860-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id BE73F1C2109F for ; Mon, 27 May 2024 14:28:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 651BB17F373; Mon, 27 May 2024 14:15:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BaxaNOqm" 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 0E004163A97 for ; Mon, 27 May 2024 14:15:07 +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=1716819309; cv=none; b=epwiv6CIsRPb8ELoO2f/4wbnp6cogSPsLOl15ZyUgicRx9ej+a0znKxKN9NzHvmSO4Fvo3RTvW1EjswxHKQ0WoN52fQ7P/BTfLrnctwYSdhKBINn4hzT88MkqaqFWkrJ9YqhtAgFwF0XLJyzDWhKUALlYc9Go25JfFUP0HLkJWI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716819309; c=relaxed/simple; bh=z4n3mZWA/a7cnUz8UErNnCGa/NYYJfT1fQxIgQIa0q4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a49XOEtpWnYrCSGphOqTnGqMvOpPghzw9+ZsGndygqCCO9OWYotkGaKcSjb3koxbuhMtDxk2Kl5w170cqoKgt3AAJHh1cUl8i4phaknkD0xXpZax/ma0dlTJWVQAkpmHpEM/WG3zktD8YLoeTkkG+PehNfqlnXcnDkSC6BpY6to= 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=BaxaNOqm; 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=1716819307; 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=fI7k3N6P8qJ4FuS4bDw6lNsnGteHRLAJN+b2iNRt+tE=; b=BaxaNOqmFo4OQwCw2NeWbk9DVC18uQoXni/tWetHd254iaayZ7RoZI62L8okNMoRjUyt0S DR8nqaKRUWFudK3n7sKN1QzTrXVog5W1O+WFCqw4nDDixreKf1cQ93mEYQJWuj0Vtsydc6 1uvHW1u9I0Uq30pOk5etSu79NSs3tug= 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-550-kXZuQwgiNe2ZxgXhztVTPw-1; Mon, 27 May 2024 10:15:03 -0400 X-MC-Unique: kXZuQwgiNe2ZxgXhztVTPw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 CA8BD8029E1; Mon, 27 May 2024 14:15:02 +0000 (UTC) Received: from t490s.redhat.com (unknown [10.39.192.209]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0613A1C0654B; Mon, 27 May 2024 14:15:00 +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 v1 1/6] mm: update _mapcount and page_type documentation Date: Mon, 27 May 2024 16:14:49 +0200 Message-ID: <20240527141454.113132-2-david@redhat.com> In-Reply-To: <20240527141454.113132-1-david@redhat.com> References: <20240527141454.113132-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.7 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 9849dfda44d4..018e7c0265ca 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 24323c7d0bd4..6b2aeba792c4 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 + * (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