From patchwork Wed May 29 11:18:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13678708 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 DBDDDC25B75 for ; Wed, 29 May 2024 11:19:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3B14E6B009A; Wed, 29 May 2024 07:19:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 310336B009C; Wed, 29 May 2024 07:19:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 13C3F6B009D; Wed, 29 May 2024 07:19:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id E45C16B009A for ; Wed, 29 May 2024 07:19:14 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 648EC1C12DD for ; Wed, 29 May 2024 11:19:14 +0000 (UTC) X-FDA: 82171187028.07.AF823B7 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf28.hostedemail.com (Postfix) with ESMTP id C97BEC0013 for ; Wed, 29 May 2024 11:19:11 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FM0fS1Qx; spf=pass (imf28.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1716981551; 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=jPxv1H9FEvCkjhG3HJ1KbEh1kIcR6+OYpFhiyO9bfXs=; b=UqPBo/8ZL/yESIDx+d3n0ZbhDPKbp45Xh5dKs+VGIoG0lDi8MKHOqEVwC+PIZW1h0POqF1 IZ4VLztoRlR+3iGaoqzayq5COEjyccgIkS487gi2vCzAswkgrdha4ZQQiUOGzbwZOyboDH pLeBPKLX7WhJE30x0xd8eXURQPYhBOA= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FM0fS1Qx; spf=pass (imf28.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716981551; a=rsa-sha256; cv=none; b=6VbUlu+IpsbTVIbDu5ao5XZ1fleORG6oASCOcHs/wubrlsEZyBlfJxQRlbS2C2JJ5E7hWb 8RjmUxYR5AkMKXVLqZRc88ey9TJ4LIK9UNoWd6hn8ESQwJZe3PHr7/Frog0k/Oz72UA70t 0v2g46CCYoILigWHJjpZreMy6uXu4oo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716981551; 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=jPxv1H9FEvCkjhG3HJ1KbEh1kIcR6+OYpFhiyO9bfXs=; b=FM0fS1Qx+Bn6JAMopCwYs5CG+dKBklgTEjC2vwn8T+3CMMHvletdRRAzN5sJeRaZmYTX1/ 1a5O30fG38cmAt7PvDMimzD5VEzigTW6nw5zYDlncFj6G6net/6Av8yct+eC1Zep4Xai0r 5Ai0nO+mwqiZnGkPieRJN+3yj89XYCo= 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-336-hdrW9_VDPtqk-vfyiUgC2g-1; Wed, 29 May 2024 07:19:07 -0400 X-MC-Unique: hdrW9_VDPtqk-vfyiUgC2g-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 12C47800169; Wed, 29 May 2024 11:19:07 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.193.127]) by smtp.corp.redhat.com (Postfix) with ESMTP id F0116C15BB1; Wed, 29 May 2024 11:19:04 +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 0/6] mm: page_type, zsmalloc and page_mapcount_reset() Date: Wed, 29 May 2024 13:18:58 +0200 Message-ID: <20240529111904.2069608-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: C97BEC0013 X-Stat-Signature: dgs1z3wa5errgk868bh6k5z7ety39y69 X-Rspam-User: X-HE-Tag: 1716981551-860095 X-HE-Meta: U2FsdGVkX1/l0SmJZoz068HQU7ys6uIka2TSQh2ZLtIuJ1opBjONhYy56MeZv0YwLc6EAztWvuEUtf8actcMJo+OqnEKxbPuGu9dN52sC6uJrLkUa+xDjmBRPbupeg30gABxFwL3BjanOClmUSTgXtBoP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UMsO+zlVVCEZClr4M7P8cgALVIv9euuGq4shShUadecLfAIK/ajRkmq7Ow4tDnMa6O+Uho0RkWrk6rrr3tNeTZeUMDYaN667IkTrZA1VxHjwFYF+HSd0QlZN2XjCDHm9nyaCa2Zirci9+P9eKVvJgJK1YHQYzmrY0l5IM8Owu5xXrNWDVAvNqswqQORaqU7TQK5WcQ4eU6s/DNn2T9hkUiBI58of/zSRuphPnB938tLQNshJ//zDKl1r++pYQMI0JMuQw6MSVDIsxz7m/w5smA== 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(). 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 mm/mm-unstable * "mm: update _mapcount and page_type documentation" -> Minor comment change * "mm: allow reuse of the lower 16 bit of the page type with an actual type" -> Fixup 18 vs 16 in description -> Reduce PAGE_TYPE_BASE to a single bit and hand-out bits from highest to lowest -> Adjust description RFC -> v1: * 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 | 25 ++++++++++++++++--------- mm/Kconfig | 10 ++++++++-- mm/filemap.c | 2 +- mm/mm_init.c | 2 +- mm/page_alloc.c | 6 ++++-- mm/zsmalloc.c | 29 +++++++++++++++++++++++++---- 9 files changed, 78 insertions(+), 40 deletions(-) Tested-by: Sergey Senozhatsky # zram/zsmalloc workloads