From patchwork Mon Aug 12 07:42:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13760272 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 8BAAEC3DA7F for ; Mon, 12 Aug 2024 07:42:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 808396B00A3; Mon, 12 Aug 2024 03:42:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 78F5E6B00A5; Mon, 12 Aug 2024 03:42:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6094C6B00A7; Mon, 12 Aug 2024 03:42:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 2D4CD6B00A3 for ; Mon, 12 Aug 2024 03:42:30 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E47A6C08D7 for ; Mon, 12 Aug 2024 07:42:29 +0000 (UTC) X-FDA: 82442800818.14.5A5B5C0 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) by imf01.hostedemail.com (Postfix) with ESMTP id ECD5D40014 for ; Mon, 12 Aug 2024 07:42:26 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=GgFzvq5h; spf=pass (imf01.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.131 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723448479; 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=qDA/WcF+N7bRZ8xnTFUSXzMx22fwcCPeP/T81buhQT0=; b=cGzbAnkEVaVmotl8NIYvz3i+vnUqGmzZQVoXo4cKttc9FYoO3fo6qheGvq0Fz/jOOfPpD6 1h4NLP49se8Bt7eax3pdWF5l62pp6zQZGAa0OAAN8DEW1sBjtwVKbFGYiQ0sK7oj5VDDjL FymTOrJ/Q1aSC939p7FZMN7PK2BUlMY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723448479; a=rsa-sha256; cv=none; b=48t/ymliUUEgQNXy/2vb8dH9KE1Evc9NWXeVMkNSGYfBK1cqHUf4o0MTj4QdGlgU4KQ/8f 4KioDqiJCEeahmfjwmpV+a39stxHwRAVHvbFUvxb4/pcoSBVk3vWIJ7u0pHBIffpe+bILZ mglkMLivOfNAlHTIaev2eMxkEZn5TTI= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=GgFzvq5h; spf=pass (imf01.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.131 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com; dmarc=pass (policy=none) header.from=linux.alibaba.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1723448539; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=qDA/WcF+N7bRZ8xnTFUSXzMx22fwcCPeP/T81buhQT0=; b=GgFzvq5hpStqDw/IfRpnl5Rxi2TeiqjyWsZgwsQ9CAH96BysfyrMzny4liABsEwXVEmzOUhGsiUPbQcGkgtJRbIGdjHFOJ35WolmFahrIp62GijMK9JnxhIbBYiLf/1CUr4TJZkEtGNhG6LIxeofgEI32dH+pX2nxqMBo6mNnNU= Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0WCbU5t2_1723448537) by smtp.aliyun-inc.com; Mon, 12 Aug 2024 15:42:17 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: willy@infradead.org, david@redhat.com, wangkefeng.wang@huawei.com, chrisl@kernel.org, ying.huang@intel.com, 21cnbao@gmail.com, ryan.roberts@arm.com, shy828301@gmail.com, ziy@nvidia.com, ioworker0@gmail.com, da.gomez@samsung.com, p.raghav@samsung.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 0/9] support large folio swap-out and swap-in for shmem Date: Mon, 12 Aug 2024 15:42:01 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: ECD5D40014 X-Stat-Signature: nce1wh5du7oxk8zx716z6wwbeco147xn X-HE-Tag: 1723448546-843968 X-HE-Meta: U2FsdGVkX1/qj4FMk7FlJL8h9Lzh854uE1HHk37PMc4SUhOIxq8EJ4xJlg9SPWaxF33agzmNIsKndCZzu42K1Nzeo+f1jcx8R1Pjm5sfHtAcTa2Vr7hwakKkud+wcrDQBReKCbn5umTJ52OsVw6JQfg54Dfh1auDm6uF1Bcc81KWVCcbBPJm3qAqLevTHGJDlsnh2Ha6cAQoaFQ/dwjL230ccyZbKnPfNja2PBeETiIaHZXTtVDuQME6/oXfz4vJqMb0C2Lw074irdPAYAXoXX0pg8v88hUcwKs2uxI3I0rV5HCYD/QkgqdIe60kUBHcIXknj5pXspzK7S7lgLaoQCq3mYg5yYWvQ4ClHJwpn8yk7rV2b7+fqdOFfXQP3kh52ueff31C4XA2nyBL4gkd3JrTx8ZyGhK2P9Ghc6lIw0jnliHZVGmG4Qu/07BxcCnUkN/til0a2+7j7IF/pGMUvRcGU42i41/u6Q2uVbX1ro+ngc+SR+8OaA1ncXg8QDAdvspB2MYgBbAbCo1gSq27ZRB7M7MGdBI/UEXBBZk2DXzDX3jtoSnZy7SPVqcrdI8jEB2TQKkrB8n5GMSsKxuokfXW+kqosHAdFUny1HdUBwBfthyP1XRDZ9oe+52E7Z5DklAx30t8zV7eiO8T2OaHcfdRzzTc1v5iUJk8UdqII79fuHyEdCuYNmkKqSLc8EAfWPbf0+rMXzUckjQgpzhKSKfUa5HVD5tbIn3SuuJhhBFVyAapUHUXIpp/jtR+uBxHr1di11W7xSPWI2Hy0bWigMFgcVZFLirVkZrxcqfLa48C1fzsGMi/ncfh73YgB/aOn7UWHAjtjZRCdNMyG/edXYR1j+WwCUpOKjnqIyNHCRGmuuB9XgId0NHZ03HFhjyv1+fCFql2tJg0lqXEnYv+CsOPBMUmeogfhw0jJZjImUPfIlDju5goraOE32y1v63Zmz3jRZuqUYGEAbQvgAI 7V3WudnB zNeA3HudXJD1F1WnLj9k0iiyV9LtnuEHs3hVo2hPljtXhELmJLovumylDHBTrZYtmq+4tjT3l2TfLiB52zAz/oC59yShtUKlcXCydQm138LVvVU3wEccUaFmZOiytO8ySJGT9Z30AntD1JID+XXO8fqBV5Q6f6YcUaMwnKMD1fMRG1BT4FvGccoP1ZRegZqL3SC27Wu83PZ9G7CmcHRBcqEx1RpgCtR+PTdG+zdoG+K/zy1GExz1TK89oMRbjS7FMsSENPu6GAGnftUBG9bD6AE5Ua6mXU9YygIUmfyuS4O98ve/OO7YAkatmw4yTJRKC5TH0UUu6VaUE1Jw= 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: Shmem will support large folio allocation [1] [2] to get a better performance, however, the memory reclaim still splits the precious large folios when trying to swap-out shmem, which may lead to the memory fragmentation issue and can not take advantage of the large folio for shmeme. Moreover, the swap code already supports for swapping out large folio without split, and large folio swap-in[3] series is queued into mm-unstable branch. Hence this patch set also supports the large folio swap-out and swap-in for shmem. Please help to review. Thanks. Functional testing ================== Machine environment: 32 Arm cores, 120G memory and 50G swap device. 1. Run xfstests suite to test tmpfs filesystem, and I did not catch any regressions with this patch set. FSTYP=tmpfs export TEST_DIR=/mnt/tempfs_mnt export TEST_DEV=/mnt/tempfs_mnt export SCRATCH_MNT=/mnt/scratchdir export SCRATCH_DEV=/mnt/scratchdir 2. Run all mm selftests in tools/testing/selftests/mm/, and no regressions found. 3. I also wrote several shmem swap test cases, including shmem splitting, shmem swapout, shmem swapin, swapoff during shmem swapout, shmem reclaim, shmem swapin replacement, etc. I tested these cases under 4K and 64K shmem folio sizes with a swap device, and shmem swap functionality works well on my machine. [1] https://lore.kernel.org/all/cover.1717495894.git.baolin.wang@linux.alibaba.com/ [2] https://lore.kernel.org/all/20240515055719.32577-1-da.gomez@samsung.com/ [3] https://lore.kernel.org/all/20240508224040.190469-6-21cnbao@gmail.com/T/ [4] https://lore.kernel.org/all/8db63194-77fd-e0b8-8601-2bbf04889a5b@google.com/ Changes from v4: - Add reviewed tag from Barry. Thanks. - Drop patch 1 and move shmem split to shmem_writepage(), which can avoid other unnecessary split, per David. Changes from v3: - Rebase to the latest mm-unstable. - Simplify patch 2 based on Barry's patch: https://lkml.kernel.org/r/20240730071339.107447-2-21cnbao@gmail.com Chagens from v2: - Add new patch to split large swap entry if swapin folio is order 0 folio. - Update some commit message. Changes from v1: - Remove useless 'order' variable in shmem_partial_swap_usage(), per Daniel. - Add a new patch to return number of pages beeing freed in shmem_free_swap(), per Daniel. - Drop 'orders' parameter for find_get_entries() and find_lock_entries(). - Round down the index when adding the swapin folio into the pagecache, suggested by Hugh. - Fix the reference issue when removing folio from pagecache in patch 8. - Fix replacing old folio in swap cache in patch 7. Changes from RFC: - Rebased to the latest mm-unstable. - Drop the counter name fixing patch, which was queued into mm-hotfixes-stable branch. Baolin Wang (8): mm: swap: extend swap_shmem_alloc() to support batch SWAP_MAP_SHMEM flag setting mm: shmem: extend shmem_partial_swap_usage() to support large folio swap mm: filemap: use xa_get_order() to get the swap entry order mm: shmem: use swap_free_nr() to free shmem swap entries mm: shmem: support large folio allocation for shmem_replace_folio() mm: shmem: drop folio reference count using 'nr_pages' in shmem_delete_from_page_cache() mm: shmem: split large entry if the swapin folio is not large mm: shmem: support large folio swap out Daniel Gomez (1): mm: shmem: return number of pages beeing freed in shmem_free_swap drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 1 + include/linux/swap.h | 4 +- include/linux/writeback.h | 4 + mm/filemap.c | 4 + mm/shmem.c | 217 +++++++++++++++++----- mm/swapfile.c | 4 +- mm/vmscan.c | 32 +++- 7 files changed, 209 insertions(+), 57 deletions(-)