From patchwork Tue May 21 11:03:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baolin Wang X-Patchwork-Id: 13669304 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 E1873C25B74 for ; Tue, 21 May 2024 11:03:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CEB416B009D; Tue, 21 May 2024 07:03:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C71886B009E; Tue, 21 May 2024 07:03:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A50AC6B009F; Tue, 21 May 2024 07:03:46 -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 817346B009D for ; Tue, 21 May 2024 07:03:46 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 188ED1C1E66 for ; Tue, 21 May 2024 11:03:46 +0000 (UTC) X-FDA: 82142117652.20.FCDE898 Received: from out30-131.freemail.mail.aliyun.com (out30-131.freemail.mail.aliyun.com [115.124.30.131]) by imf02.hostedemail.com (Postfix) with ESMTP id 055838000F for ; Tue, 21 May 2024 11:03:43 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=a0abYcVE; spf=pass (imf02.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=1716289424; 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=ArTvZKlaOes4XoFtzrKMEwLUH8CHPrOqCRPSPeGMt/g=; b=uDtQ6ZUvhPch8xetSaXjEzHRDa4LWnfP2W0HBM//Rnlt70JbVmOPCzhfQkgubWNpXGuWdi rUjxi/bkpEO0uVDsb12PZnqCpNFZLGrMpE1J/DEheK+Zesrd87xMXQw9PvRNgsQ6jKMkKe RaUeY0u1/4ALMLPr29xo+oO10srSN1Q= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1716289424; a=rsa-sha256; cv=none; b=iENqIF4Re27da65yHuR+e/Zw5sq/czDHxgMIjgibCPxuPgDI80kqiUkU4W9qLbvGtj0OvF e5+QuAnp6j32VhGoqSxhy3biEju6Y2HdBeK7d6J+BYZwYfSaPEcAA5ofxjh89xGQxMNzSX ZPurR2rSwyGDnG8oQfzs0BtsSdx4JHw= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=linux.alibaba.com header.s=default header.b=a0abYcVE; spf=pass (imf02.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=1716289417; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=ArTvZKlaOes4XoFtzrKMEwLUH8CHPrOqCRPSPeGMt/g=; b=a0abYcVElqGnhHB+0BarctgCnQwfetl3e4cTU2SDMdZg6QXiM3aff4nrNph168S8acADzcyo7xn/8G4ZLvhYctlWrNMdKetxd6kr96VgLnCFf5jjrqcrrspsbk4ewqh9OQuVcYFhvn5Z70qdgDnppgNdXGWqMk4KYkCj/NTA6KY= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R211e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045075189;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=17;SR=0;TI=SMTPD_---0W6xeTCm_1716289415; Received: from localhost(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0W6xeTCm_1716289415) by smtp.aliyun-inc.com; Tue, 21 May 2024 19:03:36 +0800 From: Baolin Wang To: akpm@linux-foundation.org, hughd@google.com Cc: willy@infradead.org, david@redhat.com, ioworker0@gmail.com, hrisl@kernel.org, p.raghav@samsung.com, da.gomez@samsung.com, wangkefeng.wang@huawei.com, ying.huang@intel.com, 21cnbao@gmail.com, ryan.roberts@arm.com, shy828301@gmail.com, ziy@nvidia.com, baolin.wang@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 4/8] mm: shmem: support large folio allocation for shmem_replace_folio() Date: Tue, 21 May 2024 19:03:14 +0800 Message-Id: <73d93136d8469658715388878c947e8952164c53.1716285099.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: 9jjtpsie3e6x959uk783myb7ngam37o1 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 055838000F X-HE-Tag: 1716289423-590634 X-HE-Meta: U2FsdGVkX1/jgbvdR6dwd3a+ajguohq8X8JJfNVzouzVmua657ArLhaPUc6ZE0/VmWIePp2FYCYyNjUngWdXVvTF39bSghIos+VJGgyIGWU+Q0Hsbvifx0Mip4XidSduldlMfY0gzXwwA4rxOJqdQHXlMzOGnCmI8T/68DJ5NQoRryuj7syIlRC/Ep791JZklPDbARhLS9bwb64DwHRy6BMzERZ1etvgHz3fvzzN0hUF6hGzEdivQ/Lr9JBdPZZ24uFi3kw1AwFz2CGoz3s8WA4ZY0IAI74OEqzbBkGmXKvAmLURbDFl1gx8lC+NffsaLTYGJvb4kbYoCYnXKFvHo3P9tefrCKaDJlwzHmyO9l8UTd89PJi4dUGEXQNHm+zCG2FpPqXT3ufnR8OBp6xHGkC03M9iWiplfbRSRwABrOlYHSs8i7B2gvTR0s3mTjO9GonAFo9yW6UlQKqhXj/bwZx3ciYFbUiwA9uxBqE3JA5BAjqjeEenrqPDrhjvyFTaDVPfihTDgzBgiHwNs0aWmz+Ecdg4II+6KKsRa/Y5E8EAzeDkK+E6AyaVwt0a3vtb7miepkrmc74TAvXgXC9H+vvUYup62oa1YROowdl0ygDaLkhr8k588kdwsJlVaO8BtOOAHz5rSHcXH6Prs17i2er4P6pEJ72Um6sGUu4SjhVJfPD/3OHsG6eo06COyhf+Rof2l1Nd5caFY61f4VSRtVipG/+3HmDXbfshEdJ6+sqVPAYw1RXcweqOH5AfhpaXFHWTVq8ckUL1Hn+p7T0WcbMqnn2Bc2voUpfCK7dvF8EYAnGTkyqRz6nKqLNAqZGs1eG4E8HZwG3Oa3jXIyuJTBtfGrXnf/yupAe0Pxka3LI+7MrIUsS4RrimVkIthnz0V1ylvTW3QOWB8MEQjR/gCsNcgFx49JGNFuLqZqyK4gi0RjWnuHVU7bOcUzFpaJNZU1RQn8l8bWOzgx3gaN+ vlQqtJNm c6IDUABql1tqpL6sODzo2Xtnozu/n5pYX3q2e3j2cuICjP+ExB0yiKLYiH+nD1+rrP5FkFxeTrrk89kuYZPsij0tQtsVAGSlkrdU3EplHfHZq8D77fwCvvBDgroRc/oYvI6KWqi8qld56LET1c789usrvfEbQ1jYpCU7yJIuhKN5151BCa/0UoX4ZWivTJDy0ZrylPbxMg9gXZzT3gGUBOON21QmbjrHkSpOokkeeJ3aGn2V4d1z63fJ100QFuXCm5ZnEcM5ypZjixbmXsYMtZMX0s52bWvGl/x/6 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: 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 | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index daab124c3e61..74821a7031b8 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1901,8 +1901,7 @@ static int shmem_replace_folio(struct folio **foliop, gfp_t gfp, * limit chance of success by further cpuset and node constraints. */ gfp &= ~GFP_CONSTRAINT_MASK; - VM_BUG_ON_FOLIO(folio_test_large(old), old); - new = shmem_alloc_folio(gfp, info, index); + new = shmem_alloc_hugefolio(gfp, info, index, folio_order(old)); if (!new) return -ENOMEM; @@ -1923,11 +1922,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);