From patchwork Thu Jun 6 11:58:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13688378 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 CC6D3C27C54 for ; Thu, 6 Jun 2024 11:59:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 142066B009D; Thu, 6 Jun 2024 07:59:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0FBDA6B00A0; Thu, 6 Jun 2024 07:59:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E83D16B009F; Thu, 6 Jun 2024 07:59:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id CC8066B009D for ; Thu, 6 Jun 2024 07:59:19 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 796931414DA for ; Thu, 6 Jun 2024 11:59:19 +0000 (UTC) X-FDA: 82200318438.22.968C1FF Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by imf08.hostedemail.com (Postfix) with ESMTP id 6431316000F for ; Thu, 6 Jun 2024 11:59:17 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=aGYlBpUs; spf=pass (imf08.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.132 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=1717675157; 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:in-reply-to:references:references:dkim-signature; bh=6L2s5n2sjWQ9jCz7vuGuOZ+fZmIEW+s447Fnt0+HHXo=; b=gMlOzLUhRrIphIlboZ/gcImt4WzKFx4naCydrSCczBw1Hofb8Lvgir4tHZHn3XGwkgUT3V XinpnQ3aDloStKHiMJ9DsTQdxmQ/DSFtmx50nMDdrAuQjnuBl/8VupHUH3/YbS4xmve1i7 ehwkOQykEHvxag7yDhQItbcvTegkK0g= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717675157; a=rsa-sha256; cv=none; b=Ap0Q9XBoVuYvmAvWydk77IizCywZzC1eFRr21LiVkJt9dQ4z8BFOjE39Rd9iV73ovxy1mU Gv6M5iy3mFDTtiEid/AEVIjaZ1pVSxQ+lICxzua2DerQcLaMpM/hX6P9wd1qV8KpiuhUnt FXxCzdMzLBQsj8nyXi+uIEKJmd9KH/U= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=aGYlBpUs; spf=pass (imf08.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.132 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=1717675155; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=6L2s5n2sjWQ9jCz7vuGuOZ+fZmIEW+s447Fnt0+HHXo=; b=aGYlBpUs+IHwplrsJKybxO6Wt0Y/iWc5bmRfbUtPiJ9sM038kBfcjNXiAMQ8X87zEKyumGPOMeONihniOiZh7JPUZZQRpJktNabKzCfzWFuf8QHJgtSxLBEN6VhvC6pSPs5GEMzspYFa86zmwhu++1KUtPVL5ApAF7eUDvR2M9o= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R151e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033022160150;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=17;SR=0;TI=SMTPD_---0W7y5mvE_1717675153; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W7y5mvE_1717675153) by smtp.aliyun-inc.com; Thu, 06 Jun 2024 19:59:14 +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 3/7] mm: shmem: support large folio allocation for shmem_replace_folio() Date: Thu, 6 Jun 2024 19:58:53 +0800 Message-Id: <230e35b2fdc13c6199d8437e4cb6f68fded4072d.1717673614.git.baolin.wang@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 9p4xgxnkgzxtow86st66cuby5jnt861b X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 6431316000F X-HE-Tag: 1717675157-534443 X-HE-Meta: U2FsdGVkX1+LSZEwcn0ndXyVGOwbSuLqf2fzpqqZUFWrpHsTHQwB9vcd/3uBjIy85ZKHJk/NCrH/toU88ygZODmY5m/ueD9aXZ0iozlmVH2cp1IJiR4LNuS2eY73TmeXJYa8gGS7pHPk2NM0zParRZsSm4hV/EXKaZy9b2ApBVPouu7F+GrEcbDe5AUGb7VanaWYHX86rdfaENqpu78rnGjnHKcQGt4rhrfktg7y20Bo/4FoBFdIeuyTzALriOITe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vack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: To support large folio swapin for shmem in the following patches, add large folio allocation for the new replacement folio in shmem_replace_folio(), as well as updating statistics using the number of pages in the folio. Signed-off-by: Baolin Wang --- mm/shmem.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 174d8ae25b9b..eefdf5c61c04 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1889,7 +1889,7 @@ static int shmem_replace_folio(struct folio **foliop, gfp_t gfp, */ gfp &= ~GFP_CONSTRAINT_MASK; VM_BUG_ON_FOLIO(folio_test_large(old), old); - new = shmem_alloc_folio(gfp, 0, info, index); + new = shmem_alloc_folio(gfp, folio_order(old), info, index); if (!new) return -ENOMEM; @@ -1910,11 +1910,13 @@ static int shmem_replace_folio(struct folio **foliop, gfp_t gfp, xa_lock_irq(&swap_mapping->i_pages); error = shmem_replace_entry(swap_mapping, swap_index, old, new); if (!error) { + int nr_pages = folio_nr_pages(old); + mem_cgroup_migrate(old, new); - __lruvec_stat_mod_folio(new, NR_FILE_PAGES, 1); - __lruvec_stat_mod_folio(new, NR_SHMEM, 1); - __lruvec_stat_mod_folio(old, NR_FILE_PAGES, -1); - __lruvec_stat_mod_folio(old, NR_SHMEM, -1); + __lruvec_stat_mod_folio(new, NR_FILE_PAGES, nr_pages); + __lruvec_stat_mod_folio(new, NR_SHMEM, nr_pages); + __lruvec_stat_mod_folio(old, NR_FILE_PAGES, -nr_pages); + __lruvec_stat_mod_folio(old, NR_SHMEM, -nr_pages); } xa_unlock_irq(&swap_mapping->i_pages);