From patchwork Mon May 27 14:14:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13675407 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 253ACC25B74 for ; Mon, 27 May 2024 14:15:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA78E6B0095; Mon, 27 May 2024 10:15:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B57676B0096; Mon, 27 May 2024 10:15:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A481B6B0098; Mon, 27 May 2024 10:15:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 850426B0095 for ; Mon, 27 May 2024 10:15:08 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 234D541525 for ; Mon, 27 May 2024 14:15:08 +0000 (UTC) X-FDA: 82164372696.14.09F7B82 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf20.hostedemail.com (Postfix) with ESMTP id 7EE301C0017 for ; Mon, 27 May 2024 14:15:05 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=jC3iBprP; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf20.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716819305; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=KKccOQIZycQoZBPSPGMUHOGUVheMa94LVY3B/d+1+Zo=; b=f+G/T+JB1352YpaI1Tv2GujqyKExG7xtyptCzA9FYGd4ALu1+1y1rbF73M+Jjd4Za8fWke JD5ypZ1IOExU0tRN+VPSM7yzRvA6qJ7a7c/B2jf1qdvjlV2/xyg8EkvX3pzUG1qRmFIjqe Jouk4QwsnNdto/kfc++RhGymiAzhavw= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=jC3iBprP; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf20.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716819305; a=rsa-sha256; cv=none; b=j/CQBiwMSlttYlSEBYNC48CeqfOb9RNRw4coiqOnf+Nyypg4QS2vLV59B2u6pQVdBJpRJS tPLZfzMeWRCzyXbVujnIxhignuymN3BFp9CQttkqZUdgWU63KAhDkLYctiS7i9X5C5w4Y9 o4sLEdRljNBQ2g3QHYfw4CbZNAxmswU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716819304; 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; bh=KKccOQIZycQoZBPSPGMUHOGUVheMa94LVY3B/d+1+Zo=; b=jC3iBprPu092b9YbOMD9gV9Jlya5YRAlIVEy6sdF0Kpyxk4tSJp4iYtvHItcX3bcECWsFr hy4zDczlhVuAr9wl446GDkSc6auNbeuw1/KaGWZ0JRruEpIMDjMtNXft5QIJJurVvSPRkM xRJEmXvIXeeWsGcxfc8Hr7TysYNIfto= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-387-spO2U6whOJWTtFQD_qaNog-1; Mon, 27 May 2024 10:15:01 -0400 X-MC-Unique: spO2U6whOJWTtFQD_qaNog-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 C284C1C0512D; Mon, 27 May 2024 14:15:00 +0000 (UTC) Received: from t490s.redhat.com (unknown [10.39.192.209]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 595A11C00047; Mon, 27 May 2024 14:14:58 +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 0/6] mm: page_type, zsmalloc and page_mapcount_reset() Date: Mon, 27 May 2024 16:14:48 +0200 Message-ID: <20240527141454.113132-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 7EE301C0017 X-Stat-Signature: qkpawnzmizku1m6fd8yp9bjncusawgf9 X-HE-Tag: 1716819305-318079 X-HE-Meta: U2FsdGVkX1/V5MN0GiQat5vWG/EJuvRYh4XH/ng5ftiT/A4zO76oO7M2M0AHS96KDpeK/dMoYdpsn0YNEYI6/abzog58xr5RtppWCl5Z3QtCsSLR3P7KFNGgAYAe+bNwTIHmEXtgCfL2z/PO2pNP8LQKs6pNKJl79R+pyNlMGABAgKVK+Yv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JZXgc98zyK+gFxAk/HWe/WcARI+N96Db9IXqaPBumJe6HJ7AYOP2aiP9ByKbyCbFFQCfu1xNA1ZBjq5WzPzKyMV5S/aI+GrLLCV4lszSpOISrOjEWYGZLMsTlUDpVmOToJ3efxcC3d/96G7jxdJ9s/qIlxlRg5viFW9A8dY4EU/KM7lSHFwSyPEdB6QfRlbImpkxqYjst85rrWixBW4YXM/Mk0cHtOdLaESbHifENtYT0ps1O3xpR+TYkAw8sN6aeXJTWlKr0HNM02xb2891r+Wm+MkQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Wanting to remove the remaining abuser of _mapcount/page_type along with page_mapcount_reset(), I stumbled over zsmalloc, which is yet to be converted away from "struct page" [1]. Unfortunately, we cannot stop using the page_type field in zsmalloc code completely for its own purposes. All other fields in "struct page" are used one way or the other. Could we simply store a 2-byte offset value at the beginning of each page? Likely, but that will require a bit more work; and once we have memdesc we might want to move the offset in there (struct zsalloc?) again. ... but we can limit the abuse to 16 bit, glue it to a page type that must be set, and document it. page_has_type() will always successfully indicate such zsmalloc pages, and such zsmalloc pages only. We lose zsmalloc support for PAGE_SIZE > 64KB, which should be tolerable. We could use more bits from the page type, but 16 bit sounds like a good idea for now. So clarify the _mapcount/page_type documentation, use a proper page_type for zsmalloc, and remove page_mapcount_reset(). Survived a couple of days with the built bots and my cross-compile attempts. Briefly tested with zram on x86-64. [1] https://lore.kernel.org/all/20231130101242.2590384-1-42.hyeyoo@gmail.com/ Cc: Andrew Morton Cc: "Matthew Wilcox (Oracle)" Cc: Mike Rapoport Cc: Minchan Kim Cc: Sergey Senozhatsky Cc: Hyeonggon Yoo <42.hyeyoo@gmail.com> v1 -> v2: * Rebased to v6.10-rc1 * "mm: update _mapcount and page_type documentation" -> Exchange members and fixup doc as suggested by Mike * "mm: allow reuse of the lower 16bit of the page type with an actual type" -> Remove "highest bit" comment, fixup PG_buddy, extend description * "mm/zsmalloc: use a proper page type" -> Add and use HAVE_ZSMALLOC to fixup compilcation -> Fixup BUILD_BUG_ON -> Add some VM_WARN_ON_ONCE(!PageZsmalloc(page)); * "mm/mm_init: initialize page->_mapcount directly in __init_single_page()" -> Fixup patch subject David Hildenbrand (6): mm: update _mapcount and page_type documentation mm: allow reuse of the lower 16 bit of the page type with an actual type mm/zsmalloc: use a proper page type mm/page_alloc: clear PageBuddy using __ClearPageBuddy() for bad pages mm/filemap: reinitialize folio->_mapcount directly mm/mm_init: initialize page->_mapcount directly in __init_single_page() drivers/block/zram/Kconfig | 1 + include/linux/mm.h | 10 ---------- include/linux/mm_types.h | 33 ++++++++++++++++++++++----------- include/linux/page-flags.h | 23 +++++++++++++++-------- mm/Kconfig | 10 ++++++++-- mm/filemap.c | 2 +- mm/mm_init.c | 2 +- mm/page_alloc.c | 6 ++++-- mm/zsmalloc.c | 29 +++++++++++++++++++++++++---- 9 files changed, 77 insertions(+), 39 deletions(-) base-commit: 1613e604df0cd359cf2a7fbd9be7a0bcfacfabd0