Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp322080lqt; Thu, 6 Jun 2024 04:59:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWeqk0qBXShpRQ/ocsHOgNC8Z1P7YGYMWx4HjAdn95cofQNuDwPHo1PP2xITzQaA6/R2ALQkRE7nzTVMx1kALsVn/juucfhLH0pd9fQag== X-Google-Smtp-Source: AGHT+IGHtSP7UadMluFvxIu9yRe1gXiWEYYl0wTsGvyXrtZVuTDkmNUhObRZ1rZRbSWKz/dp5eA0 X-Received: by 2002:a05:6a00:2e85:b0:702:5e60:14c1 with SMTP id d2e1a72fcca58-703e5a7af56mr5381356b3a.26.1717675187292; Thu, 06 Jun 2024 04:59:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717675187; cv=pass; d=google.com; s=arc-20160816; b=L13SgYoWCr+QV6///qyhWRZgoWxCezQcXrioJd1vnOl6dJrUSGe0V6a9iaDgKE9ZCs NfT2BrwHquOYdgJJ+aQxf+1TyIT5o0f8T8BHVSnZwjxNijWekCpl6AlveJ4SPovjaq+a 5HAiOrm+dwvZE1cfkuRZLignMpN+NW4I4Sz6KUuRa8mp/MM28xhKTAuWfLR2T8ueIftG 62vo19xMuZf3rmNNb9NOrB99AqEmEiu99sUB8jVeBXqOtHo5pYjHqHKzEn93AqPresLF sXc9oCE/64hzu2/q0FUM9WSFlJ3OFMqmIe1YHycW9WjGsYH2ennNvDaSGwrPXD/11gCv 73wg== 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=6L2s5n2sjWQ9jCz7vuGuOZ+fZmIEW+s447Fnt0+HHXo=; fh=Ga7JTaoZDeof86+j9POZ6Xv2e481OdNpwFcgcgBxajo=; b=ewG49e55xdmUEWEaamkXxY4k+JEew5FfffUs888HelTyfWXt6x+ghvzjOhVWO0rtL6 l1JCr7kkInQu0SFCYoj3IvsOYb0Upmm9rxefYVQIEyrolUi8e8ihqPb5zZ4T0Gay+g9r 23nBtAMWrjY2ZbfLdBBA9E6mD3kyZSrd2YcB/EeAhYMVZ2sT1l4W5HzGU4FDYWCc9Lpv aH8UZ776P4QiI7v9AyubZQWWHrCJkAfLVwUmzue1nmNSbjiE9dOz7V2h8zSVB/ToDP3d qgcfPlzSnMK4peZkblPE7SjoqOlFxj3sfnpxGdLoYzykeTniFluuPspUDtBNYBfKi7JA vYyg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=aGYlBpUs; 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-204217-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204217-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 sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6de21978fb1si1011289a12.242.2024.06.06.04.59.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 04:59:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-204217-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.alibaba.com header.s=default header.b=aGYlBpUs; 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-204217-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204217-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 970E6288C7A for ; Thu, 6 Jun 2024 11:59:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2BB2A195B31; Thu, 6 Jun 2024 11:59:20 +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="aGYlBpUs" Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) (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 5CEAC19596C for ; Thu, 6 Jun 2024 11:59:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.99 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717675159; cv=none; b=eDxciIEGJyRntcKihPif88FShtdZtDt7tAQmgHjQQR4QEXjwJZmyc4aEKkxITEt2oscBI5K/Rm7mczZAEvDkCvBbclPCXS3X8KcjVsyC8wM487Vb8v64KdsHszydydoPBUdDAGnB82g6nthCoyMlmtwjEQZgIy3YJWi5yKOYDHc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717675159; c=relaxed/simple; bh=b3ofusNovId4cRoSubuTegS38gGdSYyOQ2tUiNCWnmU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=nXNLN7jDBBMAGrGtBDd8II/9aDvx96NATJSpk7INi6jBfVpx06Y+jqzNO9mHij05D7+DeusqyPuywS77ApqufB8zGmSIUL3MFl9fQMBmtwKMuAB/eujgkOmXcMOm9FytTbT66LoBAjuR+LBjxGoWgeGGfDcnEAHUTppmWkiNSb4= 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=aGYlBpUs; arc=none smtp.client-ip=115.124.30.99 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=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: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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); -- 2.39.3