From patchwork Thu Jul 4 11:24:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13723631 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 8F242C30653 for ; Thu, 4 Jul 2024 11:25:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 154866B00B3; Thu, 4 Jul 2024 07:25:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1042E6B00A7; Thu, 4 Jul 2024 07:25:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E72046B00C1; Thu, 4 Jul 2024 07:25: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 C66716B00A4 for ; Thu, 4 Jul 2024 07:25:15 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8383A161197 for ; Thu, 4 Jul 2024 11:25:15 +0000 (UTC) X-FDA: 82301838990.23.BB8D267 Received: from out30-124.freemail.mail.aliyun.com (out30-124.freemail.mail.aliyun.com [115.124.30.124]) by imf10.hostedemail.com (Postfix) with ESMTP id A0B79C0010 for ; Thu, 4 Jul 2024 11:25:12 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=cokb6ypV; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf10.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.124 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720092286; 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=O9qIRjAHBzIZT+8EnwoZqAhzP4xcW4fjSuW9RePEmE0=; b=ytI1j4FMv0hucruf5AY5tkC/RDKruU8C+tzfYjOuxCL4P0O8uBsCFn0T8dXwA6JsWEzKph RL7YS4/CIezJsXILdEgsM5Jxt9P9hy5dxFQQ+i+3AG/mqB0GJPqshcHErfhexgjA7m0lcF 6C6cqU32+dyFDq8SM1Jw3pXTUbm/nJc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720092286; a=rsa-sha256; cv=none; b=QpBApckcMcVFpja7kR7njQVbuk/m/2MiaDdoTdtXTm+EB4p2UPX35RWpiR00cbSrvtUc2K MQLVkKpWhezSQi39ualKZhWtvBtrFJA7UGDSTu0veVfD5/2M9UVnWOt0+J1ht6ZawmTFKX qnVxj9qZxDZff6zTOq+IhJHhA7pNqMc= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=cokb6ypV; dmarc=pass (policy=none) header.from=linux.alibaba.com; spf=pass (imf10.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.124 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1720092309; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=O9qIRjAHBzIZT+8EnwoZqAhzP4xcW4fjSuW9RePEmE0=; b=cokb6ypVmP1mG4Jqor4PP0xzMDc/TVdqvb6sRorOx9qmmAIJ416pbmcfosIHAGrq9rn2bBAkhgZ4gBQflcgDGgO/BbX4qIKpdPwKUHlHOya2RLaSMtnwIWeyARi7IF4APaWm3bTvQOs0pv8PcWfnM+YrqO95h30R5q2L8IXfctY= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033023225041;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=17;SR=0;TI=SMTPD_---0W9qjOvo_1720092306; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W9qjOvo_1720092306) by smtp.aliyun-inc.com; Thu, 04 Jul 2024 19:25:07 +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 v3 00/10] support large folio swap-out and swap-in for shmem Date: Thu, 4 Jul 2024 19:24:49 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A0B79C0010 X-Stat-Signature: 98emg9zktijy7t37d4qiaf77c4ahogzu X-Rspam-User: X-HE-Tag: 1720092312-450410 X-HE-Meta: U2FsdGVkX1/vBNv5npUckT8+h8SphEA4ZvcZKsSF4woXEx59dIiw65oqRywgRhJobj8VGHeVabPhp1Ana+7YwBcq5nNztJTTlUG/ndaWUxsEXxBSpswhSBg9hRuI7BcLQQEumFLHbGHGfNCUWthYylQjq6/XxYmcfpQ2ApT5i6gaSIWtM7IYSuPAjxTzldSIloBfxk209hsEsSPqrK23Q74otCucVySFaV7LJuIhg1U/SPQx4ccgk/IBch6u8iTVpLefdo+iHQewU92kAenloMjGG3yPzMRSrB8HU5uuNbLY/M7Ek2jF6D01aP53UVZEdcofN9ynHHYHoVOua2xXuiTPfFdxV7BCn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@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. Note: this series is targeted for v6.12. Please help to review. Thanks. Functional testing ================== I use the latest mm-unstable branch to test with reverting Chris's "mm: swap: mTHP swap allocator base on swap cluster order" series which can cause some problems (Hugh also reported in [4]). 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/ 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 (9): mm: vmscan: add validation before spliting shmem large folio 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 | 1 + mm/filemap.c | 4 + mm/shmem.c | 203 +++++++++++++++++----- mm/swapfile.c | 98 ++++++----- mm/vmscan.c | 22 ++- 7 files changed, 238 insertions(+), 95 deletions(-)