Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp322583lqt; Thu, 6 Jun 2024 05:00:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXTEoXCdpikAWn180a1a4UbJkC+AP2M99wS/HqrNo7vkwx3V1ghHnYZRBXxyNvVIcU9LwK9QNNpyUptOh1Coixaihgkg2v0LkqTolOcgA== X-Google-Smtp-Source: AGHT+IEp63g98jEFG4d0040Ni0SZtMZGLqeimE1OgFCwyTuWUnHU69EFMDDBMY3MPv4u07xrvKH6 X-Received: by 2002:a50:cddb:0:b0:57a:2431:eabf with SMTP id 4fb4d7f45d1cf-57a8bcb3bfcmr2993059a12.37.1717675231388; Thu, 06 Jun 2024 05:00:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717675231; cv=pass; d=google.com; s=arc-20160816; b=d8RxtXxcOun8FaEgORRoBSVnOAFoGCOkhLhHB71Ns4/1I7Ubiby24hFBW6luLV2E6z Dqw2FRv7jydWuWkSyxyLeJCHEQNVGFRUHDr8LA+PcNMrTXkeLtpnzO9/BJjB2eTqBBPh 06BqqGQSLoiM9R3F3tv2yPczZj12lcHGs15FPbKGQ56UHLvb0UlxkG1Lk6NByCnpSUrn Upe1IKQ6YwsjSXUUF8n6GrlEv7+ByzNhyu7XDy8vco667nYqSa8Ww0U2W7mqlNz9ccIF 3zcnHnxCd+4ia9B/o9Gjt0KJ5Itb0I1H84NCtAoTNiyBHdx7n9CfIGPGRCF06wjypdDI gWhw== 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=RKBAfrZjR8AbxPwpVk449LMfTdrMSV2SRdqL98hLFps=; fh=Ga7JTaoZDeof86+j9POZ6Xv2e481OdNpwFcgcgBxajo=; b=Yd1XQiZwEyvkKVkik93mBL/kxjA+tDip7Ex/UpJ4wg5hNoNpP9jO62yq2Z2DgL3RaH SygIQ4kQxFuXXqNUFohHlalKGJ6S+0xd0r97HP+BdQOKrqGyXBNUQbZjJo8L5/Y03Y6C uqjoi6m9CIeNFbvlyOQ7iM1GoQZhVKeNuwmGjcImNkmktyJz8iibJofB0cxzCIZCI5Yr G+0X0Cy+wobX1qLAYEsKVgEtixipcgF2AUpAtY3VFs94rPxeWYZ1Zce/A/H8824vROlD ZBuGzHbtUWyC/cZKLZZO4Q+CydVUAyxglzTYUq7eHt0+YUtpdLK6xrHhfjtlNPkkZ5V+ k6kg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=Owc+0AsP; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-204221-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204221-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57aae26d975si628510a12.596.2024.06.06.05.00.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 05:00:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-204221-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=Owc+0AsP; arc=pass (i=1 spf=pass spfdomain=linux.alibaba.com dkim=pass dkdomain=linux.alibaba.com dmarc=pass fromdomain=linux.alibaba.com); spf=pass (google.com: domain of linux-kernel+bounces-204221-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204221-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.alibaba.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 210041F24A6E for ; Thu, 6 Jun 2024 12:00:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E6DD196425; Thu, 6 Jun 2024 11:59:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="Owc+0AsP" Received: from out30-124.freemail.mail.aliyun.com (out30-124.freemail.mail.aliyun.com [115.124.30.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 971AE19597C for ; Thu, 6 Jun 2024 11:59:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717675168; cv=none; b=Obuk6UjIkVwtDxwxssYbXZJPhEClhkfP90zSVkZjFlknysuoc1i0vJiwoLaBPPZXRa79r720YEvldDHF5nj+l91R5ZF3H4p13sOGumIstuoYqfgz+3zuA/UJbGqqMRe+ZqokIO4CMYt5STksUl2Yr1fjqOJE3pu8UouHabe+1Kw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717675168; c=relaxed/simple; bh=ioPMjW+e5XxWxzJBHD7MfcWdCcWPLFr48yIIRugIBwQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=r+/Rieg7pVZHrhUSi1lt0kQ3yVp6B7cy3bAB2iGd7EAsZGqp2GD3/0xCR9jvwNBfdhewSetRMiW/Is++HeFy6NJb9Cv+wC35EcCD29UJ+Fn/PJuq9FOIr5SBoG+T/eKscIV6HlkH2xYJcww+jdVfVU5ohh0wKnTuQrXEcjvlJiI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=Owc+0AsP; arc=none smtp.client-ip=115.124.30.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1717675159; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=RKBAfrZjR8AbxPwpVk449LMfTdrMSV2SRdqL98hLFps=; b=Owc+0AsPHpVCRRu6x6Gg1l+dYL5zMc7HdkqwV12gBkHYHmIfqDDF35EkF6q1oTZQ4VAeAh7SW2nBqK8qqoKkVzulH2NBymlx2RMC2y9Oek9+PpQ4DsXtTJqkbqjJyaWnNtDIJaGKT4z+kEtghKQ0mnRr76MaL6n1Vc/M2e0l++8= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R231e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045046011;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=17;SR=0;TI=SMTPD_---0W7y5mwW_1717675157; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W7y5mwW_1717675157) by smtp.aliyun-inc.com; Thu, 06 Jun 2024 19:59:18 +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 7/7] mm: shmem: support large folio swap out Date: Thu, 6 Jun 2024 19:58:57 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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, hence this patch set supports the large folio swap out for shmem. Note the i915_gem_shmem driver still need to be split when swapping, thus add a new flag 'split_large_folio' for writeback_control to indicate spliting the large folio. [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/ Signed-off-by: Baolin Wang --- drivers/gpu/drm/i915/gem/i915_gem_shmem.c | 1 + include/linux/writeback.h | 1 + mm/shmem.c | 3 +-- mm/vmscan.c | 14 ++++++++++++-- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c index c5e1c718a6d2..c66cb9c585e1 100644 --- a/drivers/gpu/drm/i915/gem/i915_gem_shmem.c +++ b/drivers/gpu/drm/i915/gem/i915_gem_shmem.c @@ -308,6 +308,7 @@ void __shmem_writeback(size_t size, struct address_space *mapping) .range_start = 0, .range_end = LLONG_MAX, .for_reclaim = 1, + .split_large_folio = 1, }; unsigned long i; diff --git a/include/linux/writeback.h b/include/linux/writeback.h index 112d806ddbe4..6f2599244ae0 100644 --- a/include/linux/writeback.h +++ b/include/linux/writeback.h @@ -63,6 +63,7 @@ struct writeback_control { unsigned range_cyclic:1; /* range_start is cyclic */ unsigned for_sync:1; /* sync(2) WB_SYNC_ALL writeback */ unsigned unpinned_netfs_wb:1; /* Cleared I_PINNING_NETFS_WB */ + unsigned split_large_folio:1; /* Split large folio for shmem writeback */ /* * When writeback IOs are bounced through async layers, only the diff --git a/mm/shmem.c b/mm/shmem.c index 33af3b2e5ecf..22a5116888ce 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -776,7 +776,6 @@ static int shmem_add_to_page_cache(struct folio *folio, VM_BUG_ON_FOLIO(index != round_down(index, nr), folio); VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); VM_BUG_ON_FOLIO(!folio_test_swapbacked(folio), folio); - VM_BUG_ON(expected && folio_test_large(folio)); folio_ref_add(folio, nr); folio->mapping = mapping; @@ -1460,7 +1459,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) * "force", drivers/gpu/drm/i915/gem/i915_gem_shmem.c gets huge pages, * and its shmem_writeback() needs them to be split when swapping. */ - if (folio_test_large(folio)) { + if (wbc->split_large_folio && folio_test_large(folio)) { /* Ensure the subpages are still dirty */ folio_test_set_dirty(folio); if (split_huge_page(page) < 0) diff --git a/mm/vmscan.c b/mm/vmscan.c index 9146fd0dc61e..3523fd2dc524 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1263,8 +1263,12 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, if (!total_swap_pages) goto activate_locked; - /* Split shmem folio */ - if (split_folio_to_list(folio, folio_list)) + /* + * Only split shmem folio when CONFIG_THP_SWAP + * is not enabled. + */ + if (!IS_ENABLED(CONFIG_THP_SWAP) && + split_folio_to_list(folio, folio_list)) goto keep_locked; } @@ -1366,10 +1370,16 @@ static unsigned int shrink_folio_list(struct list_head *folio_list, * starts and then write it out here. */ try_to_unmap_flush_dirty(); +try_pageout: switch (pageout(folio, mapping, &plug)) { case PAGE_KEEP: goto keep_locked; case PAGE_ACTIVATE: + if (shmem_mapping(mapping) && folio_test_large(folio) && + !split_folio_to_list(folio, folio_list)) { + nr_pages = 1; + goto try_pageout; + } goto activate_locked; case PAGE_SUCCESS: stat->nr_pageout += nr_pages; -- 2.39.3